1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.asn1.ber.digester ;
18
19
20 import java.util.ArrayList;
21 import java.util.HashMap;
22 import java.util.Iterator;
23 import java.util.List;
24
25
26 /***
27 * A speed (verses size) optimized data structure to match tag patterns.
28 * As tuples are pushed and popped off of the decoder's stack and the tag
29 * nesting path changes this tree is traversed. A position member of type
30 * TagNode is used to track the current position in this tree. If the nesting
31 * does not correspond to a valid node then it is null and thus underfined so
32 * no rules are correlated with the position. When a node is located and set
33 * the rules contained in that node are triggered.
34 *
35 * @author <a href="mailto:dev@directory.apache.org">
36 * Apache Directory Project</a>
37 * @version $Rev: 157644 $
38 */
39 public class TagNode
40 {
41 private Integer tag ;
42 private int depth ;
43 private HashMap children = new HashMap( 3 ) ;
44 private ArrayList rules = new ArrayList( 3 ) ;
45
46
47 TagNode( Integer tag )
48 {
49 this.tag = tag ;
50 }
51
52
53 void addNode( TagNode node )
54 {
55 children.put( node.getTag(), node ) ;
56 node.setDepth( depth + 1 ) ;
57 }
58
59
60 void addRule( Rule rule )
61 {
62 rules.add( rule ) ;
63 }
64
65
66 void setDepth( int depth )
67 {
68 this.depth = depth ;
69 }
70
71
72 public Integer getTag()
73 {
74 return tag ;
75 }
76
77
78 public int getDepth()
79 {
80 return depth ;
81 }
82
83
84 public List getRules()
85 {
86 return rules ;
87 }
88
89
90 public boolean hasChild( Integer tag )
91 {
92 return children.containsKey( tag ) ;
93 }
94
95
96 public boolean isLeaf()
97 {
98 return children.isEmpty() ;
99 }
100
101
102 public Iterator getChildren()
103 {
104 return children.values().iterator() ;
105 }
106
107
108 public TagNode getChild( Integer tag )
109 {
110 return ( TagNode ) children.get( tag ) ;
111 }
112 }