1 22 23 package org.xquark.mediator.algebra; 24 25 import java.util.ArrayList ; 26 27 import org.xquark.mediator.decomposer.GetVariablePathsVisitor; 28 import org.xquark.mediator.decomposer.IsolateWhereVisitor; 29 import org.xquark.mediator.plan.ExecutionPlan; 30 import org.xquark.mediator.plan.OpSourceEval; 31 import org.xquark.mediator.plan.Operator; 32 import org.xquark.mediator.runtime.MediatorException; 33 import org.xquark.xquery.parser.*; 34 import org.xquark.xquery.typing.*; 35 import org.xquark.xquery.typing.QTypeAtom; 36 37 43 public class AlgSourceEval extends Algebra { 44 private static final String RCSRevision = "$Revision: 1.10 $"; 48 private static final String RCSName = "$Name: $"; 49 73 public AlgSourceEval(XQueryExpression origexp, ArrayList variables, AlgebraManager depmanager, boolean islet) throws MediatorException { 74 super(origexp, variables, depmanager, islet); 76 } 77 78 public AlgSourceEval(XQueryExpression origexp, Variable varleaf, AlgebraManager depmanager, boolean islet) throws MediatorException { 79 super(origexp, varleaf, depmanager, islet); 81 } 82 83 87 public void ParentHasIdentifier() { 88 hasIdentifier = true; 89 } 90 91 104 105 private void createFLWRExpression() throws MediatorException { 106 if (!(expression instanceof FLWRExpression)) 107 throw new MediatorException("DepNodeEval : " + expression + " is not a FLWR."); 108 109 try { 110 FLWRExpression origflwr = (FLWRExpression) expression; 111 112 ArrayList newvariables = (ArrayList )variables.clone(); 114 newvariables.addAll(this.parent.getVarsDependingOn()); 115 newvariables.addAll(this.getVarsDependingOn()); 116 newvariables.addAll(this.getVarsWhereOn()); 118 119 XQueryExpression newWhereClause = null; 121 if (origflwr.getWhereClause() != null) { 122 newWhereClause = (XQueryExpression) origflwr.getWhereClause().clone(); 123 IsolateWhereVisitor visitor = new IsolateWhereVisitor(newvariables); 124 newWhereClause.accept(visitor); 125 newWhereClause = visitor.getIsolatedExpression(); 126 ((FLWRExpression) expression).setWhereClause(visitor.getRemainingExpression()); 128 } 129 130 if (newWhereClause != null) { 132 GetVariablePathsVisitor gvpv = new GetVariablePathsVisitor(true); 133 newWhereClause.accept(gvpv); 134 ArrayList tmplist = gvpv.getPaths(); 135 if (tmplist != null) 136 for (int i = 0; i < tmplist.size(); i++) 137 if (!this.algManager.getPathsList().contains(tmplist.get(i).toString())) 138 paths.add(tmplist.get(i)); 139 } 140 ArrayList newOrderbys = null; 142 FLWRExpression newFlwr = null; 176 if (newWhereClause != null && newWhereClause.getQType() == null) 179 newWhereClause.setQType(new QTypeAtom(this.algManager.getPlan().getSchemaManager().getBooleanType())); 180 newFlwr = new FLWRExpression(variables, newOrderbys, newWhereClause, new XQueryVoid(expression.getParentModule()), expression.getParentModule()); 181 newFlwr.setParentModule(origflwr.getParentModule()); 182 expression = newFlwr; 186 } catch (TypeException te) { 187 throw new MediatorException("DepNodeSource.createFLWRExpression : " + te.getMessage(), te); 188 } catch (CloneNotSupportedException e) { 189 throw new MediatorException("DepNodeSource.createFLWRExpression : " + e.getMessage(), e); 190 } catch (XQueryException e) { 191 throw new MediatorException("DepNodeSource.createFLWRExpression : " + e.getMessage(), e); 192 } 193 } 194 195 202 208 214 215 223 public Operator createOperator(ExecutionPlan plan) throws MediatorException { 224 createFLWRExpression(); 225 Operator algebra = new OpSourceEval(plan, expression, paths, hasIdentifier); 226 algebra.isLet(islet); 227 return algebra; 228 } 229 230 public Object clone() throws CloneNotSupportedException { 231 AlgSourceEval newobj = (AlgSourceEval) super.clone(); 232 newobj.hasIdentifier = this.hasIdentifier; 233 return newobj; 234 } 235 236 243 245 249 251 258 302 public void execute(ExecutionPlan plan) throws MediatorException {} 303 304 } 305 | Popular Tags |