View Javadoc

1   package org.apache.commons.digester3;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  
23  /**
24   * <p>
25   * <code>AbstractRuleImpl</code> provides basic services for <code>Rules</code> implementations. Extending this class
26   * should make it easier to create a <code>Rules</code> implementation.
27   * </p>
28   * <p>
29   * <code>AbstractRuleImpl</code> manages the <code>Digester</code> and <code>namespaceUri</code> properties. If the
30   * subclass overrides {@link #registerRule} (rather than {@link #add}), then the <code>Digester</code> and
31   * <code>namespaceURI</code> of the <code>Rule</code> will be set correctly before it is passed to
32   * <code>registerRule</code>. The subclass can then perform whatever it needs to do to register the rule.
33   * </p>
34   * 
35   * @since 1.5
36   */
37  public abstract class AbstractRulesImpl
38      implements Rules
39  {
40  
41      // ------------------------------------------------------------- Fields
42  
43      /** Digester using this <code>Rules</code> implementation */
44      private Digester digester;
45  
46      /** Namespace uri to assoicate with subsequent <code>Rule</code>'s */
47      private String namespaceURI;
48  
49      // ------------------------------------------------------------- Properties
50  
51      /**
52       * {@inheritDoc}
53       */
54      public Digester getDigester()
55      {
56          return digester;
57      }
58  
59      /**
60       * {@inheritDoc}
61       */
62      public void setDigester( Digester digester )
63      {
64          this.digester = digester;
65      }
66  
67      /**
68       * {@inheritDoc}
69       */
70      public String getNamespaceURI()
71      {
72          return namespaceURI;
73      }
74  
75      /**
76       * {@inheritDoc}
77       */
78      public void setNamespaceURI( String namespaceURI )
79      {
80          this.namespaceURI = namespaceURI;
81      }
82  
83      // --------------------------------------------------------- Public Methods
84  
85      /**
86       * {@inheritDoc}
87       */
88      public final void add( String pattern, Rule rule )
89      {
90          // set up rule
91          if ( this.digester != null )
92          {
93              rule.setDigester( this.digester );
94          }
95  
96          if ( this.namespaceURI != null )
97          {
98              rule.setNamespaceURI( this.namespaceURI );
99          }
100 
101         registerRule( pattern, rule );
102     }
103 
104     /**
105      * Register rule at given pattern. The the Digester and namespaceURI properties of the given <code>Rule</code> can
106      * be assumed to have been set properly before this method is called.
107      * 
108      * @param pattern Nesting pattern to be matched for this Rule
109      * @param rule Rule instance to be registered
110      */
111     protected abstract void registerRule( String pattern, Rule rule );
112 
113 }