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.
7 import java.io.IOException;
8 import java.io.OutputStream;
11 public interface Tree {
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();
18 /** Set the parent of this leaf.
19 * @throws UnsupportedOperationException if this leaf is immutable. */
20 public void setParent(Tree.Node p) throws UnsupportedOperationException;
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;
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;
33 public interface Node extends Leaf {
34 /** Returns a list of children that all implement <tt>Tree.Leaf</tt>. */
35 public Basket.List getChildren();
38 public interface Stream {
39 /** Returns the number of <tt>Leaf</tt>s that can be read before blocking. */
40 public int available();
42 /** Return the current node depth in the tree. <tt>0</tt> at root node. */
43 public int getDepth();
45 /** Returns the next leaf in the tree, or null if at the end. */
46 public Leaf next() throws IOException;
48 /** Skip the next leaf and its subtree. */
49 public void skip() throws IOException;
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();
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();
64 /** Set the object to act as an attribute source. */
65 public void setAttributes(Attributes a);
67 /** Set the object to act as a prefix source. */
68 public void setPrefixes(Prefixes a);
70 /** Returns a List of children that all implement <tt>Tree.Leaf</tt>. */
71 public Basket.List getChildren();
73 /** Qualified Name of current element. */
74 public String getQName();
76 /** LocalPart of current element. */
77 public String getLocalName();
79 /** Prefix of current element. Substring of qName. */
80 public String getPrefix();
82 /** URI of current tag. */
83 public String getUri();
86 /** Represents a collection of attributes and their associated
89 * <p>Prefix definition attributes are <b>not</b> included here.</p>
91 public static interface Attributes {
92 /** Returns the index of an attribute with the given qname. */
93 public int getIndex(String qname);
95 /** Returns the index of an attribute with the given uri and key. */
96 public int getIndex(String uri, String key);
98 /** Returns the name of the attribute with the given index. */
99 public String getKey(int index);
101 /** Returns the value of the attribute with the given index. */
102 public String getVal(int index);
104 /** Returns the uri of the attribute with the given index. */
105 public String getUri(int index);
107 /** Returns the prefix of the attribute with the given index. */
108 public String getPrefix(int index);
110 /** Returns the qname of the attribute with the given index. */
111 public String getQName(int index);
113 /** Returns number of attributes currently stored. */
114 public int attrSize();
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);
123 /** Returns the index of a prefix mapping with the given uri. */
124 public int getPrefixIndexVal(String uri);
126 /** Returns the prefix of a prefix mapping with the given index. */
127 public String getPrefixKey(int i);
129 /** Returns the uri of a prefix mapping with the given index. */
130 public String getPrefixVal(int i);
132 /** Returns number of prefixes currently stored. */
133 public int pfxSize();