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.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 *
31 */
32 class WithMemoryRulesBinder
33 implements RulesBinder
34 {
35
36 /**
37 * A stack used to maintain the current pattern. The Rules XML document type allows nesting of patterns. If an
38 * element defines a matching pattern, the resulting pattern is a concatenation of that pattern with all the
39 * ancestor elements' patterns. Hence the need for a stack.
40 */
41 private final PatternStack patternStack = new PatternStack();
42
43 /**
44 * Used to detect circular includes
45 */
46 private final Set<String> includedFiles = new HashSet<String>();
47
48 private final RulesBinder wrappedRulesBinder;
49
50 public WithMemoryRulesBinder( RulesBinder wrappedRulesBinder )
51 {
52 this.wrappedRulesBinder = wrappedRulesBinder;
53 }
54
55 /**
56 * {@inheritDoc}
57 */
58 public ClassLoader getContextClassLoader()
59 {
60 return this.wrappedRulesBinder.getContextClassLoader();
61 }
62
63 /**
64 * {@inheritDoc}
65 */
66 public void addError( String messagePattern, Object... arguments )
67 {
68 this.wrappedRulesBinder.addError( messagePattern, arguments );
69 }
70
71 /**
72 * {@inheritDoc}
73 */
74 public void addError( Throwable t )
75 {
76 this.wrappedRulesBinder.addError( t );
77 }
78
79 /**
80 * {@inheritDoc}
81 */
82 public void install( RulesModule rulesModule )
83 {
84 this.wrappedRulesBinder.install( rulesModule );
85 }
86
87 /**
88 * {@inheritDoc}
89 */
90 public LinkedRuleBuilder forPattern( String pattern )
91 {
92 return this.wrappedRulesBinder.forPattern( pattern );
93 }
94
95 /**
96 * @return the pattern stack
97 */
98 public PatternStack getPatternStack()
99 {
100 return this.patternStack;
101 }
102
103 /**
104 * @return the set of included files
105 */
106 public Set<String> getIncludedFiles()
107 {
108 return this.includedFiles;
109 }
110
111 }