001 /* Generated By:JJTree: Do not edit this line. SimpleNode.java */
002
003 package net.sourceforge.javajson.parser;
004
005 public class SimpleNode extends net.sourceforge.javajson.parser.MyNode implements Node {
006 protected Node parent;
007 protected Node[] children;
008 protected int id;
009 protected JsonParser parser;
010
011 public SimpleNode(int i) {
012 id = i;
013 }
014
015 public SimpleNode(JsonParser p, int i) {
016 this(i);
017 parser = p;
018 }
019
020 public void jjtOpen() {
021 }
022
023 public void jjtClose() {
024 }
025
026 public void jjtSetParent(Node n) { parent = n; }
027 public Node jjtGetParent() { return parent; }
028
029 public void jjtAddChild(Node n, int i) {
030 if (children == null) {
031 children = new Node[i + 1];
032 } else if (i >= children.length) {
033 Node c[] = new Node[i + 1];
034 System.arraycopy(children, 0, c, 0, children.length);
035 children = c;
036 }
037 children[i] = n;
038 }
039
040 public Node jjtGetChild(int i) {
041 return children[i];
042 }
043
044 public int jjtGetNumChildren() {
045 return (children == null) ? 0 : children.length;
046 }
047
048 /* You can override these two methods in subclasses of SimpleNode to
049 customize the way the node appears when the tree is dumped. If
050 your output uses more than one line you should override
051 toString(String), otherwise overriding toString() is probably all
052 you need to do. */
053
054 public String toString() { return JsonParserTreeConstants.jjtNodeName[id]; }
055 public String toString(String prefix) { return prefix + toString(); }
056
057 /* Override this method if you want to customize how the node dumps
058 out its children. */
059
060 public void dump(String prefix) {
061 System.out.println(toString(prefix));
062 if (children != null) {
063 for (int i = 0; i < children.length; ++i) {
064 SimpleNode n = (SimpleNode)children[i];
065 if (n != null) {
066 n.dump(prefix + " ");
067 }
068 }
069 }
070 }
071 }
072