1 12 13 package org.xquark.mediator.decomposer; 14 15 import java.util.ArrayList ; 16 import java.util.HashSet ; 17 import java.util.Set ; 18 19 import org.xquark.xquery.metadata.MetaDataImpl; 20 import org.xquark.xquery.parser.*; 21 22 public class MakeStepsListVisitor extends DefaultParserVisitor { 23 private static final String RCSRevision = "$Revision: 1.6 $"; 27 28 private static final String RCSName = "$Name: $"; 29 30 private StepLists steplists = null; 34 35 private boolean noOrderBy = false; 36 37 43 public MakeStepsListVisitor(MetaDataImpl metadata, boolean noOrderBy) { 44 this.steplists = new StepLists(metadata); 45 this.noOrderBy = noOrderBy; 46 } 47 48 public MakeStepsListVisitor() { 59 } 60 61 public StepLists getStepsLists() { 65 return steplists; 66 } 67 68 public void setStepsLists(StepLists steplists) { 69 this.steplists = steplists; 70 } 71 72 public void visit(Element arg) throws XQueryException { 82 ArrayList al = arg.getSubExpressions(); 83 if (al == null) 84 return; 85 for (int i = 0; i < al.size(); i++) { 86 ((XQueryExpression) al.get(i)).accept(this); 87 } 88 } 89 90 public void visit(FLWRExpression arg) throws XQueryException { 91 ArrayList vars = arg.getVariables(); 92 Set sources = null; 93 Set urls = null; 94 for (int i = 0; i < vars.size(); i++) { 95 Variable vari = (Variable) vars.get(i); 96 steplists.registerVar(vari); 97 if (vari.getSourceNames() != null && !vari.getSourceNames().isEmpty()) { 98 if (sources == null) 99 sources = new HashSet (vari.getSourceNames()); 100 else 101 sources.addAll(vari.getSourceNames()); 102 } 103 if (vari.getUrls() != null && !vari.getUrls().isEmpty()) { 104 if (urls == null) 105 urls = new HashSet (vari.getUrls()); 106 else 107 urls.addAll(vari.getUrls()); 108 } 109 } 110 111 XQueryExpression expr = arg.getWhereClause(); 112 if (expr != null) { 113 steplists.newStepslist(); 114 expr.accept(this); 115 if (expr.getSourceNames() != null && !expr.getSourceNames().isEmpty()) { 116 if (sources == null) 117 sources = new HashSet (expr.getSourceNames()); 118 else 119 sources.addAll(expr.getSourceNames()); 120 } 121 if (expr.getUrls() != null && !expr.getUrls().isEmpty()) { 122 if (urls == null) 123 urls = new HashSet (expr.getUrls()); 124 else 125 urls.addAll(expr.getUrls()); 126 } 127 128 } 129 expr = arg.getReturnClause(); 130 expr.accept(this); 131 if (expr.getSourceNames() != null && !expr.getSourceNames().isEmpty()) { 132 if (sources == null) 133 sources = new HashSet (expr.getSourceNames()); 134 else 135 sources.addAll(expr.getSourceNames()); 136 } 137 if (expr.getUrls() != null && !expr.getUrls().isEmpty()) { 138 if (urls == null) 139 urls = new HashSet (expr.getUrls()); 140 else 141 urls.addAll(expr.getUrls()); 142 } 143 144 151 arg.setSourceNames(sources); 178 arg.setUrls(urls); 179 } 180 181 public void visit(QuantifiedExpression arg) throws XQueryException { 182 ArrayList vars = arg.getVariables(); 183 Set sources = null; 184 Set urls = null; 185 for (int i = 0; i < vars.size(); i++) { 186 Variable vari = (Variable) vars.get(i); 187 steplists.registerVar(vari); 188 if (vari.getSourceNames() != null && !vari.getSourceNames().isEmpty()) { 189 if (sources == null) 190 sources = new HashSet (vari.getSourceNames()); 191 else 192 sources.addAll(vari.getSourceNames()); 193 } 194 if (vari.getUrls() != null && !vari.getUrls().isEmpty()) { 195 if (urls == null) 196 urls = new HashSet (vari.getUrls()); 197 else 198 urls.addAll(vari.getUrls()); 199 } 200 } 201 202 if (arg.getExpression() != null) { 203 steplists.newStepslist(); 204 arg.getExpression().accept(this); 205 } 206 207 arg.setSourceNames(sources); 208 arg.setUrls(urls); 209 } 210 211 public void visit(FunctionCall arg) throws XQueryException { 212 ArrayList args = arg.getArguments(); 213 if (args == null) 214 return; 215 Set sources = null; 216 Set urls = null; 217 for (int i = 0; i < args.size(); i++) { 218 XQueryExpression expri = (XQueryExpression) args.get(i); 219 expri.accept(this); 220 if (expri.getSourceNames() != null && !expri.getSourceNames().isEmpty()) { 221 if (sources == null) 222 sources = new HashSet (expri.getSourceNames()); 223 else 224 sources.addAll(expri.getSourceNames()); 225 } 226 if (expri.getUrls() != null && !expri.getUrls().isEmpty()) { 227 if (urls == null) 228 urls = new HashSet (expri.getUrls()); 229 else 230 urls.addAll(expri.getUrls()); 231 } 232 } 233 arg.setSourceNames(sources); 234 arg.setUrls(urls); 235 } 236 237 250 public void visit(LocatedExpression arg) throws XQueryException { 251 steplists.newStepslist(); 252 ArrayList steps = arg.getSteps(); 253 for (int i = 0; i < steps.size(); i++) 254 ((Step) steps.get(i)).accept(this); 255 } 256 257 public void visit(SortedExpression arg) throws XQueryException { 265 arg.getExpression().accept(this); 266 arg.setSourceNames(arg.getExpression().getSourceNames()); 267 arg.setUrls(arg.getExpression().getUrls()); 268 } 269 270 public void visit(Step arg) throws XQueryException { 271 steplists.addStep(arg); 272 } 273 274 public void visit(Variable arg) throws XQueryException { 285 steplists.addStep(arg); 286 } 287 288 public void visit(XQueryBinaryOperatorExpression arg) throws XQueryException { 289 arg.getExpression1().accept(this); 290 arg.getExpression2().accept(this); 291 } 292 293 296 public void visit(XQueryExpressionSequence arg) throws XQueryException { 297 ArrayList al = arg.getSubExpressions(); 298 if (al == null) 299 return; 300 for (int i = 0; i < al.size(); i++) 301 ((XQueryExpression) al.get(i)).accept(this); 302 } 303 304 307 public void visit(XQueryUnaryOperatorExpression arg) throws XQueryException { 308 arg.getExpression().accept(this); 309 310 } 311 } | Popular Tags |