View Javadoc

1   package org.apache.commons.digester3.xmlrules;
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  import java.util.Stack;
23  
24  import org.apache.commons.digester3.binder.LinkedRuleBuilder;
25  import org.apache.commons.digester3.binder.RulesBinder;
26  import org.apache.commons.digester3.binder.RulesModule;
27  
28  /**
29   * @since 3.0
30   */
31  final class NameSpaceURIRulesBinder
32      implements RulesBinder
33  {
34  
35      // a stack is needed because of includes!!!
36      private final Stack<String> namespaceURIs = new Stack<String>();
37  
38      private final RulesBinder wrappedBinder;
39  
40      public NameSpaceURIRulesBinder( RulesBinder wrappedBinder )
41      {
42          this.wrappedBinder = wrappedBinder;
43      }
44  
45      /**
46       * 
47       * @param namespaceURI
48       */
49      public void addNamespaceURI( String namespaceURI )
50      {
51          namespaceURIs.push( namespaceURI );
52      }
53  
54      /**
55       * 
56       */
57      public void removeNamespaceURI()
58      {
59          namespaceURIs.pop();
60      }
61  
62      /**
63       * {@inheritDoc}
64       */
65      public ClassLoader getContextClassLoader()
66      {
67          return wrappedBinder.getContextClassLoader();
68      }
69  
70      /**
71       * {@inheritDoc}
72       */
73      public void addError( String messagePattern, Object... arguments )
74      {
75          wrappedBinder.addError( messagePattern, arguments );
76      }
77  
78      /**
79       * {@inheritDoc}
80       */
81      public void addError( Throwable t )
82      {
83          wrappedBinder.addError( t );
84      }
85  
86      /**
87       * {@inheritDoc}
88       */
89      public void install( RulesModule rulesModule )
90      {
91          wrappedBinder.install( rulesModule );
92      }
93  
94      /**
95       * {@inheritDoc}
96       */
97      public LinkedRuleBuilder forPattern( String pattern )
98      {
99          return wrappedBinder.forPattern( pattern ).withNamespaceURI( namespaceURIs.peek() );
100     }
101 
102 }