| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.expr.parser; |
| 9 |
|
| 10 |
import net.sf.saxon.expr.*; |
| 11 |
import net.sf.saxon.functions.Doc; |
| 12 |
import net.sf.saxon.functions.DocumentFn; |
| 13 |
import net.sf.saxon.functions.ResolveURI; |
| 14 |
import net.sf.saxon.lib.Logger; |
| 15 |
import net.sf.saxon.om.AxisInfo; |
| 16 |
import net.sf.saxon.pattern.AnyNodeTest; |
| 17 |
import net.sf.saxon.pattern.NodeKindTest; |
| 18 |
import net.sf.saxon.pattern.NodeTest; |
| 19 |
import net.sf.saxon.trans.XPathException; |
| 20 |
|
| 21 |
import java.net.URI; |
| 22 |
import java.net.URISyntaxException; |
| 23 |
import java.util.*; |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
public class PathMap { |
| 44 |
|
| 45 |
private List<PathMapRoot> pathMapRoots = new ArrayList<PathMapRoot>(); |
| 46 |
private HashMap<Binding, PathMapNodeSet> pathsForVariables = |
| 47 |
new HashMap<Binding, PathMapNodeSet>(); |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
public static class PathMapNode { |
| 55 |
List<PathMapArc> arcs; |
| 56 |
private boolean returnable; |
| 57 |
private boolean atomized; |
| 58 |
private boolean hasUnknownDependencies; |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
private PathMapNode() { |
| 65 |
arcs = new ArrayList<PathMapArc>(); |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
public PathMapNode createArc(byte axis, NodeTest test) { |
| 77 |
for (PathMapArc a : arcs) { |
| 78 |
if (a.getAxis() == axis && a.getNodeTest().equals(test)) { |
| 79 |
return a.getTarget(); |
| 80 |
} |
| 81 |
} |
| 82 |
PathMapNode target = new PathMapNode(); |
| 83 |
PathMapArc arc = new PathMapArc(axis, test, target); |
| 84 |
arcs.add(arc); |
| 85 |
return target; |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
public void createArc(byte axis, NodeTest test, PathMapNode target) { |
| 97 |
for (PathMapArc a : arcs) { |
| 98 |
if (a.getAxis() == axis && a.getNodeTest().equals(test) && a.getTarget() == target) { |
| 99 |
|
| 100 |
a.getTarget().setReturnable(a.getTarget().isReturnable() || target.isReturnable()); |
| 101 |
if (target.isAtomized()) { |
| 102 |
a.getTarget().setAtomized(); |
| 103 |
} |
| 104 |
return; |
| 105 |
} |
| 106 |
} |
| 107 |
PathMapArc arc = new PathMapArc(axis, test, target); |
| 108 |
arcs.add(arc); |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
public PathMapArc[] getArcs() { |
| 118 |
return arcs.toArray(new PathMapArc[arcs.size()]); |
| 119 |
} |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
public void setReturnable(boolean returnable) { |
| 129 |
this.returnable = returnable; |
| 130 |
} |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
public boolean isReturnable() { |
| 140 |
return returnable; |
| 141 |
} |
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
public boolean hasReachableReturnables() { |
| 151 |
if (isReturnable()) { |
| 152 |
return true; |
| 153 |
} |
| 154 |
for (PathMapArc arc : arcs) { |
| 155 |
if (arc.getTarget().hasReachableReturnables()) { |
| 156 |
return true; |
| 157 |
} |
| 158 |
} |
| 159 |
return false; |
| 160 |
} |
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
public void setAtomized() { |
| 170 |
this.atomized = true; |
| 171 |
} |
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
public boolean isAtomized() { |
| 181 |
return atomized; |
| 182 |
} |
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
public void setHasUnknownDependencies() { |
| 190 |
hasUnknownDependencies = true; |
| 191 |
} |
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
public boolean hasUnknownDependencies() { |
| 201 |
return hasUnknownDependencies; |
| 202 |
} |
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
public boolean allPathsAreWithinStreamableSnapshot() { |
| 212 |
if (hasUnknownDependencies() || isReturnable() || isAtomized()) { |
| 213 |
return false; |
| 214 |
} |
| 215 |
for (PathMapArc arc : arcs) { |
| 216 |
int axis = arc.getAxis(); |
| 217 |
if (axis == AxisInfo.ATTRIBUTE) { |
| 218 |
PathMapNode next = arc.getTarget(); |
| 219 |
if (next.isReturnable()) { |
| 220 |
return false; |
| 221 |
} |
| 222 |
if (next.getArcs().length != 0 && !next.allPathsAreWithinStreamableSnapshot()) { |
| 223 |
return false; |
| 224 |
} |
| 225 |
} else if (axis == AxisInfo.SELF || axis == AxisInfo.ANCESTOR || axis == AxisInfo.ANCESTOR_OR_SELF || |
| 226 |
axis == AxisInfo.PARENT) { |
| 227 |
PathMapNode next = arc.getTarget(); |
| 228 |
if (next.isAtomized()) { |
| 229 |
return false; |
| 230 |
} |
| 231 |
if (!next.allPathsAreWithinStreamableSnapshot()) { |
| 232 |
return false; |
| 233 |
} |
| 234 |
} else { |
| 235 |
return false; |
| 236 |
} |
| 237 |
} |
| 238 |
return true; |
| 239 |
} |
| 240 |
} |
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
public static class PathMapRoot extends PathMapNode { |
| 249 |
|
| 250 |
private Expression rootExpression; |
| 251 |
private boolean isDownwardsOnly; |
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
private PathMapRoot(Expression root) { |
| 259 |
this.rootExpression = root; |
| 260 |
} |
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
public Expression getRootExpression() { |
| 268 |
return rootExpression; |
| 269 |
} |
| 270 |
|
| 271 |
} |
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
public static class PathMapArc { |
| 279 |
private PathMapNode target; |
| 280 |
private byte axis; |
| 281 |
private NodeTest test; |
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
private PathMapArc(byte axis, NodeTest test, PathMapNode target) { |
| 291 |
this.axis = axis; |
| 292 |
this.test = test; |
| 293 |
this.target = target; |
| 294 |
} |
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
public byte getAxis() { |
| 303 |
return axis; |
| 304 |
} |
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
public NodeTest getNodeTest() { |
| 313 |
return test; |
| 314 |
} |
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
public PathMapNode getTarget() { |
| 323 |
return target; |
| 324 |
} |
| 325 |
} |
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
public static class PathMapNodeSet extends HashSet<PathMapNode> { |
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
public PathMapNodeSet() { |
| 338 |
} |
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
public PathMapNodeSet(PathMapNode singleton) { |
| 347 |
add(singleton); |
| 348 |
} |
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
public PathMapNodeSet createArc(byte axis, NodeTest test) { |
| 361 |
PathMapNodeSet targetSet = new PathMapNodeSet(); |
| 362 |
for (PathMapNode node : this) { |
| 363 |
targetSet.add(node.createArc(axis, test)); |
| 364 |
} |
| 365 |
return targetSet; |
| 366 |
} |
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
public void addNodeSet( PathMapNodeSet nodes) { |
| 375 |
if (nodes != null) { |
| 376 |
for (PathMapNode node : nodes) { |
| 377 |
add(node); |
| 378 |
} |
| 379 |
} |
| 380 |
} |
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
public void setAtomized() { |
| 387 |
for (PathMapNode node : this) { |
| 388 |
node.setAtomized(); |
| 389 |
} |
| 390 |
} |
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
public void setReturnable(boolean isReturned) { |
| 397 |
for (PathMapNode node : this) { |
| 398 |
node.setReturnable(isReturned); |
| 399 |
} |
| 400 |
} |
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
public boolean hasReachableReturnables() { |
| 407 |
for (PathMapNode node : this) { |
| 408 |
if (node.hasReachableReturnables()) { |
| 409 |
return true; |
| 410 |
} |
| 411 |
} |
| 412 |
return false; |
| 413 |
} |
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
public boolean allPathsAreWithinStreamableSnapshot() { |
| 421 |
for (PathMapNode node : this) { |
| 422 |
if (!node.allPathsAreWithinStreamableSnapshot()) { |
| 423 |
return false; |
| 424 |
} |
| 425 |
} |
| 426 |
return true; |
| 427 |
} |
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
public void addDescendants() { |
| 434 |
for (PathMapNode node : this) { |
| 435 |
node.createArc(AxisInfo.DESCENDANT, AnyNodeTest.getInstance()); |
| 436 |
} |
| 437 |
} |
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
public void setHasUnknownDependencies() { |
| 444 |
for (PathMapNode node : this) { |
| 445 |
node.setHasUnknownDependencies(); |
| 446 |
} |
| 447 |
} |
| 448 |
|
| 449 |
} |
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
public PathMap( Expression exp) { |
| 458 |
PathMapNodeSet finalNodes = exp.addToPathMap(this, null); |
| 459 |
if (finalNodes != null) { |
| 460 |
for (PathMapNode node : finalNodes) { |
| 461 |
node.setReturnable(true); |
| 462 |
} |
| 463 |
} |
| 464 |
} |
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
public PathMapRoot makeNewRoot( Expression exp) { |
| 475 |
for (PathMapRoot r : pathMapRoots) { |
| 476 |
if (exp.isEqual(r.getRootExpression())) { |
| 477 |
return r; |
| 478 |
} |
| 479 |
} |
| 480 |
PathMapRoot root = new PathMapRoot(exp); |
| 481 |
pathMapRoots.add(root); |
| 482 |
return root; |
| 483 |
} |
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
public PathMapRoot[] getPathMapRoots() { |
| 492 |
return pathMapRoots.toArray(new PathMapRoot[pathMapRoots.size()]); |
| 493 |
} |
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
public void registerPathForVariable(Binding binding, PathMapNodeSet nodeset) { |
| 503 |
pathsForVariables.put(binding, nodeset); |
| 504 |
} |
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
public PathMapNodeSet getPathForVariable(Binding binding) { |
| 514 |
return pathsForVariables.get(binding); |
| 515 |
} |
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
public PathMapRoot getContextDocumentRoot() { |
| 526 |
|
| 527 |
|
| 528 |
PathMap.PathMapRoot[] roots = getPathMapRoots(); |
| 529 |
PathMapRoot contextRoot = null; |
| 530 |
for (PathMapRoot root : roots) { |
| 531 |
PathMapRoot newRoot = reduceToDownwardsAxes(root); |
| 532 |
if (newRoot.getRootExpression() instanceof RootExpression) { |
| 533 |
if (contextRoot != null) { |
| 534 |
throw new IllegalStateException("More than one context document root found in path map"); |
| 535 |
} else { |
| 536 |
contextRoot = newRoot; |
| 537 |
} |
| 538 |
} |
| 539 |
} |
| 540 |
|
| 541 |
|
| 542 |
return contextRoot; |
| 543 |
} |
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
public PathMapRoot getContextItemRoot() { |
| 554 |
|
| 555 |
|
| 556 |
PathMap.PathMapRoot[] roots = getPathMapRoots(); |
| 557 |
PathMapRoot contextRoot = null; |
| 558 |
for (PathMapRoot root : roots) { |
| 559 |
if (root.getRootExpression() instanceof ContextItemExpression) { |
| 560 |
if (contextRoot != null) { |
| 561 |
throw new IllegalStateException("More than one context document root found in path map"); |
| 562 |
} else { |
| 563 |
contextRoot = root; |
| 564 |
} |
| 565 |
} |
| 566 |
} |
| 567 |
return contextRoot; |
| 568 |
} |
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
public PathMapRoot getRootForDocument( String requiredUri) { |
| 580 |
|
| 581 |
|
| 582 |
PathMap.PathMapRoot[] roots = getPathMapRoots(); |
| 583 |
PathMapRoot requiredRoot = null; |
| 584 |
for (PathMapRoot root : roots) { |
| 585 |
PathMapRoot newRoot = reduceToDownwardsAxes(root); |
| 586 |
Expression exp = newRoot.getRootExpression(); |
| 587 |
String baseUri; |
| 588 |
if (exp.isCallOn(Doc.class)) { |
| 589 |
baseUri = exp.getStaticBaseURIString(); |
| 590 |
} else if (exp.isCallOn(DocumentFn.class)) { |
| 591 |
baseUri = exp.getStaticBaseURIString(); |
| 592 |
} else { |
| 593 |
continue; |
| 594 |
} |
| 595 |
Expression arg = ((SystemFunctionCall) exp).getArg(0); |
| 596 |
String suppliedUri = null; |
| 597 |
if (arg instanceof Literal) { |
| 598 |
try { |
| 599 |
String argValue = ((Literal) arg).getValue().getStringValue(); |
| 600 |
if (baseUri == null) { |
| 601 |
if (new URI(argValue).isAbsolute()) { |
| 602 |
suppliedUri = argValue; |
| 603 |
} else { |
| 604 |
suppliedUri = null; |
| 605 |
} |
| 606 |
} else { |
| 607 |
suppliedUri = ResolveURI.makeAbsolute(argValue, baseUri).toString(); |
| 608 |
} |
| 609 |
} catch (URISyntaxException err) { |
| 610 |
suppliedUri = null; |
| 611 |
} catch (XPathException err) { |
| 612 |
suppliedUri = null; |
| 613 |
} |
| 614 |
} |
| 615 |
if (requiredUri.equals(suppliedUri)) { |
| 616 |
if (requiredRoot != null) { |
| 617 |
throw new IllegalStateException("More than one document root found in path map for " + requiredUri); |
| 618 |
} else { |
| 619 |
requiredRoot = newRoot; |
| 620 |
} |
| 621 |
} |
| 622 |
} |
| 623 |
|
| 624 |
|
| 625 |
return requiredRoot; |
| 626 |
} |
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
public PathMapRoot reduceToDownwardsAxes( PathMapRoot root) { |
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
if (root.isDownwardsOnly) { |
| 645 |
return root; |
| 646 |
} |
| 647 |
PathMapRoot newRoot = root; |
| 648 |
if (root.getRootExpression() instanceof ContextItemExpression) { |
| 649 |
RootExpression slash = new RootExpression(); |
| 650 |
|
| 651 |
|
| 652 |
newRoot = makeNewRoot(slash); |
| 653 |
for (int i = root.arcs.size() - 1; i >= 0; i--) { |
| 654 |
PathMapArc arc = root.arcs.get(i); |
| 655 |
byte axis = arc.getAxis(); |
| 656 |
switch (axis) { |
| 657 |
case AxisInfo.ATTRIBUTE: |
| 658 |
case AxisInfo.NAMESPACE: { |
| 659 |
PathMapNode newTarget = new PathMapNode(); |
| 660 |
newTarget.arcs.add(arc); |
| 661 |
newRoot.createArc(AxisInfo.DESCENDANT, NodeKindTest.ELEMENT, newTarget); |
| 662 |
break; |
| 663 |
} |
| 664 |
default: { |
| 665 |
newRoot.createArc(AxisInfo.DESCENDANT_OR_SELF, arc.getNodeTest(), arc.getTarget()); |
| 666 |
break; |
| 667 |
} |
| 668 |
} |
| 669 |
} |
| 670 |
for (int i = 0; i < pathMapRoots.size(); i++) { |
| 671 |
if (pathMapRoots.get(i) == root) { |
| 672 |
pathMapRoots.remove(i); |
| 673 |
break; |
| 674 |
} |
| 675 |
} |
| 676 |
} |
| 677 |
|
| 678 |
|
| 679 |
Stack<PathMapNode> nodeStack = new Stack<PathMapNode>(); |
| 680 |
nodeStack.push(newRoot); |
| 681 |
reduceToDownwardsAxes(newRoot, nodeStack); |
| 682 |
newRoot.isDownwardsOnly = true; |
| 683 |
return newRoot; |
| 684 |
} |
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
private void reduceToDownwardsAxes( PathMapRoot root, Stack<PathMapNode> nodeStack) { |
| 695 |
|
| 696 |
|
| 697 |
PathMapNode node = nodeStack.peek(); |
| 698 |
if (node.hasUnknownDependencies()) { |
| 699 |
root.setHasUnknownDependencies(); |
| 700 |
} |
| 701 |
|
| 702 |
for (int i = 0; i < node.arcs.size(); i++) { |
| 703 |
nodeStack.push((node.arcs.get(i)).getTarget()); |
| 704 |
reduceToDownwardsAxes(root, nodeStack); |
| 705 |
nodeStack.pop(); |
| 706 |
} |
| 707 |
|
| 708 |
for (int i = node.arcs.size() - 1; i >= 0; i--) { |
| 709 |
PathMapArc thisArc = node.arcs.get(i); |
| 710 |
|
| 711 |
PathMapNode grandParent = |
| 712 |
(nodeStack.size() < 2 ? null : nodeStack.get(nodeStack.size() - 2)); |
| 713 |
byte lastAxis = -1; |
| 714 |
if (grandParent != null) { |
| 715 |
for (PathMapArc arc1 : grandParent.arcs) { |
| 716 |
PathMapArc arc = (arc1); |
| 717 |
if (arc.getTarget() == node) { |
| 718 |
lastAxis = arc.getAxis(); |
| 719 |
} |
| 720 |
} |
| 721 |
} |
| 722 |
switch (thisArc.getAxis()) { |
| 723 |
|
| 724 |
case AxisInfo.ANCESTOR_OR_SELF: |
| 725 |
case AxisInfo.DESCENDANT_OR_SELF: |
| 726 |
if (thisArc.getNodeTest() == NodeKindTest.DOCUMENT) { |
| 727 |
|
| 728 |
node.arcs.remove(i); |
| 729 |
for (PathMapArc arc : thisArc.getTarget().arcs) { |
| 730 |
root.arcs.add(arc); |
| 731 |
} |
| 732 |
break; |
| 733 |
} else { |
| 734 |
|
| 735 |
} |
| 736 |
|
| 737 |
case AxisInfo.ANCESTOR: |
| 738 |
case AxisInfo.FOLLOWING: |
| 739 |
case AxisInfo.PRECEDING: { |
| 740 |
|
| 741 |
if (thisArc.getAxis() != AxisInfo.DESCENDANT_OR_SELF) { |
| 742 |
root.createArc(AxisInfo.DESCENDANT_OR_SELF, thisArc.getNodeTest(), thisArc.getTarget()); |
| 743 |
node.arcs.remove(i); |
| 744 |
} |
| 745 |
break; |
| 746 |
} |
| 747 |
|
| 748 |
case AxisInfo.ATTRIBUTE: |
| 749 |
case AxisInfo.CHILD: |
| 750 |
case AxisInfo.DESCENDANT: |
| 751 |
case AxisInfo.NAMESPACE: |
| 752 |
|
| 753 |
break; |
| 754 |
|
| 755 |
case AxisInfo.FOLLOWING_SIBLING: |
| 756 |
case AxisInfo.PRECEDING_SIBLING: { |
| 757 |
if (grandParent != null) { |
| 758 |
grandParent.createArc(lastAxis, thisArc.getNodeTest(), thisArc.getTarget()); |
| 759 |
node.arcs.remove(i); |
| 760 |
break; |
| 761 |
} else { |
| 762 |
root.createArc(AxisInfo.CHILD, thisArc.getNodeTest(), thisArc.getTarget()); |
| 763 |
node.arcs.remove(i); |
| 764 |
break; |
| 765 |
} |
| 766 |
} |
| 767 |
case AxisInfo.PARENT: { |
| 768 |
|
| 769 |
if (lastAxis == AxisInfo.CHILD || lastAxis == AxisInfo.ATTRIBUTE || lastAxis == AxisInfo.NAMESPACE) { |
| 770 |
|
| 771 |
|
| 772 |
if (node.isReturnable()) { |
| 773 |
grandParent.setReturnable(true); |
| 774 |
} |
| 775 |
|
| 776 |
|
| 777 |
PathMapNode target = thisArc.getTarget(); |
| 778 |
for (int a = 0; a < target.arcs.size(); a++) { |
| 779 |
grandParent.arcs.add(target.arcs.get(a)); |
| 780 |
} |
| 781 |
node.arcs.remove(i); |
| 782 |
} else if (lastAxis == AxisInfo.DESCENDANT) { |
| 783 |
if (thisArc.getTarget().arcs.isEmpty()) { |
| 784 |
grandParent.createArc(AxisInfo.DESCENDANT_OR_SELF, thisArc.getNodeTest()); |
| 785 |
} else { |
| 786 |
grandParent.createArc(AxisInfo.DESCENDANT_OR_SELF, thisArc.getNodeTest(), thisArc.getTarget()); |
| 787 |
} |
| 788 |
node.arcs.remove(i); |
| 789 |
} else { |
| 790 |
|
| 791 |
if (thisArc.getTarget().arcs.isEmpty()) { |
| 792 |
root.createArc(AxisInfo.DESCENDANT_OR_SELF, thisArc.getNodeTest()); |
| 793 |
} else { |
| 794 |
root.createArc(AxisInfo.DESCENDANT_OR_SELF, thisArc.getNodeTest(), thisArc.getTarget()); |
| 795 |
} |
| 796 |
node.arcs.remove(i); |
| 797 |
} |
| 798 |
break; |
| 799 |
} |
| 800 |
case AxisInfo.SELF: { |
| 801 |
|
| 802 |
node.arcs.remove(i); |
| 803 |
break; |
| 804 |
} |
| 805 |
} |
| 806 |
} |
| 807 |
|
| 808 |
} |
| 809 |
|
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
|
| 814 |
|
| 815 |
|
| 816 |
public void diagnosticDump( Logger out) { |
| 817 |
for (int i = 0; i < pathMapRoots.size(); i++) { |
| 818 |
out.info("\nROOT EXPRESSION " + i); |
| 819 |
PathMapRoot mapRoot = pathMapRoots.get(i); |
| 820 |
if (mapRoot.hasUnknownDependencies()) { |
| 821 |
out.info(" -- has unknown dependencies --"); |
| 822 |
} |
| 823 |
Expression exp = mapRoot.rootExpression; |
| 824 |
exp.explain(out); |
| 825 |
out.info("\nTREE FOR EXPRESSION " + i); |
| 826 |
showArcs(out, mapRoot, 2); |
| 827 |
} |
| 828 |
} |
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
|
| 834 |
|
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
|
| 841 |
private void showArcs(Logger out, PathMapNode node, int indent) { |
| 842 |
String pad = " ".substring(0, indent); |
| 843 |
List<PathMapArc> arcs = node.arcs; |
| 844 |
for (PathMapArc arc : arcs) { |
| 845 |
out.info(pad + AxisInfo.axisName[arc.axis] + |
| 846 |
"::" + |
| 847 |
arc.test.toString() + |
| 848 |
(arc.target.isAtomized() ? " @" : "") + |
| 849 |
(arc.target.isReturnable() ? " #" : "") + |
| 850 |
(arc.target.hasUnknownDependencies() ? " ...??" : "")); |
| 851 |
showArcs(out, arc.target, indent + 2); |
| 852 |
} |
| 853 |
} |
| 854 |
|
| 855 |
} |
| 856 |
|