1 23 24 package org.xquark.mediator.decomposer; 25 26 import java.util.ArrayList ; 27 28 import org.xquark.mediator.algebra.AlgFLWR; 29 import org.xquark.mediator.algebra.Algebra; 30 import org.xquark.xquery.parser.*; 31 32 public class GetUsedVariablesVisitor extends DefaultParserVisitor { 33 34 private static final String RCSRevision = "$Revision: 1.7 $"; 35 private static final String RCSName = "Name"; 36 37 private ArrayList variables = null; 39 private ArrayList declaredvariables = null; 40 44 public GetUsedVariablesVisitor() { 45 variables = new ArrayList () ; 46 declaredvariables = new ArrayList () ; 47 } 48 49 public ArrayList getVariables() { return variables; } 50 53 public void reset() { 59 if (variables != null) variables.clear(); 60 declaredvariables.clear(); 61 } 62 63 65 public void visit(Algebra arg) throws XQueryException { 66 arg.getExpression().accept(this); 67 ArrayList children = arg.getChildren(); 68 if (children != null) 69 for (int i=0;i<children.size();i++) { 70 visit((Algebra)children.get(i)); 72 } 73 if (arg.isQDB()) { 74 AlgFLWR tmpdepmem = (AlgFLWR)arg; 75 if (tmpdepmem.getDependencyList() != null) 76 for (int i=0;i<tmpdepmem.getDependencyList().size();i++) { 77 visit((AlgFLWR)tmpdepmem.getDependencyList().get(i)); 79 } 80 } 81 } 82 83 public void visit(Element arg) throws XQueryException { 91 if (arg.getStartTag() != null) { 93 arg.getStartTag().accept(this); 94 } 95 if (arg.getAttributes() != null) { 96 for (int i = 0; i < arg.getAttributes().size(); i++) { 97 ((AttributeValuePair)arg.getAttributes().get(i)).accept(this); 99 } 100 } 101 if (arg.getSubExpressions() != null) { 102 for (int j = 0; j < arg.getSubExpressions().size(); j++) { 103 ((XQueryExpression)arg.getSubExpressions().get(j)).accept(this); 105 } 106 } 107 } 109 110 public void visit(FLWRExpression arg) throws XQueryException { 111 for (int i = 0; i < arg.getVariables().size(); i++) { 112 Variable vari = (Variable)arg.getVariables().get(i); 114 declaredvariables.add(vari); 115 vari.getExpression().accept(this); 116 } 117 if (arg.getWhereClause() != null) 119 arg.getWhereClause().accept(this); 127 } 129 130 public void visit(FunctionCall arg) throws XQueryException { 131 if (arg.getArguments() != null) { 132 for (int i = 0; i < arg.getArguments().size(); i++) { 133 ((XQueryExpression)arg.getArguments().get(i)).accept(this); 135 } 136 } 137 } 138 139 143 public void visit(ITEExpression arg) throws XQueryException { 144 arg.getIfExpression().accept(this); 146 arg.getElseExpression().accept(this); 148 arg.getThenExpression().accept(this); 150 } 151 152 public void visit(LocatedExpression arg) throws XQueryException { 161 for (int i = 0; i < arg.getSteps().size(); i++) { 162 ((Step)arg.getSteps().get(i)).accept(this); 164 } 165 } 166 167 public void visit(QuantifiedExpression arg) throws XQueryException { 172 177 } 178 public void visit(Variable arg) throws XQueryException { 190 if (!declaredvariables.contains(arg)) { 191 if (!variables.contains(arg)) variables.add(arg); 193 } 194 } 195 196 public void visit(XQueryBinaryOperatorExpression arg) throws XQueryException { 197 if (arg.getExpression1() != null) { 198 arg.getExpression1().accept(this); 200 } 201 if (arg.getExpression2() != null) { 202 arg.getExpression2().accept(this); 204 } 205 } 206 207 209 211 212 public void visit(XQueryExpressionSequence arg) throws XQueryException { 213 for (int i = 0; i < arg.getSubExpressions().size(); i++) { 214 ((XQueryExpression)arg.getSubExpressions().get(i)).accept(this); 216 } 217 } 218 219 public void visit(XQueryUnaryOperatorExpression arg) throws XQueryException { 222 if (arg.getExpression() != null) { 223 arg.getExpression().accept(this); 225 } 226 } 227 228 public void visit(XQueryModule arg) throws XQueryException { 229 for (int i = 0 ; i < arg.getExpressions().size() ; i ++) { 230 XQueryExpression expressioni = (XQueryExpression) arg.getExpressions().get(i) ; 232 expressioni.accept(this) ; 233 } 234 } 235 236 238 } 239 | Popular Tags |