+// Copyright 2000-2005 the Contributors, as shown in the revision logs.
+// Licensed under the Apache Public Source License 2.0 ("the License").
+// You may not use this file except in compliance with the License.
+
+package org.ibex.util;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.Writer;
+
+public interface Tree {
+
+ /** Represents a primitive block of a Tree. */
+ public interface Leaf {
+ /** Return the parent Node of the current leaf. */
+ public Node getParent();
+
+ /** Set the parent of this leaf.
+ * @throws UnsupportedOperationException if this leaf is immutable. */
+ public void setParent(Tree.Node p) throws UnsupportedOperationException;
+
+ /** Writes a character representation of this leaf.
+ * @throws UnsupportedOperationException if this leaf has no character representation.
+ * @throws IOException */
+ public void out(Writer out) throws IOException, UnsupportedOperationException;
+
+ /** Writes a byte representation of this leaf.
+ * @throws UnsupportedOperationException if this leaf has no byte representation.
+ * @throws IOException */
+ public void out(OutputStream out) throws IOException, UnsupportedOperationException;
+ }
+
+ public interface Node extends Leaf {
+ /** Returns a list of children that all implement <tt>Tree.Leaf</tt>. */
+ public Basket.List getChildren();
+ }
+
+ public interface Stream {
+ /** Returns the number of <tt>Leaf</tt>s that can be read before blocking. */
+ public int available();
+
+ /** Return the current node depth in the tree. <tt>0</tt> at root node. */
+ public int getDepth();
+
+ /** Returns the next leaf in the tree, or null if at the end. */
+ public Leaf next() throws IOException;
+
+ /** Skip the next leaf and its subtree. */
+ public void skip() throws IOException;
+ }
+
+
+ /** Represents an element in an document, containing
+ * attributes and child elements. */
+ public interface Element extends Node {
+ /** Returns the attributes of this element in the form of
+ * an <tt>Tree.Attributes</tt> object. */
+ public Attributes getAttributes();
+
+ /** Returns the prefix/uri mappings created in this element
+ * in the form of an <tt>Tree.Prefixes</tt> object. */
+ public Prefixes getPrefixes();
+
+ /** Set the object to act as an attribute source. */
+ public void setAttributes(Attributes a);
+
+ /** Set the object to act as a prefix source. */
+ public void setPrefixes(Prefixes a);
+
+ /** Returns a List of children that all implement <tt>Tree.Leaf</tt>. */
+ public Basket.List getChildren();
+
+ /** Qualified Name of current element. */
+ public String getQName();
+
+ /** LocalPart of current element. */
+ public String getLocalName();
+
+ /** Prefix of current element. Substring of qName. */
+ public String getPrefix();
+
+ /** URI of current tag. */
+ public String getUri();
+ }
+
+ /** Represents a collection of attributes and their associated
+ * namespace URIs.
+ *
+ * <p>Prefix definition attributes are <b>not</b> included here.</p>
+ */
+ public static interface Attributes {
+ /** Returns the index of an attribute with the given qname. */
+ public int getIndex(String qname);
+
+ /** Returns the index of an attribute with the given uri and key. */
+ public int getIndex(String uri, String key);
+
+ /** Returns the name of the attribute with the given index. */
+ public String getKey(int index);
+
+ /** Returns the value of the attribute with the given index. */
+ public String getVal(int index);
+
+ /** Returns the uri of the attribute with the given index. */
+ public String getUri(int index);
+
+ /** Returns the prefix of the attribute with the given index. */
+ public String getPrefix(int index);
+
+ /** Returns the qname of the attribute with the given index. */
+ public String getQName(int index);
+
+ /** Returns number of attributes currently stored. */
+ public int attrSize();
+ }
+
+ /** Represents a collection of Namespace prefixes and their
+ * associated URIs. */
+ public static interface Prefixes {
+ /** Returns the index of a prefix mapping with the given prefix. */
+ public int getPrefixIndexKey(String prefix);
+
+ /** Returns the index of a prefix mapping with the given uri. */
+ public int getPrefixIndexVal(String uri);
+
+ /** Returns the prefix of a prefix mapping with the given index. */
+ public String getPrefixKey(int i);
+
+ /** Returns the uri of a prefix mapping with the given index. */
+ public String getPrefixVal(int i);
+
+ /** Returns number of prefixes currently stored. */
+ public int pfxSize();
+ }
+}