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.asn1.ber ;
18  
19  
20  import java.nio.ByteBuffer;
21  import java.util.Iterator;
22  import java.util.List;
23  
24  
25  /***
26   * A TLV Tuple tree node modeled in the likeness of a TreeNode.
27   *
28   * @author <a href="mailto:dev@directory.apache.org">
29   * Apache Directory Project</a>
30   * @version $Rev: 157644 $
31   */
32  public interface TupleNode
33  {
34      /***
35       * Gets the parent tuple node to this node or null if a parent does not 
36       * exist.  The analogous method on the <code>TreeNode</code> interface 
37       * would be <code>getParent()</code>.
38       * 
39       * @return the parent node or null if one does not exist
40       */
41      TupleNode getParentTupleNode() ;
42      
43      /***
44       * Gets an iterator over this node's children.  The analogous interface on
45       * the <code>TreeNode</code> interface would be <code>children</code> which
46       * returns an <code>Enumeration</code> instead of an <code>Iterator</code>.
47       *  
48       * @return an iterator over this node's children
49       */
50      Iterator getChildren() ;
51      
52      /***
53       * Gets a tuple node at an index.  The analogous interface on <code>TreeNode
54       * </code> would be the <code>getChildAt</code> method.
55       * 
56       * @param index the index of the child to get
57       * @return the child node at the specified index
58       */
59      TupleNode getChildTupleNodeAt( int index ) ;
60      
61      /***
62       * Gets the chunked value buffer fragments collected within this node.  
63       * 
64       * @return the value buffer parts for this node
65       */
66      List getValueChunks() ;
67      
68      /***
69       * Gets the index of a child if the child node if it exists.  The analog
70       * within <code>TreeNode<code> takes a <code>TreeNode</code> instead of a 
71       * <code>TupleNode</code>.
72       * 
73       * @param node the child node to get the index for
74       * @return the index of the child node or -1 if the node does not exist
75       */
76      int getIndex( TupleNode node ) ;
77      
78      /***
79       * Gets the number of child nodes contained.  This is the same as in 
80       * <code>TreeNode.getChildCount()</code> as well.
81       * 
82       * @return the number of child nodes contained.
83       */
84      int getChildCount() ;
85      
86      /***
87       * Gets the number of child nodes contained.  This is the same as in 
88       * <code>TreeNode.size()</code> as well.
89       * 
90       * @return the number of children
91       */
92      int size() ;
93      
94      /***
95       * Gets the Tuple this node represents.   This is the analogous to <code>
96       * TreeNode.getUserObject()</code>.
97       * 
98       * @return the tuple this node represents or null if one has not been 
99       * assigned
100      */
101     Tuple getTuple() ;
102     
103     /***
104      * Recursively encodes the tree rooted at this node. 
105      * 
106      * @param buf the buffer populated with the BER encoded tlv tree contents
107      */
108     void encode( ByteBuffer buf ) ;
109     
110     /***
111      * Checks to see if two trees are equal.  Note that the order of children
112      * within the tree as well as the tuples and their contents make a 
113      * difference to <code>equals()</code>.
114      * 
115      * @param obj the object to compare this node to
116      * @return true if the obj and this node are exact replicas of one another
117      */
118     boolean equals( Object obj ) ;
119 
120     /***
121      * Element/node accept method for visitor pattern.
122      *
123      * @param visitor the tuple node tree structure visitor
124      * @see TupleNodeVisitor
125      */
126     void accept( TupleNodeVisitor visitor ) ;
127 }