1 23 24 package org.xquark.mediator.DOMUtils; 25 26 import java.util.ArrayList ; 27 28 import org.xquark.schema.SchemaManager; 29 import org.xquark.xquery.parser.*; 30 import org.xquark.xquery.parser.util.Constants; 31 import org.xquark.xquery.typing.TypeVisitor; 32 33 34 public class GetUnknownPathsVisitor extends DefaultParserVisitor { 35 private static final String RCSRevision = "$Revision: 1.11 $"; 39 private static final String RCSName = "$Name: $"; 40 private XQueryExpression resultExpr = null; 44 private SchemaManager schemamanager = null; 45 private TypeVisitor typevisitor = null; 46 private ArrayList newVars = new ArrayList (); 47 private ArrayList knownVars = new ArrayList (); 48 54 public GetUnknownPathsVisitor(SchemaManager schemamanager, TypeVisitor typevisitor) { 55 this.schemamanager = schemamanager; 56 this.typevisitor = typevisitor; 57 } 58 59 public ArrayList getNewVariables() { 60 if (newVars.isEmpty()) 61 return null; 62 return newVars; 63 } 64 65 public void visit(XQueryExpression arg) throws XQueryException { 69 resultExpr = null; 70 } 71 72 public void visit(FunctionCall arg) throws XQueryException { 73 ArrayList arguments = arg.getArguments(); 74 if (arguments != null) { 75 for (int i = 0; i < arguments.size(); i++) { 76 XQueryExpression argi = (XQueryExpression) arguments.get(i); 77 argi.accept(this); 78 if (resultExpr != null) 79 arguments.set(i, resultExpr); 80 } 81 } 82 resultExpr = null; 83 } 84 85 public void visit(FLWRExpression arg) throws XQueryException { 86 knownVars.addAll(arg.getVariables()); 88 for (int i = 0; i < arg.getVariables().size(); i++) { 89 Variable vari = (Variable) arg.getVariables().get(i); 90 vari.getExpression().accept(this); 91 if (resultExpr != null) 92 vari.setExpression(resultExpr, false); 93 } 94 if (arg.getWhereClause() != null) { 96 arg.getWhereClause().accept(this); 97 if (resultExpr != null) 98 arg.setWhereClause(resultExpr); 99 } 100 knownVars.removeAll(arg.getVariables()); 106 } 107 108 public void visit(QuantifiedExpression arg) throws XQueryException { 109 knownVars.addAll(arg.getVariables()); 111 for (int i = 0; i < arg.getVariables().size(); i++) { 112 Variable vari = (Variable) arg.getVariables().get(i); 113 vari.getExpression().accept(this); 114 if (resultExpr != null) 115 vari.setExpression(resultExpr, false); 116 } 117 arg.getConstraintExpresson().accept(this); 118 if (resultExpr != null) 119 arg.setConstraintExpresson(resultExpr); 120 knownVars.removeAll(arg.getVariables()); 122 } 123 124 public void visit(XQueryBinaryOperatorExpression arg) throws XQueryException { 125 arg.getExpression1().accept(this); 126 if (resultExpr != null) 127 arg.setExpression1(resultExpr); 128 arg.getExpression2().accept(this); 129 if (resultExpr != null) 130 arg.setExpression2(resultExpr); 131 resultExpr = null; 132 } 133 134 public void visit(LocatedExpression arg) throws XQueryException { 135 resultExpr = null; 136 if (arg.getStepNum(0).getExpression() instanceof Variable) { 137 Variable var = (Variable)arg.getStepNum(0).getExpression(); 138 if (!knownVars.contains(var)) { 139 resultExpr = typevisitor.getStaticContext().createVariable(Constants.DECLARATION_BINDINGTYPE, arg, Variable.CAN_CREATOR); 140 newVars.add(resultExpr); 141 } 142 } 143 } 144 145 public void visit(Variable arg) throws XQueryException { 146 resultExpr = null; 147 if (!knownVars.contains(arg)) { 148 resultExpr = typevisitor.getStaticContext().createVariable(Constants.DECLARATION_BINDINGTYPE, arg, Variable.CAN_CREATOR); 149 newVars.add(resultExpr); 150 } 151 } 152 153 public void visit(ExternalVariable arg) throws XQueryException { 154 resultExpr = null; 155 if (!knownVars.contains(arg)) { 156 resultExpr = typevisitor.getStaticContext().createVariable(Constants.DECLARATION_BINDINGTYPE, arg, Variable.CAN_CREATOR); 157 newVars.add(resultExpr); 158 } 159 } 160 161 } 162 | Popular Tags |