001: package org.obe.sql;
002:
003: import java.io.IOException;
004: import java.io.Writer;
005:
006: public class SimpleNode implements Node, SQLParserTreeConstants {
007: protected Node parent;
008: protected Node[] children;
009: protected int id;
010: protected SQLParser parser;
011: protected String text;
012:
013: public static SimpleNode jjtCreate(int id) {
014: SimpleNode node;
015: switch (id) {
016: case JJTSQLANDEXPR:
017: node = new SQLAndExpr(id);
018: break;
019: case JJTSQLBETWEENCLAUSE:
020: node = new SQLBetweenClause(id);
021: break;
022: case JJTSQLCOLREF:
023: node = new SQLColRef(id);
024: break;
025: case JJTSQLCOMPAREEXPR:
026: node = new SQLCompareExpr(id);
027: break;
028: case JJTSQLCOMPAREEXPRRIGHT:
029: node = new SQLCompareExprRight(id);
030: break;
031: case JJTSQLCOMPAREOP:
032: node = new SQLCompareOp(id);
033: break;
034: // case JJTSQLCURSORARGS:
035: // case JJTSQLCURSORCLOSE:
036: // case JJTSQLDATATYPE:
037: // case JJTSQLDELETE:
038: // case JJTSQLEXISTSCLAUSE:
039: // case JJTSQLFUNCTION:
040: // node = new SQLFunction(id);
041: // break;
042: // case JJTSQLFUNCTIONARGS:
043: // node = new SQLFunctionArgs(id);
044: // break;
045: // case JJTSQLGROUPBY:
046: case JJTSQLINCLAUSE:
047: node = new SQLInClause(id);
048: break;
049: // case JJTSQLINSERT:
050: case JJTSQLISCLAUSE:
051: node = new SQLIsClause(id);
052: break;
053: // case JJTSQLLEFTJOINCLAUSE:
054: case JJTSQLLIKECLAUSE:
055: node = new SQLLikeClause(id);
056: break;
057: case JJTSQLLITERAL:
058: node = new SQLLiteral(id);
059: break;
060: case JJTSQLLVALUE:
061: node = new SQLLvalue(id);
062: break;
063: case JJTSQLLVALUETERM:
064: node = new SQLLvalueTerm(id);
065: break;
066: case JJTSQLNOTEXPR:
067: node = new SQLNotExpr(id);
068: break;
069: // case JJTSQLORDERBY:
070: // case JJTSQLORDERBYELEM:
071: // case JJTSQLORDERBYLIST:
072: // case JJTSQLORDERDIRECTION:
073: case JJTSQLOREXPR:
074: node = new SQLOrExpr(id);
075: break;
076: case JJTSQLPATTERN:
077: node = new SQLPattern(id);
078: break;
079: case JJTSQLPRODUCTEXPR:
080: node = new SQLProductExpr(id);
081: break;
082: // case JJTSQLRIGHTJOINCLAUSE:
083: // case JJTSQLSELECT:
084: // case JJTSQLSELECTCOLS:
085: // case JJTSQLSELECTLIST:
086: // case JJTSQLSTATEMENT:
087: case JJTSQLSUMEXPR:
088: node = new SQLSumExpr(id);
089: break;
090: // case JJTSQLTABLELIST:
091: // case JJTSQLTABLEREF:
092: case JJTSQLTERM:
093: node = new SQLTerm(id);
094: break;
095: case JJTSQLUNARYEXPR:
096: node = new SQLUnaryExpr(id);
097: break;
098: // case JJTSQLUPDATE:
099: // case JJTSQLUPDATEASSIGNMENT:
100: case JJTSQLLVALUEELEMENT:
101: node = new SQLLValueElement(id);
102: break;
103: case JJTSQLLVALUELIST:
104: node = new SQLLValueList(id);
105: break;
106: // case JJTSQLWHERE:
107: default:
108: node = new SimpleNode(id);
109: }
110: return node;
111: }
112:
113: public SimpleNode(int i) {
114: id = i;
115: text = SQLParserTreeConstants.jjtNodeName[i];
116: }
117:
118: public SimpleNode(SQLParser p, int i) {
119: this (i);
120: parser = p;
121: }
122:
123: public int getId() {
124: return id;
125: }
126:
127: public String getText() {
128: return text;
129: }
130:
131: public void setText(String text) {
132: this .text = text;
133: }
134:
135: public void jjtOpen() {
136: }
137:
138: public void jjtClose() {
139: }
140:
141: public void jjtSetParent(Node n) {
142: parent = n;
143: }
144:
145: public Node jjtGetParent() {
146: return parent;
147: }
148:
149: public void jjtAddChild(Node n, int i) {
150: if (children == null) {
151: children = new Node[i + 1];
152: } else if (i >= children.length) {
153: Node c[] = new Node[i + 1];
154: System.arraycopy(children, 0, c, 0, children.length);
155: children = c;
156: }
157: children[i] = n;
158: }
159:
160: public Node jjtGetChild(int i) {
161: return children[i];
162: }
163:
164: public int jjtGetNumChildren() {
165: return children == null ? 0 : children.length;
166: }
167:
168: /** Accept the visitor. **/
169: public Object jjtAccept(SQLParserVisitor visitor, Object data) {
170: return visitor.visit(this , data);
171: }
172:
173: /** Accept the visitor. **/
174: public Object childrenAccept(SQLParserVisitor visitor, Object data) {
175: if (children != null) {
176: for (int i = 0; i < children.length; ++i)
177: children[i].jjtAccept(visitor, data);
178: }
179: return data;
180: }
181:
182: /* You can override these two methods in subclasses of SimpleNode to
183: customize the way the node appears when the tree is dumped. If
184: your output uses more than one line you should override
185: toString(String), otherwise overriding toString() is probably all
186: you need to do. */
187:
188: public String toString() {
189: return SQLParserTreeConstants.jjtNodeName[id];
190: }
191:
192: public String toString(String prefix) {
193: return prefix + toString();
194: }
195:
196: /* Override this method if you want to customize how the node dumps
197: out its children. */
198:
199: public void dump(String prefix) {
200: System.out.println(prefix + this );
201: if (children != null) {
202: prefix += ' ';
203: for (int i = 0; i < children.length; ++i) {
204: SimpleNode n = (SimpleNode) children[i];
205: if (n != null)
206: n.dump(prefix);
207: }
208: }
209: }
210:
211: public void invert() {
212: throw new UnsupportedOperationException("invert");
213: }
214:
215: public void addOperator(String name) {
216: throw new UnsupportedOperationException("addOperator");
217: }
218:
219: public void addPathElement(String name) {
220: throw new UnsupportedOperationException("addPathElement");
221: }
222:
223: public void setName(String name) {
224: throw new UnsupportedOperationException("setName");
225: }
226:
227: public void setString(String name) {
228: throw new UnsupportedOperationException("setString");
229: }
230:
231: public void setInteger(String name) {
232: throw new UnsupportedOperationException("setInteger");
233: }
234:
235: public void setDouble(String name) {
236: throw new UnsupportedOperationException("setDouble");
237: }
238:
239: public void setParameter() {
240: throw new UnsupportedOperationException("setParameter");
241: }
242:
243: public boolean isParameter() {
244: throw new UnsupportedOperationException("isParameter");
245: }
246:
247: public void write(Writer out) throws IOException {
248: if (children != null) {
249: for (int i = 0; i < children.length; ++i) {
250: SimpleNode n = (SimpleNode) children[i];
251: if (n != null)
252: n.write(out);
253: }
254: }
255: }
256:
257: public Object execute(Object context) {
258: throw new UnsupportedOperationException();
259: }
260:
261: public Object execute(Object context, Object lhs) {
262: throw new UnsupportedOperationException(toString());
263: }
264:
265: public Object execute(Object context, Object lhs, Object rhs) {
266: throw new UnsupportedOperationException(toString());
267: }
268: }
|