KickJava   Java API By Example, From Geeks To Geeks.

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


1 /* $Id: AbstractRulesImpl.java 155412 2005-02-26 12:58:36Z dirkv $
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 java.util.List JavaDoc;
23
24
25 /**
26  * <p><code>AbstractRuleImpl</code> provides basic services for <code>Rules</code> implementations.
27  * Extending this class should make it easier to create a <code>Rules</code> implementation.</p>
28  *
29  * <p><code>AbstractRuleImpl</code> manages the <code>Digester</code>
30  * and <code>namespaceUri</code> properties.
31  * If the subclass overrides {@link #registerRule} (rather than {@link #add}),
32  * then the <code>Digester</code> and <code>namespaceURI</code> of the <code>Rule</code>
33  * will be set correctly before it is passed to <code>registerRule</code>.
34  * The subclass can then perform whatever it needs to do to register the rule.</p>
35  *
36  * @since 1.5
37  */

38
39 abstract public class AbstractRulesImpl implements Rules {
40
41     // ------------------------------------------------------------- Fields
42

43     /** Digester using this <code>Rules</code> implementation */
44     private Digester digester;
45     /** Namespace uri to assoicate with subsequent <code>Rule</code>'s */
46     private String JavaDoc namespaceURI;
47     
48     // ------------------------------------------------------------- Properties
49

50     /**
51      * Return the Digester instance with which this Rules instance is
52      * associated.
53      */

54     public Digester getDigester() {
55         return digester;
56     }
57
58     /**
59      * Set the Digester instance with which this Rules instance is associated.
60      *
61      * @param digester The newly associated Digester instance
62      */

63     public void setDigester(Digester digester) {
64         this.digester = digester;
65     }
66
67     /**
68      * Return the namespace URI that will be applied to all subsequently
69      * added <code>Rule</code> objects.
70      */

71     public String JavaDoc getNamespaceURI() {
72         return namespaceURI;
73     }
74
75     /**
76      * Set the namespace URI that will be applied to all subsequently
77      * added <code>Rule</code> objects.
78      *
79      * @param namespaceURI Namespace URI that must match on all
80      * subsequently added rules, or <code>null</code> for matching
81      * regardless of the current namespace URI
82      */

83     public void setNamespaceURI(String JavaDoc namespaceURI) {
84         this.namespaceURI = namespaceURI;
85     }
86
87     // --------------------------------------------------------- Public Methods
88

89     /**
90      * Registers a new Rule instance matching the specified pattern.
91      * This implementation sets the <code>Digester</code> and the
92      * <code>namespaceURI</code> on the <code>Rule</code> before calling {@link #registerRule}.
93      *
94      * @param pattern Nesting pattern to be matched for this Rule
95      * @param rule Rule instance to be registered
96      */

97     public void add(String JavaDoc pattern, Rule rule) {
98         // set up rule
99
if (this.digester != null) {
100             rule.setDigester(this.digester);
101         }
102         
103         if (this.namespaceURI != null) {
104             rule.setNamespaceURI(this.namespaceURI);
105         }
106         
107         registerRule(pattern, rule);
108         
109     }
110     
111     /**
112      * Register rule at given pattern.
113      * The the Digester and namespaceURI properties of the given <code>Rule</code>
114      * can be assumed to have been set properly before this method is called.
115      *
116      * @param pattern Nesting pattern to be matched for this Rule
117      * @param rule Rule instance to be registered
118      */

119     abstract protected void registerRule(String JavaDoc pattern, Rule rule);
120
121     /**
122      * Clear all existing Rule instance registrations.
123      */

124     abstract public void clear();
125
126
127     /**
128      * Return a List of all registered Rule instances that match the specified
129      * nesting pattern, or a zero-length List if there are no matches. If more
130      * than one Rule instance matches, they <strong>must</strong> be returned
131      * in the order originally registered through the <code>add()</code>
132      * method.
133      *
134      * @param pattern Nesting pattern to be matched
135      *
136      * @deprecated Call match(namespaceURI,pattern) instead.
137      */

138     public List JavaDoc match(String JavaDoc pattern) {
139         return match(namespaceURI, pattern);
140     }
141
142
143     /**
144      * Return a List of all registered Rule instances that match the specified
145      * nesting pattern, or a zero-length List if there are no matches. If more
146      * than one Rule instance matches, they <strong>must</strong> be returned
147      * in the order originally registered through the <code>add()</code>
148      * method.
149      *
150      * @param namespaceURI Namespace URI for which to select matching rules,
151      * or <code>null</code> to match regardless of namespace URI
152      * @param pattern Nesting pattern to be matched
153      */

154     abstract public List JavaDoc match(String JavaDoc namespaceURI, String JavaDoc pattern);
155
156
157     /**
158      * Return a List of all registered Rule instances, or a zero-length List
159      * if there are no registered Rule instances. If more than one Rule
160      * instance has been registered, they <strong>must</strong> be returned
161      * in the order originally registered through the <code>add()</code>
162      * method.
163      */

164     abstract public List JavaDoc rules();
165
166 }
167
Popular Tags