1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.chain.config;
17
18
19 import org.apache.commons.digester.Digester;
20 import org.apache.commons.digester.RuleSetBase;
21
22
23 /***
24 * <p>Digester <code>RuleSet</code> for configuring <em>Chain of
25 * Responsibility</em> command chains, and adding them to an appropriate
26 * {@link org.apache.commons.chain.Catalog}. The following properties
27 * may be configured prior to executing the <code>addRuleInstance()</code>
28 * method in order to influence the rules that get added, with default
29 * values in square brackets:</p>
30 * <ul>
31 * <li><strong>catalogClass</strong> -- Fully qualified name of the
32 * implementation class used to create new
33 * {@link org.apache.commons.chain.Catalog} instances.
34 * If not specified, the default value is
35 * <code>org.apache.commons.chain.impl.CatalogBsae</code>.</li>
36 * <li><strong>catalogElement</strong> -- Name of the XML element representing
37 * the addition of a {@link org.apache.commons.chain.Catalog}.
38 * Any such catalog that is created will be registered with the
39 * {@link org.apache.commons.chain.CatalogFactory} instance for our
40 * application, under the name specified by the <code>nameAttribute</code>
41 * attribute (if present), or as the default {@link org.apache.commons.chain.Catalog}.
42 * If not specified, the default value is <code>catalog</code>.</li>
43 * <li><strong>chainClass</strong> -- Fully qualified name of the implementation
44 * class used to create new {@link org.apache.commons.chain.Chain} instances.
45 * If not specified, the default value is
46 * <code>org.apache.commons.chain.impl.ChainBase</code>.
47 * </li>
48 * <li><strong>chainElement</strong> -- Name of the XML element representing
49 * the addition of a {@link org.apache.commons.chain.Chain}. A chain
50 * element has the same functionality as a command element, except that
51 * it defaults the implementation class to
52 * <code>org.apache.commons.chain.impl.ChainBase</code>. [chain]</li>
53 * <li><strong>classAttribute</strong> -- Attribute on a chain (optional) or
54 * command (required) element that specifies the fully qualified class
55 * name of the implementation class that should be instantiated.
56 * [className]</li>
57 * <li><strong>commandElement</strong> -- Name of the XML element
58 * representing the addition of a {@link org.apache.commons.chain.Command}.
59 * An implementation class name must be provided on the attribute named by the
60 * <code>classAttribute</code> property. [command]</li>
61 * <li><strong>defineElement</strong> -- Name of the XML element
62 * that associates the element specified by the <code>nameAttribute</code>
63 * attributes with a {@link org.apache.commons.chain.Command} or
64 * {@link org.apache.commons.chain.Chain} implementation class
65 * named by the <code>classAttribute</code> attribute. [define]</li>
66 * <li><strong>nameAttribute</strong> -- Attribute on an outermost chain or
67 * command element that will be used to register this command with the
68 * associated {@link org.apache.commons.chain.Catalog} instance on the stack.
69 * [name]</li>
70 * <li><strong>namespaceURI</strong> -- The XML namespace URI with which these
71 * rules will be associated, or <code>null</code> for no namespace.
72 * [null]</li>
73 * </ul>
74 *
75 * @author Craig R. McClanahan
76 * @version $Revision: 411876 $ $Date: 2006-06-05 19:02:19 +0100 (Mon, 05 Jun 2006) $
77 */
78
79 public class ConfigRuleSet extends RuleSetBase {
80
81
82
83
84
85 private String catalogClass = "org.apache.commons.chain.impl.CatalogBase";
86 private String catalogElement = "catalog";
87 private String chainClass = "org.apache.commons.chain.impl.ChainBase";
88 private String chainElement = "chain";
89 private String classAttribute = "className";
90 private String commandElement = "command";
91 private String defineElement = "define";
92 private String nameAttribute = "name";
93
94
95
96
97
98 /***
99 * <p>Return the fully qualified {@link org.apache.commons.chain.Catalog}
100 * implementation class.</p>
101 * @return The Catalog's class name.
102 */
103 public String getCatalogClass() {
104 return (this.catalogClass);
105 }
106
107
108 /***
109 * <p>Set the fully qualified {@link org.apache.commons.chain.Catalog}
110 * implementation class.</p>
111 *
112 * @param catalogClass The new {@link org.apache.commons.chain.Catalog}
113 * implementation class
114 */
115 public void setCatalogClass(String catalogClass) {
116 this.catalogClass = catalogClass;
117 }
118
119
120 /***
121 * <p>Return the element name of a catalog element.</p>
122 * @return The element name of a catalog element.
123 */
124 public String getCatalogElement() {
125 return (this.catalogElement);
126 }
127
128
129 /***
130 * <p>Set the element name of a catalog element.</p>
131 *
132 * @param catalogElement The new element name
133 */
134 public void setCatalogElement(String catalogElement) {
135 this.catalogElement = catalogElement;
136 }
137
138
139 /***
140 * <p>Return the fully qualified {@link org.apache.commons.chain.Chain}
141 * implementation class.</p>
142 * @return The Chain's class name.
143 */
144 public String getChainClass() {
145 return (this.chainClass);
146 }
147
148
149 /***
150 * <p>Set the fully qualified {@link org.apache.commons.chain.Chain}
151 * implementation class.</p>
152 *
153 * @param chainClass The new {@link org.apache.commons.chain.Chain}
154 * implementation class
155 */
156 public void setChainClass(String chainClass) {
157 this.chainClass = chainClass;
158 }
159
160
161 /***
162 * <p>Return the element name of a chain element.</p>
163 * @return The element name of a catalog element.
164 */
165 public String getChainElement() {
166 return (this.chainElement);
167 }
168
169
170 /***
171 * <p>Set the element name of a chain element.</p>
172 *
173 * @param chainElement The new element name
174 */
175 public void setChainElement(String chainElement) {
176 this.chainElement = chainElement;
177 }
178
179
180 /***
181 * <p>Return the attribute name of a class attribute.</p>
182 * @return The attribute name of a class attribute.
183 */
184 public String getClassAttribute() {
185 return (this.classAttribute);
186 }
187
188
189 /***
190 * <p>Set the attribute name of a class attribute.</p>
191 *
192 * @param classAttribute The new attribute name
193 */
194 public void setClassAttribute(String classAttribute) {
195 this.classAttribute = classAttribute;
196 }
197
198
199 /***
200 * <p>Return the element name of a command element.</p>
201 * @return The element name of a command element.
202 */
203 public String getCommandElement() {
204 return (this.commandElement);
205 }
206
207
208 /***
209 * <p>Set the element name of a command element.</p>
210 *
211 * @param commandElement The new element name
212 */
213 public void setCommandElement(String commandElement) {
214 this.commandElement = commandElement;
215 }
216
217
218 /***
219 * <p>Return the element name of a define element.</p>
220 * @return The element name of a define element.
221 */
222 public String getDefineElement() {
223 return (this.defineElement);
224 }
225
226
227 /***
228 * <p>Set the element name of a define element.</p>
229 *
230 * @param defineElement The new element name
231 */
232 public void setDefineElement(String defineElement) {
233 this.defineElement = defineElement;
234 }
235
236
237 /***
238 * <p>Return the attribute name of a name attribute.</p>
239 * @return The attribute name of an attribute element.
240 */
241 public String getNameAttribute() {
242 return (this.nameAttribute);
243 }
244
245
246 /***
247 * <p>Set the attribute name of a name attribute.</p>
248 *
249 * @param nameAttribute The new attribute name
250 */
251 public void setNameAttribute(String nameAttribute) {
252 this.nameAttribute = nameAttribute;
253 }
254
255
256
257
258
259 /***
260 * <p>Add the set of Rule instances defined in this RuleSet to the
261 * specified <code>Digester</code> instance, associating them with
262 * our namespace URI (if any). This method should only be called
263 * by a Digester instance.</p>
264 *
265 * @param digester Digester instance to which the new Rule instances
266 * should be added.
267 */
268 public void addRuleInstances(Digester digester) {
269
270
271 digester.addRule("*/" + getCatalogElement(),
272 new ConfigCatalogRule(nameAttribute, catalogClass));
273 digester.addSetProperties("*/" + getCatalogElement());
274
275
276 digester.addObjectCreate("*/" + getChainElement(),
277 getChainClass(),
278 getClassAttribute());
279 digester.addSetProperties("*/" + getChainElement());
280 digester.addRule("*/" + getChainElement(),
281 new ConfigRegisterRule(nameAttribute));
282
283
284 digester.addObjectCreate("*/" + getCommandElement(),
285 null,
286 getClassAttribute());
287 digester.addSetProperties("*/" + getCommandElement());
288 digester.addRule("*/" + getCommandElement(),
289 new ConfigRegisterRule(nameAttribute));
290
291
292 digester.addRule("*/" + getDefineElement(),
293 new ConfigDefineRule(getNameAttribute(),
294 getClassAttribute()));
295
296 }
297
298
299 }