56 * @author G. Todd Miller
57 * @author Morten Jorensen
58 * @author Erwin Bolwidt <ejb@klomp.org>
59 * @author John Howard <JohnH@schemasoft.com>
60 */
61 public abstract class SyntaxTreeNode implements Constants {
62
63 // Reference to the AST parser
64 private Parser _parser;
65
66 // AST navigation pointers
67 protected SyntaxTreeNode _parent; // Parent node
68 private Stylesheet _stylesheet; // Stylesheet ancestor node
69 private Template _template; // Template ancestor node
70 private final List<SyntaxTreeNode> _contents = new ArrayList<>(2); // Child nodes
71
72 // Element description data
73 protected QName _qname; // The element QName
74 private int _line; // Source file line number
75 protected AttributesImpl _attributes = null; // Attributes of this element
76 private Map<String, String> _prefixMapping = null; // Namespace declarations
77
78 // Sentinel - used to denote unrecognised syntaxt tree nodes.
79 protected static final SyntaxTreeNode Dummy = new AbsolutePathPattern(null);
80
81 // These two are used for indenting nodes in the AST (debug output)
82 protected static final int IndentIncrement = 4;
83 private static final char[] _spaces =
84 " ".toCharArray();
85
86 /**
87 * Creates a new SyntaxTreeNode with a 'null' QName and no source file
88 * line number reference.
89 */
90 public SyntaxTreeNode() {
91 _line = 0;
92 _qname = null;
93 }
94
95 /**
96 * Creates a new SyntaxTreeNode with a 'null' QName.
811 * Returns the number of children this node has.
812 * @return Number of child nodes.
813 */
814 protected final int elementCount() {
815 return _contents.size();
816 }
817
818 /**
819 * Returns an Iterator of all child nodes of this node.
820 * @return An Iterator of all child nodes of this node.
821 */
822 protected final Iterator<SyntaxTreeNode> elements() {
823 return _contents.iterator();
824 }
825
826 /**
827 * Returns a child node at a given position.
828 * @param pos The child node's position.
829 * @return The child node.
830 */
831 protected final Object elementAt(int pos) {
832 return _contents.get(pos);
833 }
834
835 /**
836 * Returns this element's last child
837 * @return The child node.
838 */
839 protected final SyntaxTreeNode lastChild() {
840 if (_contents.isEmpty()) return null;
841 return (SyntaxTreeNode)_contents.get(_contents.size() - 1);
842 }
843
844 /**
845 * Displays the contents of this syntax tree node (to stdout).
846 * This method is intended for debugging _only_, and should be overridden
847 * by all syntax tree node implementations.
848 * @param indent Indentation level for syntax tree levels.
849 */
850 public void display(int indent) {
851 displayContents(indent);
|
56 * @author G. Todd Miller
57 * @author Morten Jorensen
58 * @author Erwin Bolwidt <ejb@klomp.org>
59 * @author John Howard <JohnH@schemasoft.com>
60 */
61 public abstract class SyntaxTreeNode implements Constants {
62
63 // Reference to the AST parser
64 private Parser _parser;
65
66 // AST navigation pointers
67 protected SyntaxTreeNode _parent; // Parent node
68 private Stylesheet _stylesheet; // Stylesheet ancestor node
69 private Template _template; // Template ancestor node
70 private final List<SyntaxTreeNode> _contents = new ArrayList<>(2); // Child nodes
71
72 // Element description data
73 protected QName _qname; // The element QName
74 private int _line; // Source file line number
75 protected AttributesImpl _attributes = null; // Attributes of this element
76 private Map<String, String> _prefixMapping = null; // Namespace declarations
77
78 // Sentinel - used to denote unrecognised syntaxt tree nodes.
79 protected static final SyntaxTreeNode Dummy = new AbsolutePathPattern(null);
80
81 // These two are used for indenting nodes in the AST (debug output)
82 protected static final int IndentIncrement = 4;
83 private static final char[] _spaces =
84 " ".toCharArray();
85
86 /**
87 * Creates a new SyntaxTreeNode with a 'null' QName and no source file
88 * line number reference.
89 */
90 public SyntaxTreeNode() {
91 _line = 0;
92 _qname = null;
93 }
94
95 /**
96 * Creates a new SyntaxTreeNode with a 'null' QName.
811 * Returns the number of children this node has.
812 * @return Number of child nodes.
813 */
814 protected final int elementCount() {
815 return _contents.size();
816 }
817
818 /**
819 * Returns an Iterator of all child nodes of this node.
820 * @return An Iterator of all child nodes of this node.
821 */
822 protected final Iterator<SyntaxTreeNode> elements() {
823 return _contents.iterator();
824 }
825
826 /**
827 * Returns a child node at a given position.
828 * @param pos The child node's position.
829 * @return The child node.
830 */
831 protected final SyntaxTreeNode elementAt(int pos) {
832 return _contents.get(pos);
833 }
834
835 /**
836 * Returns this element's last child
837 * @return The child node.
838 */
839 protected final SyntaxTreeNode lastChild() {
840 if (_contents.isEmpty()) return null;
841 return (SyntaxTreeNode)_contents.get(_contents.size() - 1);
842 }
843
844 /**
845 * Displays the contents of this syntax tree node (to stdout).
846 * This method is intended for debugging _only_, and should be overridden
847 * by all syntax tree node implementations.
848 * @param indent Indentation level for syntax tree levels.
849 */
850 public void display(int indent) {
851 displayContents(indent);
|