001: /* Generated By:JJTree: Do not edit this line. SimpleNode.java */
002:
003: package org.objectweb.speedo.query.jdo.parser;
004:
005: import java.util.ArrayList;
006: import java.util.Iterator;
007:
008: public class SimpleNode implements Node {
009: protected Node parent;
010: protected Node[] children;
011: protected int id;
012: protected SpeedoQL parser;
013:
014: // added by S. Chassande-Barrioz
015: public ArrayList ops = new ArrayList(); //operators
016: public Object value = null;
017:
018: // end added
019:
020: public SimpleNode(int i) {
021: id = i;
022: }
023:
024: public SimpleNode(SpeedoQL p, int i) {
025: this (i);
026: parser = p;
027: }
028:
029: public void jjtOpen() {
030: }
031:
032: public void jjtClose() {
033: }
034:
035: public void jjtSetParent(Node n) {
036: parent = n;
037: }
038:
039: public Node jjtGetParent() {
040: return parent;
041: }
042:
043: public void jjtAddChild(Node n, int i) {
044: if (children == null) {
045: children = new Node[i + 1];
046: } else if (i >= children.length) {
047: Node c[] = new Node[i + 1];
048: System.arraycopy(children, 0, c, 0, children.length);
049: children = c;
050: }
051: children[i] = n;
052: }
053:
054: public Node jjtGetChild(int i) {
055: return children[i];
056: }
057:
058: public int jjtGetNumChildren() {
059: return (children == null) ? 0 : children.length;
060: }
061:
062: /* You can override these two methods in subclasses of SimpleNode to
063: customize the way the node appears when the tree is dumped. If
064: your output uses more than one line you should override
065: toString(String), otherwise overriding toString() is probably all
066: you need to do. */
067:
068: public String toString() {
069: String ret = "";
070:
071: if (ops.size() != 0) {
072: ret += "(";
073: for (Iterator i = ops.iterator(); i.hasNext();) {
074: String token = SpeedoQLConstants.tokenImage[((Integer) i
075: .next()).intValue()];
076: ret += token.substring(1, token.length() - 1) + ",";
077: //ret+=token+",";
078: }
079: ret = ret.substring(0, ret.length() - 1);
080: }
081: if (value != null)
082: ret += "value=[" + value + "]";
083: if (ops.size() != 0)
084: ret += ")";
085: return SpeedoQLTreeConstants.jjtNodeName[id] + " " + ret;
086: }
087:
088: public String toString(String prefix) {
089: return prefix + toString();
090: }
091:
092: /* Override this method if you want to customize how the node dumps
093: out its children. */
094:
095: public void dump(String prefix) {
096: System.out.println(toString(prefix));
097: if (children != null) {
098: for (int i = 0; i < children.length; ++i) {
099: SimpleNode n = (SimpleNode) children[i];
100: if (n != null) {
101: n.dump(prefix + " ");
102: }
103: }
104: }
105: }
106:
107: /** Accept the visitor. **/
108: public Object jjtAccept(SpeedoQLVisitor visitor, Object data) {
109: return visitor.visit(this , data);
110: }
111:
112: /** Accept the visitor. **/
113: public Object childrenAccept(SpeedoQLVisitor visitor, Object data) {
114: if (children != null) {
115: for (int i = 0; i < children.length; ++i) {
116: children[i].jjtAccept(visitor, data);
117: }
118: }
119: return data;
120: }
121: }
|