KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > chain > config > ConfigRuleSet


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
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 Catalog}. The following properties may be configured prior to
27  * executing the <code>addRuleInstance()</code> method in order to influence
28  * the rules that get added, with default values in square brackets:</p>
29  * <ul>
30  * <li><strong>catalogClass</strong> -- Fully qualified name of the
31  * implementation class used to create new {@link Catalog} instances.
32  * If not specified, the default value is
33  * <code>org.apache.commons.chain.impl.CatalogBsae</code>.</li>
34  * <li><strong>catalogElement</strong> -- Name of the XML element representing
35  * the addition of a {@link Catalog}. Any such catalog that is created
36  * will be registered with the {@link CatalogFactory} instance for our
37  * application, under the name specified by the <code>nameAttribute</code>
38  * attribute (if present), or as the default {@link Catalog}. If not
39  * specified, the default value is <code>catalog</code>.</li>
40  * <li><strong>chainClass</strong> -- Fully qualified name of the implementation
41  * class used to create new {@link Chain} instances. If not specified, the
42  * default value is <code>org.apache.commons.chain.impl.ChainBase</code>.
43  * </li>
44  * <li><strong>chainElement</strong> -- Name of the XML element representing
45  * the addition of a {@link Chain}. A chain element has the same
46  * functionality as a command element, except that it defaults the
47  * implementation class to
48  * <code>org.apache.commons.chain.impl.ChainBase</code>. [chain]</li>
49  * <li><strong>classAttribute</strong> -- Attribute on a chain (optional) or
50  * command (required) element that specifies the fully qualified class
51  * name of the implementation class that should be instantiated.
52  * [className]</li>
53  * <li><strong>commandElement</strong> -- Name of the XML element
54  * representing the addition of a {@link Command}. An implementation
55  * class name must be provided on the attribute named by the
56  * <code>classAttribute</code> property. [command]</li>
57  * <li><strong>defineElement</strong> -- Name of the XML element
58  * that associates the element specified by the <code>nameAttribute</code>
59  * attributes with a {@link Command} or {@link Chain} implementation class
60  * named by the <code>classAttribute</code> attribute. [define]</li>
61  * <li><strong>nameAttribute</strong> -- Attribute on an outermost chain or
62  * command element that will be used to register this command with the
63  * associated {@link Catalog} instance on the stack. [name]</li>
64  * <li><strong>namespaceURI</strong> -- The XML namespace URI with which these
65  * rules will be associated, or <code>null</code> for no namespace.
66  * [null]</li>
67  * </ul>
68  *
69  * @author Craig R. McClanahan
70  * @version $Revision: 1.9 $ $Date: 2004/11/30 05:52:23 $
71  */

72
73 public class ConfigRuleSet extends RuleSetBase {
74
75
76     // ----------------------------------------------------- Instance Variables
77

78
79     private String JavaDoc catalogClass = "org.apache.commons.chain.impl.CatalogBase";
80     private String JavaDoc catalogElement = "catalog";
81     private String JavaDoc chainClass = "org.apache.commons.chain.impl.ChainBase";
82     private String JavaDoc chainElement = "chain";
83     private String JavaDoc classAttribute = "className";
84     private String JavaDoc commandElement = "command";
85     private String JavaDoc defineElement = "define";
86     private String JavaDoc nameAttribute = "name";
87
88
89     // ------------------------------------------------------------- Properties
90

91
92     /**
93      * <p>Return the fully qualified {@link Catalog} implementation class.</p>
94      */

95     public String JavaDoc getCatalogClass() {
96         return (this.catalogClass);
97     }
98
99
100     /**
101      * <p>Set the fully qualified {@link Catalog} implementation class.</p>
102      *
103      * @param catalogClass The new {@link Catalog} implementation class
104      */

105     public void setCatalogClass(String JavaDoc catalogClass) {
106         this.catalogClass = catalogClass;
107     }
108
109
110     /**
111      * <p>Return the element name of a catalog element.</p>
112      */

113     public String JavaDoc getCatalogElement() {
114         return (this.catalogElement);
115     }
116
117
118     /**
119      * <p>Set the element name of a catalog element.</p>
120      *
121      * @param catalogElement The new element name
122      */

123     public void setCatalogElement(String JavaDoc catalogElement) {
124         this.catalogElement = catalogElement;
125     }
126
127
128     /**
129      * <p>Return the fully qualified {@link Chain} implementation class.</p>
130      */

131     public String JavaDoc getChainClass() {
132         return (this.chainClass);
133     }
134
135
136     /**
137      * <p>Set the fully qualified {@link Chain} implementation class.</p>
138      *
139      * @param chainClass The new {@link Chain} implementation class
140      */

141     public void setChainClass(String JavaDoc chainClass) {
142         this.chainClass = chainClass;
143     }
144
145
146     /**
147      * <p>Return the element name of a chain element.</p>
148      */

149     public String JavaDoc getChainElement() {
150         return (this.chainElement);
151     }
152
153
154     /**
155      * <p>Set the element name of a chain element.</p>
156      *
157      * @param chainElement The new element name
158      */

159     public void setChainElement(String JavaDoc chainElement) {
160         this.chainElement = chainElement;
161     }
162
163
164     /**
165      * <p>Return the attribute name of a class attribute.</p>
166      */

167     public String JavaDoc getClassAttribute() {
168         return (this.classAttribute);
169     }
170
171
172     /**
173      * <p>Set the attribute name of a class attribute.</p>
174      *
175      * @param classAttribute The new attribute name
176      */

177     public void setClassAttribute(String JavaDoc classAttribute) {
178         this.classAttribute = classAttribute;
179     }
180
181
182     /**
183      * <p>Return the element name of a command element.</p>
184      */

185     public String JavaDoc getCommandElement() {
186         return (this.commandElement);
187     }
188
189
190     /**
191      * <p>Set the element name of a command element.</p>
192      *
193      * @param commandElement The new element name
194      */

195     public void setCommandElement(String JavaDoc commandElement) {
196         this.commandElement = commandElement;
197     }
198
199
200     /**
201      * <p>Return the element name of a define element.</p>
202      */

203     public String JavaDoc getDefineElement() {
204         return (this.defineElement);
205     }
206
207
208     /**
209      * <p>Set the element name of a define element.</p>
210      *
211      * @param defineElement The new element name
212      */

213     public void setDefineElement(String JavaDoc defineElement) {
214         this.defineElement = defineElement;
215     }
216
217
218     /**
219      * <p>Return the attribute name of a name attribute.</p>
220      */

221     public String JavaDoc getNameAttribute() {
222         return (this.nameAttribute);
223     }
224
225
226     /**
227      * <p>Set the attribute name of a name attribute.</p>
228      *
229      * @param nameAttribute The new attribute name
230      */

231     public void setNameAttribute(String JavaDoc nameAttribute) {
232         this.nameAttribute = nameAttribute;
233     }
234
235
236     // --------------------------------------------------------- Public Methods
237

238
239     /**
240      * <p>Add the set of Rule instances defined in this RuleSet to the
241      * specified <code>Digester</code> instance, associating them with
242      * our namespace URI (if any). This method should only be called
243      * by a Digester instance.</p>
244      *
245      * @param digester Digester instance to which the new Rule instances
246      * should be added.
247      */

248     public void addRuleInstances(Digester digester) {
249
250         // Add rules for a catalog element
251
digester.addRule("*/" + getCatalogElement(),
252                          new ConfigCatalogRule(nameAttribute, catalogClass));
253         digester.addSetProperties("*/" + getCatalogElement());
254
255         // Add rules for a chain element
256
digester.addObjectCreate("*/" + getChainElement(),
257                                  getChainClass(),
258                                  getClassAttribute());
259         digester.addSetProperties("*/" + getChainElement());
260         digester.addRule("*/" + getChainElement(),
261                          new ConfigRegisterRule(nameAttribute));
262
263         // Add rules for a command element
264
digester.addObjectCreate("*/" + getCommandElement(),
265                                  null,
266                                  getClassAttribute());
267         digester.addSetProperties("*/" + getCommandElement());
268         digester.addRule("*/" + getCommandElement(),
269                          new ConfigRegisterRule(nameAttribute));
270
271         // Add rules for a define element
272
digester.addRule("*/" + getDefineElement(),
273                          new ConfigDefineRule(getNameAttribute(),
274                                               getClassAttribute()));
275
276     }
277
278
279 }
280
Popular Tags