View Javadoc

1   package org.apache.commons.digester3.annotations;
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.HashSet;
23  import java.util.Set;
24  
25  import org.apache.commons.digester3.binder.LinkedRuleBuilder;
26  import org.apache.commons.digester3.binder.RulesBinder;
27  import org.apache.commons.digester3.binder.RulesModule;
28  
29  /**
30   * A {@link RulesBinder} implementation with memory to maintain
31   * which classes have already been analyzed.
32   *
33   * @since 3.0
34   */
35  final class WithMemoryRulesBinder
36      implements RulesBinder
37  {
38  
39      /**
40       * Maintains all the classes that this RuleSet produces mapping for.
41       */
42      private final Set<Class<?>> boundClasses = new HashSet<Class<?>>();
43  
44      private final RulesBinder wrappedRulesBinder;
45  
46      public WithMemoryRulesBinder( final RulesBinder wrappedRulesBinder )
47      {
48          this.wrappedRulesBinder = wrappedRulesBinder;
49      }
50  
51      /**
52       * {@inheritDoc}
53       */
54      public ClassLoader getContextClassLoader()
55      {
56          return wrappedRulesBinder.getContextClassLoader();
57      }
58  
59      /**
60       * {@inheritDoc}
61       */
62      public void addError( String messagePattern, Object... arguments )
63      {
64          wrappedRulesBinder.addError( messagePattern, arguments );
65      }
66  
67      /**
68       * {@inheritDoc}
69       */
70      public void addError( Throwable t )
71      {
72          wrappedRulesBinder.addError( t );
73      }
74  
75      /**
76       * {@inheritDoc}
77       */
78      public void install( RulesModule rulesModule )
79      {
80          wrappedRulesBinder.install( rulesModule );
81      }
82  
83      /**
84       * {@inheritDoc}
85       */
86      public LinkedRuleBuilder forPattern( String pattern )
87      {
88          return wrappedRulesBinder.forPattern( pattern );
89      }
90  
91      /**
92       * 
93       *
94       * @param bindingClass
95       * @return true if the specified element has not yet been marked
96       */
97      public boolean markAsBound( Class<?> bindingClass )
98      {
99          return boundClasses.add( bindingClass );
100     }
101 
102     /**
103      * 
104      *
105      * @param bindingClass
106      * @return true if the specified element has been marked
107      */
108     public boolean isAlreadyBound( Class<?> bindingClass )
109     {
110         return boundClasses.contains( bindingClass );
111     }
112 
113 }