remove unnecessary import
[org.ibex.util.git] / src / org / ibex / util / Tree.java
1 // Copyright 2000-2005 the Contributors, as shown in the revision logs.
2 // Licensed under the Apache Public Source License 2.0 ("the License").
3 // You may not use this file except in compliance with the License.
4
5 package org.ibex.util;
6
7 import java.io.IOException;
8 import java.io.OutputStream;
9 import java.io.Writer;
10
11 public interface Tree {
12
13     /** Represents a primitive block of a Tree. */
14     public interface Leaf {
15         /** Return the parent Node of the current leaf. */
16         public Node getParent();
17
18         /** Set the parent of this leaf.
19          *  @throws UnsupportedOperationException if this leaf is immutable. */
20         public void setParent(Tree.Node p) throws UnsupportedOperationException;
21
22         /** Writes a character representation of this leaf.
23          *  @throws UnsupportedOperationException if this leaf has no character representation.
24          *  @throws IOException */
25         public void out(Writer out) throws IOException, UnsupportedOperationException;
26
27         /** Writes a byte representation of this leaf.
28          *  @throws UnsupportedOperationException if this leaf has no byte representation.
29          *  @throws IOException */
30         public void out(OutputStream out) throws IOException, UnsupportedOperationException;
31     }
32
33     public interface Node extends Leaf {
34         /** Returns a list of children that all implement <tt>Tree.Leaf</tt>. */
35         public Basket.List getChildren();
36     }
37
38     public interface Stream {
39         /** Returns the number of <tt>Leaf</tt>s that can be read before blocking. */
40         public int available();
41
42         /** Return the current node depth in the tree. <tt>0</tt> at root node. */
43         public int getDepth();
44
45         /** Returns the next leaf in the tree, or null if at the end. */
46         public Leaf next() throws IOException;
47
48         /** Skip the next leaf and its subtree. */
49         public void skip() throws IOException;
50     }
51
52
53     /** Represents an element in an document, containing
54      *  attributes and child elements. */
55     public interface Element extends Node {
56         /** Returns the attributes of this element in the form of
57          *  an <tt>Tree.Attributes</tt> object. */
58         public Attributes getAttributes();
59
60         /** Returns the prefix/uri mappings created in this element
61          *  in the form of an <tt>Tree.Prefixes</tt> object. */
62         public Prefixes getPrefixes();
63
64         /** Set the object to act as an attribute source. */
65         public void setAttributes(Attributes a);
66
67         /** Set the object to act as a prefix source. */
68         public void setPrefixes(Prefixes a);
69
70         /** Returns a List of children that all implement <tt>Tree.Leaf</tt>. */
71         public Basket.List getChildren();
72
73         /** Qualified Name of current element. */
74         public String getQName();
75
76         /** LocalPart of current element. */
77         public String getLocalName();
78
79         /** Prefix of current element. Substring of qName. */
80         public String getPrefix();
81
82         /** URI of current tag. */
83         public String getUri();
84     }
85
86     /** Represents a collection of attributes and their associated
87      *  namespace URIs.
88      *
89      *  <p>Prefix definition attributes are <b>not</b> included here.</p>
90      */
91     public static interface Attributes {
92         /** Returns the index of an attribute with the given qname. */
93         public int getIndex(String qname);
94
95         /** Returns the index of an attribute with the given uri and key. */
96         public int getIndex(String uri, String key);
97
98         /** Returns the name of the attribute with the given index. */
99         public String getKey(int index);
100
101         /** Returns the value of the attribute with the given index. */
102         public String getVal(int index);
103
104         /** Returns the uri of the attribute with the given index. */
105         public String getUri(int index);
106
107         /** Returns the prefix of the attribute with the given index. */
108         public String getPrefix(int index);
109
110         /** Returns the qname of the attribute with the given index. */
111         public String getQName(int index);
112
113         /** Returns number of attributes currently stored. */
114         public int attrSize();
115     }
116
117     /** Represents a collection of Namespace prefixes and their
118      *  associated URIs. */
119     public static interface Prefixes {
120         /** Returns the index of a prefix mapping with the given prefix. */
121         public int getPrefixIndexKey(String prefix);
122
123         /** Returns the index of a prefix mapping with the given uri. */
124         public int getPrefixIndexVal(String uri);
125
126         /** Returns the prefix of a prefix mapping with the given index. */
127         public String getPrefixKey(int i);
128
129         /** Returns the uri of a prefix mapping with the given index. */
130         public String getPrefixVal(int i);
131
132         /** Returns number of prefixes currently stored. */
133         public int pfxSize();
134     }
135 }