001: /*
002: * Copyright 1999-2004 The Apache Software Foundation
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.apache.commons.chain.config;
017:
018: import org.apache.commons.digester.Digester;
019: import org.apache.commons.digester.RuleSetBase;
020:
021: /**
022: * <p>Digester <code>RuleSet</code> for configuring <em>Chain of
023: * Responsibility</em> command chains, and adding them to an appropriate
024: * {@link org.apache.commons.chain.Catalog}. The following properties
025: * may be configured prior to executing the <code>addRuleInstance()</code>
026: * method in order to influence the rules that get added, with default
027: * values in square brackets:</p>
028: * <ul>
029: * <li><strong>catalogClass</strong> -- Fully qualified name of the
030: * implementation class used to create new
031: * {@link org.apache.commons.chain.Catalog} instances.
032: * If not specified, the default value is
033: * <code>org.apache.commons.chain.impl.CatalogBsae</code>.</li>
034: * <li><strong>catalogElement</strong> -- Name of the XML element representing
035: * the addition of a {@link org.apache.commons.chain.Catalog}.
036: * Any such catalog that is created will be registered with the
037: * {@link org.apache.commons.chain.CatalogFactory} instance for our
038: * application, under the name specified by the <code>nameAttribute</code>
039: * attribute (if present), or as the default {@link org.apache.commons.chain.Catalog}.
040: * If not specified, the default value is <code>catalog</code>.</li>
041: * <li><strong>chainClass</strong> -- Fully qualified name of the implementation
042: * class used to create new {@link org.apache.commons.chain.Chain} instances.
043: * If not specified, the default value is
044: * <code>org.apache.commons.chain.impl.ChainBase</code>.
045: * </li>
046: * <li><strong>chainElement</strong> -- Name of the XML element representing
047: * the addition of a {@link org.apache.commons.chain.Chain}. A chain
048: * element has the same functionality as a command element, except that
049: * it defaults the implementation class to
050: * <code>org.apache.commons.chain.impl.ChainBase</code>. [chain]</li>
051: * <li><strong>classAttribute</strong> -- Attribute on a chain (optional) or
052: * command (required) element that specifies the fully qualified class
053: * name of the implementation class that should be instantiated.
054: * [className]</li>
055: * <li><strong>commandElement</strong> -- Name of the XML element
056: * representing the addition of a {@link org.apache.commons.chain.Command}.
057: * An implementation class name must be provided on the attribute named by the
058: * <code>classAttribute</code> property. [command]</li>
059: * <li><strong>defineElement</strong> -- Name of the XML element
060: * that associates the element specified by the <code>nameAttribute</code>
061: * attributes with a {@link org.apache.commons.chain.Command} or
062: * {@link org.apache.commons.chain.Chain} implementation class
063: * named by the <code>classAttribute</code> attribute. [define]</li>
064: * <li><strong>nameAttribute</strong> -- Attribute on an outermost chain or
065: * command element that will be used to register this command with the
066: * associated {@link org.apache.commons.chain.Catalog} instance on the stack.
067: * [name]</li>
068: * <li><strong>namespaceURI</strong> -- The XML namespace URI with which these
069: * rules will be associated, or <code>null</code> for no namespace.
070: * [null]</li>
071: * </ul>
072: *
073: * @author Craig R. McClanahan
074: * @version $Revision: 411876 $ $Date: 2006-06-05 19:02:19 +0100 (Mon, 05 Jun 2006) $
075: */
076:
077: public class ConfigRuleSet extends RuleSetBase {
078:
079: // ----------------------------------------------------- Instance Variables
080:
081: private String catalogClass = "org.apache.commons.chain.impl.CatalogBase";
082: private String catalogElement = "catalog";
083: private String chainClass = "org.apache.commons.chain.impl.ChainBase";
084: private String chainElement = "chain";
085: private String classAttribute = "className";
086: private String commandElement = "command";
087: private String defineElement = "define";
088: private String nameAttribute = "name";
089:
090: // ------------------------------------------------------------- Properties
091:
092: /**
093: * <p>Return the fully qualified {@link org.apache.commons.chain.Catalog}
094: * implementation class.</p>
095: * @return The Catalog's class name.
096: */
097: public String getCatalogClass() {
098: return (this .catalogClass);
099: }
100:
101: /**
102: * <p>Set the fully qualified {@link org.apache.commons.chain.Catalog}
103: * implementation class.</p>
104: *
105: * @param catalogClass The new {@link org.apache.commons.chain.Catalog}
106: * implementation class
107: */
108: public void setCatalogClass(String catalogClass) {
109: this .catalogClass = catalogClass;
110: }
111:
112: /**
113: * <p>Return the element name of a catalog element.</p>
114: * @return The element name of a catalog element.
115: */
116: public String getCatalogElement() {
117: return (this .catalogElement);
118: }
119:
120: /**
121: * <p>Set the element name of a catalog element.</p>
122: *
123: * @param catalogElement The new element name
124: */
125: public void setCatalogElement(String catalogElement) {
126: this .catalogElement = catalogElement;
127: }
128:
129: /**
130: * <p>Return the fully qualified {@link org.apache.commons.chain.Chain}
131: * implementation class.</p>
132: * @return The Chain's class name.
133: */
134: public String getChainClass() {
135: return (this .chainClass);
136: }
137:
138: /**
139: * <p>Set the fully qualified {@link org.apache.commons.chain.Chain}
140: * implementation class.</p>
141: *
142: * @param chainClass The new {@link org.apache.commons.chain.Chain}
143: * implementation class
144: */
145: public void setChainClass(String chainClass) {
146: this .chainClass = chainClass;
147: }
148:
149: /**
150: * <p>Return the element name of a chain element.</p>
151: * @return The element name of a catalog element.
152: */
153: public String getChainElement() {
154: return (this .chainElement);
155: }
156:
157: /**
158: * <p>Set the element name of a chain element.</p>
159: *
160: * @param chainElement The new element name
161: */
162: public void setChainElement(String chainElement) {
163: this .chainElement = chainElement;
164: }
165:
166: /**
167: * <p>Return the attribute name of a class attribute.</p>
168: * @return The attribute name of a class attribute.
169: */
170: public String getClassAttribute() {
171: return (this .classAttribute);
172: }
173:
174: /**
175: * <p>Set the attribute name of a class attribute.</p>
176: *
177: * @param classAttribute The new attribute name
178: */
179: public void setClassAttribute(String classAttribute) {
180: this .classAttribute = classAttribute;
181: }
182:
183: /**
184: * <p>Return the element name of a command element.</p>
185: * @return The element name of a command element.
186: */
187: public String getCommandElement() {
188: return (this .commandElement);
189: }
190:
191: /**
192: * <p>Set the element name of a command element.</p>
193: *
194: * @param commandElement The new element name
195: */
196: public void setCommandElement(String commandElement) {
197: this .commandElement = commandElement;
198: }
199:
200: /**
201: * <p>Return the element name of a define element.</p>
202: * @return The element name of a define element.
203: */
204: public String getDefineElement() {
205: return (this .defineElement);
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 defineElement) {
214: this .defineElement = defineElement;
215: }
216:
217: /**
218: * <p>Return the attribute name of a name attribute.</p>
219: * @return The attribute name of an attribute element.
220: */
221: public String getNameAttribute() {
222: return (this .nameAttribute);
223: }
224:
225: /**
226: * <p>Set the attribute name of a name attribute.</p>
227: *
228: * @param nameAttribute The new attribute name
229: */
230: public void setNameAttribute(String nameAttribute) {
231: this .nameAttribute = nameAttribute;
232: }
233:
234: // --------------------------------------------------------- Public Methods
235:
236: /**
237: * <p>Add the set of Rule instances defined in this RuleSet to the
238: * specified <code>Digester</code> instance, associating them with
239: * our namespace URI (if any). This method should only be called
240: * by a Digester instance.</p>
241: *
242: * @param digester Digester instance to which the new Rule instances
243: * should be added.
244: */
245: public void addRuleInstances(Digester digester) {
246:
247: // Add rules for a catalog element
248: digester.addRule("*/" + getCatalogElement(),
249: new ConfigCatalogRule(nameAttribute, catalogClass));
250: digester.addSetProperties("*/" + getCatalogElement());
251:
252: // Add rules for a chain element
253: digester.addObjectCreate("*/" + getChainElement(),
254: getChainClass(), getClassAttribute());
255: digester.addSetProperties("*/" + getChainElement());
256: digester.addRule("*/" + getChainElement(),
257: new ConfigRegisterRule(nameAttribute));
258:
259: // Add rules for a command element
260: digester.addObjectCreate("*/" + getCommandElement(), null,
261: getClassAttribute());
262: digester.addSetProperties("*/" + getCommandElement());
263: digester.addRule("*/" + getCommandElement(),
264: new ConfigRegisterRule(nameAttribute));
265:
266: // Add rules for a define element
267: digester.addRule("*/" + getDefineElement(),
268: new ConfigDefineRule(getNameAttribute(),
269: getClassAttribute()));
270:
271: }
272:
273: }
|