001: /* $Id: Rule.java 467222 2006-10-24 03:17:11Z markt $
002: *
003: * Licensed to the Apache Software Foundation (ASF) under one or more
004: * contributor license agreements. See the NOTICE file distributed with
005: * this work for additional information regarding copyright ownership.
006: * The ASF licenses this file to You under the Apache License, Version 2.0
007: * (the "License"); you may not use this file except in compliance with
008: * the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: package org.apache.tomcat.util.digester;
020:
021: import org.xml.sax.Attributes;
022:
023: /**
024: * Concrete implementations of this class implement actions to be taken when
025: * a corresponding nested pattern of XML elements has been matched.
026: */
027:
028: public abstract class Rule {
029:
030: // ----------------------------------------------------------- Constructors
031:
032: /**
033: * Constructor sets the associated Digester.
034: *
035: * @param digester The digester with which this rule is associated
036: * @deprecated The digester instance is now set in the {@link Digester#addRule} method. Use {@link #Rule()} instead.
037: */
038: public Rule(Digester digester) {
039:
040: super ();
041: setDigester(digester);
042:
043: }
044:
045: /**
046: * <p>Base constructor.
047: * Now the digester will be set when the rule is added.</p>
048: */
049: public Rule() {
050: }
051:
052: // ----------------------------------------------------- Instance Variables
053:
054: /**
055: * The Digester with which this Rule is associated.
056: */
057: protected Digester digester = null;
058:
059: /**
060: * The namespace URI for which this Rule is relevant, if any.
061: */
062: protected String namespaceURI = null;
063:
064: // ------------------------------------------------------------- Properties
065:
066: /**
067: * Return the Digester with which this Rule is associated.
068: */
069: public Digester getDigester() {
070:
071: return (this .digester);
072:
073: }
074:
075: /**
076: * Set the <code>Digester</code> with which this <code>Rule</code> is associated.
077: */
078: public void setDigester(Digester digester) {
079:
080: this .digester = digester;
081:
082: }
083:
084: /**
085: * Return the namespace URI for which this Rule is relevant, if any.
086: */
087: public String getNamespaceURI() {
088:
089: return (this .namespaceURI);
090:
091: }
092:
093: /**
094: * Set the namespace URI for which this Rule is relevant, if any.
095: *
096: * @param namespaceURI Namespace URI for which this Rule is relevant,
097: * or <code>null</code> to match independent of namespace.
098: */
099: public void setNamespaceURI(String namespaceURI) {
100:
101: this .namespaceURI = namespaceURI;
102:
103: }
104:
105: // --------------------------------------------------------- Public Methods
106:
107: /**
108: * This method is called when the beginning of a matching XML element
109: * is encountered.
110: *
111: * @param attributes The attribute list of this element
112: * @deprecated Use the {@link #begin(String,String,Attributes) begin}
113: * method with <code>namespace</code> and <code>name</code>
114: * parameters instead.
115: */
116: public void begin(Attributes attributes) throws Exception {
117:
118: ; // The default implementation does nothing
119:
120: }
121:
122: /**
123: * This method is called when the beginning of a matching XML element
124: * is encountered. The default implementation delegates to the deprecated
125: * method {@link #begin(Attributes) begin} without the
126: * <code>namespace</code> and <code>name</code> parameters, to retain
127: * backwards compatibility.
128: *
129: * @param namespace the namespace URI of the matching element, or an
130: * empty string if the parser is not namespace aware or the element has
131: * no namespace
132: * @param name the local name if the parser is namespace aware, or just
133: * the element name otherwise
134: * @param attributes The attribute list of this element
135: * @since Digester 1.4
136: */
137: public void begin(String namespace, String name,
138: Attributes attributes) throws Exception {
139:
140: begin(attributes);
141:
142: }
143:
144: /**
145: * This method is called when the body of a matching XML element
146: * is encountered. If the element has no body, this method is
147: * not called at all.
148: *
149: * @param text The text of the body of this element
150: * @deprecated Use the {@link #body(String,String,String) body} method
151: * with <code>namespace</code> and <code>name</code> parameters
152: * instead.
153: */
154: public void body(String text) throws Exception {
155:
156: ; // The default implementation does nothing
157:
158: }
159:
160: /**
161: * This method is called when the body of a matching XML element is
162: * encountered. If the element has no body, this method is not called at
163: * all. The default implementation delegates to the deprecated method
164: * {@link #body(String) body} without the <code>namespace</code> and
165: * <code>name</code> parameters, to retain backwards compatibility.
166: *
167: * @param namespace the namespace URI of the matching element, or an
168: * empty string if the parser is not namespace aware or the element has
169: * no namespace
170: * @param name the local name if the parser is namespace aware, or just
171: * the element name otherwise
172: * @param text The text of the body of this element
173: * @since Digester 1.4
174: */
175: public void body(String namespace, String name, String text)
176: throws Exception {
177:
178: body(text);
179:
180: }
181:
182: /**
183: * This method is called when the end of a matching XML element
184: * is encountered.
185: *
186: * @deprecated Use the {@link #end(String,String) end} method with
187: * <code>namespace</code> and <code>name</code> parameters instead.
188: */
189: public void end() throws Exception {
190:
191: ; // The default implementation does nothing
192:
193: }
194:
195: /**
196: * This method is called when the end of a matching XML element
197: * is encountered. The default implementation delegates to the deprecated
198: * method {@link #end end} without the
199: * <code>namespace</code> and <code>name</code> parameters, to retain
200: * backwards compatibility.
201: *
202: * @param namespace the namespace URI of the matching element, or an
203: * empty string if the parser is not namespace aware or the element has
204: * no namespace
205: * @param name the local name if the parser is namespace aware, or just
206: * the element name otherwise
207: * @since Digester 1.4
208: */
209: public void end(String namespace, String name) throws Exception {
210:
211: end();
212:
213: }
214:
215: /**
216: * This method is called after all parsing methods have been
217: * called, to allow Rules to remove temporary data.
218: */
219: public void finish() throws Exception {
220:
221: ; // The default implementation does nothing
222:
223: }
224:
225: }
|