KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > mediator > decomposer > MakeStepsListVisitor


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

12
13 package org.xquark.mediator.decomposer;
14
15 import java.util.ArrayList JavaDoc;
16 import java.util.HashSet JavaDoc;
17 import java.util.Set JavaDoc;
18
19 import org.xquark.xquery.metadata.MetaDataImpl;
20 import org.xquark.xquery.parser.*;
21
22 public class MakeStepsListVisitor extends DefaultParserVisitor {
23     // **********************************************************************
24
// * VERSIONING
25
// **********************************************************************
26
private static final String JavaDoc RCSRevision = "$Revision: 1.6 $";
27
28     private static final String JavaDoc RCSName = "$Name: $";
29
30     // **********************************************************************
31
// * CLASS VARIABLES
32
// **********************************************************************
33
private StepLists steplists = null;
34
35     private boolean noOrderBy = false;
36
37     // **********************************************************************
38
// * INITIALIZATION
39
// **********************************************************************
40
/**
41      *
42      */

43     public MakeStepsListVisitor(MetaDataImpl metadata, boolean noOrderBy) {
44         this.steplists = new StepLists(metadata);
45         this.noOrderBy = noOrderBy;
46     }
47
48     // public MakeStepsListVisitor(StepLists steplists, boolean noOrderBy) {
49
// this.steplists = steplists;
50
// this.noOrderBy = noOrderBy;
51
// }
52
// public MakeStepsListVisitor(MetaDataImpl metadata) {
53
// this.steplists = new StepLists(metadata);
54
// }
55
// public MakeStepsListVisitor(StepLists steplists) {
56
// this.steplists = steplists;
57
// }
58
public MakeStepsListVisitor() {
59     }
60
61     // **********************************************************************
62
// * METHODS
63
// **********************************************************************
64
public StepLists getStepsLists() {
65         return steplists;
66     }
67
68     public void setStepsLists(StepLists steplists) {
69         this.steplists = steplists;
70     }
71
72     // **********************************************************************
73
// * VISITATION
74
// **********************************************************************
75
// public void visit(AttributeValuePair arg) throws XQueryException
76
// public void visit(BinOpANDExpression arg) throws XQueryException
77
// public void visit(BinOpORExpression arg) throws XQueryException
78
// public void visit(CastTreatExpression arg) throws XQueryException
79
// public void visit(ContextDeclaration arg) throws XQueryException
80
// public void visit(Dereference arg) throws XQueryException
81
public void visit(Element arg) throws XQueryException {
82         ArrayList JavaDoc al = arg.getSubExpressions();
83         if (al == null)
84             return;
85         for (int i = 0; i < al.size(); i++) {
86             ((XQueryExpression) al.get(i)).accept(this);
87         }
88     }
89
90     public void visit(FLWRExpression arg) throws XQueryException {
91         ArrayList JavaDoc vars = arg.getVariables();
92         Set JavaDoc sources = null;
93         Set JavaDoc urls = null;
94         for (int i = 0; i < vars.size(); i++) {
95             Variable vari = (Variable) vars.get(i);
96             steplists.registerVar(vari);
97             if (vari.getSourceNames() != null && !vari.getSourceNames().isEmpty()) {
98                 if (sources == null)
99                     sources = new HashSet JavaDoc(vari.getSourceNames());
100                 else
101                     sources.addAll(vari.getSourceNames());
102             }
103             if (vari.getUrls() != null && !vari.getUrls().isEmpty()) {
104                 if (urls == null)
105                     urls = new HashSet JavaDoc(vari.getUrls());
106                 else
107                     urls.addAll(vari.getUrls());
108             }
109         }
110
111         XQueryExpression expr = arg.getWhereClause();
112         if (expr != null) {
113             steplists.newStepslist();
114             expr.accept(this);
115             if (expr.getSourceNames() != null && !expr.getSourceNames().isEmpty()) {
116                 if (sources == null)
117                     sources = new HashSet JavaDoc(expr.getSourceNames());
118                 else
119                     sources.addAll(expr.getSourceNames());
120             }
121             if (expr.getUrls() != null && !expr.getUrls().isEmpty()) {
122                 if (urls == null)
123                     urls = new HashSet JavaDoc(expr.getUrls());
124                 else
125                     urls.addAll(expr.getUrls());
126             }
127
128         }
129         expr = arg.getReturnClause();
130         expr.accept(this);
131         if (expr.getSourceNames() != null && !expr.getSourceNames().isEmpty()) {
132             if (sources == null)
133                 sources = new HashSet JavaDoc(expr.getSourceNames());
134             else
135                 sources.addAll(expr.getSourceNames());
136         }
137         if (expr.getUrls() != null && !expr.getUrls().isEmpty()) {
138             if (urls == null)
139                 urls = new HashSet JavaDoc(expr.getUrls());
140             else
141                 urls.addAll(expr.getUrls());
142         }
143
144         //
145
// if (!noOrderBy && arg.getOrderBy() != null) {
146
// ArrayList al = arg.getOrderBy();
147
// for (int i = 0; i < al.size(); i++)
148
// ((XQueryExpression) al.get(i)).accept(this);
149
// }
150

151         // Set set = this.steplists.getRegisteredVariables();
152
// if (set == null) {
153
// arg.setSourceNames(null);
154
// arg.setUrls(null);
155
// }
156
// else {
157
// ArrayList sourceNames = null;
158
// ArrayList urls = null;
159
// for (Iterator it=set.iterator();it.hasNext();) {
160
// Variable var = (Variable)it.next();
161
// if (var.getSourceNames() != null && !var.getSourceNames().isEmpty()) {
162
// if (sourceNames == null)
163
// sourceNames = (ArrayList)var.getSourceNames().clone();
164
// else
165
// ArrayListUtil.add(sourceNames,var.getSourceNames());
166
// }
167
// if (var.getUrls() != null && !var.getUrls().isEmpty()) {
168
// if (urls == null)
169
// urls = (ArrayList)var.getUrls().clone();
170
// else
171
// ArrayListUtil.add(urls,var.getUrls());
172
// }
173
// }
174
// arg.setSourceNames(sourceNames);
175
// arg.setUrls(urls);
176
// }
177
arg.setSourceNames(sources);
178         arg.setUrls(urls);
179     }
180
181     public void visit(QuantifiedExpression arg) throws XQueryException {
182         ArrayList JavaDoc vars = arg.getVariables();
183         Set JavaDoc sources = null;
184         Set JavaDoc urls = null;
185         for (int i = 0; i < vars.size(); i++) {
186             Variable vari = (Variable) vars.get(i);
187             steplists.registerVar(vari);
188             if (vari.getSourceNames() != null && !vari.getSourceNames().isEmpty()) {
189                 if (sources == null)
190                     sources = new HashSet JavaDoc(vari.getSourceNames());
191                 else
192                     sources.addAll(vari.getSourceNames());
193             }
194             if (vari.getUrls() != null && !vari.getUrls().isEmpty()) {
195                 if (urls == null)
196                     urls = new HashSet JavaDoc(vari.getUrls());
197                 else
198                     urls.addAll(vari.getUrls());
199             }
200         }
201
202         if (arg.getExpression() != null) {
203             steplists.newStepslist();
204             arg.getExpression().accept(this);
205         }
206
207         arg.setSourceNames(sources);
208         arg.setUrls(urls);
209     }
210
211     public void visit(FunctionCall arg) throws XQueryException {
212         ArrayList JavaDoc args = arg.getArguments();
213         if (args == null)
214             return;
215         Set JavaDoc sources = null;
216         Set JavaDoc urls = null;
217         for (int i = 0; i < args.size(); i++) {
218             XQueryExpression expri = (XQueryExpression) args.get(i);
219             expri.accept(this);
220             if (expri.getSourceNames() != null && !expri.getSourceNames().isEmpty()) {
221                 if (sources == null)
222                     sources = new HashSet JavaDoc(expri.getSourceNames());
223                 else
224                     sources.addAll(expri.getSourceNames());
225             }
226             if (expri.getUrls() != null && !expri.getUrls().isEmpty()) {
227                 if (urls == null)
228                     urls = new HashSet JavaDoc(expri.getUrls());
229                 else
230                     urls.addAll(expri.getUrls());
231             }
232         }
233         arg.setSourceNames(sources);
234         arg.setUrls(urls);
235     }
236
237     // public void visit(FunctionDefinition arg) throws XQueryException
238
// public void visit(InstanceOfExpression arg) throws XQueryException
239
// public void visit(InternalFunctionCall arg) throws XQueryException
240
// public void visit(ITEExpression arg) throws XQueryException
241
// public void visit(LibraryFunctionCall arg) throws XQueryException
242
// public void visit(ListOpAFTERExpression arg) throws XQueryException
243
// public void visit(ListOpArithExpression arg) throws XQueryException
244
// public void visit(ListOpBEFOREExpression arg) throws XQueryException
245
// public void visit(ListOpCompExpression arg) throws XQueryException
246
// public void visit(ListOpEXCEPTExpression arg) throws XQueryException
247
// public void visit(ListOpINTERSECTExpression arg) throws XQueryException
248
// public void visit(ListOpUNIONExpression arg) throws XQueryException
249

250     public void visit(LocatedExpression arg) throws XQueryException {
251         steplists.newStepslist();
252         ArrayList JavaDoc steps = arg.getSteps();
253         for (int i = 0; i < steps.size(); i++)
254             ((Step) steps.get(i)).accept(this);
255     }
256
257     // public void visit(NodeType arg) throws XQueryException
258
// public void visit(Parameter arg) throws XQueryException
259
// public void visit(PrimitiveFunctionCall arg) throws XQueryException
260
// public void visit (QName arg) throws XQueryException
261
// public void visit(QuantifiedExpression arg) throws XQueryException
262
// public void visit(RangeExpression arg) throws XQueryException
263
// public void visit(RootNodeFunctionCall arg) throws XQueryException
264
public void visit(SortedExpression arg) throws XQueryException {
265         arg.getExpression().accept(this);
266         arg.setSourceNames(arg.getExpression().getSourceNames());
267         arg.setUrls(arg.getExpression().getUrls());
268     }
269
270     public void visit(Step arg) throws XQueryException {
271         steplists.addStep(arg);
272     }
273
274     // public void visit(TypeSwitchExpression arg) throws XQueryException
275
// public void visit(UnOpMinusExpression arg) throws XQueryException
276
// public void visit(Value arg) throws XQueryException {
277
// steplists.addStep(new Step(-1,-1,arg,null,null)) ;
278
// }
279
// public void visit(ValueBoolean arg) throws XQueryException
280
// public void visit(ValueFloat arg) throws XQueryException
281
// public void visit(ValueInteger arg) throws XQueryException
282
// public void visit(ValueString arg) throws XQueryException
283
// public void visit(ValueText arg) throws XQueryException
284
public void visit(Variable arg) throws XQueryException {
285         steplists.addStep(arg);
286     }
287
288     public void visit(XQueryBinaryOperatorExpression arg) throws XQueryException {
289         arg.getExpression1().accept(this);
290         arg.getExpression2().accept(this);
291     }
292
293     // public void visit(XQueryBooleanOperatorExpression arg) throws XQueryException
294
// public void visit (XQueryExpression arg) throws XQueryException
295

296     public void visit(XQueryExpressionSequence arg) throws XQueryException {
297         ArrayList JavaDoc al = arg.getSubExpressions();
298         if (al == null)
299             return;
300         for (int i = 0; i < al.size(); i++)
301             ((XQueryExpression) al.get(i)).accept(this);
302     }
303
304     // public void visit(XQueryListBinaryOperatorExpression arg) throws XQueryException
305
// public void visit(XQueryListUnaryOperatorExpression arg) throws XQueryException
306

307     public void visit(XQueryUnaryOperatorExpression arg) throws XQueryException {
308         arg.getExpression().accept(this);
309
310     }
311 }
Popular Tags