KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > mediator > algebra > AlgLocated


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.mediator.algebra;
24
25 import java.util.ArrayList JavaDoc;
26
27 import org.xquark.mediator.decomposer.VariableDependencies;
28 import org.xquark.mediator.plan.*;
29 import org.xquark.mediator.runtime.MediatorException;
30 import org.xquark.xquery.parser.*;
31
32 public class AlgLocated extends Algebra {
33     // **********************************************************************
34
// * VERSIONING
35
// **********************************************************************
36
private static final String JavaDoc RCSRevision = "$Revision: 1.6 $";
37     private static final String JavaDoc RCSName = "$Name: $";
38
39     // **********************************************************************
40
// * CLASS VARIABLES
41
// **********************************************************************
42

43     // ************************************************************************
44
// * INITIALIZATION
45
// ************************************************************************
46

47     /**
48      *
49      * @param typevisitor
50      * @param expression
51      * @param var
52      * @param parent
53      */

54     public AlgLocated(LocatedExpression expression, Variable addvar, Variable var, AlgebraManager depmanager, boolean islet) {
55         super(expression, var, depmanager, islet);
56         this.addDependSourceVariable(addvar);
57
58     }
59
60     // ******************************************************************
61
// * METHODS
62
// ******************************************************************
63

64     public void ParentHasIdentifier() {
65         hasIdentifier = true;
66     }
67
68     // ******************************************************************
69
// * CREATE EXECUTION PLAN
70
// ******************************************************************
71

72     /**
73      *
74      * @param plan
75      * @return
76      */

77     public Operator createOperator(ExecutionPlan plan) throws MediatorException {
78         Variable var = (Variable) variables.get(0);
79         //Algebra algebra = new AlgNotSource(plan, expression, var, isLet(), this.hasIdentifier);
80
Operator algebra = new OpNotSource(plan, this);
81         
82         if (parent != null && parent instanceof AlgFLWR) {
83             AlgFLWR parentdep = (AlgFLWR)parent;
84             VariableDependencies vardepend = parentdep.getVarDependencies();
85             ArrayList JavaDoc tmplist = null;
86             if (vardepend != null) {
87                 // change LARS 11/03/04 all condition -> complex condition
88
ArrayList JavaDoc conds = vardepend.getAllComplexConditionsWithVar(var);
89                 if (conds != null)
90                     for (int i=0;i<conds.size();i++) {
91                         ArrayList JavaDoc vars = vardepend.getVarsOfCond((XQueryExpression)conds.get(i));
92                         if (algManager.getScopeVariables().containsAll(vars)) {
93                             if (tmplist == null)
94                                 tmplist = new ArrayList JavaDoc();
95                             tmplist.add(conds.get(i));
96                         }
97                     }
98             }
99             if (tmplist != null) {
100                 XQueryExpression tmpexpr = null;
101                 if (tmplist.size() == 1) {
102                     tmpexpr = (XQueryExpression)tmplist.get(0);
103                 }
104                 else {
105                     try {
106                         tmpexpr = new BinOpANDExpression((XQueryExpression) tmplist.get(0), (XQueryExpression) tmplist.get(1), expression.getParentModule());
107                         for (int i = 2; i < tmplist.size(); i++)
108                             tmpexpr = new BinOpANDExpression(tmpexpr, (XQueryExpression) tmplist.get(i), expression.getParentModule());
109                     } catch (XQueryException e) {
110                         throw new MediatorException("Could not build where clause", e);
111                     }
112                 }
113                 algebra = new OpRestrict(plan,tmpexpr,algebra);
114             }
115         }
116         return algebra;
117
118         
119         //algebra.isLet(islet);
120
//algebra.setDepends(depends);
121
//return null;
122
}
123
124     public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
125         AlgLocated newobj = (AlgLocated) super.clone();
126
127         return newobj;
128     }
129
130     public void execute(ExecutionPlan plan) throws MediatorException {}
131
132     // ******************************************************************
133
// * DEBUGGING
134
// ******************************************************************
135

136 }
137
Popular Tags