KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tomcat > util > digester > AbstractRulesImpl


1 /* $Id: AbstractRulesImpl.java 467222 2006-10-24 03:17:11Z markt $
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19
20 package org.apache.tomcat.util.digester;
21
22
23 import java.util.List JavaDoc;
24
25
26 /**
27  * <p><code>AbstractRuleImpl</code> provides basic services for <code>Rules</code> implementations.
28  * Extending this class should make it easier to create a <code>Rules</code> implementation.</p>
29  *
30  * <p><code>AbstractRuleImpl</code> manages the <code>Digester</code>
31  * and <code>namespaceUri</code> properties.
32  * If the subclass overrides {@link #registerRule} (rather than {@link #add}),
33  * then the <code>Digester</code> and <code>namespaceURI</code> of the <code>Rule</code>
34  * will be set correctly before it is passed to <code>registerRule</code>.
35  * The subclass can then perform whatever it needs to do to register the rule.</p>
36  *
37  * @since 1.5
38  */

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

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

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

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

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

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

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

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

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

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

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

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

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

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