1
14 package ch.qos.logback.core.joran.action;
15
16 import org.xml.sax.Attributes;
17
18 import ch.qos.logback.core.joran.spi.InterpretationContext;
19 import ch.qos.logback.core.joran.util.PropertySetter;
20 import ch.qos.logback.core.joran.util.beans.BeanDescriptionCache;
21
22 public class ParamAction extends Action {
23 static String NO_NAME = "No name attribute in <param> element";
24 static String NO_VALUE = "No value attribute in <param> element";
25 boolean inError = false;
26
27 private final BeanDescriptionCache beanDescriptionCache;
28 public ParamAction(BeanDescriptionCache beanDescriptionCache) {
29 this.beanDescriptionCache=beanDescriptionCache;
30 }
31
32 public void begin(InterpretationContext ec, String localName, Attributes attributes) {
33 String name = attributes.getValue(NAME_ATTRIBUTE);
34 String value = attributes.getValue(VALUE_ATTRIBUTE);
35
36 if (name == null) {
37 inError = true;
38 addError(NO_NAME);
39 return;
40 }
41
42 if (value == null) {
43 inError = true;
44 addError(NO_VALUE);
45 return;
46 }
47
48
49 value = value.trim();
50
51 Object o = ec.peekObject();
52 PropertySetter propSetter = new PropertySetter(beanDescriptionCache,o);
53 propSetter.setContext(context);
54 value = ec.subst(value);
55
56
57 name = ec.subst(name);
58
59
60
61 propSetter.setProperty(name, value);
62 }
63
64 public void end(InterpretationContext ec, String localName) {
65 }
66
67 public void finish(InterpretationContext ec) {
68 }
69 }
70