1
|
|
|
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
|
0
|
public SimpleNode(int i) {
|
12
|
0
|
id = i;
|
13
|
|
}
|
14
|
|
|
15
|
0
|
public SimpleNode(MobisnapSQL p, int i) {
|
16
|
0
|
this(i);
|
17
|
0
|
parser = p;
|
18
|
|
}
|
19
|
|
|
20
|
0
|
public void jjtOpen() {
|
21
|
|
}
|
22
|
|
|
23
|
0
|
public void jjtClose() {
|
24
|
|
}
|
25
|
|
|
26
|
0
|
public void jjtSetParent(Node n) { parent = n; }
|
27
|
0
|
public Node jjtGetParent() { return parent; }
|
28
|
|
|
29
|
0
|
public void jjtAddChild(Node n, int i) {
|
30
|
0
|
if (children == null) {
|
31
|
0
|
children = new Node[i + 1];
|
32
|
0
|
} else if (i >= children.length) {
|
33
|
0
|
Node c[] = new Node[i + 1];
|
34
|
0
|
System.arraycopy(children, 0, c, 0, children.length);
|
35
|
0
|
children = c;
|
36
|
|
}
|
37
|
0
|
children[i] = n;
|
38
|
|
}
|
39
|
|
|
40
|
0
|
public Node jjtGetChild(int i) {
|
41
|
0
|
return children[i];
|
42
|
|
}
|
43
|
|
|
44
|
0
|
public int jjtGetNumChildren() {
|
45
|
0
|
return (children == null) ? 0 : children.length;
|
46
|
|
}
|
47
|
|
|
48
|
|
|
49
|
0
|
public Object jjtAccept(MobisnapSQLVisitor visitor, Object data) {
|
50
|
0
|
return visitor.visit( this, data);
|
51
|
|
}
|
52
|
|
|
53
|
|
|
54
|
0
|
public Object childrenAccept( MobisnapSQLVisitor visitor, Object data) {
|
55
|
0
|
if (children != null) {
|
56
|
0
|
for (int i = 0; i < children.length; ++i) {
|
57
|
0
|
children[i].jjtAccept(visitor, data);
|
58
|
|
}
|
59
|
|
}
|
60
|
0
|
return data;
|
61
|
|
}
|
62
|
|
|
63
|
|
|
64
|
|
|
65
|
|
|
66
|
|
|
67
|
|
|
68
|
|
|
69
|
|
|
70
|
0
|
public String toString(String prefix) { return prefix + toString(); }
|
71
|
0
|
public String toString() {
|
72
|
0
|
return toString( mobisnap.MobisnapConstants.MSQL_SERVER);
|
73
|
|
}
|
74
|
|
|
75
|
0
|
public String toString( int msql_type) {
|
76
|
0
|
try {
|
77
|
0
|
StringBuffer buf = new StringBuffer();
|
78
|
0
|
sourceCode( msql_type, buf);
|
79
|
0
|
return buf.toString();
|
80
|
|
} catch( Exception e) {
|
81
|
0
|
e.printStackTrace();
|
82
|
0
|
return "Exception";
|
83
|
|
}
|
84
|
|
}
|
85
|
|
|
86
|
|
|
87
|
|
|
88
|
|
|
89
|
0
|
public void dump(String prefix) {
|
90
|
0
|
System.out.println(toString(prefix));
|
91
|
0
|
if (children != null) {
|
92
|
0
|
for (int i = 0; i < children.length; ++i) {
|
93
|
0
|
SimpleNode n = (SimpleNode)children[i];
|
94
|
0
|
if (n != null) {
|
95
|
0
|
n.dump(prefix + " ");
|
96
|
|
}
|
97
|
|
}
|
98
|
|
}
|
99
|
|
}
|
100
|
|
|
101
|
|
|
102
|
|
|
103
|
|
|
104
|
|
|
105
|
|
|
106
|
|
|
107
|
|
|
108
|
|
|
109
|
|
|
110
|
|
|
111
|
|
|
112
|
|
|
113
|
|
|
114
|
0
|
public void process( int msql_type) throws Exception {
|
115
|
0
|
if( children != null)
|
116
|
0
|
for( int i = 0; i < children.length; i++)
|
117
|
0
|
if( children[i] instanceof SimpleNode)
|
118
|
0
|
((SimpleNode)children[i]).process( msql_type);
|
119
|
|
}
|
120
|
|
|
121
|
|
|
122
|
|
|
123
|
|
|
124
|
|
|
125
|
|
|
126
|
|
|
127
|
|
|
128
|
|
|
129
|
|
|
130
|
|
|
131
|
|
|
132
|
0
|
public Object value( int msql_type, boolean cond) throws Exception {
|
133
|
0
|
return new mobisnap.MobisnapException( "Node has no value");
|
134
|
|
}
|
135
|
|
|
136
|
|
|
137
|
|
|
138
|
|
|
139
|
|
|
140
|
|
|
141
|
|
|
142
|
|
|
143
|
|
|
144
|
|
|
145
|
|
|
146
|
|
|
147
|
0
|
public SimpleNode simplify( int msql_type, boolean cond) {
|
148
|
0
|
return this;
|
149
|
|
}
|
150
|
|
|
151
|
|
|
152
|
|
|
153
|
|
|
154
|
|
public Token firstToken, lastToken;
|
155
|
|
|
156
|
|
|
157
|
|
|
158
|
|
|
159
|
|
|
160
|
|
|
161
|
|
|
162
|
|
|
163
|
|
|
164
|
0
|
public void sourceCode( int msql_type, StringBuffer buffer) throws Exception {
|
165
|
0
|
Token t = firstToken;
|
166
|
0
|
boolean allPrinted = false;
|
167
|
0
|
for ( int i = 0; i < jjtGetNumChildren(); i++) {
|
168
|
0
|
SimpleNodeAux sna = sourceNode0( i, t, msql_type, buffer);
|
169
|
0
|
t = sna.nextToken;
|
170
|
0
|
allPrinted = sna.allPrinted;
|
171
|
|
}
|
172
|
0
|
while ( ! allPrinted && t != null) {
|
173
|
0
|
if( t == lastToken)
|
174
|
0
|
allPrinted = true;
|
175
|
0
|
sourceCode( t, msql_type, buffer);
|
176
|
0
|
t = t.next;
|
177
|
|
}
|
178
|
|
}
|
179
|
|
|
180
|
|
|
181
|
|
|
182
|
|
|
183
|
0
|
public void sourceCodeSpecial(Token t, int msql_type, StringBuffer buffer) {
|
184
|
0
|
Token tt = t.specialToken;
|
185
|
0
|
if (tt != null) {
|
186
|
0
|
while (tt.specialToken != null) tt = tt.specialToken;
|
187
|
0
|
while (tt != null) {
|
188
|
0
|
if( buffer != null)
|
189
|
0
|
buffer.append(addUnicodeEscapes(tt.image));
|
190
|
0
|
tt = tt.next;
|
191
|
|
}
|
192
|
|
}
|
193
|
|
}
|
194
|
|
|
195
|
0
|
public void sourceCode( Token t, int msql_type, StringBuffer buffer) {
|
196
|
0
|
sourceCodeSpecial( t, msql_type, buffer);
|
197
|
0
|
if( buffer != null)
|
198
|
0
|
buffer.append( addUnicodeEscapes(t.image));
|
199
|
|
}
|
200
|
|
|
201
|
|
|
202
|
|
|
203
|
|
|
204
|
|
|
205
|
0
|
public SimpleNodeAux sourceNode0( int pos, Token t, int msql_type, StringBuffer buffer) throws Exception {
|
206
|
0
|
SimpleNode node = (SimpleNode)jjtGetChild(pos);
|
207
|
0
|
if( pos + 1 < jjtGetNumChildren() && ((SimpleNode)jjtGetChild( pos + 1)).firstToken == firstToken)
|
208
|
0
|
return new SimpleNodeAux( t, false);
|
209
|
0
|
while( t != null && t != node.firstToken) {
|
210
|
0
|
sourceCode( t, msql_type, buffer);
|
211
|
0
|
t = t.next;
|
212
|
|
}
|
213
|
0
|
node.sourceCode( msql_type, buffer);
|
214
|
0
|
return new SimpleNodeAux( node.lastToken.next, node.lastToken == lastToken);
|
215
|
|
}
|
216
|
|
|
217
|
0
|
public String addUnicodeEscapes(String str) {
|
218
|
0
|
String retval = "";
|
219
|
0
|
char ch;
|
220
|
0
|
for (int i = 0; i < str.length(); i++) {
|
221
|
0
|
ch = str.charAt(i);
|
222
|
0
|
if ((ch < 0x20 || ch > 0x7e) && ch != '\t' && ch != '\n' && ch != '\r' && ch != '\f') {
|
223
|
0
|
String s = "0000" + Integer.toString(ch, 16);
|
224
|
0
|
retval += "\\u" + s.substring(s.length() - 4, s.length());
|
225
|
|
} else {
|
226
|
0
|
retval += ch;
|
227
|
|
}
|
228
|
|
}
|
229
|
0
|
return retval;
|
230
|
|
}
|
231
|
|
|
232
|
|
}
|
233
|
|
|
234
|
|
|