1 /*
2 * Copyright 2004 The Apache Software Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17 package org.apache.asn1.ber.digester ;
18
19
20 import java.util.ArrayList;
21 import java.util.Collections;
22 import java.util.List;
23
24 import org.apache.commons.collections.primitives.IntStack;
25
26
27 /***
28 * A base Rules implementation using a fast pattern match.
29 *
30 * @author <a href="mailto:dev@directory.apache.org">
31 * Apache Directory Project</a>
32 * @version $Rev: 157644 $
33 */
34 public class RulesBase implements Rules
35 {
36 private TagTree tagTree ;
37 private ArrayList rules ;
38 private BERDigester digester ;
39
40
41 /***
42 * Creates a base Rules instance.
43 */
44 public RulesBase()
45 {
46 tagTree = new TagTree() ;
47 rules = new ArrayList() ;
48 }
49
50
51 /* (non-Javadoc)
52 * @see org.apache.snickers.ber.rulesBase.Rules#setDigester(
53 * org.apache.snickers.ber.rulesBase.BERDigester)
54 */
55 public void setDigester( BERDigester digester )
56 {
57 this.digester = digester ;
58 }
59
60
61 /* (non-Javadoc)
62 * @see org.apache.snickers.ber.rulesBase.Rules#getDigester()
63 */
64 public BERDigester getDigester()
65 {
66 return digester ;
67 }
68
69
70 /* (non-Javadoc)
71 * @see org.apache.snickers.ber.rulesBase.Rules#add(int[],
72 * org.apache.snickers.ber.rulesBase.Rule)
73 */
74 public void add( int[] pattern, Rule rule )
75 {
76 tagTree.addRule( pattern, rule ) ;
77 rules.add( rule ) ;
78 }
79
80
81 /* (non-Javadoc)
82 * @see org.apache.snickers.ber.rulesBase.Rules#clear()
83 */
84 public void clear()
85 {
86 tagTree = new TagTree() ;
87 rules.clear() ;
88 }
89
90
91 /* (non-Javadoc)
92 * @see org.apache.snickers.ber.rulesBase.Rules#match(int[])
93 */
94 public List match( int[] pattern )
95 {
96 return tagTree.match( new IntStack( pattern ) ) ;
97 }
98
99
100 /* (non-Javadoc)
101 * @see org.apache.snickers.ber.rulesBase.Rules#match(int[])
102 */
103 public List match( IntStack pattern )
104 {
105 return tagTree.match( pattern ) ;
106 }
107
108
109 /* (non-Javadoc)
110 * @see org.apache.snickers.ber.rulesBase.Rules#rules()
111 */
112 public List rules()
113 {
114 return Collections.unmodifiableList( rules ) ;
115 }
116 }