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