1 package ch.qos.logback.core.joran;
2
3 import ch.qos.logback.core.Context;
4 import ch.qos.logback.core.joran.util.PropertySetter;
5 import ch.qos.logback.core.joran.util.beans.BeanDescriptionCache;
6 import ch.qos.logback.core.model.Model;
7 import ch.qos.logback.core.model.ParamModel;
8 import ch.qos.logback.core.model.processor.ModelHandlerBase;
9 import ch.qos.logback.core.model.processor.ModelHandlerException;
10 import ch.qos.logback.core.model.processor.ModelInterpretationContext;
11
12 public class ParamModelHandler extends ModelHandlerBase {
13
14 private final BeanDescriptionCache beanDescriptionCache;
15
16 public ParamModelHandler(Context context, BeanDescriptionCache beanDescriptionCache) {
17 super(context);
18 this.beanDescriptionCache = beanDescriptionCache;
19 }
20
21 static public ModelHandlerBase makeInstance(Context context, ModelInterpretationContext ic) {
22 return new ParamModelHandler(context, ic.getBeanDescriptionCache());
23 }
24
25 @Override
26 protected Class<ParamModel> getSupportedModelClass() {
27 return ParamModel.class;
28 }
29
30 @Override
31 public void handle(ModelInterpretationContext intercon, Model model) throws ModelHandlerException {
32
33 ParamModel paramModel = (ParamModel) model;
34
35 String valueStr = intercon.subst(paramModel.getValue());
36
37 Object o = intercon.peekObject();
38
39 PropertySetter propSetter = new PropertySetter(beanDescriptionCache, o);
40 propSetter.setContext(context);
41
42
43 String finalName = intercon.subst(paramModel.getName());
44 propSetter.setProperty(finalName, valueStr);
45 }
46
47 }