KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > digester > Rule


1 /* $Id: Rule.java 179716 2005-06-03 04:06:00Z skitching $
2  *
3  * Copyright 2001-2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18
19 package org.apache.commons.digester;
20
21
22 import org.xml.sax.Attributes JavaDoc;
23
24
25 /**
26  * Concrete implementations of this class implement actions to be taken when
27  * a corresponding nested pattern of XML elements has been matched.
28  */

29
30 public abstract class Rule {
31
32
33     // ----------------------------------------------------------- Constructors
34

35
36     /**
37      * Constructor sets the associated Digester.
38      *
39      * @param digester The digester with which this rule is associated
40      * @deprecated The digester instance is now set in the {@link Digester#addRule} method. Use {@link #Rule()} instead.
41      */

42     public Rule(Digester digester) {
43
44         super();
45         setDigester(digester);
46
47     }
48     
49     /**
50      * <p>Base constructor.
51      * Now the digester will be set when the rule is added.</p>
52      */

53     public Rule() {}
54
55
56     // ----------------------------------------------------- Instance Variables
57

58
59     /**
60      * The Digester with which this Rule is associated.
61      */

62     protected Digester digester = null;
63
64
65     /**
66      * The namespace URI for which this Rule is relevant, if any.
67      */

68     protected String JavaDoc namespaceURI = null;
69
70
71     // ------------------------------------------------------------- Properties
72

73
74     /**
75      * Return the Digester with which this Rule is associated.
76      */

77     public Digester getDigester() {
78
79         return (this.digester);
80
81     }
82     
83     /**
84      * Set the <code>Digester</code> with which this <code>Rule</code> is associated.
85      */

86     public void setDigester(Digester digester) {
87         
88         this.digester = digester;
89         
90     }
91
92     /**
93      * Return the namespace URI for which this Rule is relevant, if any.
94      */

95     public String JavaDoc getNamespaceURI() {
96
97         return (this.namespaceURI);
98
99     }
100
101
102     /**
103      * Set the namespace URI for which this Rule is relevant, if any.
104      *
105      * @param namespaceURI Namespace URI for which this Rule is relevant,
106      * or <code>null</code> to match independent of namespace.
107      */

108     public void setNamespaceURI(String JavaDoc namespaceURI) {
109
110         this.namespaceURI = namespaceURI;
111
112     }
113
114
115     // --------------------------------------------------------- Public Methods
116

117
118     /**
119      * This method is called when the beginning of a matching XML element
120      * is encountered.
121      *
122      * @param attributes The attribute list of this element
123      * @deprecated Use the {@link #begin(String,String,Attributes) begin}
124      * method with <code>namespace</code> and <code>name</code>
125      * parameters instead.
126      */

127     public void begin(Attributes JavaDoc attributes) throws Exception JavaDoc {
128
129         ; // The default implementation does nothing
130

131     }
132
133
134     /**
135      * This method is called when the beginning of a matching XML element
136      * is encountered. The default implementation delegates to the deprecated
137      * method {@link #begin(Attributes) begin} without the
138      * <code>namespace</code> and <code>name</code> parameters, to retain
139      * backwards compatibility.
140      *
141      * @param namespace the namespace URI of the matching element, or an
142      * empty string if the parser is not namespace aware or the element has
143      * no namespace
144      * @param name the local name if the parser is namespace aware, or just
145      * the element name otherwise
146      * @param attributes The attribute list of this element
147      * @since Digester 1.4
148      */

149     public void begin(String JavaDoc namespace, String JavaDoc name, Attributes JavaDoc attributes)
150         throws Exception JavaDoc {
151
152         begin(attributes);
153
154     }
155
156
157     /**
158      * This method is called when the body of a matching XML element
159      * is encountered. If the element has no body, this method is
160      * called with an empty string as the body text.
161      *
162      * @param text The text of the body of this element
163      * @deprecated Use the {@link #body(String,String,String) body} method
164      * with <code>namespace</code> and <code>name</code> parameters
165      * instead.
166      */

167     public void body(String JavaDoc text) throws Exception JavaDoc {
168
169         ; // The default implementation does nothing
170

171     }
172
173
174     /**
175      * This method is called when the body of a matching XML element is
176      * encountered. If the element has no body, this method is
177      * called with an empty string as the body text.
178      * <p>
179      * The default implementation delegates to the deprecated method
180      * {@link #body(String) body} without the <code>namespace</code> and
181      * <code>name</code> parameters, to retain backwards compatibility.
182      *
183      * @param namespace the namespace URI of the matching element, or an
184      * empty string if the parser is not namespace aware or the element has
185      * no namespace
186      * @param name the local name if the parser is namespace aware, or just
187      * the element name otherwise
188      * @param text The text of the body of this element
189      * @since Digester 1.4
190      */

191     public void body(String JavaDoc namespace, String JavaDoc name, String JavaDoc text)
192         throws Exception JavaDoc {
193
194         body(text);
195
196     }
197
198
199     /**
200      * This method is called when the end of a matching XML element
201      * is encountered.
202      *
203      * @deprecated Use the {@link #end(String,String) end} method with
204      * <code>namespace</code> and <code>name</code> parameters instead.
205      */

206     public void end() throws Exception JavaDoc {
207
208         ; // The default implementation does nothing
209

210     }
211
212
213     /**
214      * This method is called when the end of a matching XML element
215      * is encountered. The default implementation delegates to the deprecated
216      * method {@link #end end} without the
217      * <code>namespace</code> and <code>name</code> parameters, to retain
218      * backwards compatibility.
219      *
220      * @param namespace the namespace URI of the matching element, or an
221      * empty string if the parser is not namespace aware or the element has
222      * no namespace
223      * @param name the local name if the parser is namespace aware, or just
224      * the element name otherwise
225      * @since Digester 1.4
226      */

227     public void end(String JavaDoc namespace, String JavaDoc name)
228         throws Exception JavaDoc {
229
230         end();
231
232     }
233
234
235     /**
236      * This method is called after all parsing methods have been
237      * called, to allow Rules to remove temporary data.
238      */

239     public void finish() throws Exception JavaDoc {
240
241         ; // The default implementation does nothing
242

243     }
244
245
246 }
247
Popular Tags