00001
00002
00003 package org.objectweb.jonas_ejb.deployment.ejbql;
00004
00005
00006 import java.util.ArrayList;
00007 import java.util.Iterator;
00008
00015 public class SimpleNode implements Node {
00016 protected Node parent;
00017 protected Node[] children;
00018 protected int id;
00019 protected EJBQL parser;
00020
00021
00022 public ArrayList ops=new ArrayList();
00023 public Object value = null;
00024 public boolean distinct = false;
00025 public boolean not = false;
00026 public boolean third = false;
00027 public int eltnum = 0;
00028 public boolean asc = true;
00029
00030
00031 public SimpleNode(int i) {
00032 id = i;
00033 }
00034
00035 public SimpleNode(EJBQL p, int i) {
00036 this(i);
00037 parser = p;
00038 }
00039
00040 public void jjtOpen() {
00041 }
00042
00043 public void jjtClose() {
00044 }
00045
00046 public void jjtSetParent(Node n) { parent = n; }
00047 public Node jjtGetParent() { return parent; }
00048
00049 public void jjtAddChild(Node n, int i) {
00050 if (children == null) {
00051 children = new Node[i + 1];
00052 } else if (i >= children.length) {
00053 Node c[] = new Node[i + 1];
00054 System.arraycopy(children, 0, c, 0, children.length);
00055 children = c;
00056 }
00057 children[i] = n;
00058 }
00059
00060 public Node jjtGetChild(int i) {
00061 return children[i];
00062 }
00063
00064 public int jjtGetNumChildren() {
00065 return (children == null) ? 0 : children.length;
00066 }
00067
00069 public Object jjtAccept(EJBQLVisitor visitor, Object data) {
00070 return visitor.visit(this, data);
00071 }
00072
00074 public Object childrenAccept(EJBQLVisitor visitor, Object data) {
00075 if (children != null) {
00076 for (int i = 0; i < children.length; ++i) {
00077 children[i].jjtAccept(visitor, data);
00078 }
00079 }
00080 return data;
00081 }
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091 public String toString() {
00092 String ret = "";
00093 if (not) ret+="NOT ";
00094 if (distinct) ret+="DISTINCT ";
00095 if (asc) {
00096 ret+="ASC ";
00097 } else {
00098 ret+="DESC ";
00099 }
00100
00101 if (ops.size()!=0) {
00102 ret+="(";
00103 for (Iterator i = ops.iterator(); i.hasNext();) {
00104 String token=EJBQLConstants.tokenImage[((Integer)i.next()).intValue()];
00105 ret+=token.substring(1,token.length()-1)+",";
00106 }
00107 ret = ret.substring(0,ret.length()-1);
00108 }
00109 if (value!=null) ret+=value;
00110 if (ops.size()!=0) ret+=")";
00111 return EJBQLTreeConstants.jjtNodeName[id]+" "+ret;
00112 }
00113
00114 public String toString(String prefix) { return prefix + toString(); }
00115
00116
00117
00118
00119 public void dump(String prefix) {
00120 System.out.println(toString(prefix));
00121 if (children != null) {
00122 for (int i = 0; i < children.length; ++i) {
00123 SimpleNode n = (SimpleNode)children[i];
00124 if (n != null) {
00125 n.dump(prefix + " ");
00126 }
00127 }
00128 }
00129 }
00130 }
00131