1 /* Generated By:JJTree: Do not edit this line. SimpleNode.java */
2
3 package mobisnap.mobile_trx;
4
5 public class SimpleNode implements Node {
6 protected Node parent;
7 protected Node[] children;
8 protected int id;
9 protected MobisnapSQL parser;
10
11 public SimpleNode(int i) {
12 id = i;
13 }
14
15 public SimpleNode(MobisnapSQL p, int i) {
16 this(i);
17 parser = p;
18 }
19
20 public void jjtOpen() {
21 }
22
23 public void jjtClose() {
24 }
25
26 public void jjtSetParent(Node n) { parent = n; }
27 public Node jjtGetParent() { return parent; }
28
29 public void jjtAddChild(Node n, int i) {
30 if (children == null) {
31 children = new Node[i + 1];
32 } else if (i >= children.length) {
33 Node c[] = new Node[i + 1];
34 System.arraycopy(children, 0, c, 0, children.length);
35 children = c;
36 }
37 children[i] = n;
38 }
39
40 public Node jjtGetChild(int i) {
41 return children[i];
42 }
43
44 public int jjtGetNumChildren() {
45 return (children == null) ? 0 : children.length;
46 }
47
48 /*** Accept the visitor. **/
49 public Object jjtAccept(MobisnapSQLVisitor visitor, Object data) {
50 return visitor.visit( this, data);
51 }
52
53 /*** Accept the visitor. **/
54 public Object childrenAccept( MobisnapSQLVisitor visitor, Object data) {
55 if (children != null) {
56 for (int i = 0; i < children.length; ++i) {
57 children[i].jjtAccept(visitor, data);
58 }
59 }
60 return data;
61 }
62
63 /* You can override these two methods in subclasses of SimpleNode to
64 customize the way the node appears when the tree is dumped. If
65 your output uses more than one line you should override
66 toString(String), otherwise overriding toString() is probably all
67 you need to do. */
68
69 // public String toString() { return MobisnapSQLTreeConstants.jjtNodeName[id]; }
70 public String toString(String prefix) { return prefix + toString(); }
71 public String toString() {
72 return toString( mobisnap.MobisnapConstants.MSQL_SERVER);
73 }
74
75 public String toString( int msql_type) {
76 try {
77 StringBuffer buf = new StringBuffer();
78 sourceCode( msql_type, buf);
79 return buf.toString();
80 } catch( Exception e) {
81 e.printStackTrace();
82 return "Exception";
83 }
84 }
85
86 /* Override this method if you want to customize how the node dumps
87 out its children. */
88
89 public void dump(String prefix) {
90 System.out.println(toString(prefix));
91 if (children != null) {
92 for (int i = 0; i < children.length; ++i) {
93 SimpleNode n = (SimpleNode)children[i];
94 if (n != null) {
95 n.dump(prefix + " ");
96 }
97 }
98 }
99 }
100
101
102 // Manually inserted code begins here
103
104 // public Token firstToken, lastToken;
105
106 /***
107 * Process the given node, interpreting the source code
108 *
109 * @param msql_type Specifies which type of processing should be performed
110 * MobisnapConstants.MSQL_SERVER = 1
111 * MobisnapConstants.MSQL_TENTATIVE_CLIENT = 2
112 * MobisnapConstants.MSQL_STABLE_CLIENT = 3
113 */
114 public void process( int msql_type) throws Exception {
115 if( children != null)
116 for( int i = 0; i < children.length; i++)
117 if( children[i] instanceof SimpleNode)
118 ((SimpleNode)children[i]).process( msql_type);
119 }
120
121 /***
122 * Returns the value of the expression
123 *
124 * @param msql_type Specifies which type of processing should be performed
125 * MobisnapConstants.MSQL_SERVER = 1
126 * MobisnapConstants.MSQL_TENTATIVE_CLIENT = 2
127 * MobisnapConstants.MSQL_STABLE_CLIENT = 3
128 * MobisnapConstants.MSQL_RESERVATION_CLIENT = 4
129 * @param cond True if reservations associated iwth transaction should be
130 * propagated to the current transaction
131 */
132 public Object value( int msql_type, boolean cond) throws Exception {
133 return new mobisnap.MobisnapException( "Node has no value");
134 }
135
136 /***
137 * Returns a simplified node, if possible (usefull in expressions)
138 *
139 * @param msql_type Specifies which type of processing should be performed
140 * MobisnapConstants.MSQL_SERVER = 1
141 * MobisnapConstants.MSQL_TENTATIVE_CLIENT = 2
142 * MobisnapConstants.MSQL_STABLE_CLIENT = 3
143 * MobisnapConstants.MSQL_RESERVATION_CLIENT = 4
144 * @param cond True if reservations associated iwth transaction should be
145 * propagated to the current transaction
146 */
147 public SimpleNode simplify( int msql_type, boolean cond) {
148 return this;
149 }
150
151
152 // Code used to rebuild the source code
153
154 public Token firstToken, lastToken;
155
156 /***
157 * Displays the source code of the node
158 *
159 * @param msql_type Specifies which type of processing should be performed
160 * MobisnapConstants.MSQL_SERVER = 1
161 * MobisnapConstants.MSQL_TENTATIVE_CLIENT = 2
162 * MobisnapConstants.MSQL_STABLE_CLIENT = 3
163 */
164 public void sourceCode( int msql_type, StringBuffer buffer) throws Exception {
165 Token t = firstToken;
166 boolean allPrinted = false;
167 for ( int i = 0; i < jjtGetNumChildren(); i++) {
168 SimpleNodeAux sna = sourceNode0( i, t, msql_type, buffer);
169 t = sna.nextToken;
170 allPrinted = sna.allPrinted;
171 }
172 while ( ! allPrinted && t != null) {
173 if( t == lastToken)
174 allPrinted = true;
175 sourceCode( t, msql_type, buffer);
176 t = t.next;
177 }
178 }
179
180 // The following method prints token t, as well as all preceding
181 // special tokens (essentially, white space and comments).
182
183 public void sourceCodeSpecial(Token t, int msql_type, StringBuffer buffer) {
184 Token tt = t.specialToken;
185 if (tt != null) {
186 while (tt.specialToken != null) tt = tt.specialToken;
187 while (tt != null) {
188 if( buffer != null)
189 buffer.append(addUnicodeEscapes(tt.image));
190 tt = tt.next;
191 }
192 }
193 }
194
195 public void sourceCode( Token t, int msql_type, StringBuffer buffer) {
196 sourceCodeSpecial( t, msql_type, buffer);
197 if( buffer != null)
198 buffer.append( addUnicodeEscapes(t.image));
199 }
200
201
202 /***
203 * NOTE: Returns the next token to be printed
204 */
205 public SimpleNodeAux sourceNode0( int pos, Token t, int msql_type, StringBuffer buffer) throws Exception {
206 SimpleNode node = (SimpleNode)jjtGetChild(pos);
207 if( pos + 1 < jjtGetNumChildren() && ((SimpleNode)jjtGetChild( pos + 1)).firstToken == firstToken)
208 return new SimpleNodeAux( t, false);
209 while( t != null && t != node.firstToken) {
210 sourceCode( t, msql_type, buffer);
211 t = t.next;
212 }
213 node.sourceCode( msql_type, buffer);
214 return new SimpleNodeAux( node.lastToken.next, node.lastToken == lastToken);
215 }
216
217 public String addUnicodeEscapes(String str) {
218 String retval = "";
219 char ch;
220 for (int i = 0; i < str.length(); i++) {
221 ch = str.charAt(i);
222 if ((ch < 0x20 || ch > 0x7e) && ch != '\t' && ch != '\n' && ch != '\r' && ch != '\f') {
223 String s = "0000" + Integer.toString(ch, 16);
224 retval += "//u" + s.substring(s.length() - 4, s.length());
225 } else {
226 retval += ch;
227 }
228 }
229 return retval;
230 }
231
232 }
233
This page was automatically generated by Maven