1 57 58 package com.sun.org.apache.xerces.internal.impl.dtd; 59 60 import java.util.Hashtable ; 61 import java.util.Vector ; 62 63 import com.sun.org.apache.xerces.internal.impl.dtd.models.CMAny; 64 import com.sun.org.apache.xerces.internal.impl.dtd.models.CMBinOp; 65 import com.sun.org.apache.xerces.internal.impl.dtd.models.CMLeaf; 66 import com.sun.org.apache.xerces.internal.impl.dtd.models.CMNode; 67 import com.sun.org.apache.xerces.internal.impl.dtd.models.CMUniOp; 68 import com.sun.org.apache.xerces.internal.impl.dtd.models.ContentModelValidator; 69 import com.sun.org.apache.xerces.internal.impl.dtd.models.DFAContentModel; 70 import com.sun.org.apache.xerces.internal.impl.dtd.models.MixedContentModel; 71 import com.sun.org.apache.xerces.internal.impl.dtd.models.SimpleContentModel; 72 import com.sun.org.apache.xerces.internal.impl.dv.DatatypeValidator; 73 import com.sun.org.apache.xerces.internal.impl.validation.EntityState; 74 import com.sun.org.apache.xerces.internal.util.SymbolTable; 75 import com.sun.org.apache.xerces.internal.xni.Augmentations; 76 import com.sun.org.apache.xerces.internal.xni.QName; 77 import com.sun.org.apache.xerces.internal.xni.XMLDTDContentModelHandler; 78 import com.sun.org.apache.xerces.internal.xni.XMLDTDHandler; 79 import com.sun.org.apache.xerces.internal.xni.XMLLocator; 80 import com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier; 81 import com.sun.org.apache.xerces.internal.xni.XMLString; 82 import com.sun.org.apache.xerces.internal.xni.XNIException; 83 import com.sun.org.apache.xerces.internal.xni.grammars.Grammar; 84 import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarDescription; 85 import com.sun.org.apache.xerces.internal.xni.parser.XMLDTDContentModelSource; 86 import com.sun.org.apache.xerces.internal.xni.parser.XMLDTDSource; 87 88 100 public class DTDGrammar 101 implements XMLDTDHandler, XMLDTDContentModelHandler, EntityState, Grammar { 102 103 107 108 public static final int TOP_LEVEL_SCOPE = -1; 109 110 112 113 private static final int CHUNK_SHIFT = 8; 115 116 private static final int CHUNK_SIZE = (1 << CHUNK_SHIFT); 117 118 119 private static final int CHUNK_MASK = CHUNK_SIZE - 1; 120 121 122 private static final int INITIAL_CHUNK_COUNT = (1 << (10 - CHUNK_SHIFT)); 124 125 private static final short LIST_FLAG = 0x80; 126 127 128 private static final short LIST_MASK = ~LIST_FLAG; 129 130 132 133 private static final boolean DEBUG = false; 134 135 139 protected XMLDTDSource fDTDSource = null; 140 protected XMLDTDContentModelSource fDTDContentModelSource = null; 141 142 143 protected int fCurrentElementIndex; 144 145 146 protected int fCurrentAttributeIndex; 147 148 149 protected boolean fReadingExternalDTD = false; 150 151 152 private SymbolTable fSymbolTable; 153 154 protected XMLDTDDescription fGrammarDescription = null; 156 157 159 160 private int fElementDeclCount = 0; 161 162 163 private QName fElementDeclName[][] = new QName[INITIAL_CHUNK_COUNT][]; 164 165 169 private short fElementDeclType[][] = new short[INITIAL_CHUNK_COUNT][]; 170 171 175 private int fElementDeclContentSpecIndex[][] = new int[INITIAL_CHUNK_COUNT][]; 176 177 181 private ContentModelValidator fElementDeclContentModelValidator[][] = new ContentModelValidator[INITIAL_CHUNK_COUNT][]; 182 183 184 private int fElementDeclFirstAttributeDeclIndex[][] = new int[INITIAL_CHUNK_COUNT][]; 185 186 187 private int fElementDeclLastAttributeDeclIndex[][] = new int[INITIAL_CHUNK_COUNT][]; 188 189 191 192 private int fAttributeDeclCount = 0 ; 193 194 195 private QName fAttributeDeclName[][] = new QName[INITIAL_CHUNK_COUNT][]; 196 197 private boolean fIsImmutable = false; 199 200 204 private short fAttributeDeclType[][] = new short[INITIAL_CHUNK_COUNT][]; 205 206 207 private String [] fAttributeDeclEnumeration[][] = new String [INITIAL_CHUNK_COUNT][][]; 208 private short fAttributeDeclDefaultType[][] = new short[INITIAL_CHUNK_COUNT][]; 209 private DatatypeValidator fAttributeDeclDatatypeValidator[][] = new DatatypeValidator[INITIAL_CHUNK_COUNT][]; 210 private String fAttributeDeclDefaultValue[][] = new String [INITIAL_CHUNK_COUNT][]; 211 private String fAttributeDeclNonNormalizedDefaultValue[][] = new String [INITIAL_CHUNK_COUNT][]; 212 private int fAttributeDeclNextAttributeDeclIndex[][] = new int[INITIAL_CHUNK_COUNT][]; 213 214 216 220 private int fContentSpecCount = 0; 221 private short fContentSpecType[][] = new short[INITIAL_CHUNK_COUNT][]; 222 private Object fContentSpecValue[][] = new Object [INITIAL_CHUNK_COUNT][]; 223 private Object fContentSpecOtherValue[][] = new Object [INITIAL_CHUNK_COUNT][]; 224 225 227 private int fEntityCount = 0; 228 private String fEntityName[][] = new String [INITIAL_CHUNK_COUNT][]; 229 private String [][] fEntityValue = new String [INITIAL_CHUNK_COUNT][]; 230 private String [][] fEntityPublicId = new String [INITIAL_CHUNK_COUNT][]; 231 private String [][] fEntitySystemId = new String [INITIAL_CHUNK_COUNT][]; 232 private String [][] fEntityBaseSystemId = new String [INITIAL_CHUNK_COUNT][]; 233 private String [][] fEntityNotation = new String [INITIAL_CHUNK_COUNT][]; 234 private byte[][] fEntityIsPE = new byte[INITIAL_CHUNK_COUNT][]; 235 private byte[][] fEntityInExternal = new byte[INITIAL_CHUNK_COUNT][]; 236 237 239 private int fNotationCount = 0; 240 private String fNotationName[][] = new String [INITIAL_CHUNK_COUNT][]; 241 private String [][] fNotationPublicId = new String [INITIAL_CHUNK_COUNT][]; 242 private String [][] fNotationSystemId = new String [INITIAL_CHUNK_COUNT][]; 243 private String [][] fNotationBaseSystemId = new String [INITIAL_CHUNK_COUNT][]; 244 245 247 248 private QNameHashtable fElementIndexMap = new QNameHashtable(); 249 250 251 private QNameHashtable fEntityIndexMap = new QNameHashtable(); 252 253 254 private QNameHashtable fNotationIndexMap = new QNameHashtable(); 255 256 258 259 private boolean fMixed; 260 261 262 private QName fQName = new QName(); 263 264 265 private QName fQName2 = new QName(); 266 267 268 protected XMLAttributeDecl fAttributeDecl = new XMLAttributeDecl(); 269 270 272 private int fLeafCount = 0; 273 private int fEpsilonIndex = -1; 274 275 276 private XMLElementDecl fElementDecl = new XMLElementDecl(); 277 278 279 private XMLEntityDecl fEntityDecl = new XMLEntityDecl(); 280 281 282 private XMLSimpleType fSimpleType = new XMLSimpleType(); 283 284 285 private XMLContentSpec fContentSpec = new XMLContentSpec(); 286 287 288 Hashtable fElementDeclTab = new Hashtable (); 289 290 291 private short[] fOpStack = null; 292 293 294 private int[] fNodeIndexStack = null; 295 296 297 private int[] fPrevNodeIndexStack = null; 298 299 300 private int fDepth = 0; 301 302 303 private boolean[] fPEntityStack = new boolean[4]; 304 private int fPEDepth = 0; 305 306 308 309 private int fElementDeclIsExternal[][] = new int[INITIAL_CHUNK_COUNT][]; 310 311 312 314 315 private int fAttributeDeclIsExternal[][] = new int[INITIAL_CHUNK_COUNT][]; 316 317 319 int valueIndex = -1; 320 int prevNodeIndex = -1; 321 int nodeIndex = -1; 322 323 327 328 public DTDGrammar(SymbolTable symbolTable, XMLDTDDescription desc) { 329 fSymbolTable = symbolTable; 330 fGrammarDescription = desc; 331 } 333 335 public XMLGrammarDescription getGrammarDescription() { 337 return fGrammarDescription; 338 } 340 344 349 public boolean getElementDeclIsExternal(int elementDeclIndex) { 350 351 if (elementDeclIndex < 0) { 352 return false; 353 } 354 355 int chunk = elementDeclIndex >> CHUNK_SHIFT; 356 int index = elementDeclIndex & CHUNK_MASK; 357 return (fElementDeclIsExternal[chunk][index] != 0); 358 359 } 361 366 public boolean getAttributeDeclIsExternal(int attributeDeclIndex) { 367 368 if (attributeDeclIndex < 0) { 369 return false; 370 } 371 372 int chunk = attributeDeclIndex >> CHUNK_SHIFT; 373 int index = attributeDeclIndex & CHUNK_MASK; 374 return (fAttributeDeclIsExternal[chunk][index] != 0); 375 } 376 377 public int getAttributeDeclIndex(int elementDeclIndex, String attributeDeclName) { 378 if (elementDeclIndex == -1) { 379 return -1; 380 } 381 int attDefIndex = getFirstAttributeDeclIndex(elementDeclIndex); 382 while (attDefIndex != -1) { 383 getAttributeDecl(attDefIndex, fAttributeDecl); 384 385 if (fAttributeDecl.name.rawname == attributeDeclName 386 || attributeDeclName.equals(fAttributeDecl.name.rawname) ) { 387 return attDefIndex; 388 } 389 attDefIndex = getNextAttributeDeclIndex(attDefIndex); 390 } 391 return -1; 392 } 394 398 412 public void startDTD(XMLLocator locator, Augmentations augs) throws XNIException { 413 fOpStack = null; 415 fNodeIndexStack = null; 416 fPrevNodeIndexStack = null; 417 } 419 439 public void startParameterEntity(String name, 440 XMLResourceIdentifier identifier, 441 String encoding, 442 Augmentations augs) throws XNIException { 443 444 if (fPEDepth == fPEntityStack.length) { 446 boolean[] entityarray = new boolean[fPEntityStack.length * 2]; 447 System.arraycopy(fPEntityStack, 0, entityarray, 0, fPEntityStack.length); 448 fPEntityStack = entityarray; 449 } 450 fPEntityStack[fPEDepth] = fReadingExternalDTD; 451 fPEDepth++; 452 453 } 455 463 public void startExternalSubset(XMLResourceIdentifier identifier, 464 Augmentations augs) throws XNIException { 465 fReadingExternalDTD = true; 466 } 468 482 public void endParameterEntity(String name, Augmentations augs) throws XNIException { 483 484 fPEDepth--; 485 fReadingExternalDTD = fPEntityStack[fPEDepth]; 486 487 } 489 497 public void endExternalSubset(Augmentations augs) throws XNIException { 498 fReadingExternalDTD = false; 499 } 501 510 public void elementDecl(String name, String contentModel, Augmentations augs) 511 throws XNIException { 512 513 XMLElementDecl tmpElementDecl = (XMLElementDecl) fElementDeclTab.get(name) ; 514 515 if ( tmpElementDecl != null ) { 517 if (tmpElementDecl.type == -1) { 518 fCurrentElementIndex = getElementDeclIndex(name); 519 } 520 else { 521 return; 523 } 524 } 525 else { 526 fCurrentElementIndex = createElementDecl(); } 528 529 XMLElementDecl elementDecl = new XMLElementDecl(); 530 531 fQName.setValues(null, name, name, null); 532 533 elementDecl.name.setValues(fQName); 534 535 elementDecl.contentModelValidator = null; 536 elementDecl.scope= -1; 537 if (contentModel.equals("EMPTY")) { 538 elementDecl.type = XMLElementDecl.TYPE_EMPTY; 539 } 540 else if (contentModel.equals("ANY")) { 541 elementDecl.type = XMLElementDecl.TYPE_ANY; 542 } 543 else if (contentModel.startsWith("(") ) { 544 if (contentModel.indexOf("#PCDATA") > 0 ) { 545 elementDecl.type = XMLElementDecl.TYPE_MIXED; 546 } 547 else { 548 elementDecl.type = XMLElementDecl.TYPE_CHILDREN; 549 } 550 } 551 552 553 this.fElementDeclTab.put(name, elementDecl ); 555 556 fElementDecl = elementDecl; 557 558 if ((fDepth == 0 || 559 (fDepth == 1 && elementDecl.type == XMLElementDecl.TYPE_MIXED)) && 560 fNodeIndexStack != null) { 561 if (elementDecl.type == XMLElementDecl.TYPE_MIXED) { 562 int pcdata = addUniqueLeafNode(null); 563 if (fNodeIndexStack[0] == -1) { 564 fNodeIndexStack[0] = pcdata; 565 } 566 else { 567 fNodeIndexStack[0] = addContentSpecNode(XMLContentSpec.CONTENTSPECNODE_CHOICE, 568 pcdata, fNodeIndexStack[0]); 569 } 570 } 571 setContentSpecIndex(fCurrentElementIndex, fNodeIndexStack[fDepth]); 572 } 573 574 if ( DEBUG ) { 575 System.out.println( "name = " + fElementDecl.name.localpart ); 576 System.out.println( "Type = " + fElementDecl.type ); 577 } 578 579 setElementDecl(fCurrentElementIndex, fElementDecl ); 581 int chunk = fCurrentElementIndex >> CHUNK_SHIFT; 582 int index = fCurrentElementIndex & CHUNK_MASK; 583 ensureElementDeclCapacity(chunk); 584 fElementDeclIsExternal[chunk][index] = fReadingExternalDTD? 1 : 0; 585 586 } 588 613 public void attributeDecl(String elementName, String attributeName, 614 String type, String [] enumeration, 615 String defaultType, XMLString defaultValue, 616 XMLString nonNormalizedDefaultValue, Augmentations augs) throws XNIException { 617 618 if ( this.fElementDeclTab.containsKey( (String ) elementName) ) { 619 } 622 else { 624 fCurrentElementIndex = createElementDecl(); 626 XMLElementDecl elementDecl = new XMLElementDecl(); 627 elementDecl.name.setValues(null, elementName, elementName, null); 628 629 elementDecl.scope= -1; 630 631 this.fElementDeclTab.put(elementName, elementDecl ); 633 634 setElementDecl(fCurrentElementIndex, elementDecl ); 636 } 637 638 int elementIndex = getElementDeclIndex(elementName); 640 641 if (getAttributeDeclIndex(elementIndex, attributeName) != -1) { 644 return; 645 } 646 647 fCurrentAttributeIndex = createAttributeDecl(); 649 fSimpleType.clear(); 650 if ( defaultType != null ) { 651 if ( defaultType.equals( "#FIXED") ) { 652 fSimpleType.defaultType = XMLSimpleType.DEFAULT_TYPE_FIXED; 653 } else if ( defaultType.equals( "#IMPLIED") ) { 654 fSimpleType.defaultType = XMLSimpleType.DEFAULT_TYPE_IMPLIED; 655 } else if ( defaultType.equals( "#REQUIRED") ) { 656 fSimpleType.defaultType = XMLSimpleType.DEFAULT_TYPE_REQUIRED; 657 } 658 } 659 if ( DEBUG ) { 660 System.out.println("defaultvalue = " + defaultValue.toString() ); 661 } 662 fSimpleType.defaultValue = defaultValue!=null ? defaultValue.toString() : null; 663 fSimpleType.nonNormalizedDefaultValue = nonNormalizedDefaultValue!=null ? nonNormalizedDefaultValue.toString() : null; 664 fSimpleType.enumeration = enumeration; 665 666 if (type.equals("CDATA")) { 667 fSimpleType.type = XMLSimpleType.TYPE_CDATA; 668 } 669 else if ( type.equals("ID") ) { 670 fSimpleType.type = XMLSimpleType.TYPE_ID; 671 } 672 else if ( type.startsWith("IDREF") ) { 673 fSimpleType.type = XMLSimpleType.TYPE_IDREF; 674 if (type.indexOf("S") > 0) { 675 fSimpleType.list = true; 676 } 677 } 678 else if (type.equals("ENTITIES")) { 679 fSimpleType.type = XMLSimpleType.TYPE_ENTITY; 680 fSimpleType.list = true; 681 } 682 else if (type.equals("ENTITY")) { 683 fSimpleType.type = XMLSimpleType.TYPE_ENTITY; 684 } 685 else if (type.equals("NMTOKENS")) { 686 fSimpleType.type = XMLSimpleType.TYPE_NMTOKEN; 687 fSimpleType.list = true; 688 } 689 else if (type.equals("NMTOKEN")) { 690 fSimpleType.type = XMLSimpleType.TYPE_NMTOKEN; 691 } 692 else if (type.startsWith("NOTATION") ) { 693 fSimpleType.type = XMLSimpleType.TYPE_NOTATION; 694 } 695 else if (type.startsWith("ENUMERATION") ) { 696 fSimpleType.type = XMLSimpleType.TYPE_ENUMERATION; 697 } 698 else { 699 System.err.println("!!! unknown attribute type "+type); 701 } 702 706 fQName.setValues(null, attributeName, attributeName, null); 707 fAttributeDecl.setValues( fQName, fSimpleType, false ); 708 709 setAttributeDecl(elementIndex, fCurrentAttributeIndex, fAttributeDecl); 710 711 int chunk = fCurrentAttributeIndex >> CHUNK_SHIFT; 712 int index = fCurrentAttributeIndex & CHUNK_MASK; 713 ensureAttributeDeclCapacity(chunk); 714 fAttributeDeclIsExternal[chunk][index] = fReadingExternalDTD ? 1 : 0; 715 716 } 718 733 public void internalEntityDecl(String name, XMLString text, 734 XMLString nonNormalizedText, 735 Augmentations augs) throws XNIException { 736 737 int entityIndex = getEntityDeclIndex(name); 738 if( entityIndex == -1){ 739 entityIndex = createEntityDecl(); 740 boolean isPE = name.startsWith("%"); 741 boolean inExternal = fReadingExternalDTD; 742 XMLEntityDecl entityDecl = new XMLEntityDecl(); 743 entityDecl.setValues(name,null,null, null, null, 744 text.toString(), isPE, inExternal); 745 746 setEntityDecl(entityIndex, entityDecl); 747 } 748 749 } 751 763 public void externalEntityDecl(String name, 764 XMLResourceIdentifier identifier, 765 Augmentations augs) throws XNIException { 766 767 int entityIndex = getEntityDeclIndex(name); 768 if( entityIndex == -1){ 769 entityIndex = createEntityDecl(); 770 boolean isPE = name.startsWith("%"); 771 boolean inExternal = fReadingExternalDTD; 772 773 XMLEntityDecl entityDecl = new XMLEntityDecl(); 774 entityDecl.setValues(name, identifier.getPublicId(), identifier.getLiteralSystemId(), 775 identifier.getBaseSystemId(), 776 null, null, isPE, inExternal); 777 778 setEntityDecl(entityIndex, entityDecl); 779 } 780 } 782 793 public void unparsedEntityDecl(String name, XMLResourceIdentifier identifier, 794 String notation, 795 Augmentations augs) throws XNIException { 796 797 XMLEntityDecl entityDecl = new XMLEntityDecl(); 798 boolean isPE = name.startsWith("%"); 799 boolean inExternal = fReadingExternalDTD; 800 801 entityDecl.setValues(name,identifier.getPublicId(),identifier.getLiteralSystemId(), 802 identifier.getBaseSystemId(), notation, 803 null, isPE, inExternal); 804 int entityIndex = getEntityDeclIndex(name); 805 if (entityIndex == -1) { 806 entityIndex = createEntityDecl(); 807 setEntityDecl(entityIndex, entityDecl); 808 } 809 810 } 812 822 public void notationDecl(String name, XMLResourceIdentifier identifier, 823 Augmentations augs) throws XNIException { 824 825 XMLNotationDecl notationDecl = new XMLNotationDecl(); 826 notationDecl.setValues(name,identifier.getPublicId(),identifier.getLiteralSystemId(), 827 identifier.getBaseSystemId()); 828 int notationIndex = getNotationDeclIndex(name); 829 if (notationIndex == -1) { 830 notationIndex = createNotationDecl(); 831 setNotationDecl(notationIndex, notationDecl); 832 } 833 834 } 836 843 public void endDTD(Augmentations augs) throws XNIException { 844 fIsImmutable = true; 845 if(fGrammarDescription.getRootName() == null) { 847 int chunk, index = 0; 849 String currName = null; 850 Vector elements = new Vector (); 851 for (int i=0; i < fElementDeclCount; i++) { 852 chunk = i >> CHUNK_SHIFT; 853 index = i & CHUNK_MASK; 854 currName = fElementDeclName[chunk][index].rawname; 855 elements.addElement(currName); 856 } 857 fGrammarDescription.setPossibleRoots(elements); 858 } 859 } 861 public void setDTDSource(XMLDTDSource source) { 863 fDTDSource = source; 864 } 866 public XMLDTDSource getDTDSource() { 868 return fDTDSource; 869 } 871 873 887 public void textDecl(String version, String encoding, Augmentations augs) 888 throws XNIException {} 889 890 898 public void comment(XMLString text, Augmentations augs) throws XNIException {} 899 900 917 public void processingInstruction(String target, XMLString data, 918 Augmentations augs) throws XNIException {} 919 920 929 public void startAttlist(String elementName, Augmentations augs) 930 throws XNIException {} 931 932 938 public void endAttlist(Augmentations augs) throws XNIException {} 939 940 952 public void startConditional(short type, Augmentations augs) 953 throws XNIException {} 954 955 962 public void ignoredCharacters(XMLString text, Augmentations augs) 963 throws XNIException {} 964 965 971 public void endConditional(Augmentations augs) throws XNIException {} 972 973 977 public void setDTDContentModelSource(XMLDTDContentModelSource source) { 979 fDTDContentModelSource = source; 980 } 981 982 public XMLDTDContentModelSource getDTDContentModelSource() { 984 return fDTDContentModelSource; 985 } 986 987 997 public void startContentModel(String elementName, Augmentations augs) 998 throws XNIException { 999 1000 XMLElementDecl elementDecl = (XMLElementDecl) this.fElementDeclTab.get( elementName); 1001 if ( elementDecl != null ) { 1002 fElementDecl = elementDecl; 1003 } 1004 fDepth = 0; 1005 initializeContentModelStack(); 1006 1007 } 1009 1022 public void startGroup(Augmentations augs) throws XNIException { 1023 fDepth++; 1024 initializeContentModelStack(); 1025 fMixed = false; 1026 } 1028 1040 public void pcdata(Augmentations augs) throws XNIException { 1041 fMixed = true; 1042 } 1044 1053 public void element(String elementName, Augmentations augs) throws XNIException { 1054 if (fMixed) { 1055 if (fNodeIndexStack[fDepth] == -1 ) { 1056 fNodeIndexStack[fDepth] = addUniqueLeafNode(elementName); 1057 } 1058 else { 1059 fNodeIndexStack[fDepth] = addContentSpecNode(XMLContentSpec.CONTENTSPECNODE_CHOICE, 1060 fNodeIndexStack[fDepth], 1061 addUniqueLeafNode(elementName)); 1062 } 1063 } 1064 else { 1065 fNodeIndexStack[fDepth] = addContentSpecNode(XMLContentSpec.CONTENTSPECNODE_LEAF, elementName); 1066 } 1067 } 1069 1081 public void separator(short separator, Augmentations augs) throws XNIException { 1082 1083 if (!fMixed) { 1084 if (fOpStack[fDepth] != XMLContentSpec.CONTENTSPECNODE_SEQ && separator == XMLDTDContentModelHandler.SEPARATOR_CHOICE ) { 1085 if (fPrevNodeIndexStack[fDepth] != -1) { 1086 fNodeIndexStack[fDepth] = addContentSpecNode(fOpStack[fDepth], fPrevNodeIndexStack[fDepth], fNodeIndexStack[fDepth]); 1087 } 1088 fPrevNodeIndexStack[fDepth] = fNodeIndexStack[fDepth]; 1089 fOpStack[fDepth] = XMLContentSpec.CONTENTSPECNODE_CHOICE; 1090 } else if (fOpStack[fDepth] != XMLContentSpec.CONTENTSPECNODE_CHOICE && separator == XMLDTDContentModelHandler.SEPARATOR_SEQUENCE) { 1091 if (fPrevNodeIndexStack[fDepth] != -1) { 1092 fNodeIndexStack[fDepth] = addContentSpecNode(fOpStack[fDepth], fPrevNodeIndexStack[fDepth], fNodeIndexStack[fDepth]); 1093 } 1094 fPrevNodeIndexStack[fDepth] = fNodeIndexStack[fDepth]; 1095 fOpStack[fDepth] = XMLContentSpec.CONTENTSPECNODE_SEQ; 1096 } 1097 } 1098 1099 } 1101 1115 public void occurrence(short occurrence, Augmentations augs) throws XNIException { 1116 1117 if (!fMixed) { 1118 if (occurrence == XMLDTDContentModelHandler.OCCURS_ZERO_OR_ONE ) { 1119 fNodeIndexStack[fDepth] = addContentSpecNode(XMLContentSpec.CONTENTSPECNODE_ZERO_OR_ONE, fNodeIndexStack[fDepth], -1); 1120 } else if ( occurrence == XMLDTDContentModelHandler.OCCURS_ZERO_OR_MORE ) { 1121 fNodeIndexStack[fDepth] = addContentSpecNode(XMLContentSpec.CONTENTSPECNODE_ZERO_OR_MORE, fNodeIndexStack[fDepth], -1 ); 1122 } else if ( occurrence == XMLDTDContentModelHandler.OCCURS_ONE_OR_MORE) { 1123 fNodeIndexStack[fDepth] = addContentSpecNode(XMLContentSpec.CONTENTSPECNODE_ONE_OR_MORE, fNodeIndexStack[fDepth], -1 ); 1124 } 1125 } 1126 1127 } 1129 1136 public void endGroup(Augmentations augs) throws XNIException { 1137 1138 if (!fMixed) { 1139 if (fPrevNodeIndexStack[fDepth] != -1) { 1140 fNodeIndexStack[fDepth] = addContentSpecNode(fOpStack[fDepth], fPrevNodeIndexStack[fDepth], fNodeIndexStack[fDepth]); 1141 } 1142 int nodeIndex = fNodeIndexStack[fDepth--]; 1143 fNodeIndexStack[fDepth] = nodeIndex; 1144 } 1145 1146 } 1148 1150 1160 public void any(Augmentations augs) throws XNIException {} 1161 1162 1172 public void empty(Augmentations augs) throws XNIException {} 1173 1174 1181 public void endContentModel(Augmentations augs) throws XNIException {} 1182 1183 1187 1188 public boolean isNamespaceAware() { 1189 return false; 1190 } 1192 1193 public SymbolTable getSymbolTable() { 1194 return fSymbolTable; 1195 } 1197 1204 public int getFirstElementDeclIndex() { 1205 return fElementDeclCount >= 0 ? 0 : -1; 1206 } 1208 1214 public int getNextElementDeclIndex(int elementDeclIndex) { 1215 return elementDeclIndex < fElementDeclCount - 1 1216 ? elementDeclIndex + 1 : -1; 1217 } 1219 1226 public int getElementDeclIndex(String elementDeclName) { 1227 int mapping = fElementIndexMap.get(elementDeclName); 1228 return mapping; 1230 } 1232 1235 public int getElementDeclIndex(QName elementDeclQName) { 1236 return getElementDeclIndex(elementDeclQName.rawname); 1237 } 1239 1242 1243 public short getContentSpecType(int elementIndex){ 1244 if (elementIndex < 0 || elementIndex >= fElementDeclCount) { 1245 return -1 ; 1246 } 1247 1248 int chunk = elementIndex >> CHUNK_SHIFT; 1249 int index = elementIndex & CHUNK_MASK; 1250 1251 if(fElementDeclType[chunk][index] == -1){ 1252 return -1 ; 1253 } 1254 else{ 1255 return (short) (fElementDeclType[chunk][index] & LIST_MASK); 1256 } 1257 1258 } 1260 1268 public boolean getElementDecl(int elementDeclIndex, 1269 XMLElementDecl elementDecl) { 1270 1271 if (elementDeclIndex < 0 || elementDeclIndex >= fElementDeclCount) { 1272 return false; 1273 } 1274 1275 int chunk = elementDeclIndex >> CHUNK_SHIFT; 1276 int index = elementDeclIndex & CHUNK_MASK; 1277 1278 elementDecl.name.setValues(fElementDeclName[chunk][index]); 1279 1280 if (fElementDeclType[chunk][index] == -1) { 1281 elementDecl.type = -1; 1282 elementDecl.simpleType.list = false; 1283 } else { 1284 elementDecl.type = (short) (fElementDeclType[chunk][index] & LIST_MASK); 1285 elementDecl.simpleType.list = (fElementDeclType[chunk][index] & LIST_FLAG) != 0; 1286 } 1287 1288 1289 if (elementDecl.type == XMLElementDecl.TYPE_CHILDREN || elementDecl.type == XMLElementDecl.TYPE_MIXED) { 1290 elementDecl.contentModelValidator = getElementContentModelValidator(elementDeclIndex); 1291 } 1292 1293 elementDecl.simpleType.datatypeValidator = null; 1294 elementDecl.simpleType.defaultType = -1; 1295 elementDecl.simpleType.defaultValue = null; 1296 1297 return true; 1298 1299 } 1301 1303 1310 public int getFirstAttributeDeclIndex(int elementDeclIndex) { 1311 int chunk = elementDeclIndex >> CHUNK_SHIFT; 1312 int index = elementDeclIndex & CHUNK_MASK; 1313 1314 return fElementDeclFirstAttributeDeclIndex[chunk][index]; 1315 } 1317 1324 public int getNextAttributeDeclIndex(int attributeDeclIndex) { 1325 int chunk = attributeDeclIndex >> CHUNK_SHIFT; 1326 int index = attributeDeclIndex & CHUNK_MASK; 1327 1328 return fAttributeDeclNextAttributeDeclIndex[chunk][index]; 1329 } 1331 1339 public boolean getAttributeDecl(int attributeDeclIndex, XMLAttributeDecl attributeDecl) { 1340 if (attributeDeclIndex < 0 || attributeDeclIndex >= fAttributeDeclCount) { 1341 return false; 1342 } 1343 int chunk = attributeDeclIndex >> CHUNK_SHIFT; 1344 int index = attributeDeclIndex & CHUNK_MASK; 1345 1346 attributeDecl.name.setValues(fAttributeDeclName[chunk][index]); 1347 1348 short attributeType; 1349 boolean isList; 1350 1351 if (fAttributeDeclType[chunk][index] == -1) { 1352 1353 attributeType = -1; 1354 isList = false; 1355 } else { 1356 attributeType = (short) (fAttributeDeclType[chunk][index] & LIST_MASK); 1357 isList = (fAttributeDeclType[chunk][index] & LIST_FLAG) != 0; 1358 } 1359 attributeDecl.simpleType.setValues(attributeType,fAttributeDeclName[chunk][index].localpart, 1360 fAttributeDeclEnumeration[chunk][index], 1361 isList, fAttributeDeclDefaultType[chunk][index], 1362 fAttributeDeclDefaultValue[chunk][index], 1363 fAttributeDeclNonNormalizedDefaultValue[chunk][index], 1364 fAttributeDeclDatatypeValidator[chunk][index]); 1365 return true; 1366 1367 } 1369 1370 1378 public boolean isCDATAAttribute(QName elName, QName atName) { 1379 int elDeclIdx = getElementDeclIndex(elName); 1380 int atDeclIdx = getAttributeDeclIndex(elDeclIdx, atName.rawname); 1381 if (getAttributeDecl(elDeclIdx, fAttributeDecl) 1382 && fAttributeDecl.simpleType.type != XMLSimpleType.TYPE_CDATA){ 1383 return false; 1384 } 1385 return true; 1386 } 1387 1388 1395 public int getEntityDeclIndex(String entityDeclName) { 1396 if (entityDeclName == null) { 1397 return -1; 1398 } 1399 1400 return fEntityIndexMap.get(entityDeclName); 1401 } 1403 1412 public boolean getEntityDecl(int entityDeclIndex, XMLEntityDecl entityDecl) { 1413 if (entityDeclIndex < 0 || entityDeclIndex >= fEntityCount) { 1414 return false; 1415 } 1416 int chunk = entityDeclIndex >> CHUNK_SHIFT; 1417 int index = entityDeclIndex & CHUNK_MASK; 1418 1419 entityDecl.setValues(fEntityName[chunk][index], 1420 fEntityPublicId[chunk][index], 1421 fEntitySystemId[chunk][index], 1422 fEntityBaseSystemId[chunk][index], 1423 fEntityNotation[chunk][index], 1424 fEntityValue[chunk][index], 1425 fEntityIsPE[chunk][index] == 0 ? false : true , 1426 fEntityInExternal[chunk][index] == 0 ? false : true ); 1427 1428 return true; 1429 } 1431 1438 public int getNotationDeclIndex(String notationDeclName) { 1439 if (notationDeclName == null) { 1440 return -1; 1441 } 1442 1443 return fNotationIndexMap.get(notationDeclName); 1444 } 1446 1455 public boolean getNotationDecl(int notationDeclIndex, XMLNotationDecl notationDecl) { 1456 if (notationDeclIndex < 0 || notationDeclIndex >= fNotationCount) { 1457 return false; 1458 } 1459 int chunk = notationDeclIndex >> CHUNK_SHIFT; 1460 int index = notationDeclIndex & CHUNK_MASK; 1461 1462 notationDecl.setValues(fNotationName[chunk][index], 1463 fNotationPublicId[chunk][index], 1464 fNotationSystemId[chunk][index], 1465 fNotationBaseSystemId[chunk][index]); 1466 1467 return true; 1468 1469 } 1471 1479 public boolean getContentSpec(int contentSpecIndex, XMLContentSpec contentSpec) { 1480 if (contentSpecIndex < 0 || contentSpecIndex >= fContentSpecCount ) 1481 return false; 1482 1483 int chunk = contentSpecIndex >> CHUNK_SHIFT; 1484 int index = contentSpecIndex & CHUNK_MASK; 1485 1486 contentSpec.type = fContentSpecType[chunk][index]; 1487 contentSpec.value = fContentSpecValue[chunk][index]; 1488 contentSpec.otherValue = fContentSpecOtherValue[chunk][index]; 1489 return true; 1490 } 1491 1492 1499 public String getContentSpecAsString(int elementDeclIndex){ 1500 1501 if (elementDeclIndex < 0 || elementDeclIndex >= fElementDeclCount) { 1502 return null; 1503 } 1504 1505 int chunk = elementDeclIndex >> CHUNK_SHIFT; 1506 int index = elementDeclIndex & CHUNK_MASK; 1507 1508 int contentSpecIndex = fElementDeclContentSpecIndex[chunk][index]; 1509 1510 XMLContentSpec contentSpec = new XMLContentSpec(); 1512 1513 if (getContentSpec(contentSpecIndex, contentSpec)) { 1514 1515 StringBuffer str = new StringBuffer (); 1517 int parentContentSpecType = contentSpec.type & 0x0f; 1518 int nextContentSpec; 1519 switch (parentContentSpecType) { 1520 case XMLContentSpec.CONTENTSPECNODE_LEAF: { 1521 str.append('('); 1522 if (contentSpec.value == null && contentSpec.otherValue == null) { 1523 str.append("#PCDATA"); 1524 } 1525 else { 1526 str.append(contentSpec.value); 1527 } 1528 str.append(')'); 1529 break; 1530 } 1531 case XMLContentSpec.CONTENTSPECNODE_ZERO_OR_ONE: { 1532 getContentSpec(((int[])contentSpec.value)[0], contentSpec); 1533 nextContentSpec = contentSpec.type; 1534 1535 if (nextContentSpec == XMLContentSpec.CONTENTSPECNODE_LEAF) { 1536 str.append('('); 1537 str.append(contentSpec.value); 1538 str.append(')'); 1539 } else if( nextContentSpec == XMLContentSpec.CONTENTSPECNODE_ONE_OR_MORE || 1540 nextContentSpec == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_MORE || 1541 nextContentSpec == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_ONE ) { 1542 str.append('(' ); 1543 appendContentSpec(contentSpec, str, 1544 true, parentContentSpecType ); 1545 str.append(')'); 1546 } else { 1547 appendContentSpec(contentSpec, str, 1548 true, parentContentSpecType ); 1549 } 1550 str.append('?'); 1551 break; 1552 } 1553 case XMLContentSpec.CONTENTSPECNODE_ZERO_OR_MORE: { 1554 getContentSpec(((int[])contentSpec.value)[0], contentSpec); 1555 nextContentSpec = contentSpec.type; 1556 1557 if ( nextContentSpec == XMLContentSpec.CONTENTSPECNODE_LEAF) { 1558 str.append('('); 1559 if (contentSpec.value == null && contentSpec.otherValue == null) { 1560 str.append("#PCDATA"); 1561 } 1562 else if (contentSpec.otherValue != null) { 1563 str.append("##any:uri="+contentSpec.otherValue); 1564 } 1565 else if (contentSpec.value == null) { 1566 str.append("##any"); 1567 } 1568 else { 1569 appendContentSpec(contentSpec, str, 1570 true, parentContentSpecType ); 1571 } 1572 str.append(')'); 1573 } else if( nextContentSpec == XMLContentSpec.CONTENTSPECNODE_ONE_OR_MORE || 1574 nextContentSpec == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_MORE || 1575 nextContentSpec == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_ONE ) { 1576 str.append('(' ); 1577 appendContentSpec(contentSpec, str, 1578 true, parentContentSpecType ); 1579 str.append(')'); 1580 } else { 1581 appendContentSpec(contentSpec, str, 1582 true, parentContentSpecType ); 1583 } 1584 str.append('*'); 1585 break; 1586 } 1587 case XMLContentSpec.CONTENTSPECNODE_ONE_OR_MORE: { 1588 getContentSpec(((int[])contentSpec.value)[0], contentSpec); 1589 nextContentSpec = contentSpec.type; 1590 1591 if ( nextContentSpec == XMLContentSpec.CONTENTSPECNODE_LEAF) { 1592 str.append('('); 1593 if (contentSpec.value == null && contentSpec.otherValue == null) { 1594 str.append("#PCDATA"); 1595 } 1596 else if (contentSpec.otherValue != null) { 1597 str.append("##any:uri="+contentSpec.otherValue); 1598 } 1599 else if (contentSpec.value == null) { 1600 str.append("##any"); 1601 } 1602 else { 1603 str.append(contentSpec.value); 1604 } 1605 str.append(')'); 1606 } else if( nextContentSpec == XMLContentSpec.CONTENTSPECNODE_ONE_OR_MORE || 1607 nextContentSpec == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_MORE || 1608 nextContentSpec == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_ONE ) { 1609 str.append('(' ); 1610 appendContentSpec(contentSpec, str, 1611 true, parentContentSpecType ); 1612 str.append(')'); 1613 } else { 1614 appendContentSpec(contentSpec, str, 1615 true, parentContentSpecType); 1616 } 1617 str.append('+'); 1618 break; 1619 } 1620 case XMLContentSpec.CONTENTSPECNODE_CHOICE: 1621 case XMLContentSpec.CONTENTSPECNODE_SEQ: { 1622 appendContentSpec(contentSpec, str, 1623 true, parentContentSpecType ); 1624 break; 1625 } 1626 case XMLContentSpec.CONTENTSPECNODE_ANY: { 1627 str.append("##any"); 1628 if (contentSpec.otherValue != null) { 1629 str.append(":uri="); 1630 str.append(contentSpec.otherValue); 1631 } 1632 break; 1633 } 1634 case XMLContentSpec.CONTENTSPECNODE_ANY_OTHER: { 1635 str.append("##other:uri="); 1636 str.append(contentSpec.otherValue); 1637 break; 1638 } 1639 case XMLContentSpec.CONTENTSPECNODE_ANY_LOCAL: { 1640 str.append("##local"); 1641 break; 1642 } 1643 default: { 1644 str.append("???"); 1645 } 1646 1647 } 1649 return str.toString(); 1651 } 1652 1653 return null; 1655 1656 } 1658 1660 public void printElements( ) { 1661 int elementDeclIndex = 0; 1662 XMLElementDecl elementDecl = new XMLElementDecl(); 1663 while (getElementDecl(elementDeclIndex++, elementDecl)) { 1664 1665 System.out.println("element decl: "+elementDecl.name+ 1666 ", "+ elementDecl.name.rawname ); 1667 1668 } 1670 } 1671 1672 public void printAttributes(int elementDeclIndex) { 1673 int attributeDeclIndex = getFirstAttributeDeclIndex(elementDeclIndex); 1674 System.out.print(elementDeclIndex); 1675 System.out.print(" ["); 1676 while (attributeDeclIndex != -1) { 1677 System.out.print(' '); 1678 System.out.print(attributeDeclIndex); 1679 printAttribute(attributeDeclIndex); 1680 attributeDeclIndex = getNextAttributeDeclIndex(attributeDeclIndex); 1681 if (attributeDeclIndex != -1) { 1682 System.out.print(","); 1683 } 1684 } 1685 System.out.println(" ]"); 1686 } 1687 1688 1692 1699 protected ContentModelValidator getElementContentModelValidator(int elementDeclIndex) { 1700 1701 int chunk = elementDeclIndex >> CHUNK_SHIFT; 1702 int index = elementDeclIndex & CHUNK_MASK; 1703 1704 ContentModelValidator contentModel = fElementDeclContentModelValidator[chunk][index]; 1705 1706 if (contentModel != null) { 1708 return contentModel; 1709 } 1710 1711 int contentType = fElementDeclType[chunk][index]; 1712 if (contentType == XMLElementDecl.TYPE_SIMPLE) { 1713 return null; 1714 } 1715 1716 int contentSpecIndex = fElementDeclContentSpecIndex[chunk][index]; 1718 1719 1723 1724 XMLContentSpec contentSpec = new XMLContentSpec(); 1725 getContentSpec( contentSpecIndex, contentSpec ); 1726 1727 if ( contentType == XMLElementDecl.TYPE_MIXED ) { 1729 ChildrenList children = new ChildrenList(); 1734 contentSpecTree(contentSpecIndex, contentSpec, children); 1735 contentModel = new MixedContentModel(children.qname, 1736 children.type, 1737 0, children.length, 1738 false); 1739 } else if (contentType == XMLElementDecl.TYPE_CHILDREN) { 1740 contentModel = createChildModel(contentSpecIndex); 1747 } else { 1748 throw new RuntimeException ("Unknown content type for a element decl " 1749 + "in getElementContentModelValidator() in AbstractDTDGrammar class"); 1750 } 1751 1752 fElementDeclContentModelValidator[chunk][index] = contentModel; 1754 1755 return contentModel; 1756 1757 } 1759 protected int createElementDecl() { 1760 int chunk = fElementDeclCount >> CHUNK_SHIFT; 1761 int index = fElementDeclCount & CHUNK_MASK; 1762 ensureElementDeclCapacity(chunk); 1763 fElementDeclName[chunk][index] = new QName(); 1764 fElementDeclType[chunk][index] = -1; 1765 fElementDeclContentModelValidator[chunk][index] = null; 1766 fElementDeclFirstAttributeDeclIndex[chunk][index] = -1; 1767 fElementDeclLastAttributeDeclIndex[chunk][index] = -1; 1768 return fElementDeclCount++; 1769 } 1770 1771 protected void setElementDecl(int elementDeclIndex, XMLElementDecl elementDecl) { 1772 if (elementDeclIndex < 0 || elementDeclIndex >= fElementDeclCount) { 1773 return; 1774 } 1775 int chunk = elementDeclIndex >> CHUNK_SHIFT; 1776 int index = elementDeclIndex & CHUNK_MASK; 1777 1778 int scope = elementDecl.scope; 1779 1780 1781 fElementDeclName[chunk][index].setValues(elementDecl.name); 1782 fElementDeclType[chunk][index] = elementDecl.type; 1783 1784 fElementDeclContentModelValidator[chunk][index] = elementDecl.contentModelValidator; 1785 1786 1787 if (elementDecl.simpleType.list == true ) { 1788 fElementDeclType[chunk][index] |= LIST_FLAG; 1789 } 1790 1791 fElementIndexMap.put(elementDecl.name.rawname, elementDeclIndex); 1792 } 1793 1794 1795 1796 1797 protected void putElementNameMapping(QName name, int scope, 1798 int elementDeclIndex) { 1799 } 1800 1801 protected void setFirstAttributeDeclIndex(int elementDeclIndex, int newFirstAttrIndex){ 1802 1803 if (elementDeclIndex < 0 || elementDeclIndex >= fElementDeclCount) { 1804 return; 1805 } 1806 1807 int chunk = elementDeclIndex >> CHUNK_SHIFT; 1808 int index = elementDeclIndex & CHUNK_MASK; 1809 1810 fElementDeclFirstAttributeDeclIndex[chunk][index] = newFirstAttrIndex; 1811 } 1812 1813 protected void setContentSpecIndex(int elementDeclIndex, int contentSpecIndex){ 1814 1815 if (elementDeclIndex < 0 || elementDeclIndex >= fElementDeclCount) { 1816 return; 1817 } 1818 1819 int chunk = elementDeclIndex >> CHUNK_SHIFT; 1820 int index = elementDeclIndex & CHUNK_MASK; 1821 1822 fElementDeclContentSpecIndex[chunk][index] = contentSpecIndex; 1823 } 1824 1825 1826 protected int createAttributeDecl() { 1827 int chunk = fAttributeDeclCount >> CHUNK_SHIFT; 1828 int index = fAttributeDeclCount & CHUNK_MASK; 1829 1830 ensureAttributeDeclCapacity(chunk); 1831 fAttributeDeclName[chunk][index] = new QName(); 1832 fAttributeDeclType[chunk][index] = -1; 1833 fAttributeDeclDatatypeValidator[chunk][index] = null; 1834 fAttributeDeclEnumeration[chunk][index] = null; 1835 fAttributeDeclDefaultType[chunk][index] = XMLSimpleType.DEFAULT_TYPE_IMPLIED; 1836 fAttributeDeclDefaultValue[chunk][index] = null; 1837 fAttributeDeclNonNormalizedDefaultValue[chunk][index] = null; 1838 fAttributeDeclNextAttributeDeclIndex[chunk][index] = -1; 1839 return fAttributeDeclCount++; 1840 } 1841 1842 1843 protected void setAttributeDecl(int elementDeclIndex, int attributeDeclIndex, 1844 XMLAttributeDecl attributeDecl) { 1845 int attrChunk = attributeDeclIndex >> CHUNK_SHIFT; 1846 int attrIndex = attributeDeclIndex & CHUNK_MASK; 1847 fAttributeDeclName[attrChunk][attrIndex].setValues(attributeDecl.name); 1848 fAttributeDeclType[attrChunk][attrIndex] = attributeDecl.simpleType.type; 1849 1850 if (attributeDecl.simpleType.list) { 1851 fAttributeDeclType[attrChunk][attrIndex] |= LIST_FLAG; 1852 } 1853 fAttributeDeclEnumeration[attrChunk][attrIndex] = attributeDecl.simpleType.enumeration; 1854 fAttributeDeclDefaultType[attrChunk][attrIndex] = attributeDecl.simpleType.defaultType; 1855 fAttributeDeclDatatypeValidator[attrChunk][attrIndex] = attributeDecl.simpleType.datatypeValidator; 1856 1857 fAttributeDeclDefaultValue[attrChunk][attrIndex] = attributeDecl.simpleType.defaultValue; 1858 fAttributeDeclNonNormalizedDefaultValue[attrChunk][attrIndex] = attributeDecl.simpleType.nonNormalizedDefaultValue; 1859 1860 int elemChunk = elementDeclIndex >> CHUNK_SHIFT; 1861 int elemIndex = elementDeclIndex & CHUNK_MASK; 1862 int index = fElementDeclFirstAttributeDeclIndex[elemChunk][elemIndex]; 1863 while (index != -1) { 1864 if (index == attributeDeclIndex) { 1865 break; 1866 } 1867 attrChunk = index >> CHUNK_SHIFT; 1868 attrIndex = index & CHUNK_MASK; 1869 index = fAttributeDeclNextAttributeDeclIndex[attrChunk][attrIndex]; 1870 } 1871 if (index == -1) { 1872 if (fElementDeclFirstAttributeDeclIndex[elemChunk][elemIndex] == -1) { 1873 fElementDeclFirstAttributeDeclIndex[elemChunk][elemIndex] = attributeDeclIndex; 1874 } else { 1875 index = fElementDeclLastAttributeDeclIndex[elemChunk][elemIndex]; 1876 attrChunk = index >> CHUNK_SHIFT; 1877 attrIndex = index & CHUNK_MASK; 1878 fAttributeDeclNextAttributeDeclIndex[attrChunk][attrIndex] = attributeDeclIndex; 1879 } 1880 fElementDeclLastAttributeDeclIndex[elemChunk][elemIndex] = attributeDeclIndex; 1881 } 1882 } 1883 1884 protected int createContentSpec() { 1885 int chunk = fContentSpecCount >> CHUNK_SHIFT; 1886 int index = fContentSpecCount & CHUNK_MASK; 1887 1888 ensureContentSpecCapacity(chunk); 1889 fContentSpecType[chunk][index] = -1; 1890 fContentSpecValue[chunk][index] = null; 1891 fContentSpecOtherValue[chunk][index] = null; 1892 1893 return fContentSpecCount++; 1894 } 1895 1896 protected void setContentSpec(int contentSpecIndex, XMLContentSpec contentSpec) { 1897 int chunk = contentSpecIndex >> CHUNK_SHIFT; 1898 int index = contentSpecIndex & CHUNK_MASK; 1899 1900 fContentSpecType[chunk][index] = contentSpec.type; 1901 fContentSpecValue[chunk][index] = contentSpec.value; 1902 fContentSpecOtherValue[chunk][index] = contentSpec.otherValue; 1903 } 1904 1905 1906 protected int createEntityDecl() { 1907 int chunk = fEntityCount >> CHUNK_SHIFT; 1908 int index = fEntityCount & CHUNK_MASK; 1909 1910 ensureEntityDeclCapacity(chunk); 1911 fEntityIsPE[chunk][index] = 0; 1912 fEntityInExternal[chunk][index] = 0; 1913 1914 return fEntityCount++; 1915 } 1916 1917 protected void setEntityDecl(int entityDeclIndex, XMLEntityDecl entityDecl) { 1918 int chunk = entityDeclIndex >> CHUNK_SHIFT; 1919 int index = entityDeclIndex & CHUNK_MASK; 1920 1921 fEntityName[chunk][index] = entityDecl.name; 1922 fEntityValue[chunk][index] = entityDecl.value; 1923 fEntityPublicId[chunk][index] = entityDecl.publicId; 1924 fEntitySystemId[chunk][index] = entityDecl.systemId; 1925 fEntityBaseSystemId[chunk][index] = entityDecl.baseSystemId; 1926 fEntityNotation[chunk][index] = entityDecl.notation; 1927 fEntityIsPE[chunk][index] = entityDecl.isPE ? (byte)1 : (byte)0; 1928 fEntityInExternal[chunk][index] = entityDecl.inExternal ? (byte)1 : (byte)0; 1929 1930 fEntityIndexMap.put(entityDecl.name, entityDeclIndex); 1931 } 1932 1933 1934 protected int createNotationDecl() { 1935 int chunk = fNotationCount >> CHUNK_SHIFT; 1936 int index = fNotationCount & CHUNK_MASK; 1937 1938 ensureNotationDeclCapacity(chunk); 1939 1940 return fNotationCount++; 1941 } 1942 1943 protected void setNotationDecl(int notationDeclIndex, XMLNotationDecl notationDecl) { 1944 int chunk = notationDeclIndex >> CHUNK_SHIFT; 1945 int index = notationDeclIndex & CHUNK_MASK; 1946 1947 fNotationName[chunk][index] = notationDecl.name; 1948 fNotationPublicId[chunk][index] = notationDecl.publicId; 1949 fNotationSystemId[chunk][index] = notationDecl.systemId; 1950 fNotationBaseSystemId[chunk][index] = notationDecl.baseSystemId; 1951 1952 fNotationIndexMap.put(notationDecl.name, notationDeclIndex); 1953 } 1954 1955 1962 protected int addContentSpecNode(short nodeType, String nodeValue) { 1963 1964 int contentSpecIndex = createContentSpec(); 1966 1967 fContentSpec.setValues(nodeType, nodeValue, null); 1969 setContentSpec(contentSpecIndex, fContentSpec); 1970 1971 return contentSpecIndex; 1973 1974 } 1976 1982 protected int addUniqueLeafNode(String elementName) { 1983 1984 int contentSpecIndex = createContentSpec(); 1986 1987 fContentSpec.setValues( XMLContentSpec.CONTENTSPECNODE_LEAF, 1989 elementName, null); 1990 setContentSpec(contentSpecIndex, fContentSpec); 1991 1992 return contentSpecIndex; 1994 1995 } 1997 2005 protected int addContentSpecNode(short nodeType, 2006 int leftNodeIndex, int rightNodeIndex) { 2007 2008 int contentSpecIndex = createContentSpec(); 2010 2011 int[] leftIntArray = new int[1]; 2013 int[] rightIntArray = new int[1]; 2014 2015 leftIntArray[0] = leftNodeIndex; 2016 rightIntArray[0] = rightNodeIndex; 2017 fContentSpec.setValues(nodeType, leftIntArray, rightIntArray); 2018 setContentSpec(contentSpecIndex, fContentSpec); 2019 2020 return contentSpecIndex; 2022 2023 } 2025 2026 protected void initializeContentModelStack() { 2027 2028 if (fOpStack == null) { 2029 fOpStack = new short[8]; 2030 fNodeIndexStack = new int[8]; 2031 fPrevNodeIndexStack = new int[8]; 2032 } else if (fDepth == fOpStack.length) { 2033 short[] newStack = new short[fDepth * 2]; 2034 System.arraycopy(fOpStack, 0, newStack, 0, fDepth); 2035 fOpStack = newStack; 2036 int[] newIntStack = new int[fDepth * 2]; 2037 System.arraycopy(fNodeIndexStack, 0, newIntStack, 0, fDepth); 2038 fNodeIndexStack = newIntStack; 2039 newIntStack = new int[fDepth * 2]; 2040 System.arraycopy(fPrevNodeIndexStack, 0, newIntStack, 0, fDepth); 2041 fPrevNodeIndexStack = newIntStack; 2042 } 2043 fOpStack[fDepth] = -1; 2044 fNodeIndexStack[fDepth] = -1; 2045 fPrevNodeIndexStack[fDepth] = -1; 2046 2047 } 2049 boolean isImmutable() { 2050 return fIsImmutable; 2051 } 2052 2053 2057 private void appendContentSpec(XMLContentSpec contentSpec, 2058 StringBuffer str, boolean parens, 2059 int parentContentSpecType ) { 2060 2061 int thisContentSpec = contentSpec.type & 0x0f; 2062 switch (thisContentSpec) { 2063 case XMLContentSpec.CONTENTSPECNODE_LEAF: { 2064 if (contentSpec.value == null && contentSpec.otherValue == null) { 2065 str.append("#PCDATA"); 2066 } 2067 else if (contentSpec.value == null && contentSpec.otherValue != null) { 2068 str.append("##any:uri="+contentSpec.otherValue); 2069 } 2070 else if (contentSpec.value == null) { 2071 str.append("##any"); 2072 } 2073 else { 2074 str.append(contentSpec.value); 2075 } 2076 break; 2077 } 2078 case XMLContentSpec.CONTENTSPECNODE_ZERO_OR_ONE: { 2079 if (parentContentSpecType == XMLContentSpec.CONTENTSPECNODE_ONE_OR_MORE || 2080 parentContentSpecType == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_MORE || 2081 parentContentSpecType == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_ONE ) { 2082 getContentSpec(((int[])contentSpec.value)[0], contentSpec); 2083 str.append('('); 2084 appendContentSpec(contentSpec, str, true, thisContentSpec ); 2085 str.append(')'); 2086 } 2087 else { 2088 getContentSpec(((int[])contentSpec.value)[0], contentSpec); 2089 appendContentSpec( contentSpec, str, true, thisContentSpec ); 2090 } 2091 str.append('?'); 2092 break; 2093 } 2094 case XMLContentSpec.CONTENTSPECNODE_ZERO_OR_MORE: { 2095 if (parentContentSpecType == XMLContentSpec.CONTENTSPECNODE_ONE_OR_MORE || 2096 parentContentSpecType == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_MORE || 2097 parentContentSpecType == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_ONE ) { 2098 getContentSpec(((int[])contentSpec.value)[0], contentSpec); 2099 str.append('('); 2100 appendContentSpec(contentSpec, str, true, thisContentSpec); 2101 str.append(')' ); 2102 } 2103 else { 2104 getContentSpec(((int[])contentSpec.value)[0], contentSpec); 2105 appendContentSpec(contentSpec, str, true, thisContentSpec); 2106 } 2107 str.append('*'); 2108 break; 2109 } 2110 case XMLContentSpec.CONTENTSPECNODE_ONE_OR_MORE: { 2111 if (parentContentSpecType == XMLContentSpec.CONTENTSPECNODE_ONE_OR_MORE || 2112 parentContentSpecType == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_MORE || 2113 parentContentSpecType == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_ONE ) { 2114 2115 str.append('('); 2116 getContentSpec(((int[])contentSpec.value)[0], contentSpec); 2117 appendContentSpec(contentSpec, str, true, thisContentSpec); 2118 str.append(')' ); 2119 } 2120 else { 2121 getContentSpec(((int[])contentSpec.value)[0], contentSpec); 2122 appendContentSpec(contentSpec, str, true, thisContentSpec); 2123 } 2124 str.append('+'); 2125 break; 2126 } 2127 case XMLContentSpec.CONTENTSPECNODE_CHOICE: 2128 case XMLContentSpec.CONTENTSPECNODE_SEQ: { 2129 if (parens) { 2130 str.append('('); 2131 } 2132 int type = contentSpec.type; 2133 int otherValue = ((int[])contentSpec.otherValue)[0]; 2134 getContentSpec(((int[])contentSpec.value)[0], contentSpec); 2135 appendContentSpec(contentSpec, str, contentSpec.type != type, thisContentSpec); 2136 if (type == XMLContentSpec.CONTENTSPECNODE_CHOICE) { 2137 str.append('|'); 2138 } 2139 else { 2140 str.append(','); 2141 } 2142 getContentSpec(otherValue, contentSpec); 2143 appendContentSpec(contentSpec, str, true, thisContentSpec); 2144 if (parens) { 2145 str.append(')'); 2146 } 2147 break; 2148 } 2149 case XMLContentSpec.CONTENTSPECNODE_ANY: { 2150 str.append("##any"); 2151 if (contentSpec.otherValue != null) { 2152 str.append(":uri="); 2153 str.append(contentSpec.otherValue); 2154 } 2155 break; 2156 } 2157 case XMLContentSpec.CONTENTSPECNODE_ANY_OTHER: { 2158 str.append("##other:uri="); 2159 str.append(contentSpec.otherValue); 2160 break; 2161 } 2162 case XMLContentSpec.CONTENTSPECNODE_ANY_LOCAL: { 2163 str.append("##local"); 2164 break; 2165 } 2166 default: { 2167 str.append("???"); 2168 break; 2169 } 2170 2171 } 2173 } 2175 2177 private void printAttribute(int attributeDeclIndex) { 2178 2179 XMLAttributeDecl attributeDecl = new XMLAttributeDecl(); 2180 if (getAttributeDecl(attributeDeclIndex, attributeDecl)) { 2181 System.out.print(" { "); 2182 System.out.print(attributeDecl.name.localpart); 2183 System.out.print(" }"); 2184 } 2185 2186 } 2188 2190 2196 private ContentModelValidator createChildModel(int contentSpecIndex) { 2197 2198 XMLContentSpec contentSpec = new XMLContentSpec(); 2204 getContentSpec(contentSpecIndex, contentSpec); 2205 2206 if ((contentSpec.type & 0x0f ) == XMLContentSpec.CONTENTSPECNODE_ANY || 2207 (contentSpec.type & 0x0f ) == XMLContentSpec.CONTENTSPECNODE_ANY_OTHER || 2208 (contentSpec.type & 0x0f ) == XMLContentSpec.CONTENTSPECNODE_ANY_LOCAL) { 2209 } 2211 2212 else if (contentSpec.type == XMLContentSpec.CONTENTSPECNODE_LEAF) { 2213 if (contentSpec.value == null && contentSpec.otherValue == null) 2218 throw new RuntimeException ("ImplementationMessages.VAL_NPCD"); 2219 2220 2226 fQName.setValues(null, (String )contentSpec.value, 2227 (String )contentSpec.value, (String )contentSpec.otherValue); 2228 return new SimpleContentModel(contentSpec.type, fQName, null); 2229 } else if ((contentSpec.type == XMLContentSpec.CONTENTSPECNODE_CHOICE) 2230 || (contentSpec.type == XMLContentSpec.CONTENTSPECNODE_SEQ)) { 2231 XMLContentSpec contentSpecLeft = new XMLContentSpec(); 2236 XMLContentSpec contentSpecRight = new XMLContentSpec(); 2237 2238 getContentSpec( ((int[])contentSpec.value)[0], contentSpecLeft); 2239 getContentSpec( ((int[])contentSpec.otherValue)[0], contentSpecRight); 2240 2241 if ((contentSpecLeft.type == XMLContentSpec.CONTENTSPECNODE_LEAF) 2242 && (contentSpecRight.type == XMLContentSpec.CONTENTSPECNODE_LEAF)) { 2243 fQName.setValues(null, (String )contentSpecLeft.value, 2248 (String )contentSpecLeft.value, (String )contentSpecLeft.otherValue); 2249 fQName2.setValues(null, (String )contentSpecRight.value, 2250 (String )contentSpecRight.value, (String )contentSpecRight.otherValue); 2251 return new SimpleContentModel(contentSpec.type, fQName, fQName2); 2252 } 2253 } else if ((contentSpec.type == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_ONE) 2254 || (contentSpec.type == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_MORE) 2255 || (contentSpec.type == XMLContentSpec.CONTENTSPECNODE_ONE_OR_MORE)) { 2256 XMLContentSpec contentSpecLeft = new XMLContentSpec(); 2262 getContentSpec(((int[])contentSpec.value)[0], contentSpecLeft); 2263 2264 if (contentSpecLeft.type == XMLContentSpec.CONTENTSPECNODE_LEAF) { 2265 fQName.setValues(null, (String )contentSpecLeft.value, 2271 (String )contentSpecLeft.value, (String )contentSpecLeft.otherValue); 2272 return new SimpleContentModel(contentSpec.type, fQName, null); 2273 } 2274 } else { 2275 throw new RuntimeException ("ImplementationMessages.VAL_CST"); 2276 } 2277 2278 2284 fLeafCount = 0; 2285 fLeafCount = 0; 2287 CMNode cmn = buildSyntaxTree(contentSpecIndex, contentSpec); 2288 2289 return new DFAContentModel( cmn, fLeafCount, false); 2291 2292 } 2294 private final CMNode buildSyntaxTree(int startNode, 2295 XMLContentSpec contentSpec) { 2296 2297 CMNode nodeRet = null; 2299 getContentSpec(startNode, contentSpec); 2300 if ((contentSpec.type & 0x0f) == XMLContentSpec.CONTENTSPECNODE_ANY) { 2301 nodeRet = new CMAny(contentSpec.type, (String )contentSpec.otherValue, fLeafCount++); 2303 } 2304 else if ((contentSpec.type & 0x0f) == XMLContentSpec.CONTENTSPECNODE_ANY_OTHER) { 2305 nodeRet = new CMAny(contentSpec.type, (String )contentSpec.otherValue, fLeafCount++); 2306 } 2307 else if ((contentSpec.type & 0x0f) == XMLContentSpec.CONTENTSPECNODE_ANY_LOCAL) { 2308 nodeRet = new CMAny(contentSpec.type, null, fLeafCount++); 2309 } 2310 else if (contentSpec.type == XMLContentSpec.CONTENTSPECNODE_LEAF) { 2315 fQName.setValues(null, (String )contentSpec.value, 2322 (String )contentSpec.value, (String )contentSpec.otherValue); 2323 nodeRet = new CMLeaf(fQName, fLeafCount++); 2324 } 2325 else { 2326 final int leftNode = ((int[])contentSpec.value)[0]; 2330 final int rightNode = ((int[])contentSpec.otherValue)[0]; 2331 2332 if ((contentSpec.type == XMLContentSpec.CONTENTSPECNODE_CHOICE) 2333 || (contentSpec.type == XMLContentSpec.CONTENTSPECNODE_SEQ)) { 2334 2340 nodeRet = new CMBinOp( contentSpec.type, buildSyntaxTree(leftNode, contentSpec) 2341 , buildSyntaxTree(rightNode, contentSpec)); 2342 } 2343 else if (contentSpec.type == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_MORE) { 2344 nodeRet = new CMUniOp( contentSpec.type, buildSyntaxTree(leftNode, contentSpec)); 2345 } 2346 else if (contentSpec.type == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_MORE 2347 || contentSpec.type == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_ONE 2348 || contentSpec.type == XMLContentSpec.CONTENTSPECNODE_ONE_OR_MORE) { 2349 nodeRet = new CMUniOp(contentSpec.type, buildSyntaxTree(leftNode, contentSpec)); 2350 } 2351 else { 2352 throw new RuntimeException ("ImplementationMessages.VAL_CST"); 2353 } 2354 } 2355 return nodeRet; 2357 } 2358 2359 2369 private void contentSpecTree(int contentSpecIndex, 2370 XMLContentSpec contentSpec, 2371 ChildrenList children) { 2372 2373 getContentSpec( contentSpecIndex, contentSpec); 2375 if ( contentSpec.type == XMLContentSpec.CONTENTSPECNODE_LEAF || 2376 (contentSpec.type & 0x0f) == XMLContentSpec.CONTENTSPECNODE_ANY || 2377 (contentSpec.type & 0x0f) == XMLContentSpec.CONTENTSPECNODE_ANY_LOCAL || 2378 (contentSpec.type & 0x0f) == XMLContentSpec.CONTENTSPECNODE_ANY_OTHER) { 2379 2380 if (children.length == children.qname.length) { 2382 QName[] newQName = new QName[children.length * 2]; 2383 System.arraycopy(children.qname, 0, newQName, 0, children.length); 2384 children.qname = newQName; 2385 int[] newType = new int[children.length * 2]; 2386 System.arraycopy(children.type, 0, newType, 0, children.length); 2387 children.type = newType; 2388 } 2389 2390 children.qname[children.length] = new QName(null, (String )contentSpec.value, 2392 (String ) contentSpec.value, 2393 (String ) contentSpec.otherValue); 2394 children.type[children.length] = contentSpec.type; 2395 children.length++; 2396 return; 2397 } 2398 2399 final int leftNode = contentSpec.value != null 2404 ? ((int[])(contentSpec.value))[0] : -1; 2405 int rightNode = -1 ; 2406 if (contentSpec.otherValue != null ) 2407 rightNode = ((int[])(contentSpec.otherValue))[0]; 2408 else 2409 return; 2410 2411 if (contentSpec.type == XMLContentSpec.CONTENTSPECNODE_CHOICE || 2412 contentSpec.type == XMLContentSpec.CONTENTSPECNODE_SEQ) { 2413 contentSpecTree(leftNode, contentSpec, children); 2414 contentSpecTree(rightNode, contentSpec, children); 2415 return; 2416 } 2417 2418 if (contentSpec.type == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_ONE || 2419 contentSpec.type == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_MORE || 2420 contentSpec.type == XMLContentSpec.CONTENTSPECNODE_ONE_OR_MORE) { 2421 contentSpecTree(leftNode, contentSpec, children); 2422 return; 2423 } 2424 2425 throw new RuntimeException ("Invalid content spec type seen in contentSpecTree() method of AbstractDTDGrammar class : "+contentSpec.type); 2427 2428 } 2430 2432 private void ensureElementDeclCapacity(int chunk) { 2433 if (chunk >= fElementDeclName.length) { 2434 fElementDeclIsExternal = resize(fElementDeclIsExternal, 2435 fElementDeclIsExternal.length * 2); 2436 2437 fElementDeclName = resize(fElementDeclName, fElementDeclName.length * 2); 2438 fElementDeclType = resize(fElementDeclType, fElementDeclType.length * 2); 2439 fElementDeclContentModelValidator = resize(fElementDeclContentModelValidator, fElementDeclContentModelValidator.length * 2); 2440 fElementDeclContentSpecIndex = resize(fElementDeclContentSpecIndex,fElementDeclContentSpecIndex.length * 2); 2441 fElementDeclFirstAttributeDeclIndex = resize(fElementDeclFirstAttributeDeclIndex, fElementDeclFirstAttributeDeclIndex.length * 2); 2442 fElementDeclLastAttributeDeclIndex = resize(fElementDeclLastAttributeDeclIndex, fElementDeclLastAttributeDeclIndex.length * 2); 2443 } 2444 else if (fElementDeclName[chunk] != null) { 2445 return; 2446 } 2447 2448 fElementDeclIsExternal[chunk] = new int[CHUNK_SIZE]; 2449 fElementDeclName[chunk] = new QName[CHUNK_SIZE]; 2450 fElementDeclType[chunk] = new short[CHUNK_SIZE]; 2451 fElementDeclContentModelValidator[chunk] = new ContentModelValidator[CHUNK_SIZE]; 2452 fElementDeclContentSpecIndex[chunk] = new int[CHUNK_SIZE]; 2453 fElementDeclFirstAttributeDeclIndex[chunk] = new int[CHUNK_SIZE]; 2454 fElementDeclLastAttributeDeclIndex[chunk] = new int[CHUNK_SIZE]; 2455 return; 2456 } 2457 2458 private void ensureAttributeDeclCapacity(int chunk) { 2459 2460 if (chunk >= fAttributeDeclName.length) { 2461 fAttributeDeclIsExternal = resize(fAttributeDeclIsExternal, 2462 fAttributeDeclIsExternal.length * 2); 2463 fAttributeDeclName = resize(fAttributeDeclName, fAttributeDeclName.length * 2); 2464 fAttributeDeclType = resize(fAttributeDeclType, fAttributeDeclType.length * 2); 2465 fAttributeDeclEnumeration = resize(fAttributeDeclEnumeration, fAttributeDeclEnumeration.length * 2); 2466 fAttributeDeclDefaultType = resize(fAttributeDeclDefaultType, fAttributeDeclDefaultType.length * 2); 2467 fAttributeDeclDatatypeValidator = resize(fAttributeDeclDatatypeValidator, fAttributeDeclDatatypeValidator.length * 2); 2468 fAttributeDeclDefaultValue = resize(fAttributeDeclDefaultValue, fAttributeDeclDefaultValue.length * 2); 2469 fAttributeDeclNonNormalizedDefaultValue = resize(fAttributeDeclNonNormalizedDefaultValue, fAttributeDeclNonNormalizedDefaultValue.length * 2); 2470 fAttributeDeclNextAttributeDeclIndex = resize(fAttributeDeclNextAttributeDeclIndex, fAttributeDeclNextAttributeDeclIndex.length * 2); 2471 } 2472 else if (fAttributeDeclName[chunk] != null) { 2473 return; 2474 } 2475 2476 fAttributeDeclIsExternal[chunk] = new int[CHUNK_SIZE]; 2477 fAttributeDeclName[chunk] = new QName[CHUNK_SIZE]; 2478 fAttributeDeclType[chunk] = new short[CHUNK_SIZE]; 2479 fAttributeDeclEnumeration[chunk] = new String [CHUNK_SIZE][]; 2480 fAttributeDeclDefaultType[chunk] = new short[CHUNK_SIZE]; 2481 fAttributeDeclDatatypeValidator[chunk] = new DatatypeValidator[CHUNK_SIZE]; 2482 fAttributeDeclDefaultValue[chunk] = new String [CHUNK_SIZE]; 2483 fAttributeDeclNonNormalizedDefaultValue[chunk] = new String [CHUNK_SIZE]; 2484 fAttributeDeclNextAttributeDeclIndex[chunk] = new int[CHUNK_SIZE]; 2485 return; 2486 } 2487 2488 private void ensureEntityDeclCapacity(int chunk) { 2489 if (chunk >= fEntityName.length) { 2490 fEntityName = resize(fEntityName, fEntityName.length * 2); 2491 fEntityValue = resize(fEntityValue, fEntityValue.length * 2); 2492 fEntityPublicId = resize(fEntityPublicId, fEntityPublicId.length * 2); 2493 fEntitySystemId = resize(fEntitySystemId, fEntitySystemId.length * 2); 2494 fEntityBaseSystemId = resize(fEntityBaseSystemId, fEntityBaseSystemId.length * 2); 2495 fEntityNotation = resize(fEntityNotation, fEntityNotation.length * 2); 2496 fEntityIsPE = resize(fEntityIsPE, fEntityIsPE.length * 2); 2497 fEntityInExternal = resize(fEntityInExternal, fEntityInExternal.length * 2); 2498 } 2499 else if (fEntityName[chunk] != null) { 2500 return; 2501 } 2502 2503 fEntityName[chunk] = new String [CHUNK_SIZE]; 2504 fEntityValue[chunk] = new String [CHUNK_SIZE]; 2505 fEntityPublicId[chunk] = new String [CHUNK_SIZE]; 2506 fEntitySystemId[chunk] = new String [CHUNK_SIZE]; 2507 fEntityBaseSystemId[chunk] = new String [CHUNK_SIZE]; 2508 fEntityNotation[chunk] = new String [CHUNK_SIZE]; 2509 fEntityIsPE[chunk] = new byte[CHUNK_SIZE]; 2510 fEntityInExternal[chunk] = new byte[CHUNK_SIZE]; 2511 return; 2512 } 2513 2514 private void ensureNotationDeclCapacity(int chunk) { 2515 if (chunk >= fNotationName.length) { 2516 fNotationName = resize(fNotationName, fNotationName.length * 2); 2517 fNotationPublicId = resize(fNotationPublicId, fNotationPublicId.length * 2); 2518 fNotationSystemId = resize(fNotationSystemId, fNotationSystemId.length * 2); 2519 fNotationBaseSystemId = resize(fNotationBaseSystemId, fNotationBaseSystemId.length * 2); 2520 } 2521 else if (fNotationName[chunk] != null) { 2522 return; 2523 } 2524 2525 fNotationName[chunk] = new String [CHUNK_SIZE]; 2526 fNotationPublicId[chunk] = new String [CHUNK_SIZE]; 2527 fNotationSystemId[chunk] = new String [CHUNK_SIZE]; 2528 fNotationBaseSystemId[chunk] = new String [CHUNK_SIZE]; 2529 return; 2530 } 2531 2532 private void ensureContentSpecCapacity(int chunk) { 2533 if (chunk >= fContentSpecType.length) { 2534 fContentSpecType = resize(fContentSpecType, fContentSpecType.length * 2); 2535 fContentSpecValue = resize(fContentSpecValue, fContentSpecValue.length * 2); 2536 fContentSpecOtherValue = resize(fContentSpecOtherValue, fContentSpecOtherValue.length * 2); 2537 } 2538 else if (fContentSpecType[chunk] != null) { 2539 return; 2540 } 2541 2542 fContentSpecType[chunk] = new short[CHUNK_SIZE]; 2543 fContentSpecValue[chunk] = new Object [CHUNK_SIZE]; 2544 fContentSpecOtherValue[chunk] = new Object [CHUNK_SIZE]; 2545 return; 2546 } 2547 2548 2552 2554 private static byte[][] resize(byte array[][], int newsize) { 2555 byte newarray[][] = new byte[newsize][]; 2556 System.arraycopy(array, 0, newarray, 0, array.length); 2557 return newarray; 2558 } 2559 2560 private static short[][] resize(short array[][], int newsize) { 2561 short newarray[][] = new short[newsize][]; 2562 System.arraycopy(array, 0, newarray, 0, array.length); 2563 return newarray; 2564 } 2565 2566 private static int[][] resize(int array[][], int newsize) { 2567 int newarray[][] = new int[newsize][]; 2568 System.arraycopy(array, 0, newarray, 0, array.length); 2569 return newarray; 2570 } 2571 2572 private static DatatypeValidator[][] resize(DatatypeValidator array[][], int newsize) { 2573 DatatypeValidator newarray[][] = new DatatypeValidator[newsize][]; 2574 System.arraycopy(array, 0, newarray, 0, array.length); 2575 return newarray; 2576 } 2577 2578 private static ContentModelValidator[][] resize(ContentModelValidator array[][], int newsize) { 2579 ContentModelValidator newarray[][] = new ContentModelValidator[newsize][]; 2580 System.arraycopy(array, 0, newarray, 0, array.length); 2581 return newarray; 2582 } 2583 2584 private static Object [][] resize(Object array[][], int newsize) { 2585 Object newarray[][] = new Object [newsize][]; 2586 System.arraycopy(array, 0, newarray, 0, array.length); 2587 return newarray; 2588 } 2589 2590 private static QName[][] resize(QName array[][], int newsize) { 2591 QName newarray[][] = new QName[newsize][]; 2592 System.arraycopy(array, 0, newarray, 0, array.length); 2593 return newarray; 2594 } 2595 2596 private static String [][] resize(String array[][], int newsize) { 2597 String newarray[][] = new String [newsize][]; 2598 System.arraycopy(array, 0, newarray, 0, array.length); 2599 return newarray; 2600 } 2601 2602 private static String [][][] resize(String array[][][], int newsize) { 2603 String newarray[][][] = new String [newsize] [][]; 2604 System.arraycopy(array, 0, newarray, 0, array.length); 2605 return newarray; 2606 } 2607 2608 2612 2617 private static class ChildrenList { 2618 2619 2623 2624 public int length = 0; 2625 2626 2630 2631 public QName[] qname = new QName[2]; 2632 2633 2634 public int[] type = new int[2]; 2635 2636 } 2638 2642 2649 protected static final class QNameHashtable { 2650 2651 2655 2656 private static final int INITIAL_BUCKET_SIZE = 4; 2657 2658 2661 private static final int HASHTABLE_SIZE = 101; 2662 2663 private Object [][] fHashTable = new Object [HASHTABLE_SIZE][]; 2667 2668 2672 public void put(String key, int value) { 2673 2674 int hash = (key.hashCode() & 0x7FFFFFFF) % HASHTABLE_SIZE; 2675 Object [] bucket = fHashTable[hash]; 2676 2677 if (bucket == null) { 2678 bucket = new Object [1 + 2*INITIAL_BUCKET_SIZE]; 2679 bucket[0] = new int[]{1}; 2680 bucket[1] = key; 2681 bucket[2] = new int[]{value}; 2682 fHashTable[hash] = bucket; 2683 } else { 2684 int count = ((int[])bucket[0])[0]; 2685 int offset = 1 + 2*count; 2686 if (offset == bucket.length) { 2687 int newSize = count + INITIAL_BUCKET_SIZE; 2688 Object [] newBucket = new Object [1 + 2*newSize]; 2689 System.arraycopy(bucket, 0, newBucket, 0, offset); 2690 bucket = newBucket; 2691 fHashTable[hash] = bucket; 2692 } 2693 boolean found = false; 2694 int j=1; 2695 for (int i=0; i<count; i++){ 2696 if ((String )bucket[j] == key) { 2697 ((int[])bucket[j+1])[0] = value; 2698 found = true; 2699 break; 2700 } 2701 j += 2; 2702 } 2703 if (! found) { 2704 bucket[offset++] = key; 2705 bucket[offset]= new int[]{value}; 2706 ((int[])bucket[0])[0] = ++count; 2707 } 2708 2709 } 2710 2713 } 2715 2716 public int get(String key) { 2717 int hash = (key.hashCode() & 0x7FFFFFFF) % HASHTABLE_SIZE; 2718 Object [] bucket = fHashTable[hash]; 2719 2720 if (bucket == null) { 2721 return -1; 2722 } 2723 int count = ((int[])bucket[0])[0]; 2724 2725 int j=1; 2726 for (int i=0; i<count; i++){ 2727 if ((String )bucket[j] == key) { 2728 return ((int[])bucket[j+1])[0]; 2729 } 2730 j += 2; 2731 } 2732 return -1; 2733 2734 } 2736 } 2738 public boolean isEntityDeclared (String name){ 2742 return (getEntityDeclIndex(name)!=-1)?true:false; 2743 } 2744 2745 public boolean isEntityUnparsed (String name){ 2746 int entityIndex = getEntityDeclIndex(name); 2747 if (entityIndex >-1) { 2748 int chunk = entityIndex >> CHUNK_SHIFT; 2749 int index = entityIndex & CHUNK_MASK; 2750 return (fEntityNotation[chunk][index]!=null)?true:false; 2752 } 2753 return false; 2754 } 2755} | Popular Tags |