View Javadoc

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.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 }