1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.core.joran.action;
15
16 import java.util.Stack;
17
18 import org.xml.sax.Attributes;
19
20 import ch.qos.logback.core.joran.spi.InterpretationContext;
21 import ch.qos.logback.core.joran.spi.Pattern;
22 import ch.qos.logback.core.joran.util.PropertySetter;
23 import ch.qos.logback.core.util.AggregationType;
24
25
26
27
28
29
30
31
32 public class NestedBasicPropertyIA extends ImplicitAction {
33
34
35
36
37
38
39
40
41 Stack<IADataForBasicProperty> actionDataStack = new Stack<IADataForBasicProperty>();
42
43 public boolean isApplicable(Pattern pattern, Attributes attributes,
44 InterpretationContext ec) {
45
46
47 String nestedElementTagName = pattern.peekLast();
48
49
50 if (ec.isEmpty()) {
51 return false;
52 }
53
54 Object o = ec.peekObject();
55 PropertySetter parentBean = new PropertySetter(o);
56 parentBean.setContext(context);
57
58 AggregationType aggregationType = parentBean
59 .computeAggregationType(nestedElementTagName);
60
61 switch (aggregationType) {
62 case NOT_FOUND:
63 case AS_COMPLEX_PROPERTY:
64 case AS_COMPLEX_PROPERTY_COLLECTION:
65 return false;
66
67 case AS_BASIC_PROPERTY:
68 case AS_BASIC_PROPERTY_COLLECTION:
69 IADataForBasicProperty ad = new IADataForBasicProperty(parentBean,
70 aggregationType, nestedElementTagName);
71 actionDataStack.push(ad);
72
73 return true;
74 default:
75 addError("PropertySetter.canContainComponent returned " + aggregationType);
76 return false;
77 }
78 }
79
80 public void begin(InterpretationContext ec, String localName,
81 Attributes attributes) {
82
83 }
84
85 public void body(InterpretationContext ec, String body) {
86
87 String finalBody = ec.subst(body);
88
89
90 IADataForBasicProperty actionData = (IADataForBasicProperty) actionDataStack.peek();
91 switch (actionData.aggregationType) {
92 case AS_BASIC_PROPERTY:
93 actionData.parentBean.setProperty(actionData.propertyName, finalBody);
94 break;
95 case AS_BASIC_PROPERTY_COLLECTION:
96 actionData.parentBean
97 .addBasicProperty(actionData.propertyName, finalBody);
98 }
99 }
100
101 public void end(InterpretationContext ec, String tagName) {
102
103 actionDataStack.pop();
104 }
105 }