1 23 24 package org.xquark.xquery.parser; 25 26 import java.util.ArrayList ; 27 import java.util.HashMap ; 28 import java.util.Set ; 29 30 import org.xquark.schema.SchemaManager; 31 import org.xquark.util.NamespaceContextStack; 32 import org.xquark.xquery.normalize.PutSkolemIDsVisitor; 33 import org.xquark.xquery.normalize.SubstituteVisitor; 34 import org.xquark.xquery.parser.util.Constants; 35 import org.xquark.xquery.typing.QType; 36 import org.xquark.xquery.typing.TypeException; 37 import org.xquark.xquery.typing.TypeVisitor; 38 39 public abstract class XQueryExpression implements Cloneable { 40 private static final String RCSRevision = "$Revision: 1.51 $"; 41 private static final String RCSName = "$Name: $"; 42 43 protected boolean parenthesis = false; 45 protected boolean context = false; 46 protected int[] order = null; 48 protected ArrayList parentExpression = null; 50 protected QType qtype = null; protected ArrayList xtrees = null; 53 54 protected ArrayList skolemIDs = null; 56 protected ArrayList dependIDs = null; 57 protected boolean root = false; 58 protected boolean loop = false; 59 60 protected String loopIDs = null; 62 63 protected XQueryModule parentModule = null; 65 66 protected Set sourceNames = null; 68 protected Set urls = null; 69 70 protected String stringValue = null; 72 77 public void accept(ParserVisitor visitor) throws XQueryException { 78 visitor.visit(this); 79 } 80 81 85 public ArrayList getParentExpression() { 87 return parentExpression; 88 } 89 public void setParentExpression(XQueryExpression expression) { 90 if (expression == null) 91 return; 92 if (parentExpression == null) 93 parentExpression = new ArrayList (1); 94 else 95 parentExpression.clear(); 96 parentExpression.add(expression); 97 } 98 public void setParentExpressions(ArrayList parentExpression) { 99 this.parentExpression = parentExpression; 100 } 101 102 public QType getQType() { 104 return qtype; 105 } 106 public void setQType(QType qtype) { 107 this.qtype = qtype; 108 } 109 110 public ArrayList getXTrees() { 112 return xtrees; 113 } 114 public void setXTrees(ArrayList xtrees) { 115 this.xtrees = xtrees; 116 } 117 118 public XQueryModule getParentModule() { 120 return parentModule; 121 } 122 public void setParentModule(XQueryModule parentModule) { 123 if (parentModule == null) 124 return; 125 this.parentModule = parentModule; 126 } 127 128 public ArrayList getSkolemIDs() { 130 return skolemIDs; 131 } 132 public void setSkolemIDs(ArrayList skolemIDs) { 133 if (this.skolemIDs == null) 134 this.skolemIDs = skolemIDs; 135 else if (skolemIDs != null) { 136 for (int i = 0; i < skolemIDs.size(); i++) { 137 Variable tmpVar = (Variable) skolemIDs.get(i); 138 if (!(this.skolemIDs.contains(tmpVar))) 139 this.skolemIDs.add(0, tmpVar); 140 } 141 } 142 } 143 144 public ArrayList getDependIDs() { 145 return dependIDs; 146 } 147 public void setDependIDs(ArrayList dependIDs) { 148 this.dependIDs = dependIDs; 149 } 150 151 public boolean getRoot() { 152 return root; 153 } 154 155 160 public void setRoot(boolean root) { 161 if ((skolemIDs == null || skolemIDs.isEmpty()) && (dependIDs == null || dependIDs.isEmpty())) 162 this.root = root; 163 if (root && dependIDs != null && !dependIDs.isEmpty()) { 164 this.loop = true; 165 } 167 } 168 169 public boolean getLoop() { 170 return loop; 171 } 172 174 public String getLoopIDs() { 177 return loopIDs; 178 } 179 public void setLoopIDs(String loopIDs) { 180 this.loopIDs = loopIDs; 181 } 182 183 public boolean getParenthesis() { 185 return parenthesis; 186 } 187 public void setParenthesis(boolean parenthesis) { 188 this.parenthesis = parenthesis; 189 } 190 191 public int[] getOrder() { 193 return order; 194 } 195 public int getOrder(int index) { 196 if (order == null) 197 return Constants.NOTHING; 198 return order[index]; 199 } 200 public void setOrder(int[] order) { 201 this.order = order; 202 } 203 public void setOrder(int order) { 204 if (this.order == null) { 205 this.order = new int[2]; 206 this.order[1] = Constants.NOTHING; 207 } 208 this.order[0] = order; 209 } 210 public boolean getContext() { 212 return context; 213 } 214 public void setContext(boolean context) { 215 this.context = context; 216 } 217 218 public String getName() { 220 return null; 221 } 222 223 public void setTypeDeclaration(SequenceType typeDeclaration) { 225 return; 226 } 227 228 public void setTypeName(QName atomicType) { 230 return; 231 } 232 233 238 public void setBindingType(int bindingtype) throws XQueryException { 240 return; 241 } 242 243 public XQueryExpression erasePart(XQueryExpression expr) throws XQueryException { 245 if (this == expr) 246 return null; 247 return this; 248 } 249 250 public SchemaManager getSchemaManager() { 252 if (parentModule == null) 253 return null; 254 return parentModule.getSchemaManager(); 255 } 256 257 public boolean equals(XQueryExpression expr) { 258 259 if (this == expr) { 260 return true; 261 } 262 String thisString = this.toString(); 263 String exprString = expr.toString(); 264 if (thisString.equals(exprString)) { 265 return true; 266 } 267 return false; 268 } 269 270 public ArrayList getSteps() { 271 return null; 272 } 273 274 278 public String toString(boolean indent, boolean doNodeAccessor, boolean doPrefix) { 279 PrintVisitor pv = new PrintVisitor(); 282 pv.reset(indent, false, doNodeAccessor, doPrefix); 283 try { 284 this.accept(pv); 285 } catch (XQueryException qe) { 286 } 287 return pv.getString(); 288 } 289 public String toString() { 290 return toString(false, false, true); 291 } 292 293 public String getStringValue() { 294 return getStringValue(false, true); 295 } 296 public String getStringValue(boolean doNodeAccessor, boolean doPrefix) { 297 if ( 298 doNodeAccessor || 299 stringValue == null) { 300 stringValue = toString(false, doNodeAccessor, doPrefix); 301 } 303 return stringValue; 304 } 305 306 public String getStringValue(NamespaceContextStack context) { 309 PrintVisitor pv = new PrintVisitor(); 310 pv.reset(false, false, true, true); 311 pv.setNamespaceContextStack(context); 312 try { 313 this.accept(pv); 314 } catch (XQueryException qe) { 315 } 316 return pv.getString(); 317 } 318 319 public void resetStringValue() { 320 stringValue = null; 321 } 322 323 327 public void addParentExpression(XQueryExpression expression) { 328 if (expression == null) 329 return; 330 if (parentExpression == null) 331 parentExpression = new ArrayList (1); 332 parentExpression.add(expression); 333 } 334 335 public XQueryExpression shallowClone() { 336 try { 337 return (XQueryExpression) super.clone(); 338 } catch (CloneNotSupportedException e) { 339 } 340 return null; 341 } 342 343 public Object clone(boolean renameVars) throws CloneNotSupportedException { 344 try { 345 CloneVisitor cloneVisitor = new CloneVisitor(parentModule.getStaticContext(), renameVars); 346 this.accept(cloneVisitor); 347 return cloneVisitor.getClone(); 348 } catch (XQueryException xqe) { 349 throw new CloneNotSupportedException ("Could not clone : " + this); 350 } 351 } 352 353 public Object clone() throws CloneNotSupportedException { 354 try { 355 CloneVisitor cloneVisitor = new CloneVisitor(parentModule.getStaticContext(), true); 356 this.accept(cloneVisitor); 357 return cloneVisitor.getClone(); 358 } catch (XQueryException xqe) { 359 throw new CloneNotSupportedException ("Could not clone : " + this); 360 } 361 } 362 363 public void setSourceNames(Set sources) { 364 this.sourceNames = sources; 365 } 366 367 public Set getSourceNames() { 368 return sourceNames; 369 } 370 371 public void setUrls(Set urls) { 372 this.urls = urls; 373 } 374 375 public Set getUrls() { 376 return urls; 377 } 378 379 public boolean startsWithVariable() { 380 return false; 381 } 382 383 387 public void substitute(HashMap map, TypeVisitor typeVisitor) throws XQueryException { 388 SubstituteVisitor substituteVisitor = new SubstituteVisitor(map, typeVisitor); 389 accept(substituteVisitor); 390 } 391 392 public void putSkolemIDs(ArrayList ids) throws XQueryException { 393 PutSkolemIDsVisitor putSkolemIDsVisitor = new PutSkolemIDsVisitor(ids); 394 accept(putSkolemIDsVisitor); 395 } 396 397 } 398 | Popular Tags |