KickJava   Java API By Example, From Geeks To Geeks.

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


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

23
24 package org.xquark.mediator.decomposer;
25
26 import java.util.ArrayList JavaDoc;
27 import java.util.HashMap JavaDoc;
28 import java.util.Stack JavaDoc;
29
30 import org.xquark.mediator.algebra.*;
31 import org.xquark.mediator.runtime.MediatorException;
32 import org.xquark.xquery.parser.*;
33 import org.xquark.xquery.parser.primitivefunctions.fnfunctions.FunctionCOLLECTION;
34 import org.xquark.xquery.parser.primitivefunctions.fnfunctions.FunctionDOC;
35 import org.xquark.xquery.parser.util.Constants;
36 import org.xquark.xquery.typing.*;
37
38 /**
39  * This abstract represent a Node/Leaf use in the construction
40  * of the dependancy trees.
41  *
42  */

43
44 /** to be commented ... : objectif of this class
45  * <code>AlgebraStructureVisitor</code> visit :
46  * 1. call <code>DepManager</code> to create Dependence tree.
47  * 2. */

48
49 public class AlgebraStructureVisitor extends DefaultParserVisitor {
50     // **********************************************************************
51
// * VERSIONING
52
// **********************************************************************
53
private static final String JavaDoc RCSRevision = "$Revision: 1.10 $";
54     private static final String JavaDoc RCSName = "Name";
55
56     // **********************************************************************
57
// * CLASS VARIABLES
58
// **********************************************************************
59
private final Integer JavaDoc IN_LOCATED = new Integer JavaDoc(1);
60     private final Integer JavaDoc IN_DEFINITION = new Integer JavaDoc(2);
61     private final Integer JavaDoc IN_FLWR = new Integer JavaDoc(3);
62     private final Integer JavaDoc IN_WHERE = new Integer JavaDoc(4);
63     private final Integer JavaDoc IN_FUNCTION = new Integer JavaDoc(5);
64     private final Integer JavaDoc IN_MAIN_DEFINITION = new Integer JavaDoc(6);
65     private final Integer JavaDoc IN_SEQUENCE = new Integer JavaDoc(7);
66     //private final Integer IN_PREDICATE = new Integer(3);
67

68     // elements passed at construction time
69
private AlgebraManager depmanager = null;
70     private HashMap JavaDoc parentvariable = null;
71
72     // private temporary elements
73
private Stack JavaDoc varStack = new Stack JavaDoc();
74     private AlgFLWR currentDepFLWR = null;
75     private Algebra currentDepNode = null;
76     private TypeVisitor typevisitor = null;
77     private Stack JavaDoc stateStack = new Stack JavaDoc();
78
79     private boolean ongoingLet = false;
80     private LocatedExpression ongoingLocatedExpression = null;
81     //private ArrayList currentSources = null;
82

83     // ************************************************************************
84
// * INITIALIZATION
85
// ************************************************************************
86
public AlgebraStructureVisitor(AlgebraManager depmanager) throws XQueryException {
87         this.depmanager = depmanager;
88         this.typevisitor = depmanager.getTypeVisitor();
89         this.parentvariable = new HashMap JavaDoc();
90         stateStack.push(IN_FLWR);
91     }
92
93     // ************************************************************************
94
// * GET/SET METHODS
95
// ************************************************************************
96

97     private void addLeaf(Algebra leaf) throws MediatorException {
98         if (currentDepNode != null)
99             currentDepNode.addLeaf(leaf);
100         else if (currentDepFLWR != null)
101             currentDepFLWR.addLeaf(leaf);
102     }
103
104     // ************************************************************************
105
// * METHODS
106
// ************************************************************************
107

108     public void visit(AggregateFunctionCall arg) throws XQueryException {
109         Integer JavaDoc state = (Integer JavaDoc) stateStack.peek();
110         if (state == IN_DEFINITION /*|| state == IN_FUNCTION*/
111             ) {
112             AlgFunction depfunction = depmanager.addFunction(arg, (state == IN_DEFINITION) ? (Variable) varStack.peek() : null, true);
113             addLeaf(depfunction);
114             ongoingLet = false;
115             ArrayList JavaDoc arguments = arg.getArguments();
116             if (arguments != null) {
117                 Algebra tmpDepNode = currentDepNode;
118                 currentDepNode = depfunction;
119                 stateStack.push(IN_FUNCTION);
120                 for (int i = 0; i < arguments.size(); i++)
121                     arg.getArgument(i).accept(this);
122                 stateStack.pop();
123                 currentDepNode = tmpDepNode;
124             }
125         }
126     }
127
128
129     public void visit(ListOpArithExpression arg) throws XQueryException {
130         Integer JavaDoc state = (Integer JavaDoc) stateStack.peek();
131         if (state == IN_DEFINITION /*|| state == IN_FUNCTION*/
132             ) {
133             AlgArithFunction deparithfunction = depmanager.addArithFunction(arg, (state == IN_DEFINITION) ? (Variable) varStack.peek() : null, true);
134             addLeaf(deparithfunction);
135             ongoingLet = false;
136             Algebra tmpDepNode = currentDepNode;
137             currentDepNode = deparithfunction;
138             stateStack.push(IN_FUNCTION);
139             arg.getExpression1().accept(this);
140             arg.getExpression2().accept(this);
141             stateStack.pop();
142             currentDepNode = tmpDepNode;
143         }
144     }
145
146     public void visit(ListOpUNIONExpression arg) throws XQueryException {
147         Integer JavaDoc state = (Integer JavaDoc) stateStack.peek();
148         if (state == IN_DEFINITION /*|| state == IN_FUNCTION*/
149             ) {
150             AlgUnion depunion = depmanager.addUnion(arg, (state == IN_DEFINITION) ? (Variable) varStack.peek() : null, true);
151             addLeaf(depunion);
152             ongoingLet = false;
153             Algebra tmpDepNode = currentDepNode;
154             currentDepNode = depunion;
155             stateStack.push(IN_FUNCTION);
156             arg.getExpression1().accept(this);
157             arg.getExpression2().accept(this);
158             stateStack.pop();
159             currentDepNode = tmpDepNode;
160         }
161     }
162
163     public void visit(FLWRExpression arg) throws XQueryException {
164
165         ArrayList JavaDoc variables = arg.getVariables();
166         Integer JavaDoc currentstate = (Integer JavaDoc) stateStack.peek();
167         //currentSources = null;
168

169         Algebra tmpDepNode = currentDepNode;
170         if (currentstate == IN_DEFINITION) {
171             AlgFLWR depflwr = depmanager.addFlwr(arg, (Variable) varStack.peek(), ongoingLet);
172             addLeaf(depflwr);
173             currentDepNode = depflwr;
174             ongoingLet = false;
175         } else if (currentstate == IN_FUNCTION) {
176             AlgFLWR depflwr = depmanager.addFlwr(arg, null, ongoingLet);
177             addLeaf(depflwr);
178             currentDepNode = depflwr;
179             ongoingLet = false;
180         }
181
182         // TEST if sources is only one
183
/*
184         // if (sources != null && sources.size() == 1) {
185         // for (int i=0;i<variables.size();i++) {
186         // Variable vari = (Variable)variables.get(i);
187         // Variable parentvari = (Variable)parentvariable.get(vari);
188         // if (parentvari != null) {
189         // currentDepMem.setDependency((DepMem) depmanager.getMapNode(parentvari));
190         // variables.remove(i);
191         // i--;
192         // }
193         // else {
194         // vari.setParentFLWRExpression(arg);
195         // parentvariable.put(vari,varStack.firstElement());
196         // }
197         // }
198         // //Utils.fillSources(arg,new UnitEnvironment(),this.depmanager.getMetaData());
199         // DepNodeSource newsource = depmanager.addNodeSource(arg,arg.getVariables(), ongoingLet);
200         // addLeaf(newsource);
201         // this.currentDepMem.setMonoSource(true);
202         // return;
203         // }
204         */

205         /*
206         ArrayList removedVariables = new ArrayList();
207         for (int i=0;i<variables.size();i++) {
208             Variable vari = (Variable)variables.get(i);
209             Variable parentvari = (Variable)parentvariable.get(vari);
210             if (parentvari != null) {
211                 currentDepFLWR.setDependency((DepFLWR) depmanager.getMapNode(parentvari));
212                 removedVariables.add(vari);
213                 variables.remove(i);
214                 i--;
215             }
216         }
217         // remove conditions from where clause implicating only removed variables
218         if (arg.getWhereClause() != null && !removedVariables.isEmpty()) {
219             IsolateWhereVisitor visitor = new IsolateWhereVisitor(removedVariables) ;
220             try {
221                 arg.getWhereClause().accept(visitor) ;
222             }
223             catch (XQueryException e) {
224                 throw new MediatorException("Can't isolate where expression : " + arg.getWhereClause().pprint(), e) ;
225             }
226             arg.setWhereClause(visitor.getRemainingExpression()) ;
227         }
228         */

229         // TEST if sources is only one
230
/*
231         Utils.fillSources(arg,this.depmanager.getMetaData());
232         
233         ArrayList sources = arg.getSources();
234         if (sources != null && sources.size() == 1) {
235             for (int i=0;i<variables.size();i++) {
236                 Variable vari = (Variable)variables.get(i);
237                 vari.setParentFLWRExpression(arg);
238                 parentvariable.put(vari,varStack.firstElement());
239             }
240             //Utils.fillSources(arg,new UnitEnvironment(),this.depmanager.getMetaData());
241             DepNodeSource newsource = depmanager.addNodeSource(arg,arg.getVariables(), ongoingLet);
242             addLeaf(newsource);
243             if (currentstate == IN_MAIN_DEFINITION) currentDepFLWR.setMonoSource(true);
244             else if (currentstate == IN_DEFINITION) currentDepNode = tmpDepNode;
245             return;
246         }
247         */

248         for (int i = 0; i < variables.size(); i++) {
249             Variable vari = (Variable) variables.get(i);
250             vari.setParentFLWRExpression(arg);
251             stateStack.push(IN_FLWR);
252             vari.accept(this);
253             stateStack.pop();
254         }
255
256         // ArrayList varsOnTheSameSource = new ArrayList();
257
// String lastSource = null;
258
// ArrayList sourcesOfvari = null;
259
// for (int i = 0; i < variables.size(); i++) {
260
// Variable vari = (Variable)variables.get(i);
261
// vari.setParentFLWRExpression(arg);
262
// sourcesOfvari = vari.getSources();
263
//
264
// boolean isMonoSource = (null != sourcesOfvari && 1 == sourcesOfvari.size());
265
// if (isMonoSource && sourcesOfvari.get(0).equals(lastSource)) {
266
// /* vari is defined on the same source as the precedant variable*/
267
// varsOnTheSameSource.add(vari);
268
// }
269
// else {
270
// if (!varsOnTheSameSource.isEmpty()) {
271
// /* Generate DepNodeSource for accumulated variables*/
272
// DepNodeSource newsource = depmanager.addNodeSource(arg,varsOnTheSameSource, ongoingLet);
273
// addLeaf(newsource);
274
//
275
// varsOnTheSameSource = new ArrayList();
276
//
277
// }
278
// /**/
279
// if (isMonoSource) {
280
// lastSource = (String)sourcesOfvari.get(0);
281
// varsOnTheSameSource.add(vari);
282
// }
283
// else {
284
// stateStack.push(IN_FLWR) ;
285
// vari.accept(this);
286
// stateStack.pop() ;
287
// }
288
// }
289
// }
290
//
291
// /* treat last group of variables if there is */
292
// if (!varsOnTheSameSource.isEmpty()) {
293
// /* Generate DepNodeSource for accumulated variables*/
294
// DepNodeSource newsource = depmanager.addNodeSource(arg,varsOnTheSameSource, ongoingLet);
295
// addLeaf(newsource);
296
// }
297

298         XQueryExpression whereclause = arg.getWhereClause();
299         if (whereclause != null) {
300             stateStack.push(IN_WHERE);
301             whereclause.accept(this);
302             stateStack.pop();
303         }
304
305         //ArrayList orderbys = arg.getOrderBy() ;
306
if (currentstate == IN_DEFINITION)
307             currentDepNode = tmpDepNode;
308
309     }
310
311     public void visit(FunctionCOLLECTION arg) throws XQueryException {
312
313         Integer JavaDoc state = (Integer JavaDoc) stateStack.peek();
314         AlgSource newsource = null;
315         if (state == IN_DEFINITION)
316             newsource = depmanager.addSource(arg, (Variable) varStack.peek(), ongoingLet);
317         else if (state == IN_LOCATED)
318             newsource = depmanager.addSource(ongoingLocatedExpression, (Variable) null, ongoingLet);
319         else
320             newsource = depmanager.addSource(arg, (Variable) null, ongoingLet);
321         //if (!ongoingLet)
322
addLeaf(newsource);
323         ongoingLet = false;
324     }
325
326     public void visit(FunctionDOC arg) throws XQueryException {
327
328         Integer JavaDoc state = (Integer JavaDoc) stateStack.peek();
329         AlgSourceEval newsource = null;
330         if (state == IN_DEFINITION)
331             newsource = depmanager.addSourceEval(arg, (Variable) varStack.peek(), ongoingLet);
332         else if (state == IN_FUNCTION)
333             newsource = depmanager.addSourceEval(arg, (Variable) varStack.peek(), ongoingLet);
334         else if (state == IN_LOCATED)
335             newsource = depmanager.addSourceEval(ongoingLocatedExpression, (Variable) null, ongoingLet);
336         else
337             newsource = depmanager.addSourceEval(arg, (Variable) null, ongoingLet);
338         //if (!ongoingLet)
339
addLeaf(newsource);
340         ongoingLet = false;
341     }
342
343     public void visit(PrimitiveFunctionCall arg) throws XQueryException {
344
345         Integer JavaDoc state = (Integer JavaDoc) stateStack.peek();
346         if (state == IN_DEFINITION /*|| state == IN_FUNCTION*/
347             ) {
348             AlgFunction depfunction = depmanager.addFunction(arg, (state == IN_DEFINITION) ? (Variable) varStack.peek() : null, ongoingLet);
349             addLeaf(depfunction);
350             ongoingLet = false;
351             ArrayList JavaDoc arguments = arg.getArguments();
352             if (arguments != null) {
353                 Algebra tmpDepNode = currentDepNode;
354                 currentDepNode = depfunction;
355                 stateStack.push(IN_FUNCTION);
356                 for (int i = 0; i < arguments.size(); i++)
357                     arg.getArgument(i).accept(this);
358                 stateStack.pop();
359                 currentDepNode = tmpDepNode;
360             }
361         }
362
363     }
364
365     public void visit(LocatedExpression arg) throws XQueryException {
366         Integer JavaDoc state = (Integer JavaDoc) stateStack.peek();
367         ArrayList JavaDoc steps = arg.getSteps();
368         if (state != IN_DEFINITION)
369             stateStack.push(IN_LOCATED);
370         ongoingLocatedExpression = arg;
371         XQueryExpression exp = ((Step) steps.get(0)).getExpression();
372         exp.accept(this);
373         if (state != IN_DEFINITION)
374             stateStack.pop();
375         ongoingLocatedExpression = null;
376     }
377
378     public void visit(Value arg) throws XQueryException {
379         Integer JavaDoc state = (Integer JavaDoc) stateStack.peek();
380         if (state == IN_DEFINITION /*|| state == IN_FUNCTION*/
381             ) {
382             AlgEval depeval = depmanager.addEval(arg, (state == IN_DEFINITION) ? (Variable) varStack.peek() : null, true);
383             addLeaf(depeval);
384             ongoingLet = false;
385         }
386     }
387
388     private GetUsedVariablesVisitor guvvisitor = null;
389
390     public void visit(Variable arg) throws XQueryException {
391         // add 03/06/2003
392
Integer JavaDoc currentstate = (Integer JavaDoc) stateStack.peek();
393         if (currentstate == IN_FLWR && !this.depmanager.getPlan().getQAOnly()) {
394             // add 02/06/2003
395
// if (arg.getSourceNames() != null && arg.getSourceNames().size() == 1 && (arg.getUrls() == null || arg.getUrls().isEmpty())) {
396
// /*
397
// for (int i=0;i<variables.size();i++) {
398
// Variable vari = (Variable)variables.get(i);
399
// vari.setParentFLWRExpression(tmpflwr);
400
// parentvariable.put(vari,varStack.firstElement());
401
// }
402
// */
403
// if (!(arg.getExpression() instanceof LocatedExpression) && !(arg.getExpression() instanceof Variable)) {
404
// AlgSource newsource = depmanager.addSource(arg.getExpression(), arg, ongoingLet);
405
// if (guvvisitor == null)
406
// guvvisitor = new GetUsedVariablesVisitor();
407
// guvvisitor.reset();
408
// arg.getExpression().accept(guvvisitor);
409
// newsource.addDependSourceVariables(guvvisitor.getVariables());
410
// addLeaf(newsource);
411
// /*
412
// if (currentstate == IN_MAIN_DEFINITION) currentDepFLWR.setMonoSource(true);
413
// else if (currentstate == IN_DEFINITION) currentDepNode = currentDepNode;
414
// */
415
// parentvariable.put(arg, varStack.firstElement());
416
// return;
417
// }
418
// }
419
// end add
420
}
421         // end add
422
// add 05/02/2003
423
// if (arg.getUrls() != null && arg.getUrls().size() == 1) {
424
// /*
425
// for (int i=0;i<variables.size();i++) {
426
// Variable vari = (Variable)variables.get(i);
427
// vari.setParentFLWRExpression(tmpflwr);
428
// parentvariable.put(vari,varStack.firstElement());
429
// }
430
// */
431
// if (!(arg.getExpression() instanceof LocatedExpression) && !(arg.getExpression() instanceof Variable)) {
432
// DepNodeEval neweval = depmanager.addNodeEval(arg.getExpression(), arg, ongoingLet);
433
// if (guvvisitor == null)
434
// guvvisitor = new GetUsedVariablesVisitor();
435
// else
436
// guvvisitor.reset();
437
// arg.getExpression().accept(guvvisitor);
438
// neweval.addDependSourceVariables(guvvisitor.getVariables());
439
// addLeaf(neweval);
440
// /*
441
// if (currentstate == IN_MAIN_DEFINITION) currentDepFLWR.setMonoSource(true);
442
// else if (currentstate == IN_DEFINITION) currentDepNode = currentDepNode;
443
// */
444
// return;
445
// }
446
// }
447
// end add
448

449         if (currentstate == IN_DEFINITION) {
450             if (ongoingLocatedExpression == null) {
451                 AlgVar depvar = depmanager.addVar(arg, (Variable) varStack.peek(), ongoingLet);
452                 //if (!ongoingLet)
453
addLeaf(depvar);
454                 ongoingLet = false;
455             } else {
456                 AlgLocated deplocated = depmanager.addLocated(ongoingLocatedExpression, arg, (Variable) varStack.peek(), ongoingLet);
457                 //if (!ongoingLet)
458
addLeaf(deplocated);
459                 ongoingLet = false;
460             }
461         } else if (currentstate == IN_FLWR) {
462             if (arg.getBindingType() == Constants.LET_BINDINGTYPE) {
463                 ongoingLet = true;
464                 //depmanager.addAlias(arg, arg.getExpression ()) ;
465
//currentDepMem.isLet(true) ;
466
}
467             varStack.push(arg);
468             if (arg.getParentFLWRExpression() == null) {
469                 // remove variables if necessary
470
FLWRExpression tmpflwr = (FLWRExpression) arg.getExpression();
471                 ArrayList JavaDoc variables = tmpflwr.getVariables();
472
473                 // change 27/03/2003 not needed anymore!!!
474
//ArrayList removedVariables = null;
475
Variable lastremovedvar = null;
476                 Variable lastparentvar = null;
477                 for (int i = 0; i < variables.size(); i++) {
478                     Variable vari = (Variable) variables.get(i);
479                     Variable parentvari = (Variable) parentvariable.get(vari);
480                     if (parentvari == null)
481                         break;
482                     lastremovedvar = vari;
483                     if (parentvari != lastparentvar) {
484                         lastparentvar = parentvari;
485                         if (tmpflwr.getWhereClause() != null) {
486                             XQueryExpression tmpwhere = ((FLWRExpression) depmanager.getMapNode(lastparentvar).getExpression()).getWhereClause();
487                             if (tmpflwr.getWhereClause() != null)
488                                 tmpflwr.setWhereClause(tmpflwr.getWhereClause().erasePart(tmpwhere));
489                         }
490                     }
491                     //currentDepFLWR.setDependency((DepFLWR) depmanager.getMapNode(parentvari));
492
// if (removedVariables == null)
493
// removedVariables = new ArrayList(1);
494
// removedVariables.add(vari);
495
variables.remove(i);
496                     i--;
497                 }
498
499                 // remove conditions from where clause implicating only removed variables
500
// if (tmpflwr.getWhereClause() != null && lastremovedvar != null) {
501
//
502
// XQueryExpression tmpwhere = ((FLWRExpression)depmanager.getMapNode((Variable) parentvariable.get(lastremovedvar)).getExpression()).getWhereClause();
503
// if (tmpwhere != null)
504
// tmpflwr.setWhereClause(((BinOpANDExpression)tmpflwr.getWhereClause()).erasePart(tmpwhere));
505
//
506
// // change 27/03/2003 this was an ERROR !!!!!!!
507
//// IsolateWhereVisitor visitor = new IsolateWhereVisitor(removedVariables);
508
//// visitor.includeNone(false);
509
//// try {
510
//// tmpflwr.getWhereClause().accept(visitor);
511
//// } catch (XQueryException e) {
512
//// throw new MediatorException("Can't isolate where expression : " + tmpflwr.getWhereClause().pprint(), e);
513
//// }
514
//// tmpflwr.setWhereClause(visitor.getRemainingExpression());
515
// }
516

517                 currentDepFLWR = depmanager.addQDB(arg, ongoingLet);
518                 /*
519                 for (int i=0;i<removedVariables.size();i++)
520                     currentDepFLWR.setDependency((DepFLWR) depmanager.getMapNode((Variable) parentvariable.get((Variable) removedVariables.get(i))));
521                 */

522                 if (lastremovedvar != null)
523                     currentDepFLWR.setDependency((AlgFLWR) depmanager.getMapNode((Variable) parentvariable.get(lastremovedvar)));
524                 if (currentDepFLWR.getVarsDependingOn() != null)
525                     currentDepFLWR.updateVarDependencyList((ArrayList JavaDoc) currentDepFLWR.getVarsDependingOn().clone());
526
527                 // Utils.fillSources(tmpflwr, this.depmanager.getMetaData(),false);
528
// ArrayList sources = tmpflwr.getSourceNames();
529
// ArrayList urls = tmpflwr.getUrls();
530

531                 // test if flwr is imbricated and flwr contains located expression starting from an above defined variable
532

533                 // if (sources != null && sources.size() == 1) {
534
// for (int i = 0; i < variables.size(); i++) {
535
// Variable vari = (Variable) variables.get(i);
536
// vari.setParentFLWRExpression(tmpflwr);
537
// parentvariable.put(vari, varStack.firstElement());
538
// }
539
// DepNodeSource newsource = depmanager.addNodeSource(tmpflwr, tmpflwr.getVariables(), false);
540
// addLeaf(newsource);
541
// currentDepFLWR.setMonoSource(true);
542
// //if (currentstate == IN_MAIN_DEFINITION) currentDepFLWR.setMonoSource(true);
543
// //else if (currentstate == IN_DEFINITION) currentDepNode = currentDepNode;
544
// varStack.pop();
545
// return;
546
// }
547
// if (urls != null && urls.size() == 1) {
548
// for (int i = 0; i < variables.size(); i++) {
549
// Variable vari = (Variable) variables.get(i);
550
// vari.setParentFLWRExpression(tmpflwr);
551
// parentvariable.put(vari, varStack.firstElement());
552
// }
553
// DepNodeEval neweval = depmanager.addNodeEval(tmpflwr, tmpflwr.getVariables(), false);
554
// addLeaf(neweval);
555
// currentDepFLWR.setMonoSource(true);
556
// //if (currentstate == IN_MAIN_DEFINITION) currentDepFLWR.setMonoSource(true);
557
// //else if (currentstate == IN_DEFINITION) currentDepNode = currentDepNode;
558
// varStack.pop();
559
// return;
560
// }
561

562                 ongoingLet = false;
563                 stateStack.push(IN_MAIN_DEFINITION);
564                 //currentSources = null;
565
} else {
566                 parentvariable.put(arg, varStack.firstElement());
567                 stateStack.push(IN_DEFINITION);
568             }
569             arg.getExpression().accept(this);
570             stateStack.pop();
571             varStack.pop();
572         }
573         //currentSources = sources;
574
}
575
576     public void visit(UnOpMinusExpression arg) throws XQueryException {
577
578         Integer JavaDoc state = (Integer JavaDoc) stateStack.peek();
579         if (state == IN_DEFINITION /*|| state == IN_FUNCTION*/
580             ) {
581             AlgFunction depfunction = depmanager.addFunction(arg, (state == IN_DEFINITION) ? (Variable) varStack.peek() : null, ongoingLet);
582             addLeaf(depfunction);
583             ongoingLet = false;
584             Algebra tmpDepNode = currentDepNode;
585             currentDepNode = depfunction;
586             stateStack.push(IN_FUNCTION);
587             arg.getExpression().accept(this);
588             stateStack.pop();
589             currentDepNode = tmpDepNode;
590         }
591     }
592
593     public void visit(XQueryExpressionSequence arg) throws XQueryException {
594
595         Integer JavaDoc state = (Integer JavaDoc) stateStack.peek();
596         if (state == IN_DEFINITION /*|| state == IN_FUNCTION*/
597             ) {
598             AlgSequence depsequence = depmanager.addSequence(arg, (state == IN_DEFINITION) ? (Variable) varStack.peek() : null, ongoingLet);
599             addLeaf(depsequence);
600             ongoingLet = false;
601             ArrayList JavaDoc expressions = arg.getSubExpressions();
602             if (expressions != null) {
603                 stateStack.push(IN_FUNCTION);
604                 for (int i = 0; i < expressions.size(); i++) {
605                     Algebra tmpDepNode = currentDepNode;
606                     currentDepNode = depsequence;
607                     ((XQueryExpression) expressions.get(i)).accept(this);
608                     currentDepNode = tmpDepNode;
609                 }
610                 stateStack.pop();
611             }
612         }
613     }
614
615     // add LARS 16/09/2003
616
public void visit(Element arg) throws XQueryException {
617
618         Integer JavaDoc state = (Integer JavaDoc) stateStack.peek();
619         if (state == IN_DEFINITION) {
620             AlgEval depeval = null;
621             if (ongoingLocatedExpression == null) {
622                 depeval = depmanager.addEval(arg, (Variable) varStack.peek(), ongoingLet);
623             } else {
624                 depeval = depmanager.addEval(ongoingLocatedExpression, (Variable) varStack.peek(), ongoingLet);
625             }
626             addLeaf(depeval);
627         }
628     }
629
630     public void visit(AttributeValuePair arg) throws XQueryException {
631
632         Integer JavaDoc state = (Integer JavaDoc) stateStack.peek();
633         if (state == IN_DEFINITION) {
634             AlgEval depeval = depmanager.addEval(arg, (Variable) varStack.peek(), ongoingLet);
635             addLeaf(depeval);
636         }
637     }
638
639     public void visit(XQueryExpression arg) throws XQueryException {
640         //throw new XQueryException("CALL AlgebraStructureVisitor for XQueryExpression : " + arg.getClass().getName());
641
}
642
643 }
644
Popular Tags