1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.commons.digester3;
20
21 import java.util.List;
22
23 import org.apache.commons.digester3.Rule;
24 import org.apache.commons.digester3.binder.RuleProvider;
25 import org.xml.sax.Attributes;
26
27
28
29
30
31
32
33
34
35
36 public class TestRule
37 extends Rule
38 {
39
40
41
42
43 private String identifier;
44
45
46 private String bodyText;
47
48
49 private List<Rule> order;
50
51
52
53
54
55
56
57
58 public TestRule( String identifier )
59 {
60
61 this.identifier = identifier;
62 }
63
64
65
66
67
68
69
70 public TestRule( String identifier, String namespaceURI )
71 {
72
73 this.identifier = identifier;
74 setNamespaceURI( namespaceURI );
75
76 }
77
78
79
80
81
82
83 @Override
84 public void begin( String namespace, String name, Attributes attributes )
85 throws Exception
86 {
87 appendCall();
88 }
89
90
91
92
93 @Override
94 public void body( String namespace, String name, String text )
95 throws Exception
96 {
97 this.bodyText = text;
98 appendCall();
99 }
100
101
102
103
104 @Override
105 public void end( String namespace, String name )
106 throws Exception
107 {
108 appendCall();
109 }
110
111
112
113
114
115
116 protected void appendCall()
117 {
118 if ( order != null )
119 order.add( this );
120 }
121
122
123
124
125 public String getBodyText()
126 {
127 return bodyText;
128 }
129
130
131
132
133 public String getIdentifier()
134 {
135 return identifier;
136 }
137
138
139
140
141 public List<Rule> getOrder()
142 {
143 return order;
144 }
145
146
147
148
149 public void setOrder( List<Rule> order )
150 {
151 this.order = order;
152 }
153
154
155
156
157 @Override
158 public String toString()
159 {
160 return identifier;
161 }
162
163 public static class TestRuleProvider implements RuleProvider<TestRule>
164 {
165
166 private final String identifier;
167
168 private final List<Rule> callOrder;
169
170 public TestRuleProvider( String identifier )
171 {
172 this( identifier, null );
173 }
174
175 public TestRuleProvider( String identifier, List<Rule> callOrder )
176 {
177 this.identifier = identifier;
178 this.callOrder = callOrder;
179 }
180
181 public TestRule get()
182 {
183 TestRule testRule = new TestRule( identifier );
184 testRule.setOrder( callOrder );
185 return testRule;
186 }
187
188 }
189
190 }