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