1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.ldap.server.partition.impl.btree.gui;
18
19
20 import java.util.ArrayList;
21 import java.util.Collections;
22 import java.util.Enumeration;
23
24 import javax.swing.tree.TreeNode;
25
26 import org.apache.ldap.common.filter.BranchNode;
27 import org.apache.ldap.common.filter.ExprNode;
28
29
30 /***
31 * A node representing an entry.
32 *
33 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
34 * @version $Rev: 264732 $
35 */
36 public class ASTNode implements TreeNode
37 {
38 private final ASTNode parent;
39 private final ExprNode exprNode;
40 private final ArrayList children;
41
42
43 public ASTNode( ASTNode parent, ExprNode exprNode )
44 {
45 this.children = new ArrayList(2);
46 this.exprNode = exprNode;
47
48 if( parent == null )
49 {
50 this.parent = this;
51 }
52 else
53 {
54 this.parent = parent;
55 }
56
57 try
58 {
59 if( exprNode.isLeaf() )
60 {
61 return;
62 }
63
64 BranchNode branch = ( BranchNode ) exprNode;
65 ArrayList exprNodes = branch.getChildren();
66 for ( int ii = 0; ii < exprNodes.size(); ii++ )
67 {
68 ExprNode child = ( ExprNode ) exprNodes.get(ii);
69 children.add( new ASTNode( this, child ) );
70 }
71 }
72 catch( Exception e )
73 {
74 e.printStackTrace();
75 }
76 }
77
78
79 public Enumeration children()
80 {
81 return Collections.enumeration( children );
82 }
83
84
85 public boolean getAllowsChildren()
86 {
87 return !exprNode.isLeaf();
88 }
89
90
91 public TreeNode getChildAt( int childIndex )
92 {
93 return ( TreeNode ) children.get( childIndex );
94 }
95
96
97 public int getChildCount()
98 {
99 return children.size();
100 }
101
102
103 public int getIndex( TreeNode child )
104 {
105 return children.indexOf( child );
106 }
107
108
109 public TreeNode getParent()
110 {
111 return parent;
112 }
113
114
115 public boolean isLeaf()
116 {
117 return children.size() <= 0;
118 }
119
120
121 public String toString()
122 {
123 return exprNode.toString();
124 }
125
126
127 public ExprNode getExprNode()
128 {
129 return exprNode;
130 }
131 }