KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > extractor > algebra > RemoveProjectGoUpVisitor


1 /*
2  * This file belongs to the XQuark distribution.
3  * Copyright (C) 2003 Universite de Versailles Saint-Quentin.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307.
18  * You can also get it at http://www.gnu.org/licenses/lgpl.html
19  *
20  * For more information on this software, see http://www.xquark.org.
21  */

22
23 package org.xquark.extractor.algebra;
24
25 import java.util.List JavaDoc;
26 import java.util.Map JavaDoc;
27
28 import org.xquark.extractor.common.Debug;
29 import org.xquark.extractor.common.SqlWrapperException;
30
31 public final class RemoveProjectGoUpVisitor extends DefaultAlgebraVisitor {
32     private static final String JavaDoc RCSRevision = "$Revision: 1.4 $";
33     private static final String JavaDoc RCSName = "$Name: $";
34
35     private RemoveProjectReplaceVisitor _rprv = new RemoveProjectReplaceVisitor();
36
37     /* process of GoUp end up at "_endNode"*/
38     private Expression _endNode = null;
39
40     public RemoveProjectGoUpVisitor(){
41     }
42
43     public RemoveProjectGoUpVisitor(Map JavaDoc replaceMap){
44         setMap(replaceMap);
45     }
46
47 // public RemoveProjectReplaceVisitor getReplaceVisitor()
48
// {
49
// return _rprv;
50
// }
51
//
52
// public void setReplaceVisitor(RemoveProjectReplaceVisitor rprv)
53
// {
54
// _rprv = rprv;
55
// }
56

57     public void setMap(Map JavaDoc replaceMap) {
58         _rprv.setMap(replaceMap);
59     }
60
61     public void setEndNode(Expression endNode) {
62         _endNode = endNode;
63     }
64
65     public Expression getEndNode() {
66         return _endNode;
67     }
68
69     public void visit(Expression arg) throws SqlWrapperException {
70         //Trace.enter(this,"visit(Expression arg)", arg);
71
Debug.assertTrue(false, "NYI!! for " + arg.toString());
72         //Trace.exit(this,"visit(Expression arg)", arg);
73
}
74
75     public void visit(BinaryAlgebra arg) throws SqlWrapperException {
76         //Trace.enter(this,"visit(BinaryAlgebra arg)", arg);
77

78         /* implementation for Merg, Union, Intersect and difference, but not for OuterJoin*/
79         if (getEndNode() != arg) {
80             arg.getFather().accept(this);
81         }
82
83         //Trace.exit(this,"visit(BinaryAlgebra arg)", arg);
84
}
85
86 // public void visit(BinOpArithmetic arg) throws SqlWrapperException {
87
// Trace.enter(this,"visit(BinOpArithmetic arg)", arg);
88
// Trace.exit(this,"visit(BinOpArithmetic arg)", arg);
89
// }
90
//
91
// public void visit(BinOpBoolean arg) throws SqlWrapperException {
92
// Trace.enter(this,"visit(BinOpBoolean arg)", arg);
93
// Trace.exit(this,"visit(BinOpBoolean arg)", arg);
94
// }
95
//
96
// public void visit(BinOpCompare arg) throws SqlWrapperException {
97
// Trace.enter(this,"visit(BinOpCompare arg)", arg);
98
// Trace.exit(this,"visit(BinOpCompare arg)", arg);
99
// }
100
//
101
// public void visit(BinOpCompareAny arg) throws SqlWrapperException {
102
// Trace.enter(this,"visit(BinOpCompareAny arg)", arg);
103
// Trace.exit(this,"visit(BinOpCompareAny arg)", arg);
104
// }
105

106 // public void visit(BinOpDifference arg) throws SqlWrapperException {
107
// Trace.enter(this,"visit(BinOpDifference arg)", arg);
108
// Trace.exit(this,"visit(BinOpDifference arg)", arg);
109
// }
110
//
111
// public void visit(BinOpIntersect arg) throws SqlWrapperException {
112
// Trace.enter(this,"visit(BinOpIntersect arg)", arg);
113
// Trace.exit(this,"visit(BinOpIntersect arg)", arg);
114
// }
115
//
116
// public void visit(BinOpMerge arg) throws SqlWrapperException {
117
// Trace.enter(this,"visit(BinOpMerge arg)", arg);
118
// Trace.exit(this,"visit(BinOpMerge arg)", arg);
119
// }
120

121     public void visit(BinOpOuterJoin arg) throws SqlWrapperException {
122         //Trace.enter(this,"visit(BinOpOuterJoin arg)", arg);
123

124         List JavaDoc list = arg.getPredicateList();
125         Debug.assertTrue(null!=list,"null!=list");
126         Expression expr = null ;
127         for (int i = 0; i < list.size(); i++) {
128             expr = (Expression)list.get(i);
129             expr.accept(_rprv);
130         }
131
132         if (getEndNode() != arg) {
133             arg.getFather().accept(this);
134         }
135
136         //Trace.exit(this,"visit(BinOpOuterJoin arg)", arg);
137
}
138
139 // public void visit(BinOpUnion arg) throws SqlWrapperException {
140
// Trace.enter(this,"visit(BinOpUnion arg)", arg);
141
// Trace.exit(this,"visit(BinOpUnion arg)", arg);
142
// }
143

144     public void visit(FunAggregate arg) throws SqlWrapperException {
145         //Trace.enter(this,"visit(FunAggregate arg)", arg);
146
//Trace.exit(this,"visit(FunAggregate arg)", arg);
147
}
148
149 // public void visit(IfThenElse arg) throws SqlWrapperException {
150
// Trace.enter(this,"visit(IfThenElse arg)", arg);
151
// Trace.exit(this,"visit(IfThenElse arg)", arg);
152
// }
153

154     public void visit(Join arg) throws SqlWrapperException {
155         //Trace.enter(this,"visit(Join arg)", arg);
156

157         List JavaDoc list = arg.getPredicateList();
158         if (list != null) {
159             Expression expr = null ;
160             for (int i = 0; i < list.size(); i++) {
161                 expr = (Expression)list.get(i);
162                 expr.accept(_rprv);
163             }
164         }
165
166         if (getEndNode() != arg) {
167             arg.getFather().accept(this);
168         }
169
170         //Trace.exit(this,"visit(Join arg)", arg);
171
}
172
173     public void visit(Literal arg) throws SqlWrapperException {
174         //Trace.enter(this,"visit(Literal arg)", arg);
175
//Trace.exit(this,"visit(Literal arg)", arg);
176
}
177
178 // public void visit(LitBoolean arg) throws SqlWrapperException {
179
// Trace.enter(this,"visit(LitBoolean arg)", arg);
180
// Trace.exit(this,"visit(LitBoolean arg)", arg);
181
// }
182
//
183
// public void visit(LitDate arg) throws SqlWrapperException {
184
// Trace.enter(this,"visit(LitDate arg)", arg);
185
// Trace.exit(this,"visit(LitDate arg)", arg);
186
// }
187
//
188
// public void visit(LitDouble arg) throws SqlWrapperException {
189
// Trace.enter(this,"visit(LitDouble arg)", arg);
190
// Trace.exit(this,"visit(LitDouble arg)", arg);
191
// }
192
//
193
// public void visit(LitFloat arg) throws SqlWrapperException {
194
// Trace.enter(this,"visit(LitFloat arg)", arg);
195
// Trace.exit(this,"visit(LitFloat arg)", arg);
196
// }
197
//
198
// public void visit(LitInteger arg) throws SqlWrapperException {
199
// Trace.enter(this,"visit(LitInteger arg)", arg);
200
// Trace.exit(this,"visit(LitInteger arg)", arg);
201
// }
202
//
203
// public void visit(LitString arg) throws SqlWrapperException {
204
// Trace.enter(this,"visit(LitString arg)", arg);
205
// Trace.exit(this,"visit(LitString arg)", arg);
206
// }
207

208     public void visit(RenameItem arg) throws SqlWrapperException {
209         //Trace.enter(this,"visit(RenameItem arg)", arg);
210

211         //Trace.exit(this,"visit(RenameItem arg)", arg);
212
}
213
214     public void visit(RenameRelation arg) throws SqlWrapperException {
215         //Trace.enter(this,"visit(RenameRelation arg)", arg);
216

217         /* set "TableInstance" attribute to all AttributExpression*/
218         _rprv.updateTableInstance(arg);
219         //Trace.message(this,"visit(RenameRelation arg)","updated replac map :" +_rprv.printMap());
220

221         /* remove this node */
222         Expression father = arg.getFather();
223         boolean replaced = father.replaceChild(arg, arg.getOperand());
224         Debug.assertTrue(replaced , "replaced");
225         arg.setFather(null);
226         //Trace.message(this,"visit(RenameRelation arg)","RenameRelation removed");
227

228         if (getEndNode() != arg) {
229             father.accept(this);
230         }
231
232         //Trace.exit(this,"visit(RenameRelation arg)", arg);
233
}
234
235 // public void visit(SortSpecification arg) throws SqlWrapperException {
236
// Trace.enter(this,"visit(SortSpecification arg)", arg);
237
//
238
// Trace.exit(this,"visit(SortSpecification arg)", arg);
239
// }
240

241 // public void visit(UnOpAggregate arg) throws SqlWrapperException {
242
// Trace.enter(this,"visit(UnaryAtomicOp arg)", arg);
243
// Trace.exit(this,"visit(UnaryAtomicOp arg)", arg);
244
// }
245

246     public void visit(UnaryAtomicOp arg) throws SqlWrapperException {
247         //Trace.enter(this,"visit(UnaryAtomicOp arg)", arg);
248

249         if (getEndNode() != arg) {
250             arg.getFather().accept(this);
251         }
252
253         //Trace.exit(this,"visit(UnaryAtomicOp arg)", arg);
254
}
255
256 // public void visit(UnOpGroup arg) throws SqlWrapperException {
257
// Trace.enter(this,"visit(UnOpGroup arg)", arg);
258
// Trace.exit(this,"visit(UnOpGroup arg)", arg);
259
// }
260

261     public void visit(UnOpProject arg) throws SqlWrapperException {
262         //Trace.enter(this,"visit(UnOpProject arg)", arg);
263

264         List JavaDoc list = arg.getItemList();
265         Debug.assertTrue(null!=list,"null!=list");
266         Expression expr = null ;
267         for (int i = 0; i < list.size(); i++) {
268             expr = (Expression)list.get(i);
269             expr.accept(_rprv);
270         }
271
272         UnOpSort sort = arg.getAssociatedSort();
273         if (null != sort) {
274             SortSpecification spec = null;
275             list = sort.getSortSpecificationList();
276             for (int i = 0; i < list.size(); i++) {
277                 spec = (SortSpecification)list.get(i);
278                 expr = spec.getSortExpression();
279                 expr.accept(_rprv);
280             }
281         }
282
283         if (getEndNode() != arg) {
284             arg.getFather().accept(this);
285         }
286
287         //Trace.exit(this,"visit(UnOpProject arg)", arg);
288
}
289
290     public void visit(UnOpRestrict arg) throws SqlWrapperException {
291         //Trace.enter(this,"visit(UnOpRestrict arg)", arg);
292

293         List JavaDoc list = arg.getPredicateList();
294         Debug.assertTrue(null!=list,"null!=list");
295         Expression expr = null ;
296         for (int i = 0; i < list.size(); i++) {
297             expr = (Expression)list.get(i);
298             expr.accept(_rprv);
299         }
300
301         if (getEndNode() != arg) {
302             arg.getFather().accept(this);
303         }
304
305         //Trace.exit(this,"visit(UnOpRestrict arg)", arg);
306
}
307
308     public void visit(UnOpSort arg) throws SqlWrapperException {
309         //Trace.enter(this,"visit(UnOpSort arg)", arg);
310

311         List JavaDoc list = arg.getSortSpecificationList();
312         Debug.assertTrue(null!=list,"null!=list");
313         SortSpecification spec = null;
314         Expression expr = null ;
315         for (int i = 0; i < list.size(); i++) {
316             spec = (SortSpecification)list.get(i);
317             expr = spec.getSortExpression();
318             expr.accept(_rprv);
319         }
320
321         if (getEndNode() != arg) {
322             arg.getFather().accept(this);
323         }
324
325         //Trace.exit(this,"visit(UnOpSort arg)", arg);
326
}
327
328     public String JavaDoc printMap(){
329         return _rprv.printMap();
330     }
331 }
332
Popular Tags