1 57 58 package org.enhydra.apache.xerces.validators.common; 59 60 import org.enhydra.apache.xerces.framework.XMLContentSpec; 61 import org.enhydra.apache.xerces.utils.ImplementationMessages; 62 import org.enhydra.apache.xerces.utils.QName; 63 import org.enhydra.apache.xerces.validators.schema.SchemaGrammar; 64 import org.enhydra.apache.xerces.validators.schema.SubstitutionGroupComparator; 65 66 74 public class DFAContentModel 75 implements XMLContentModel { 76 77 82 83 private static final int EPSILON = -2; 85 86 87 private static final int EOC = -3; 89 90 92 93 private static final boolean DEBUG_VALIDATE_CONTENT = false; 94 95 99 100 private SubstitutionGroupComparator comparator = null; 101 102 108 private QName fElemMap[] = null; 109 110 114 private int fElemMapType[] = null; 115 116 117 private int fElemMapSize = 0; 118 119 120 private boolean fDTD; 121 122 123 private boolean fMixed; 124 125 130 private int fEOCIndex = 0; 131 132 136 private int fEOCPos = 0; 137 138 143 private int fEpsilonIndex = 0; 144 145 150 private boolean fFinalStateFlags[] = null; 151 152 157 private CMStateSet fFollowList[] = null; 158 159 165 private CMNode fHeadNode = null; 166 167 171 private int fLeafCount = 0; 172 173 177 private CMLeaf fLeafList[] = null; 178 179 180 private int fLeafListType[] = null; 181 182 private ContentLeafNameTypeVector fLeafNameTypeVector = null; 183 184 188 190 202 private int fTransTable[][] = null; 203 204 208 private int fTransTableSize = 0; 209 210 218 private boolean fEmptyContentIsValid = false; 219 220 222 223 private QName fQName = new QName(); 224 225 229 238 239 public DFAContentModel( CMNode syntaxTree, 241 int leafCount) throws CMException { 242 this(syntaxTree, leafCount, false, false); 243 } 244 245 254 255 public DFAContentModel( CMNode syntaxTree, 257 int leafCount, boolean dtd, boolean mixed) throws CMException { 258 259 fLeafCount = leafCount; 262 263 276 277 280 fEpsilonIndex = EPSILON; 281 fEOCIndex = EOC; 282 283 fDTD = dtd; 284 fMixed = mixed; 285 286 296 DFAContentModel.time -= System.currentTimeMillis(); 297 298 buildDFA(syntaxTree); 299 300 DFAContentModel.time += System.currentTimeMillis(); 301 302 if (DEBUG_VALIDATE_CONTENT) 303 System.out.println("DFA build: " + DFAContentModel.time + "ms"); 304 } 305 306 private static long time = 0; 307 308 312 336 public int validateContent(QName children[], int offset, int length) throws CMException { 337 338 if (DEBUG_VALIDATE_CONTENT) 339 System.out.println("DFAContentModel#validateContent"); 340 341 if (length == 0) { 355 if (DEBUG_VALIDATE_CONTENT) { 356 System.out.println("!!! no children"); 357 System.out.println("elemMap="+fElemMap); 358 for (int i = 0; i < fElemMap.length; i++) { 359 int uriIndex = fElemMap[i].uri; 360 int localpartIndex = fElemMap[i].localpart; 361 368 } 369 System.out.println("EOCIndex="+fEOCIndex); 370 } 371 372 return fEmptyContentIsValid ? -1 : 0; 373 374 } 376 int curState = 0; 382 int nextState = 0; 383 for (int childIndex = 0; childIndex < length; childIndex++) 384 { 385 final QName curElem = children[offset + childIndex]; 387 389 390 if (fMixed && (curElem.localpart == -1)) { 392 continue; 393 } 394 395 int elemIndex = 0; 397 for (; elemIndex < fElemMapSize; elemIndex++) 398 { 399 if (fDTD) { 400 if (fElemMap[elemIndex].rawname == curElem.rawname) { 401 nextState = fTransTable[curState][elemIndex]; 402 if (nextState != -1) 403 break; 404 } 405 } 406 else { 407 int type = fElemMapType[elemIndex] & 0x0f ; 408 if (type == XMLContentSpec.CONTENTSPECNODE_LEAF) { 409 if (fElemMap[elemIndex].uri==curElem.uri 410 && fElemMap[elemIndex].localpart == curElem.localpart) 411 { 412 nextState = fTransTable[curState][elemIndex]; 413 if (nextState != -1) 414 break; 415 } 416 } 417 else if (type == XMLContentSpec.CONTENTSPECNODE_ANY) { 418 nextState = fTransTable[curState][elemIndex]; 419 if (nextState != -1) 420 break; 421 } 422 else if (type == XMLContentSpec.CONTENTSPECNODE_ANY_NS) { 423 if (curElem.uri == fElemMap[elemIndex].uri) { 424 nextState = fTransTable[curState][elemIndex]; 425 if (nextState != -1) 426 break; 427 } 428 } 429 else if (type == XMLContentSpec.CONTENTSPECNODE_ANY_OTHER) { 430 if (fElemMap[elemIndex].uri != curElem.uri) { 431 nextState = fTransTable[curState][elemIndex]; 432 if (nextState != -1) 433 break; 434 } 435 } 436 } 437 } 438 439 if (nextState == -1) { 441 if (DEBUG_VALIDATE_CONTENT) 442 System.out.println("!!! not a legal transition"); 443 return childIndex; 444 } 445 446 if (elemIndex == fElemMapSize) { 448 if (DEBUG_VALIDATE_CONTENT) { 449 System.out.println("!!! didn't find it"); 450 451 System.out.println("curElem : " +curElem ); 452 for (int i=0; i<fElemMapSize; i++) { 453 System.out.println("fElemMap["+i+"] = " +fElemMap[i] ); 454 System.out.println("fElemMapType["+i+"] = " +fElemMapType[i] ); 455 } 456 } 457 458 return childIndex; 459 } 460 461 curState = nextState; 462 nextState = 0; 463 464 } 465 466 if (DEBUG_VALIDATE_CONTENT) 472 System.out.println("curState="+curState+", childCount="+length); 473 if (!fFinalStateFlags[curState]) 474 return length; 475 476 return -1; 478 } 479 480 481 private boolean isEqual(QName name1, QName name2) { 482 return name1.localpart == name2.localpart && 483 name1.uri == name2.uri; 484 } 485 486 public int validateContentSpecial(QName children[], int offset, int length) throws Exception { 487 if (DEBUG_VALIDATE_CONTENT) 488 System.out.println("DFAContentModel#validateContentSpecial"); 489 490 if (comparator==null) { 491 return validateContent(children,offset, length); 492 } 493 494 495 if (length == 0) { 496 if (DEBUG_VALIDATE_CONTENT) { 497 System.out.println("!!! no children"); 498 System.out.println("elemMap="+fElemMap); 499 for (int i = 0; i < fElemMap.length; i++) { 500 int uriIndex = fElemMap[i].uri; 501 int localpartIndex = fElemMap[i].localpart; 502 } 503 System.out.println("EOCIndex="+fEOCIndex); 504 } 505 506 return fEmptyContentIsValid ? -1 : 0; 507 508 } 510 int curState = 0; 516 int nextState = 0; 517 for (int childIndex = 0; childIndex < length; childIndex++) 518 { 519 final QName curElem = children[offset + childIndex]; 521 522 int elemIndex = 0; 524 for (; elemIndex < fElemMapSize; elemIndex++) 525 { 526 int type = fElemMapType[elemIndex] & 0x0f ; 527 if (type == XMLContentSpec.CONTENTSPECNODE_LEAF) { 528 if (comparator.isEquivalentTo(curElem,fElemMap[elemIndex]) ) { 529 nextState = fTransTable[curState][elemIndex]; 530 if (nextState != -1) 531 break; 532 } 533 } 534 else if (type == XMLContentSpec.CONTENTSPECNODE_ANY) { 535 nextState = fTransTable[curState][elemIndex]; 536 if (nextState != -1) 537 break; 538 } 539 else if (type == XMLContentSpec.CONTENTSPECNODE_ANY_NS) { 540 if (curElem.uri == fElemMap[elemIndex].uri) { 541 nextState = fTransTable[curState][elemIndex]; 542 if (nextState != -1) 543 break; 544 } 545 } 546 else if (type == XMLContentSpec.CONTENTSPECNODE_ANY_OTHER) { 547 if (fElemMap[elemIndex].uri != curElem.uri) { 548 nextState = fTransTable[curState][elemIndex]; 549 if (nextState != -1) 550 break; 551 } 552 } 553 554 } 555 556 if (nextState == -1) { 558 if (DEBUG_VALIDATE_CONTENT) 559 System.out.println("!!! not a legal transition"); 560 return childIndex; 561 } 562 563 if (elemIndex == fElemMapSize) { 565 if (DEBUG_VALIDATE_CONTENT) { 566 System.out.println("!!! didn't find it"); 567 568 System.out.println("curElem : " +curElem ); 569 for (int i=0; i<fElemMapSize; i++) { 570 System.out.println("fElemMap["+i+"] = " +fElemMap[i] ); 571 System.out.println("fElemMapType["+i+"] = " +fElemMapType[i] ); 572 } 573 } 574 575 return childIndex; 576 } 577 578 curState = nextState; 579 nextState = 0; 580 581 } 582 583 if (DEBUG_VALIDATE_CONTENT) 589 System.out.println("curState="+curState+", childCount="+length); 590 if (!fFinalStateFlags[curState]) 591 return length; 592 593 return -1; 595 } 596 597 604 public boolean isFinalState (int state) { 605 if (state < 0) 606 return false; 607 return fFinalStateFlags[state]; 608 } 609 610 621 public int oneTransition(QName curElem, int[] stateStack, int curPos) throws Exception { 622 int curState = stateStack[curPos]; 623 624 if (curState < 0) { 626 return -1; 627 } 628 629 int nextState = 0; 630 int elemIndex = 0; 631 632 for (; elemIndex < fElemMapSize; elemIndex++) { 633 int type = fElemMapType[elemIndex] & 0x0f ; 634 if (type == XMLContentSpec.CONTENTSPECNODE_LEAF) { 635 if (isEqual(curElem, fElemMap[elemIndex])) { 636 nextState = fTransTable[curState][elemIndex]; 637 if (nextState != -1) 638 break; 639 } 640 } 641 else if (type == XMLContentSpec.CONTENTSPECNODE_ANY) { 642 nextState = fTransTable[curState][elemIndex]; 643 if (nextState != -1) 644 break; 645 } 646 else if (type == XMLContentSpec.CONTENTSPECNODE_ANY_NS) { 647 if (curElem.uri == fElemMap[elemIndex].uri) { 648 nextState = fTransTable[curState][elemIndex]; 649 if (nextState != -1) 650 break; 651 } 652 } 653 else if (type == XMLContentSpec.CONTENTSPECNODE_ANY_OTHER) { 654 if (fElemMap[elemIndex].uri != curElem.uri) { 655 nextState = fTransTable[curState][elemIndex]; 656 if (nextState != -1) 657 break; 658 } 659 } 660 } 661 662 if (elemIndex == fElemMapSize && comparator != null) { 664 for (elemIndex = 0; elemIndex < fElemMapSize; elemIndex++) { 665 if (fElemMapType[elemIndex] == XMLContentSpec.CONTENTSPECNODE_LEAF) { 666 if (comparator.isEquivalentTo(curElem,fElemMap[elemIndex])) { 667 nextState = fTransTable[curState][elemIndex]; 668 if (nextState != -1) 669 break; 670 } 671 } 672 } 673 } 674 675 if (elemIndex == fElemMapSize) { 678 stateStack[curPos] = -1; 679 return -1; 680 } 681 682 stateStack[curPos] = nextState; 683 return elemIndex; 684 } 685 686 public void setSubstitutionGroupComparator(SubstitutionGroupComparator comparator) { 687 this.comparator = comparator; 688 } 689 690 718 public int whatCanGoHere(boolean fullyValid, 719 InsertableElementsInfo info) throws CMException { 720 721 int curState = 0; 726 for (int childIndex = 0; childIndex < info.insertAt; childIndex++) 727 { 728 final QName curElem = info.curChildren[childIndex]; 730 731 int elemIndex = 0; 733 for (; elemIndex < fElemMapSize; elemIndex++) 734 { 735 if (fElemMap[elemIndex].uri == curElem.uri && 736 fElemMap[elemIndex].localpart == curElem.localpart) 737 break; 738 } 739 740 if (elemIndex == fElemMapSize) 742 return childIndex; 743 744 curState = fTransTable[curState][elemIndex]; 749 750 if (curState == -1) 752 return childIndex; 753 } 754 755 final int insertState = curState; 761 762 info.canHoldPCData = fMixed; 769 info.isValidEOC = fFinalStateFlags[insertState]; 770 771 info.resultsCount = fElemMapSize; 776 777 if ((info.results == null) || (info.results.length < info.resultsCount)) 778 info.results = new boolean[info.resultsCount]; 779 780 if ((info.possibleChildren == null) 781 || (info.possibleChildren.length < info.resultsCount)) 782 { 783 info.possibleChildren = new QName[info.resultsCount]; 784 for (int i = 0; i < info.possibleChildren.length; i++) { 785 info.possibleChildren[i] = new QName(); 786 } 787 } 788 789 for (int index = 0; index < fElemMapSize; index++) 796 { 797 info.possibleChildren[index].setValues(fElemMap[index]); 798 info.results[index] = (fTransTable[insertState][index] != -1); 799 } 800 801 if (fullyValid) 812 { 813 for (int index = 0; index < info.resultsCount; index++) 814 { 815 if (!info.results[index]) 817 continue; 818 819 info.curChildren[info.insertAt] = info.possibleChildren[index]; 821 822 if (validateContent(info.curChildren, 0, info.childCount) != -1) 824 info.results[index] = false; 825 } 826 } 827 828 return -1; 829 } 830 831 public ContentLeafNameTypeVector getContentLeafNameTypeVector() { 832 return fLeafNameTypeVector; 833 } 834 835 private byte fConflictTable[][]; 839 840 public void checkUniqueParticleAttribution(SchemaGrammar gram) throws Exception { 842 for (int i = 0; i < fElemMapSize; i++) 844 fElemMap[i].uri = gram.getContentSpecOrgUri(fElemMap[i].uri); 845 846 fConflictTable = new byte[fElemMapSize][fElemMapSize]; 848 for (int j = 0; j < fElemMapSize; j++) { 849 for (int k = j+1; k < fElemMapSize; k++) 850 fConflictTable[j][k] = -1; 851 } 852 853 for (int i = 0; i < fTransTable.length && fTransTable[i] != null; i++) { 855 for (int j = 0; j < fElemMapSize; j++) { 856 for (int k = j+1; k < fElemMapSize; k++) { 857 if (fTransTable[i][j] != -1 && 858 fTransTable[i][k] != -1) { 859 if (fConflictTable[j][k] == -1) { 860 fConflictTable[j][k] = ElementWildcard.conflict 861 (fElemMapType[j], 862 fElemMap[j].localpart, 863 fElemMap[j].uri, 864 fElemMapType[k], 865 fElemMap[k].localpart, 866 fElemMap[k].uri, 867 comparator) ? (byte)1 : (byte)0; 868 } 869 } 870 } 871 } 872 } 873 874 fConflictTable = null; 875 } 876 878 882 889 private void buildDFA(CMNode syntaxTree) throws CMException 890 { 891 920 931 932 fQName.setValues(-1, fEOCIndex, fEOCIndex); 933 CMLeaf nodeEOC = new CMLeaf(fQName); 934 fHeadNode = new CMBinOp 935 ( 936 XMLContentSpec.CONTENTSPECNODE_SEQ 937 , syntaxTree 938 , nodeEOC 939 ); 940 941 fEOCPos = fLeafCount; 949 nodeEOC.setPosition(fLeafCount++); 950 951 fLeafList = new CMLeaf[fLeafCount]; 966 fLeafListType = new int[fLeafCount]; 967 postTreeBuildInit(fHeadNode, 0); 968 969 fFollowList = new CMStateSet[fLeafCount]; 975 for (int index = 0; index < fLeafCount; index++) 976 fFollowList[index] = new CMStateSet(fLeafCount); 977 calcFollowList(fHeadNode); 978 fElemMap = new QName[fLeafCount]; 990 fElemMapType = new int[fLeafCount]; 991 fElemMapSize = 0; 992 for (int outIndex = 0; outIndex < fLeafCount; outIndex++) 993 { 994 fElemMap[outIndex] = new QName(); 995 996 if ( (fLeafListType[outIndex] & 0x0f) != 0 ) { 997 if (fLeafNameTypeVector == null) { 998 fLeafNameTypeVector = new ContentLeafNameTypeVector(); 999 } 1000 } 1001 1002 final QName element = fLeafList[outIndex].getElement(); 1004 1005 int inIndex = 0; 1007 for (; inIndex < fElemMapSize; inIndex++) 1008 { 1009 if (fDTD) { 1010 if (fElemMap[inIndex].rawname == element.rawname) { 1011 break; 1012 } 1013 } 1014 else { 1015 if (fElemMapType[inIndex] == fLeafListType[outIndex] && 1016 fElemMap[inIndex].uri == element.uri && 1017 fElemMap[inIndex].localpart == element.localpart) 1018 break; 1019 } 1020 } 1021 1022 if (inIndex == fElemMapSize) { 1024 fElemMap[fElemMapSize].setValues(element); 1029 fElemMapType[fElemMapSize] = fLeafListType[outIndex]; 1031 fElemMapSize++; 1032 } 1033 } 1034 if (fLeafNameTypeVector != null) { 1036 fLeafNameTypeVector.setValues(fElemMap, fElemMapType, fElemMapSize); 1037 } 1038 1039 1044 1045 int[] fLeafSorter = new int[fLeafCount + fElemMapSize]; 1046 int fSortCount = 0; 1047 1048 for (int elemIndex = 0; elemIndex < fElemMapSize; elemIndex++) { 1049 for (int leafIndex = 0; leafIndex < fLeafCount; leafIndex++) { 1050 final QName leaf = fLeafList[leafIndex].getElement(); 1051 final int leafType = fLeafListType[leafIndex]; 1052 final QName element = fElemMap[elemIndex]; 1053 if (fDTD) { 1054 if (leaf.rawname == element.rawname) { 1055 fLeafSorter[fSortCount++] = leafIndex; 1056 } 1057 } 1058 else if (fElemMapType[elemIndex] == fLeafListType[leafIndex] && 1059 leaf.uri == element.uri && 1060 leaf.localpart == element.localpart) { 1061 fLeafSorter[fSortCount++] = leafIndex; 1062 } 1063 } 1064 fLeafSorter[fSortCount++] = -1; 1065 } 1066 1067 1068 1069 int curArraySize = fLeafCount * 4; 1083 CMStateSet[] statesToDo = new CMStateSet[curArraySize]; 1084 fFinalStateFlags = new boolean[curArraySize]; 1085 fTransTable = new int[curArraySize][]; 1086 1087 CMStateSet setT = fHeadNode.firstPos(); 1093 1094 int unmarkedState = 0; 1103 int curState = 0; 1104 1105 fTransTable[curState] = makeDefStateList(); 1110 statesToDo[curState] = setT; 1111 curState++; 1112 1113 1116 1117 java.util.Hashtable stateTable = new java.util.Hashtable (); 1118 1119 1120 1121 while (unmarkedState < curState) 1127 { 1128 setT = statesToDo[unmarkedState]; 1133 int[] transEntry = fTransTable[unmarkedState]; 1134 1135 fFinalStateFlags[unmarkedState] = setT.getBit(fEOCPos); 1137 1138 unmarkedState++; 1140 1141 CMStateSet newSet = null; 1143 1144 int sorterIndex = 0; 1145 1146 for (int elemIndex = 0; elemIndex < fElemMapSize; elemIndex++) 1147 { 1148 if (newSet == null) 1155 newSet = new CMStateSet(fLeafCount); 1156 else 1157 newSet.zeroBits(); 1158 1159 1160 int leafIndex = fLeafSorter[sorterIndex++]; 1161 1162 while (leafIndex != -1) { 1163 if (setT.getBit(leafIndex)) 1165 { 1166 newSet.union(fFollowList[leafIndex]); 1172 } 1173 1174 leafIndex = fLeafSorter[sorterIndex++]; 1175 } 1176 1177 1178 if (!newSet.isEmpty()) 1183 { 1184 1189 1190 Integer stateObj = (Integer )stateTable.get(newSet); 1191 int stateIndex = (stateObj == null ? curState : stateObj.intValue()); 1192 1193 1194 if (stateIndex == curState) 1196 { 1197 statesToDo[curState] = newSet; 1203 fTransTable[curState] = makeDefStateList(); 1204 1205 1206 stateTable.put(newSet, new Integer (curState)); 1207 1208 1209 curState++; 1211 1212 newSet = null; 1218 } 1219 1220 transEntry[elemIndex] = stateIndex; 1227 1228 if (curState == curArraySize) 1230 { 1231 final int newSize = (int)(curArraySize * 1.5); 1237 CMStateSet[] newToDo = new CMStateSet[newSize]; 1238 boolean[] newFinalFlags = new boolean[newSize]; 1239 int[][] newTransTable = new int[newSize][]; 1240 1241 for (int expIndex = 0; expIndex < curArraySize; expIndex++) 1243 { 1244 newToDo[expIndex] = statesToDo[expIndex]; 1245 newFinalFlags[expIndex] = fFinalStateFlags[expIndex]; 1246 newTransTable[expIndex] = fTransTable[expIndex]; 1247 } 1248 1249 curArraySize = newSize; 1251 statesToDo = newToDo; 1252 fFinalStateFlags = newFinalFlags; 1253 fTransTable = newTransTable; 1254 } 1255 } 1256 } 1257 } 1258 1259 fEmptyContentIsValid = ((CMBinOp)fHeadNode).getLeft().isNullable(); 1261 1262 if (DEBUG_VALIDATE_CONTENT) 1267 dumpTree(fHeadNode, 0); 1268 fHeadNode = null; 1269 fLeafList = null; 1270 fFollowList = null; 1271 1272 } 1273 1274 1281 private void calcFollowList(CMNode nodeCur) throws CMException 1282 { 1283 if (nodeCur.type() == XMLContentSpec.CONTENTSPECNODE_CHOICE) 1285 { 1286 calcFollowList(((CMBinOp)nodeCur).getLeft()); 1288 calcFollowList(((CMBinOp)nodeCur).getRight()); 1289 } 1290 else if (nodeCur.type() == XMLContentSpec.CONTENTSPECNODE_SEQ) 1291 { 1292 calcFollowList(((CMBinOp)nodeCur).getLeft()); 1294 calcFollowList(((CMBinOp)nodeCur).getRight()); 1295 1296 final CMStateSet last = ((CMBinOp)nodeCur).getLeft().lastPos(); 1302 final CMStateSet first = ((CMBinOp)nodeCur).getRight().firstPos(); 1303 1304 for (int index = 0; index < fLeafCount; index++) 1310 { 1311 if (last.getBit(index)) 1312 fFollowList[index].union(first); 1313 } 1314 } 1315 else if (nodeCur.type() == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_MORE 1316 || nodeCur.type() == XMLContentSpec.CONTENTSPECNODE_ONE_OR_MORE) 1317 { 1318 calcFollowList(((CMUniOp)nodeCur).getChild()); 1320 1321 final CMStateSet first = nodeCur.firstPos(); 1326 final CMStateSet last = nodeCur.lastPos(); 1327 1328 for (int index = 0; index < fLeafCount; index++) 1334 { 1335 if (last.getBit(index)) 1336 fFollowList[index].union(first); 1337 } 1338 } 1339 1340 else if (nodeCur.type() == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_ONE) { 1341 calcFollowList(((CMUniOp)nodeCur).getChild()); 1343 } 1344 1345 } 1346 1347 1355 private void dumpTree(CMNode nodeCur, int level) throws CMException 1356 { 1357 for (int index = 0; index < level; index++) 1358 System.out.print(" "); 1359 1360 int type = nodeCur.type(); 1361 1362 switch(type & 0x0f) { 1363 1364 case XMLContentSpec.CONTENTSPECNODE_CHOICE: 1365 case XMLContentSpec.CONTENTSPECNODE_SEQ: 1366 { 1367 if (type == XMLContentSpec.CONTENTSPECNODE_CHOICE) 1368 System.out.print("Choice Node "); 1369 else 1370 System.out.print("Seq Node "); 1371 1372 if (nodeCur.isNullable()) 1373 System.out.print("Nullable "); 1374 1375 System.out.print("firstPos="); 1376 System.out.print(nodeCur.firstPos().toString()); 1377 System.out.print(" lastPos="); 1378 System.out.println(nodeCur.lastPos().toString()); 1379 1380 dumpTree(((CMBinOp)nodeCur).getLeft(), level+1); 1381 dumpTree(((CMBinOp)nodeCur).getRight(), level+1); 1382 break; 1383 } 1384 case XMLContentSpec.CONTENTSPECNODE_ZERO_OR_MORE: 1385 case XMLContentSpec.CONTENTSPECNODE_ONE_OR_MORE: 1386 case XMLContentSpec.CONTENTSPECNODE_ZERO_OR_ONE: 1387 { 1388 System.out.print("Rep Node "); 1389 1390 if (nodeCur.isNullable()) 1391 System.out.print("Nullable "); 1392 1393 System.out.print("firstPos="); 1394 System.out.print(nodeCur.firstPos().toString()); 1395 System.out.print(" lastPos="); 1396 System.out.println(nodeCur.lastPos().toString()); 1397 1398 dumpTree(((CMUniOp)nodeCur).getChild(), level+1); 1399 break; 1400 } 1401 case XMLContentSpec.CONTENTSPECNODE_LEAF: 1402 { 1403 System.out.print 1404 ( 1405 "Leaf: (pos=" 1406 + ((CMLeaf)nodeCur).getPosition() 1407 + "), " 1408 + ((CMLeaf)nodeCur).getElement() 1409 + "(elemIndex=" 1410 + ((CMLeaf)nodeCur).getElement() 1411 + ") " 1412 ); 1413 1414 if (nodeCur.isNullable()) 1415 System.out.print(" Nullable "); 1416 1417 System.out.print("firstPos="); 1418 System.out.print(nodeCur.firstPos().toString()); 1419 System.out.print(" lastPos="); 1420 System.out.println(nodeCur.lastPos().toString()); 1421 break; 1422 } 1423 case XMLContentSpec.CONTENTSPECNODE_ANY: 1424 case XMLContentSpec.CONTENTSPECNODE_ANY_OTHER: 1425 case XMLContentSpec.CONTENTSPECNODE_ANY_NS: 1426 { 1427 if (type == XMLContentSpec.CONTENTSPECNODE_ANY) 1428 System.out.print("Any Node: "); 1429 else if (type == XMLContentSpec.CONTENTSPECNODE_ANY_LAX) 1430 System.out.print("Any lax Node: "); 1431 else if (type == XMLContentSpec.CONTENTSPECNODE_ANY_SKIP) 1432 System.out.print("Any skip Node: "); 1433 else if (type == XMLContentSpec.CONTENTSPECNODE_ANY_OTHER) 1434 System.out.print("Any other Node: "); 1435 else if (type == XMLContentSpec.CONTENTSPECNODE_ANY_OTHER_LAX) 1436 System.out.print("Any other lax Node: "); 1437 else if (type == XMLContentSpec.CONTENTSPECNODE_ANY_OTHER_SKIP) 1438 System.out.print("Any other skip Node: "); 1439 else if (type == XMLContentSpec.CONTENTSPECNODE_ANY_NS) 1440 System.out.print("Any namespace Node: "); 1441 else if (type == XMLContentSpec.CONTENTSPECNODE_ANY_NS_LAX) 1442 System.out.print("Any namespace lax Node: "); 1443 else if (type == XMLContentSpec.CONTENTSPECNODE_ANY_NS_SKIP) 1444 System.out.print("Any namespace skip Node: "); 1445 1446 System.out.print("firstPos="); 1447 System.out.print(nodeCur.firstPos().toString()); 1448 System.out.print(" lastPos="); 1449 System.out.println(nodeCur.lastPos().toString()); 1450 break; 1451 } 1452 default: 1453 { 1454 throw new CMException(ImplementationMessages.VAL_NIICM); 1455 } 1456 } 1457 1458 } 1459 1460 1461 1466 private int[] makeDefStateList() 1467 { 1468 int[] retArray = new int[fElemMapSize]; 1469 for (int index = 0; index < fElemMapSize; index++) 1470 retArray[index] = -1; 1471 return retArray; 1472 } 1473 1474 1475 private int postTreeBuildInit(CMNode nodeCur, int curIndex) throws CMException 1476 { 1477 nodeCur.setMaxStates(fLeafCount); 1479 1480 if ((nodeCur.type() & 0x0f) == XMLContentSpec.CONTENTSPECNODE_ANY || 1482 (nodeCur.type() & 0x0f) == XMLContentSpec.CONTENTSPECNODE_ANY_NS || 1483 (nodeCur.type() & 0x0f) == XMLContentSpec.CONTENTSPECNODE_ANY_OTHER) { 1484 QName qname = new QName(-1, -1, -1, ((CMAny)nodeCur).getURI()); 1486 fLeafList[curIndex] = new CMLeaf(qname, ((CMAny)nodeCur).getPosition()); 1487 fLeafListType[curIndex] = nodeCur.type(); 1488 curIndex++; 1489 } 1490 else if ((nodeCur.type() == XMLContentSpec.CONTENTSPECNODE_CHOICE) 1491 || (nodeCur.type() == XMLContentSpec.CONTENTSPECNODE_SEQ)) 1492 { 1493 curIndex = postTreeBuildInit(((CMBinOp)nodeCur).getLeft(), curIndex); 1494 curIndex = postTreeBuildInit(((CMBinOp)nodeCur).getRight(), curIndex); 1495 } 1496 else if (nodeCur.type() == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_MORE 1497 || nodeCur.type() == XMLContentSpec.CONTENTSPECNODE_ONE_OR_MORE 1498 || nodeCur.type() == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_ONE) 1499 { 1500 curIndex = postTreeBuildInit(((CMUniOp)nodeCur).getChild(), curIndex); 1501 } 1502 else if (nodeCur.type() == XMLContentSpec.CONTENTSPECNODE_LEAF) 1503 { 1504 final QName node = ((CMLeaf)nodeCur).getElement(); 1509 if (node.localpart != fEpsilonIndex) { 1510 fLeafList[curIndex] = (CMLeaf)nodeCur; 1511 fLeafListType[curIndex] = XMLContentSpec.CONTENTSPECNODE_LEAF; 1512 curIndex++; 1513 } 1514 } 1515 else 1516 { 1517 throw new CMException(ImplementationMessages.VAL_NIICM); 1518 } 1519 return curIndex; 1520 } 1521 1522 1523} | Popular Tags |