1 16 17 package org.apache.xerces.impl.dtd; 18 19 import java.util.Hashtable ; 20 import java.util.Vector ; 21 22 import org.apache.xerces.impl.dtd.models.CMAny; 23 import org.apache.xerces.impl.dtd.models.CMBinOp; 24 import org.apache.xerces.impl.dtd.models.CMLeaf; 25 import org.apache.xerces.impl.dtd.models.CMNode; 26 import org.apache.xerces.impl.dtd.models.CMUniOp; 27 import org.apache.xerces.impl.dtd.models.ContentModelValidator; 28 import org.apache.xerces.impl.dtd.models.DFAContentModel; 29 import org.apache.xerces.impl.dtd.models.MixedContentModel; 30 import org.apache.xerces.impl.dtd.models.SimpleContentModel; 31 import org.apache.xerces.impl.dv.DatatypeValidator; 32 import org.apache.xerces.impl.validation.EntityState; 33 import org.apache.xerces.util.SymbolTable; 34 import org.apache.xerces.xni.Augmentations; 35 import org.apache.xerces.xni.QName; 36 import org.apache.xerces.xni.XMLDTDContentModelHandler; 37 import org.apache.xerces.xni.XMLDTDHandler; 38 import org.apache.xerces.xni.XMLLocator; 39 import org.apache.xerces.xni.XMLResourceIdentifier; 40 import org.apache.xerces.xni.XMLString; 41 import org.apache.xerces.xni.XNIException; 42 import org.apache.xerces.xni.grammars.Grammar; 43 import org.apache.xerces.xni.grammars.XMLGrammarDescription; 44 import org.apache.xerces.xni.parser.XMLDTDContentModelSource; 45 import org.apache.xerces.xni.parser.XMLDTDSource; 46 47 61 public class DTDGrammar 62 implements XMLDTDHandler, XMLDTDContentModelHandler, EntityState, Grammar { 63 64 68 69 public static final int TOP_LEVEL_SCOPE = -1; 70 71 73 74 private static final int CHUNK_SHIFT = 8; 76 77 private static final int CHUNK_SIZE = (1 << CHUNK_SHIFT); 78 79 80 private static final int CHUNK_MASK = CHUNK_SIZE - 1; 81 82 83 private static final int INITIAL_CHUNK_COUNT = (1 << (10 - CHUNK_SHIFT)); 85 86 private static final short LIST_FLAG = 0x80; 87 88 89 private static final short LIST_MASK = ~LIST_FLAG; 90 91 93 94 private static final boolean DEBUG = false; 95 96 100 protected XMLDTDSource fDTDSource = null; 101 protected XMLDTDContentModelSource fDTDContentModelSource = null; 102 103 104 protected int fCurrentElementIndex; 105 106 107 protected int fCurrentAttributeIndex; 108 109 110 protected boolean fReadingExternalDTD = false; 111 112 113 private SymbolTable fSymbolTable; 114 115 protected XMLDTDDescription fGrammarDescription = null; 117 118 120 121 private int fElementDeclCount = 0; 122 123 124 private QName fElementDeclName[][] = new QName[INITIAL_CHUNK_COUNT][]; 125 126 130 private short fElementDeclType[][] = new short[INITIAL_CHUNK_COUNT][]; 131 132 136 private int fElementDeclContentSpecIndex[][] = new int[INITIAL_CHUNK_COUNT][]; 137 138 142 private ContentModelValidator fElementDeclContentModelValidator[][] = new ContentModelValidator[INITIAL_CHUNK_COUNT][]; 143 144 145 private int fElementDeclFirstAttributeDeclIndex[][] = new int[INITIAL_CHUNK_COUNT][]; 146 147 148 private int fElementDeclLastAttributeDeclIndex[][] = new int[INITIAL_CHUNK_COUNT][]; 149 150 152 153 private int fAttributeDeclCount = 0 ; 154 155 156 private QName fAttributeDeclName[][] = new QName[INITIAL_CHUNK_COUNT][]; 157 158 private boolean fIsImmutable = false; 160 161 165 private short fAttributeDeclType[][] = new short[INITIAL_CHUNK_COUNT][]; 166 167 168 private String [] fAttributeDeclEnumeration[][] = new String [INITIAL_CHUNK_COUNT][][]; 169 private short fAttributeDeclDefaultType[][] = new short[INITIAL_CHUNK_COUNT][]; 170 private DatatypeValidator fAttributeDeclDatatypeValidator[][] = new DatatypeValidator[INITIAL_CHUNK_COUNT][]; 171 private String fAttributeDeclDefaultValue[][] = new String [INITIAL_CHUNK_COUNT][]; 172 private String fAttributeDeclNonNormalizedDefaultValue[][] = new String [INITIAL_CHUNK_COUNT][]; 173 private int fAttributeDeclNextAttributeDeclIndex[][] = new int[INITIAL_CHUNK_COUNT][]; 174 175 177 181 private int fContentSpecCount = 0; 182 private short fContentSpecType[][] = new short[INITIAL_CHUNK_COUNT][]; 183 private Object fContentSpecValue[][] = new Object [INITIAL_CHUNK_COUNT][]; 184 private Object fContentSpecOtherValue[][] = new Object [INITIAL_CHUNK_COUNT][]; 185 186 188 private int fEntityCount = 0; 189 private String fEntityName[][] = new String [INITIAL_CHUNK_COUNT][]; 190 private String [][] fEntityValue = new String [INITIAL_CHUNK_COUNT][]; 191 private String [][] fEntityPublicId = new String [INITIAL_CHUNK_COUNT][]; 192 private String [][] fEntitySystemId = new String [INITIAL_CHUNK_COUNT][]; 193 private String [][] fEntityBaseSystemId = new String [INITIAL_CHUNK_COUNT][]; 194 private String [][] fEntityNotation = new String [INITIAL_CHUNK_COUNT][]; 195 private byte[][] fEntityIsPE = new byte[INITIAL_CHUNK_COUNT][]; 196 private byte[][] fEntityInExternal = new byte[INITIAL_CHUNK_COUNT][]; 197 198 200 private int fNotationCount = 0; 201 private String fNotationName[][] = new String [INITIAL_CHUNK_COUNT][]; 202 private String [][] fNotationPublicId = new String [INITIAL_CHUNK_COUNT][]; 203 private String [][] fNotationSystemId = new String [INITIAL_CHUNK_COUNT][]; 204 private String [][] fNotationBaseSystemId = new String [INITIAL_CHUNK_COUNT][]; 205 206 208 209 private QNameHashtable fElementIndexMap = new QNameHashtable(); 210 211 212 private QNameHashtable fEntityIndexMap = new QNameHashtable(); 213 214 215 private QNameHashtable fNotationIndexMap = new QNameHashtable(); 216 217 219 220 private boolean fMixed; 221 222 223 private QName fQName = new QName(); 224 225 226 private QName fQName2 = new QName(); 227 228 229 protected XMLAttributeDecl fAttributeDecl = new XMLAttributeDecl(); 230 231 233 private int fLeafCount = 0; 234 private int fEpsilonIndex = -1; 235 236 237 private XMLElementDecl fElementDecl = new XMLElementDecl(); 238 239 240 private XMLEntityDecl fEntityDecl = new XMLEntityDecl(); 241 242 243 private XMLSimpleType fSimpleType = new XMLSimpleType(); 244 245 246 private XMLContentSpec fContentSpec = new XMLContentSpec(); 247 248 249 Hashtable fElementDeclTab = new Hashtable (); 250 251 252 private short[] fOpStack = null; 253 254 255 private int[] fNodeIndexStack = null; 256 257 258 private int[] fPrevNodeIndexStack = null; 259 260 261 private int fDepth = 0; 262 263 264 private boolean[] fPEntityStack = new boolean[4]; 265 private int fPEDepth = 0; 266 267 269 270 private int fElementDeclIsExternal[][] = new int[INITIAL_CHUNK_COUNT][]; 271 272 273 275 276 private int fAttributeDeclIsExternal[][] = new int[INITIAL_CHUNK_COUNT][]; 277 278 280 int valueIndex = -1; 281 int prevNodeIndex = -1; 282 int nodeIndex = -1; 283 284 288 289 public DTDGrammar(SymbolTable symbolTable, XMLDTDDescription desc) { 290 fSymbolTable = symbolTable; 291 fGrammarDescription = desc; 292 } 294 296 public XMLGrammarDescription getGrammarDescription() { 298 return fGrammarDescription; 299 } 301 305 310 public boolean getElementDeclIsExternal(int elementDeclIndex) { 311 312 if (elementDeclIndex < 0) { 313 return false; 314 } 315 316 int chunk = elementDeclIndex >> CHUNK_SHIFT; 317 int index = elementDeclIndex & CHUNK_MASK; 318 return (fElementDeclIsExternal[chunk][index] != 0); 319 320 } 322 327 public boolean getAttributeDeclIsExternal(int attributeDeclIndex) { 328 329 if (attributeDeclIndex < 0) { 330 return false; 331 } 332 333 int chunk = attributeDeclIndex >> CHUNK_SHIFT; 334 int index = attributeDeclIndex & CHUNK_MASK; 335 return (fAttributeDeclIsExternal[chunk][index] != 0); 336 } 337 338 public int getAttributeDeclIndex(int elementDeclIndex, String attributeDeclName) { 339 if (elementDeclIndex == -1) { 340 return -1; 341 } 342 int attDefIndex = getFirstAttributeDeclIndex(elementDeclIndex); 343 while (attDefIndex != -1) { 344 getAttributeDecl(attDefIndex, fAttributeDecl); 345 346 if (fAttributeDecl.name.rawname == attributeDeclName 347 || attributeDeclName.equals(fAttributeDecl.name.rawname) ) { 348 return attDefIndex; 349 } 350 attDefIndex = getNextAttributeDeclIndex(attDefIndex); 351 } 352 return -1; 353 } 355 359 373 public void startDTD(XMLLocator locator, Augmentations augs) throws XNIException { 374 fOpStack = null; 376 fNodeIndexStack = null; 377 fPrevNodeIndexStack = null; 378 } 380 400 public void startParameterEntity(String name, 401 XMLResourceIdentifier identifier, 402 String encoding, 403 Augmentations augs) throws XNIException { 404 405 if (fPEDepth == fPEntityStack.length) { 407 boolean[] entityarray = new boolean[fPEntityStack.length * 2]; 408 System.arraycopy(fPEntityStack, 0, entityarray, 0, fPEntityStack.length); 409 fPEntityStack = entityarray; 410 } 411 fPEntityStack[fPEDepth] = fReadingExternalDTD; 412 fPEDepth++; 413 414 } 416 424 public void startExternalSubset(XMLResourceIdentifier identifier, 425 Augmentations augs) throws XNIException { 426 fReadingExternalDTD = true; 427 } 429 443 public void endParameterEntity(String name, Augmentations augs) throws XNIException { 444 445 fPEDepth--; 446 fReadingExternalDTD = fPEntityStack[fPEDepth]; 447 448 } 450 458 public void endExternalSubset(Augmentations augs) throws XNIException { 459 fReadingExternalDTD = false; 460 } 462 471 public void elementDecl(String name, String contentModel, Augmentations augs) 472 throws XNIException { 473 474 XMLElementDecl tmpElementDecl = (XMLElementDecl) fElementDeclTab.get(name) ; 475 476 if ( tmpElementDecl != null ) { 478 if (tmpElementDecl.type == -1) { 479 fCurrentElementIndex = getElementDeclIndex(name); 480 } 481 else { 482 return; 484 } 485 } 486 else { 487 fCurrentElementIndex = createElementDecl(); } 489 490 XMLElementDecl elementDecl = new XMLElementDecl(); 491 492 fQName.setValues(null, name, name, null); 493 494 elementDecl.name.setValues(fQName); 495 496 elementDecl.contentModelValidator = null; 497 elementDecl.scope= -1; 498 if (contentModel.equals("EMPTY")) { 499 elementDecl.type = XMLElementDecl.TYPE_EMPTY; 500 } 501 else if (contentModel.equals("ANY")) { 502 elementDecl.type = XMLElementDecl.TYPE_ANY; 503 } 504 else if (contentModel.startsWith("(") ) { 505 if (contentModel.indexOf("#PCDATA") > 0 ) { 506 elementDecl.type = XMLElementDecl.TYPE_MIXED; 507 } 508 else { 509 elementDecl.type = XMLElementDecl.TYPE_CHILDREN; 510 } 511 } 512 513 514 this.fElementDeclTab.put(name, elementDecl ); 516 517 fElementDecl = elementDecl; 518 519 if ((fDepth == 0 || 520 (fDepth == 1 && elementDecl.type == XMLElementDecl.TYPE_MIXED)) && 521 fNodeIndexStack != null) { 522 if (elementDecl.type == XMLElementDecl.TYPE_MIXED) { 523 int pcdata = addUniqueLeafNode(null); 524 if (fNodeIndexStack[0] == -1) { 525 fNodeIndexStack[0] = pcdata; 526 } 527 else { 528 fNodeIndexStack[0] = addContentSpecNode(XMLContentSpec.CONTENTSPECNODE_CHOICE, 529 pcdata, fNodeIndexStack[0]); 530 } 531 } 532 setContentSpecIndex(fCurrentElementIndex, fNodeIndexStack[fDepth]); 533 } 534 535 if ( DEBUG ) { 536 System.out.println( "name = " + fElementDecl.name.localpart ); 537 System.out.println( "Type = " + fElementDecl.type ); 538 } 539 540 setElementDecl(fCurrentElementIndex, fElementDecl ); 542 int chunk = fCurrentElementIndex >> CHUNK_SHIFT; 543 int index = fCurrentElementIndex & CHUNK_MASK; 544 ensureElementDeclCapacity(chunk); 545 fElementDeclIsExternal[chunk][index] = fReadingExternalDTD? 1 : 0; 546 547 } 549 574 public void attributeDecl(String elementName, String attributeName, 575 String type, String [] enumeration, 576 String defaultType, XMLString defaultValue, 577 XMLString nonNormalizedDefaultValue, Augmentations augs) throws XNIException { 578 579 if ( this.fElementDeclTab.containsKey( (String ) elementName) ) { 580 } 583 else { 585 fCurrentElementIndex = createElementDecl(); 587 XMLElementDecl elementDecl = new XMLElementDecl(); 588 elementDecl.name.setValues(null, elementName, elementName, null); 589 590 elementDecl.scope= -1; 591 592 this.fElementDeclTab.put(elementName, elementDecl ); 594 595 setElementDecl(fCurrentElementIndex, elementDecl ); 597 } 598 599 int elementIndex = getElementDeclIndex(elementName); 601 602 if (getAttributeDeclIndex(elementIndex, attributeName) != -1) { 605 return; 606 } 607 608 fCurrentAttributeIndex = createAttributeDecl(); 610 fSimpleType.clear(); 611 if ( defaultType != null ) { 612 if ( defaultType.equals( "#FIXED") ) { 613 fSimpleType.defaultType = XMLSimpleType.DEFAULT_TYPE_FIXED; 614 } else if ( defaultType.equals( "#IMPLIED") ) { 615 fSimpleType.defaultType = XMLSimpleType.DEFAULT_TYPE_IMPLIED; 616 } else if ( defaultType.equals( "#REQUIRED") ) { 617 fSimpleType.defaultType = XMLSimpleType.DEFAULT_TYPE_REQUIRED; 618 } 619 } 620 if ( DEBUG ) { 621 System.out.println("defaultvalue = " + defaultValue.toString() ); 622 } 623 fSimpleType.defaultValue = defaultValue!=null ? defaultValue.toString() : null; 624 fSimpleType.nonNormalizedDefaultValue = nonNormalizedDefaultValue!=null ? nonNormalizedDefaultValue.toString() : null; 625 fSimpleType.enumeration = enumeration; 626 627 if (type.equals("CDATA")) { 628 fSimpleType.type = XMLSimpleType.TYPE_CDATA; 629 } 630 else if ( type.equals("ID") ) { 631 fSimpleType.type = XMLSimpleType.TYPE_ID; 632 } 633 else if ( type.startsWith("IDREF") ) { 634 fSimpleType.type = XMLSimpleType.TYPE_IDREF; 635 if (type.indexOf("S") > 0) { 636 fSimpleType.list = true; 637 } 638 } 639 else if (type.equals("ENTITIES")) { 640 fSimpleType.type = XMLSimpleType.TYPE_ENTITY; 641 fSimpleType.list = true; 642 } 643 else if (type.equals("ENTITY")) { 644 fSimpleType.type = XMLSimpleType.TYPE_ENTITY; 645 } 646 else if (type.equals("NMTOKENS")) { 647 fSimpleType.type = XMLSimpleType.TYPE_NMTOKEN; 648 fSimpleType.list = true; 649 } 650 else if (type.equals("NMTOKEN")) { 651 fSimpleType.type = XMLSimpleType.TYPE_NMTOKEN; 652 } 653 else if (type.startsWith("NOTATION") ) { 654 fSimpleType.type = XMLSimpleType.TYPE_NOTATION; 655 } 656 else if (type.startsWith("ENUMERATION") ) { 657 fSimpleType.type = XMLSimpleType.TYPE_ENUMERATION; 658 } 659 else { 660 System.err.println("!!! unknown attribute type "+type); 662 } 663 667 fQName.setValues(null, attributeName, attributeName, null); 668 fAttributeDecl.setValues( fQName, fSimpleType, false ); 669 670 setAttributeDecl(elementIndex, fCurrentAttributeIndex, fAttributeDecl); 671 672 int chunk = fCurrentAttributeIndex >> CHUNK_SHIFT; 673 int index = fCurrentAttributeIndex & CHUNK_MASK; 674 ensureAttributeDeclCapacity(chunk); 675 fAttributeDeclIsExternal[chunk][index] = fReadingExternalDTD ? 1 : 0; 676 677 } 679 694 public void internalEntityDecl(String name, XMLString text, 695 XMLString nonNormalizedText, 696 Augmentations augs) throws XNIException { 697 698 int entityIndex = getEntityDeclIndex(name); 699 if( entityIndex == -1){ 700 entityIndex = createEntityDecl(); 701 boolean isPE = name.startsWith("%"); 702 boolean inExternal = fReadingExternalDTD; 703 XMLEntityDecl entityDecl = new XMLEntityDecl(); 704 entityDecl.setValues(name,null,null, null, null, 705 text.toString(), isPE, inExternal); 706 707 setEntityDecl(entityIndex, entityDecl); 708 } 709 710 } 712 724 public void externalEntityDecl(String name, 725 XMLResourceIdentifier identifier, 726 Augmentations augs) throws XNIException { 727 728 int entityIndex = getEntityDeclIndex(name); 729 if( entityIndex == -1){ 730 entityIndex = createEntityDecl(); 731 boolean isPE = name.startsWith("%"); 732 boolean inExternal = fReadingExternalDTD; 733 734 XMLEntityDecl entityDecl = new XMLEntityDecl(); 735 entityDecl.setValues(name, identifier.getPublicId(), identifier.getLiteralSystemId(), 736 identifier.getBaseSystemId(), 737 null, null, isPE, inExternal); 738 739 setEntityDecl(entityIndex, entityDecl); 740 } 741 } 743 754 public void unparsedEntityDecl(String name, XMLResourceIdentifier identifier, 755 String notation, 756 Augmentations augs) throws XNIException { 757 758 XMLEntityDecl entityDecl = new XMLEntityDecl(); 759 boolean isPE = name.startsWith("%"); 760 boolean inExternal = fReadingExternalDTD; 761 762 entityDecl.setValues(name,identifier.getPublicId(),identifier.getLiteralSystemId(), 763 identifier.getBaseSystemId(), notation, 764 null, isPE, inExternal); 765 int entityIndex = getEntityDeclIndex(name); 766 if (entityIndex == -1) { 767 entityIndex = createEntityDecl(); 768 setEntityDecl(entityIndex, entityDecl); 769 } 770 771 } 773 783 public void notationDecl(String name, XMLResourceIdentifier identifier, 784 Augmentations augs) throws XNIException { 785 786 XMLNotationDecl notationDecl = new XMLNotationDecl(); 787 notationDecl.setValues(name,identifier.getPublicId(),identifier.getLiteralSystemId(), 788 identifier.getBaseSystemId()); 789 int notationIndex = getNotationDeclIndex(name); 790 if (notationIndex == -1) { 791 notationIndex = createNotationDecl(); 792 setNotationDecl(notationIndex, notationDecl); 793 } 794 795 } 797 804 public void endDTD(Augmentations augs) throws XNIException { 805 fIsImmutable = true; 806 if(fGrammarDescription.getRootName() == null) { 808 int chunk, index = 0; 810 String currName = null; 811 Vector elements = new Vector (); 812 for (int i=0; i < fElementDeclCount; i++) { 813 chunk = i >> CHUNK_SHIFT; 814 index = i & CHUNK_MASK; 815 currName = fElementDeclName[chunk][index].rawname; 816 elements.addElement(currName); 817 } 818 fGrammarDescription.setPossibleRoots(elements); 819 } 820 } 822 public void setDTDSource(XMLDTDSource source) { 824 fDTDSource = source; 825 } 827 public XMLDTDSource getDTDSource() { 829 return fDTDSource; 830 } 832 834 848 public void textDecl(String version, String encoding, Augmentations augs) 849 throws XNIException {} 850 851 859 public void comment(XMLString text, Augmentations augs) throws XNIException {} 860 861 878 public void processingInstruction(String target, XMLString data, 879 Augmentations augs) throws XNIException {} 880 881 890 public void startAttlist(String elementName, Augmentations augs) 891 throws XNIException {} 892 893 899 public void endAttlist(Augmentations augs) throws XNIException {} 900 901 913 public void startConditional(short type, Augmentations augs) 914 throws XNIException {} 915 916 923 public void ignoredCharacters(XMLString text, Augmentations augs) 924 throws XNIException {} 925 926 932 public void endConditional(Augmentations augs) throws XNIException {} 933 934 938 public void setDTDContentModelSource(XMLDTDContentModelSource source) { 940 fDTDContentModelSource = source; 941 } 942 943 public XMLDTDContentModelSource getDTDContentModelSource() { 945 return fDTDContentModelSource; 946 } 947 948 958 public void startContentModel(String elementName, Augmentations augs) 959 throws XNIException { 960 961 XMLElementDecl elementDecl = (XMLElementDecl) this.fElementDeclTab.get( elementName); 962 if ( elementDecl != null ) { 963 fElementDecl = elementDecl; 964 } 965 fDepth = 0; 966 initializeContentModelStack(); 967 968 } 970 983 public void startGroup(Augmentations augs) throws XNIException { 984 fDepth++; 985 initializeContentModelStack(); 986 fMixed = false; 987 } 989 1001 public void pcdata(Augmentations augs) throws XNIException { 1002 fMixed = true; 1003 } 1005 1014 public void element(String elementName, Augmentations augs) throws XNIException { 1015 if (fMixed) { 1016 if (fNodeIndexStack[fDepth] == -1 ) { 1017 fNodeIndexStack[fDepth] = addUniqueLeafNode(elementName); 1018 } 1019 else { 1020 fNodeIndexStack[fDepth] = addContentSpecNode(XMLContentSpec.CONTENTSPECNODE_CHOICE, 1021 fNodeIndexStack[fDepth], 1022 addUniqueLeafNode(elementName)); 1023 } 1024 } 1025 else { 1026 fNodeIndexStack[fDepth] = addContentSpecNode(XMLContentSpec.CONTENTSPECNODE_LEAF, elementName); 1027 } 1028 } 1030 1042 public void separator(short separator, Augmentations augs) throws XNIException { 1043 1044 if (!fMixed) { 1045 if (fOpStack[fDepth] != XMLContentSpec.CONTENTSPECNODE_SEQ && separator == XMLDTDContentModelHandler.SEPARATOR_CHOICE ) { 1046 if (fPrevNodeIndexStack[fDepth] != -1) { 1047 fNodeIndexStack[fDepth] = addContentSpecNode(fOpStack[fDepth], fPrevNodeIndexStack[fDepth], fNodeIndexStack[fDepth]); 1048 } 1049 fPrevNodeIndexStack[fDepth] = fNodeIndexStack[fDepth]; 1050 fOpStack[fDepth] = XMLContentSpec.CONTENTSPECNODE_CHOICE; 1051 } else if (fOpStack[fDepth] != XMLContentSpec.CONTENTSPECNODE_CHOICE && separator == XMLDTDContentModelHandler.SEPARATOR_SEQUENCE) { 1052 if (fPrevNodeIndexStack[fDepth] != -1) { 1053 fNodeIndexStack[fDepth] = addContentSpecNode(fOpStack[fDepth], fPrevNodeIndexStack[fDepth], fNodeIndexStack[fDepth]); 1054 } 1055 fPrevNodeIndexStack[fDepth] = fNodeIndexStack[fDepth]; 1056 fOpStack[fDepth] = XMLContentSpec.CONTENTSPECNODE_SEQ; 1057 } 1058 } 1059 1060 } 1062 1076 public void occurrence(short occurrence, Augmentations augs) throws XNIException { 1077 1078 if (!fMixed) { 1079 if (occurrence == XMLDTDContentModelHandler.OCCURS_ZERO_OR_ONE ) { 1080 fNodeIndexStack[fDepth] = addContentSpecNode(XMLContentSpec.CONTENTSPECNODE_ZERO_OR_ONE, fNodeIndexStack[fDepth], -1); 1081 } else if ( occurrence == XMLDTDContentModelHandler.OCCURS_ZERO_OR_MORE ) { 1082 fNodeIndexStack[fDepth] = addContentSpecNode(XMLContentSpec.CONTENTSPECNODE_ZERO_OR_MORE, fNodeIndexStack[fDepth], -1 ); 1083 } else if ( occurrence == XMLDTDContentModelHandler.OCCURS_ONE_OR_MORE) { 1084 fNodeIndexStack[fDepth] = addContentSpecNode(XMLContentSpec.CONTENTSPECNODE_ONE_OR_MORE, fNodeIndexStack[fDepth], -1 ); 1085 } 1086 } 1087 1088 } 1090 1097 public void endGroup(Augmentations augs) throws XNIException { 1098 1099 if (!fMixed) { 1100 if (fPrevNodeIndexStack[fDepth] != -1) { 1101 fNodeIndexStack[fDepth] = addContentSpecNode(fOpStack[fDepth], fPrevNodeIndexStack[fDepth], fNodeIndexStack[fDepth]); 1102 } 1103 int nodeIndex = fNodeIndexStack[fDepth--]; 1104 fNodeIndexStack[fDepth] = nodeIndex; 1105 } 1106 1107 } 1109 1111 1121 public void any(Augmentations augs) throws XNIException {} 1122 1123 1133 public void empty(Augmentations augs) throws XNIException {} 1134 1135 1142 public void endContentModel(Augmentations augs) throws XNIException {} 1143 1144 1148 1149 public boolean isNamespaceAware() { 1150 return false; 1151 } 1153 1154 public SymbolTable getSymbolTable() { 1155 return fSymbolTable; 1156 } 1158 1165 public int getFirstElementDeclIndex() { 1166 return fElementDeclCount >= 0 ? 0 : -1; 1167 } 1169 1175 public int getNextElementDeclIndex(int elementDeclIndex) { 1176 return elementDeclIndex < fElementDeclCount - 1 1177 ? elementDeclIndex + 1 : -1; 1178 } 1180 1187 public int getElementDeclIndex(String elementDeclName) { 1188 int mapping = fElementIndexMap.get(elementDeclName); 1189 return mapping; 1191 } 1193 1196 public int getElementDeclIndex(QName elementDeclQName) { 1197 return getElementDeclIndex(elementDeclQName.rawname); 1198 } 1200 1203 1204 public short getContentSpecType(int elementIndex){ 1205 if (elementIndex < 0 || elementIndex >= fElementDeclCount) { 1206 return -1 ; 1207 } 1208 1209 int chunk = elementIndex >> CHUNK_SHIFT; 1210 int index = elementIndex & CHUNK_MASK; 1211 1212 if(fElementDeclType[chunk][index] == -1){ 1213 return -1 ; 1214 } 1215 else{ 1216 return (short) (fElementDeclType[chunk][index] & LIST_MASK); 1217 } 1218 1219 } 1221 1229 public boolean getElementDecl(int elementDeclIndex, 1230 XMLElementDecl elementDecl) { 1231 1232 if (elementDeclIndex < 0 || elementDeclIndex >= fElementDeclCount) { 1233 return false; 1234 } 1235 1236 int chunk = elementDeclIndex >> CHUNK_SHIFT; 1237 int index = elementDeclIndex & CHUNK_MASK; 1238 1239 elementDecl.name.setValues(fElementDeclName[chunk][index]); 1240 1241 if (fElementDeclType[chunk][index] == -1) { 1242 elementDecl.type = -1; 1243 elementDecl.simpleType.list = false; 1244 } else { 1245 elementDecl.type = (short) (fElementDeclType[chunk][index] & LIST_MASK); 1246 elementDecl.simpleType.list = (fElementDeclType[chunk][index] & LIST_FLAG) != 0; 1247 } 1248 1249 1250 if (elementDecl.type == XMLElementDecl.TYPE_CHILDREN || elementDecl.type == XMLElementDecl.TYPE_MIXED) { 1251 elementDecl.contentModelValidator = getElementContentModelValidator(elementDeclIndex); 1252 } 1253 1254 elementDecl.simpleType.datatypeValidator = null; 1255 elementDecl.simpleType.defaultType = -1; 1256 elementDecl.simpleType.defaultValue = null; 1257 1258 return true; 1259 1260 } 1262 1264 1271 public int getFirstAttributeDeclIndex(int elementDeclIndex) { 1272 int chunk = elementDeclIndex >> CHUNK_SHIFT; 1273 int index = elementDeclIndex & CHUNK_MASK; 1274 1275 return fElementDeclFirstAttributeDeclIndex[chunk][index]; 1276 } 1278 1285 public int getNextAttributeDeclIndex(int attributeDeclIndex) { 1286 int chunk = attributeDeclIndex >> CHUNK_SHIFT; 1287 int index = attributeDeclIndex & CHUNK_MASK; 1288 1289 return fAttributeDeclNextAttributeDeclIndex[chunk][index]; 1290 } 1292 1300 public boolean getAttributeDecl(int attributeDeclIndex, XMLAttributeDecl attributeDecl) { 1301 if (attributeDeclIndex < 0 || attributeDeclIndex >= fAttributeDeclCount) { 1302 return false; 1303 } 1304 int chunk = attributeDeclIndex >> CHUNK_SHIFT; 1305 int index = attributeDeclIndex & CHUNK_MASK; 1306 1307 attributeDecl.name.setValues(fAttributeDeclName[chunk][index]); 1308 1309 short attributeType; 1310 boolean isList; 1311 1312 if (fAttributeDeclType[chunk][index] == -1) { 1313 1314 attributeType = -1; 1315 isList = false; 1316 } else { 1317 attributeType = (short) (fAttributeDeclType[chunk][index] & LIST_MASK); 1318 isList = (fAttributeDeclType[chunk][index] & LIST_FLAG) != 0; 1319 } 1320 attributeDecl.simpleType.setValues(attributeType,fAttributeDeclName[chunk][index].localpart, 1321 fAttributeDeclEnumeration[chunk][index], 1322 isList, fAttributeDeclDefaultType[chunk][index], 1323 fAttributeDeclDefaultValue[chunk][index], 1324 fAttributeDeclNonNormalizedDefaultValue[chunk][index], 1325 fAttributeDeclDatatypeValidator[chunk][index]); 1326 return true; 1327 1328 } 1330 1331 1339 public boolean isCDATAAttribute(QName elName, QName atName) { 1340 int elDeclIdx = getElementDeclIndex(elName); 1341 if (getAttributeDecl(elDeclIdx, fAttributeDecl) 1342 && fAttributeDecl.simpleType.type != XMLSimpleType.TYPE_CDATA){ 1343 return false; 1344 } 1345 return true; 1346 } 1347 1348 1355 public int getEntityDeclIndex(String entityDeclName) { 1356 if (entityDeclName == null) { 1357 return -1; 1358 } 1359 1360 return fEntityIndexMap.get(entityDeclName); 1361 } 1363 1372 public boolean getEntityDecl(int entityDeclIndex, XMLEntityDecl entityDecl) { 1373 if (entityDeclIndex < 0 || entityDeclIndex >= fEntityCount) { 1374 return false; 1375 } 1376 int chunk = entityDeclIndex >> CHUNK_SHIFT; 1377 int index = entityDeclIndex & CHUNK_MASK; 1378 1379 entityDecl.setValues(fEntityName[chunk][index], 1380 fEntityPublicId[chunk][index], 1381 fEntitySystemId[chunk][index], 1382 fEntityBaseSystemId[chunk][index], 1383 fEntityNotation[chunk][index], 1384 fEntityValue[chunk][index], 1385 fEntityIsPE[chunk][index] == 0 ? false : true , 1386 fEntityInExternal[chunk][index] == 0 ? false : true ); 1387 1388 return true; 1389 } 1391 1398 public int getNotationDeclIndex(String notationDeclName) { 1399 if (notationDeclName == null) { 1400 return -1; 1401 } 1402 1403 return fNotationIndexMap.get(notationDeclName); 1404 } 1406 1415 public boolean getNotationDecl(int notationDeclIndex, XMLNotationDecl notationDecl) { 1416 if (notationDeclIndex < 0 || notationDeclIndex >= fNotationCount) { 1417 return false; 1418 } 1419 int chunk = notationDeclIndex >> CHUNK_SHIFT; 1420 int index = notationDeclIndex & CHUNK_MASK; 1421 1422 notationDecl.setValues(fNotationName[chunk][index], 1423 fNotationPublicId[chunk][index], 1424 fNotationSystemId[chunk][index], 1425 fNotationBaseSystemId[chunk][index]); 1426 1427 return true; 1428 1429 } 1431 1439 public boolean getContentSpec(int contentSpecIndex, XMLContentSpec contentSpec) { 1440 if (contentSpecIndex < 0 || contentSpecIndex >= fContentSpecCount ) 1441 return false; 1442 1443 int chunk = contentSpecIndex >> CHUNK_SHIFT; 1444 int index = contentSpecIndex & CHUNK_MASK; 1445 1446 contentSpec.type = fContentSpecType[chunk][index]; 1447 contentSpec.value = fContentSpecValue[chunk][index]; 1448 contentSpec.otherValue = fContentSpecOtherValue[chunk][index]; 1449 return true; 1450 } 1451 1452 1459 public String getContentSpecAsString(int elementDeclIndex){ 1460 1461 if (elementDeclIndex < 0 || elementDeclIndex >= fElementDeclCount) { 1462 return null; 1463 } 1464 1465 int chunk = elementDeclIndex >> CHUNK_SHIFT; 1466 int index = elementDeclIndex & CHUNK_MASK; 1467 1468 int contentSpecIndex = fElementDeclContentSpecIndex[chunk][index]; 1469 1470 XMLContentSpec contentSpec = new XMLContentSpec(); 1472 1473 if (getContentSpec(contentSpecIndex, contentSpec)) { 1474 1475 StringBuffer str = new StringBuffer (); 1477 int parentContentSpecType = contentSpec.type & 0x0f; 1478 int nextContentSpec; 1479 switch (parentContentSpecType) { 1480 case XMLContentSpec.CONTENTSPECNODE_LEAF: { 1481 str.append('('); 1482 if (contentSpec.value == null && contentSpec.otherValue == null) { 1483 str.append("#PCDATA"); 1484 } 1485 else { 1486 str.append(contentSpec.value); 1487 } 1488 str.append(')'); 1489 break; 1490 } 1491 case XMLContentSpec.CONTENTSPECNODE_ZERO_OR_ONE: { 1492 getContentSpec(((int[])contentSpec.value)[0], contentSpec); 1493 nextContentSpec = contentSpec.type; 1494 1495 if (nextContentSpec == XMLContentSpec.CONTENTSPECNODE_LEAF) { 1496 str.append('('); 1497 str.append(contentSpec.value); 1498 str.append(')'); 1499 } else if( nextContentSpec == XMLContentSpec.CONTENTSPECNODE_ONE_OR_MORE || 1500 nextContentSpec == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_MORE || 1501 nextContentSpec == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_ONE ) { 1502 str.append('(' ); 1503 appendContentSpec(contentSpec, str, 1504 true, parentContentSpecType ); 1505 str.append(')'); 1506 } else { 1507 appendContentSpec(contentSpec, str, 1508 true, parentContentSpecType ); 1509 } 1510 str.append('?'); 1511 break; 1512 } 1513 case XMLContentSpec.CONTENTSPECNODE_ZERO_OR_MORE: { 1514 getContentSpec(((int[])contentSpec.value)[0], contentSpec); 1515 nextContentSpec = contentSpec.type; 1516 1517 if ( nextContentSpec == XMLContentSpec.CONTENTSPECNODE_LEAF) { 1518 str.append('('); 1519 if (contentSpec.value == null && contentSpec.otherValue == null) { 1520 str.append("#PCDATA"); 1521 } 1522 else if (contentSpec.otherValue != null) { 1523 str.append("##any:uri="+contentSpec.otherValue); 1524 } 1525 else if (contentSpec.value == null) { 1526 str.append("##any"); 1527 } 1528 else { 1529 appendContentSpec(contentSpec, str, 1530 true, parentContentSpecType ); 1531 } 1532 str.append(')'); 1533 } else if( nextContentSpec == XMLContentSpec.CONTENTSPECNODE_ONE_OR_MORE || 1534 nextContentSpec == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_MORE || 1535 nextContentSpec == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_ONE ) { 1536 str.append('(' ); 1537 appendContentSpec(contentSpec, str, 1538 true, parentContentSpecType ); 1539 str.append(')'); 1540 } else { 1541 appendContentSpec(contentSpec, str, 1542 true, parentContentSpecType ); 1543 } 1544 str.append('*'); 1545 break; 1546 } 1547 case XMLContentSpec.CONTENTSPECNODE_ONE_OR_MORE: { 1548 getContentSpec(((int[])contentSpec.value)[0], contentSpec); 1549 nextContentSpec = contentSpec.type; 1550 1551 if ( nextContentSpec == XMLContentSpec.CONTENTSPECNODE_LEAF) { 1552 str.append('('); 1553 if (contentSpec.value == null && contentSpec.otherValue == null) { 1554 str.append("#PCDATA"); 1555 } 1556 else if (contentSpec.otherValue != null) { 1557 str.append("##any:uri="+contentSpec.otherValue); 1558 } 1559 else if (contentSpec.value == null) { 1560 str.append("##any"); 1561 } 1562 else { 1563 str.append(contentSpec.value); 1564 } 1565 str.append(')'); 1566 } else if( nextContentSpec == XMLContentSpec.CONTENTSPECNODE_ONE_OR_MORE || 1567 nextContentSpec == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_MORE || 1568 nextContentSpec == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_ONE ) { 1569 str.append('(' ); 1570 appendContentSpec(contentSpec, str, 1571 true, parentContentSpecType ); 1572 str.append(')'); 1573 } else { 1574 appendContentSpec(contentSpec, str, 1575 true, parentContentSpecType); 1576 } 1577 str.append('+'); 1578 break; 1579 } 1580 case XMLContentSpec.CONTENTSPECNODE_CHOICE: 1581 case XMLContentSpec.CONTENTSPECNODE_SEQ: { 1582 appendContentSpec(contentSpec, str, 1583 true, parentContentSpecType ); 1584 break; 1585 } 1586 case XMLContentSpec.CONTENTSPECNODE_ANY: { 1587 str.append("##any"); 1588 if (contentSpec.otherValue != null) { 1589 str.append(":uri="); 1590 str.append(contentSpec.otherValue); 1591 } 1592 break; 1593 } 1594 case XMLContentSpec.CONTENTSPECNODE_ANY_OTHER: { 1595 str.append("##other:uri="); 1596 str.append(contentSpec.otherValue); 1597 break; 1598 } 1599 case XMLContentSpec.CONTENTSPECNODE_ANY_LOCAL: { 1600 str.append("##local"); 1601 break; 1602 } 1603 default: { 1604 str.append("???"); 1605 } 1606 1607 } 1609 return str.toString(); 1611 } 1612 1613 return null; 1615 1616 } 1618 1620 public void printElements( ) { 1621 int elementDeclIndex = 0; 1622 XMLElementDecl elementDecl = new XMLElementDecl(); 1623 while (getElementDecl(elementDeclIndex++, elementDecl)) { 1624 1625 System.out.println("element decl: "+elementDecl.name+ 1626 ", "+ elementDecl.name.rawname ); 1627 1628 } 1630 } 1631 1632 public void printAttributes(int elementDeclIndex) { 1633 int attributeDeclIndex = getFirstAttributeDeclIndex(elementDeclIndex); 1634 System.out.print(elementDeclIndex); 1635 System.out.print(" ["); 1636 while (attributeDeclIndex != -1) { 1637 System.out.print(' '); 1638 System.out.print(attributeDeclIndex); 1639 printAttribute(attributeDeclIndex); 1640 attributeDeclIndex = getNextAttributeDeclIndex(attributeDeclIndex); 1641 if (attributeDeclIndex != -1) { 1642 System.out.print(","); 1643 } 1644 } 1645 System.out.println(" ]"); 1646 } 1647 1648 1652 1659 protected ContentModelValidator getElementContentModelValidator(int elementDeclIndex) { 1660 1661 int chunk = elementDeclIndex >> CHUNK_SHIFT; 1662 int index = elementDeclIndex & CHUNK_MASK; 1663 1664 ContentModelValidator contentModel = fElementDeclContentModelValidator[chunk][index]; 1665 1666 if (contentModel != null) { 1668 return contentModel; 1669 } 1670 1671 int contentType = fElementDeclType[chunk][index]; 1672 if (contentType == XMLElementDecl.TYPE_SIMPLE) { 1673 return null; 1674 } 1675 1676 int contentSpecIndex = fElementDeclContentSpecIndex[chunk][index]; 1678 1679 1683 1684 XMLContentSpec contentSpec = new XMLContentSpec(); 1685 getContentSpec( contentSpecIndex, contentSpec ); 1686 1687 if ( contentType == XMLElementDecl.TYPE_MIXED ) { 1689 ChildrenList children = new ChildrenList(); 1694 contentSpecTree(contentSpecIndex, contentSpec, children); 1695 contentModel = new MixedContentModel(children.qname, 1696 children.type, 1697 0, children.length, 1698 false); 1699 } else if (contentType == XMLElementDecl.TYPE_CHILDREN) { 1700 contentModel = createChildModel(contentSpecIndex); 1707 } else { 1708 throw new RuntimeException ("Unknown content type for a element decl " 1709 + "in getElementContentModelValidator() in AbstractDTDGrammar class"); 1710 } 1711 1712 fElementDeclContentModelValidator[chunk][index] = contentModel; 1714 1715 return contentModel; 1716 1717 } 1719 protected int createElementDecl() { 1720 int chunk = fElementDeclCount >> CHUNK_SHIFT; 1721 int index = fElementDeclCount & CHUNK_MASK; 1722 ensureElementDeclCapacity(chunk); 1723 fElementDeclName[chunk][index] = new QName(); 1724 fElementDeclType[chunk][index] = -1; 1725 fElementDeclContentModelValidator[chunk][index] = null; 1726 fElementDeclFirstAttributeDeclIndex[chunk][index] = -1; 1727 fElementDeclLastAttributeDeclIndex[chunk][index] = -1; 1728 return fElementDeclCount++; 1729 } 1730 1731 protected void setElementDecl(int elementDeclIndex, XMLElementDecl elementDecl) { 1732 if (elementDeclIndex < 0 || elementDeclIndex >= fElementDeclCount) { 1733 return; 1734 } 1735 int chunk = elementDeclIndex >> CHUNK_SHIFT; 1736 int index = elementDeclIndex & CHUNK_MASK; 1737 1738 fElementDeclName[chunk][index].setValues(elementDecl.name); 1739 fElementDeclType[chunk][index] = elementDecl.type; 1740 1741 fElementDeclContentModelValidator[chunk][index] = elementDecl.contentModelValidator; 1742 1743 if (elementDecl.simpleType.list == true ) { 1744 fElementDeclType[chunk][index] |= LIST_FLAG; 1745 } 1746 1747 fElementIndexMap.put(elementDecl.name.rawname, elementDeclIndex); 1748 } 1749 1750 1751 1752 1753 protected void putElementNameMapping(QName name, int scope, 1754 int elementDeclIndex) { 1755 } 1756 1757 protected void setFirstAttributeDeclIndex(int elementDeclIndex, int newFirstAttrIndex){ 1758 1759 if (elementDeclIndex < 0 || elementDeclIndex >= fElementDeclCount) { 1760 return; 1761 } 1762 1763 int chunk = elementDeclIndex >> CHUNK_SHIFT; 1764 int index = elementDeclIndex & CHUNK_MASK; 1765 1766 fElementDeclFirstAttributeDeclIndex[chunk][index] = newFirstAttrIndex; 1767 } 1768 1769 protected void setContentSpecIndex(int elementDeclIndex, int contentSpecIndex){ 1770 1771 if (elementDeclIndex < 0 || elementDeclIndex >= fElementDeclCount) { 1772 return; 1773 } 1774 1775 int chunk = elementDeclIndex >> CHUNK_SHIFT; 1776 int index = elementDeclIndex & CHUNK_MASK; 1777 1778 fElementDeclContentSpecIndex[chunk][index] = contentSpecIndex; 1779 } 1780 1781 1782 protected int createAttributeDecl() { 1783 int chunk = fAttributeDeclCount >> CHUNK_SHIFT; 1784 int index = fAttributeDeclCount & CHUNK_MASK; 1785 1786 ensureAttributeDeclCapacity(chunk); 1787 fAttributeDeclName[chunk][index] = new QName(); 1788 fAttributeDeclType[chunk][index] = -1; 1789 fAttributeDeclDatatypeValidator[chunk][index] = null; 1790 fAttributeDeclEnumeration[chunk][index] = null; 1791 fAttributeDeclDefaultType[chunk][index] = XMLSimpleType.DEFAULT_TYPE_IMPLIED; 1792 fAttributeDeclDefaultValue[chunk][index] = null; 1793 fAttributeDeclNonNormalizedDefaultValue[chunk][index] = null; 1794 fAttributeDeclNextAttributeDeclIndex[chunk][index] = -1; 1795 return fAttributeDeclCount++; 1796 } 1797 1798 1799 protected void setAttributeDecl(int elementDeclIndex, int attributeDeclIndex, 1800 XMLAttributeDecl attributeDecl) { 1801 int attrChunk = attributeDeclIndex >> CHUNK_SHIFT; 1802 int attrIndex = attributeDeclIndex & CHUNK_MASK; 1803 fAttributeDeclName[attrChunk][attrIndex].setValues(attributeDecl.name); 1804 fAttributeDeclType[attrChunk][attrIndex] = attributeDecl.simpleType.type; 1805 1806 if (attributeDecl.simpleType.list) { 1807 fAttributeDeclType[attrChunk][attrIndex] |= LIST_FLAG; 1808 } 1809 fAttributeDeclEnumeration[attrChunk][attrIndex] = attributeDecl.simpleType.enumeration; 1810 fAttributeDeclDefaultType[attrChunk][attrIndex] = attributeDecl.simpleType.defaultType; 1811 fAttributeDeclDatatypeValidator[attrChunk][attrIndex] = attributeDecl.simpleType.datatypeValidator; 1812 1813 fAttributeDeclDefaultValue[attrChunk][attrIndex] = attributeDecl.simpleType.defaultValue; 1814 fAttributeDeclNonNormalizedDefaultValue[attrChunk][attrIndex] = attributeDecl.simpleType.nonNormalizedDefaultValue; 1815 1816 int elemChunk = elementDeclIndex >> CHUNK_SHIFT; 1817 int elemIndex = elementDeclIndex & CHUNK_MASK; 1818 int index = fElementDeclFirstAttributeDeclIndex[elemChunk][elemIndex]; 1819 while (index != -1) { 1820 if (index == attributeDeclIndex) { 1821 break; 1822 } 1823 attrChunk = index >> CHUNK_SHIFT; 1824 attrIndex = index & CHUNK_MASK; 1825 index = fAttributeDeclNextAttributeDeclIndex[attrChunk][attrIndex]; 1826 } 1827 if (index == -1) { 1828 if (fElementDeclFirstAttributeDeclIndex[elemChunk][elemIndex] == -1) { 1829 fElementDeclFirstAttributeDeclIndex[elemChunk][elemIndex] = attributeDeclIndex; 1830 } else { 1831 index = fElementDeclLastAttributeDeclIndex[elemChunk][elemIndex]; 1832 attrChunk = index >> CHUNK_SHIFT; 1833 attrIndex = index & CHUNK_MASK; 1834 fAttributeDeclNextAttributeDeclIndex[attrChunk][attrIndex] = attributeDeclIndex; 1835 } 1836 fElementDeclLastAttributeDeclIndex[elemChunk][elemIndex] = attributeDeclIndex; 1837 } 1838 } 1839 1840 protected int createContentSpec() { 1841 int chunk = fContentSpecCount >> CHUNK_SHIFT; 1842 int index = fContentSpecCount & CHUNK_MASK; 1843 1844 ensureContentSpecCapacity(chunk); 1845 fContentSpecType[chunk][index] = -1; 1846 fContentSpecValue[chunk][index] = null; 1847 fContentSpecOtherValue[chunk][index] = null; 1848 1849 return fContentSpecCount++; 1850 } 1851 1852 protected void setContentSpec(int contentSpecIndex, XMLContentSpec contentSpec) { 1853 int chunk = contentSpecIndex >> CHUNK_SHIFT; 1854 int index = contentSpecIndex & CHUNK_MASK; 1855 1856 fContentSpecType[chunk][index] = contentSpec.type; 1857 fContentSpecValue[chunk][index] = contentSpec.value; 1858 fContentSpecOtherValue[chunk][index] = contentSpec.otherValue; 1859 } 1860 1861 1862 protected int createEntityDecl() { 1863 int chunk = fEntityCount >> CHUNK_SHIFT; 1864 int index = fEntityCount & CHUNK_MASK; 1865 1866 ensureEntityDeclCapacity(chunk); 1867 fEntityIsPE[chunk][index] = 0; 1868 fEntityInExternal[chunk][index] = 0; 1869 1870 return fEntityCount++; 1871 } 1872 1873 protected void setEntityDecl(int entityDeclIndex, XMLEntityDecl entityDecl) { 1874 int chunk = entityDeclIndex >> CHUNK_SHIFT; 1875 int index = entityDeclIndex & CHUNK_MASK; 1876 1877 fEntityName[chunk][index] = entityDecl.name; 1878 fEntityValue[chunk][index] = entityDecl.value; 1879 fEntityPublicId[chunk][index] = entityDecl.publicId; 1880 fEntitySystemId[chunk][index] = entityDecl.systemId; 1881 fEntityBaseSystemId[chunk][index] = entityDecl.baseSystemId; 1882 fEntityNotation[chunk][index] = entityDecl.notation; 1883 fEntityIsPE[chunk][index] = entityDecl.isPE ? (byte)1 : (byte)0; 1884 fEntityInExternal[chunk][index] = entityDecl.inExternal ? (byte)1 : (byte)0; 1885 1886 fEntityIndexMap.put(entityDecl.name, entityDeclIndex); 1887 } 1888 1889 protected int createNotationDecl() { 1890 int chunk = fNotationCount >> CHUNK_SHIFT; 1891 ensureNotationDeclCapacity(chunk); 1892 return fNotationCount++; 1893 } 1894 1895 protected void setNotationDecl(int notationDeclIndex, XMLNotationDecl notationDecl) { 1896 int chunk = notationDeclIndex >> CHUNK_SHIFT; 1897 int index = notationDeclIndex & CHUNK_MASK; 1898 1899 fNotationName[chunk][index] = notationDecl.name; 1900 fNotationPublicId[chunk][index] = notationDecl.publicId; 1901 fNotationSystemId[chunk][index] = notationDecl.systemId; 1902 fNotationBaseSystemId[chunk][index] = notationDecl.baseSystemId; 1903 1904 fNotationIndexMap.put(notationDecl.name, notationDeclIndex); 1905 } 1906 1907 1914 protected int addContentSpecNode(short nodeType, String nodeValue) { 1915 1916 int contentSpecIndex = createContentSpec(); 1918 1919 fContentSpec.setValues(nodeType, nodeValue, null); 1921 setContentSpec(contentSpecIndex, fContentSpec); 1922 1923 return contentSpecIndex; 1925 1926 } 1928 1934 protected int addUniqueLeafNode(String elementName) { 1935 1936 int contentSpecIndex = createContentSpec(); 1938 1939 fContentSpec.setValues( XMLContentSpec.CONTENTSPECNODE_LEAF, 1941 elementName, null); 1942 setContentSpec(contentSpecIndex, fContentSpec); 1943 1944 return contentSpecIndex; 1946 1947 } 1949 1957 protected int addContentSpecNode(short nodeType, 1958 int leftNodeIndex, int rightNodeIndex) { 1959 1960 int contentSpecIndex = createContentSpec(); 1962 1963 int[] leftIntArray = new int[1]; 1965 int[] rightIntArray = new int[1]; 1966 1967 leftIntArray[0] = leftNodeIndex; 1968 rightIntArray[0] = rightNodeIndex; 1969 fContentSpec.setValues(nodeType, leftIntArray, rightIntArray); 1970 setContentSpec(contentSpecIndex, fContentSpec); 1971 1972 return contentSpecIndex; 1974 1975 } 1977 1978 protected void initializeContentModelStack() { 1979 1980 if (fOpStack == null) { 1981 fOpStack = new short[8]; 1982 fNodeIndexStack = new int[8]; 1983 fPrevNodeIndexStack = new int[8]; 1984 } else if (fDepth == fOpStack.length) { 1985 short[] newStack = new short[fDepth * 2]; 1986 System.arraycopy(fOpStack, 0, newStack, 0, fDepth); 1987 fOpStack = newStack; 1988 int[] newIntStack = new int[fDepth * 2]; 1989 System.arraycopy(fNodeIndexStack, 0, newIntStack, 0, fDepth); 1990 fNodeIndexStack = newIntStack; 1991 newIntStack = new int[fDepth * 2]; 1992 System.arraycopy(fPrevNodeIndexStack, 0, newIntStack, 0, fDepth); 1993 fPrevNodeIndexStack = newIntStack; 1994 } 1995 fOpStack[fDepth] = -1; 1996 fNodeIndexStack[fDepth] = -1; 1997 fPrevNodeIndexStack[fDepth] = -1; 1998 1999 } 2001 boolean isImmutable() { 2002 return fIsImmutable; 2003 } 2004 2005 2009 private void appendContentSpec(XMLContentSpec contentSpec, 2010 StringBuffer str, boolean parens, 2011 int parentContentSpecType ) { 2012 2013 int thisContentSpec = contentSpec.type & 0x0f; 2014 switch (thisContentSpec) { 2015 case XMLContentSpec.CONTENTSPECNODE_LEAF: { 2016 if (contentSpec.value == null && contentSpec.otherValue == null) { 2017 str.append("#PCDATA"); 2018 } 2019 else if (contentSpec.value == null && contentSpec.otherValue != null) { 2020 str.append("##any:uri="+contentSpec.otherValue); 2021 } 2022 else if (contentSpec.value == null) { 2023 str.append("##any"); 2024 } 2025 else { 2026 str.append(contentSpec.value); 2027 } 2028 break; 2029 } 2030 case XMLContentSpec.CONTENTSPECNODE_ZERO_OR_ONE: { 2031 if (parentContentSpecType == XMLContentSpec.CONTENTSPECNODE_ONE_OR_MORE || 2032 parentContentSpecType == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_MORE || 2033 parentContentSpecType == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_ONE ) { 2034 getContentSpec(((int[])contentSpec.value)[0], contentSpec); 2035 str.append('('); 2036 appendContentSpec(contentSpec, str, true, thisContentSpec ); 2037 str.append(')'); 2038 } 2039 else { 2040 getContentSpec(((int[])contentSpec.value)[0], contentSpec); 2041 appendContentSpec( contentSpec, str, true, thisContentSpec ); 2042 } 2043 str.append('?'); 2044 break; 2045 } 2046 case XMLContentSpec.CONTENTSPECNODE_ZERO_OR_MORE: { 2047 if (parentContentSpecType == XMLContentSpec.CONTENTSPECNODE_ONE_OR_MORE || 2048 parentContentSpecType == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_MORE || 2049 parentContentSpecType == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_ONE ) { 2050 getContentSpec(((int[])contentSpec.value)[0], contentSpec); 2051 str.append('('); 2052 appendContentSpec(contentSpec, str, true, thisContentSpec); 2053 str.append(')' ); 2054 } 2055 else { 2056 getContentSpec(((int[])contentSpec.value)[0], contentSpec); 2057 appendContentSpec(contentSpec, str, true, thisContentSpec); 2058 } 2059 str.append('*'); 2060 break; 2061 } 2062 case XMLContentSpec.CONTENTSPECNODE_ONE_OR_MORE: { 2063 if (parentContentSpecType == XMLContentSpec.CONTENTSPECNODE_ONE_OR_MORE || 2064 parentContentSpecType == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_MORE || 2065 parentContentSpecType == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_ONE ) { 2066 2067 str.append('('); 2068 getContentSpec(((int[])contentSpec.value)[0], contentSpec); 2069 appendContentSpec(contentSpec, str, true, thisContentSpec); 2070 str.append(')' ); 2071 } 2072 else { 2073 getContentSpec(((int[])contentSpec.value)[0], contentSpec); 2074 appendContentSpec(contentSpec, str, true, thisContentSpec); 2075 } 2076 str.append('+'); 2077 break; 2078 } 2079 case XMLContentSpec.CONTENTSPECNODE_CHOICE: 2080 case XMLContentSpec.CONTENTSPECNODE_SEQ: { 2081 if (parens) { 2082 str.append('('); 2083 } 2084 int type = contentSpec.type; 2085 int otherValue = ((int[])contentSpec.otherValue)[0]; 2086 getContentSpec(((int[])contentSpec.value)[0], contentSpec); 2087 appendContentSpec(contentSpec, str, contentSpec.type != type, thisContentSpec); 2088 if (type == XMLContentSpec.CONTENTSPECNODE_CHOICE) { 2089 str.append('|'); 2090 } 2091 else { 2092 str.append(','); 2093 } 2094 getContentSpec(otherValue, contentSpec); 2095 appendContentSpec(contentSpec, str, true, thisContentSpec); 2096 if (parens) { 2097 str.append(')'); 2098 } 2099 break; 2100 } 2101 case XMLContentSpec.CONTENTSPECNODE_ANY: { 2102 str.append("##any"); 2103 if (contentSpec.otherValue != null) { 2104 str.append(":uri="); 2105 str.append(contentSpec.otherValue); 2106 } 2107 break; 2108 } 2109 case XMLContentSpec.CONTENTSPECNODE_ANY_OTHER: { 2110 str.append("##other:uri="); 2111 str.append(contentSpec.otherValue); 2112 break; 2113 } 2114 case XMLContentSpec.CONTENTSPECNODE_ANY_LOCAL: { 2115 str.append("##local"); 2116 break; 2117 } 2118 default: { 2119 str.append("???"); 2120 break; 2121 } 2122 2123 } 2125 } 2127 2129 private void printAttribute(int attributeDeclIndex) { 2130 2131 XMLAttributeDecl attributeDecl = new XMLAttributeDecl(); 2132 if (getAttributeDecl(attributeDeclIndex, attributeDecl)) { 2133 System.out.print(" { "); 2134 System.out.print(attributeDecl.name.localpart); 2135 System.out.print(" }"); 2136 } 2137 2138 } 2140 2142 2148 private ContentModelValidator createChildModel(int contentSpecIndex) { 2149 2150 XMLContentSpec contentSpec = new XMLContentSpec(); 2156 getContentSpec(contentSpecIndex, contentSpec); 2157 2158 if ((contentSpec.type & 0x0f ) == XMLContentSpec.CONTENTSPECNODE_ANY || 2159 (contentSpec.type & 0x0f ) == XMLContentSpec.CONTENTSPECNODE_ANY_OTHER || 2160 (contentSpec.type & 0x0f ) == XMLContentSpec.CONTENTSPECNODE_ANY_LOCAL) { 2161 } 2163 2164 else if (contentSpec.type == XMLContentSpec.CONTENTSPECNODE_LEAF) { 2165 if (contentSpec.value == null && contentSpec.otherValue == null) 2170 throw new RuntimeException ("ImplementationMessages.VAL_NPCD"); 2171 2172 2178 fQName.setValues(null, (String )contentSpec.value, 2179 (String )contentSpec.value, (String )contentSpec.otherValue); 2180 return new SimpleContentModel(contentSpec.type, fQName, null); 2181 } else if ((contentSpec.type == XMLContentSpec.CONTENTSPECNODE_CHOICE) 2182 || (contentSpec.type == XMLContentSpec.CONTENTSPECNODE_SEQ)) { 2183 XMLContentSpec contentSpecLeft = new XMLContentSpec(); 2188 XMLContentSpec contentSpecRight = new XMLContentSpec(); 2189 2190 getContentSpec( ((int[])contentSpec.value)[0], contentSpecLeft); 2191 getContentSpec( ((int[])contentSpec.otherValue)[0], contentSpecRight); 2192 2193 if ((contentSpecLeft.type == XMLContentSpec.CONTENTSPECNODE_LEAF) 2194 && (contentSpecRight.type == XMLContentSpec.CONTENTSPECNODE_LEAF)) { 2195 fQName.setValues(null, (String )contentSpecLeft.value, 2200 (String )contentSpecLeft.value, (String )contentSpecLeft.otherValue); 2201 fQName2.setValues(null, (String )contentSpecRight.value, 2202 (String )contentSpecRight.value, (String )contentSpecRight.otherValue); 2203 return new SimpleContentModel(contentSpec.type, fQName, fQName2); 2204 } 2205 } else if ((contentSpec.type == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_ONE) 2206 || (contentSpec.type == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_MORE) 2207 || (contentSpec.type == XMLContentSpec.CONTENTSPECNODE_ONE_OR_MORE)) { 2208 XMLContentSpec contentSpecLeft = new XMLContentSpec(); 2214 getContentSpec(((int[])contentSpec.value)[0], contentSpecLeft); 2215 2216 if (contentSpecLeft.type == XMLContentSpec.CONTENTSPECNODE_LEAF) { 2217 fQName.setValues(null, (String )contentSpecLeft.value, 2223 (String )contentSpecLeft.value, (String )contentSpecLeft.otherValue); 2224 return new SimpleContentModel(contentSpec.type, fQName, null); 2225 } 2226 } else { 2227 throw new RuntimeException ("ImplementationMessages.VAL_CST"); 2228 } 2229 2230 2236 fLeafCount = 0; 2237 fLeafCount = 0; 2239 CMNode cmn = buildSyntaxTree(contentSpecIndex, contentSpec); 2240 2241 return new DFAContentModel( cmn, fLeafCount, false); 2243 2244 } 2246 private final CMNode buildSyntaxTree(int startNode, 2247 XMLContentSpec contentSpec) { 2248 2249 CMNode nodeRet = null; 2251 getContentSpec(startNode, contentSpec); 2252 if ((contentSpec.type & 0x0f) == XMLContentSpec.CONTENTSPECNODE_ANY) { 2253 nodeRet = new CMAny(contentSpec.type, (String )contentSpec.otherValue, fLeafCount++); 2255 } 2256 else if ((contentSpec.type & 0x0f) == XMLContentSpec.CONTENTSPECNODE_ANY_OTHER) { 2257 nodeRet = new CMAny(contentSpec.type, (String )contentSpec.otherValue, fLeafCount++); 2258 } 2259 else if ((contentSpec.type & 0x0f) == XMLContentSpec.CONTENTSPECNODE_ANY_LOCAL) { 2260 nodeRet = new CMAny(contentSpec.type, null, fLeafCount++); 2261 } 2262 else if (contentSpec.type == XMLContentSpec.CONTENTSPECNODE_LEAF) { 2267 fQName.setValues(null, (String )contentSpec.value, 2274 (String )contentSpec.value, (String )contentSpec.otherValue); 2275 nodeRet = new CMLeaf(fQName, fLeafCount++); 2276 } 2277 else { 2278 final int leftNode = ((int[])contentSpec.value)[0]; 2282 final int rightNode = ((int[])contentSpec.otherValue)[0]; 2283 2284 if ((contentSpec.type == XMLContentSpec.CONTENTSPECNODE_CHOICE) 2285 || (contentSpec.type == XMLContentSpec.CONTENTSPECNODE_SEQ)) { 2286 2292 nodeRet = new CMBinOp( contentSpec.type, buildSyntaxTree(leftNode, contentSpec) 2293 , buildSyntaxTree(rightNode, contentSpec)); 2294 } 2295 else if (contentSpec.type == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_MORE) { 2296 nodeRet = new CMUniOp( contentSpec.type, buildSyntaxTree(leftNode, contentSpec)); 2297 } 2298 else if (contentSpec.type == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_MORE 2299 || contentSpec.type == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_ONE 2300 || contentSpec.type == XMLContentSpec.CONTENTSPECNODE_ONE_OR_MORE) { 2301 nodeRet = new CMUniOp(contentSpec.type, buildSyntaxTree(leftNode, contentSpec)); 2302 } 2303 else { 2304 throw new RuntimeException ("ImplementationMessages.VAL_CST"); 2305 } 2306 } 2307 return nodeRet; 2309 } 2310 2311 2321 private void contentSpecTree(int contentSpecIndex, 2322 XMLContentSpec contentSpec, 2323 ChildrenList children) { 2324 2325 getContentSpec( contentSpecIndex, contentSpec); 2327 if ( contentSpec.type == XMLContentSpec.CONTENTSPECNODE_LEAF || 2328 (contentSpec.type & 0x0f) == XMLContentSpec.CONTENTSPECNODE_ANY || 2329 (contentSpec.type & 0x0f) == XMLContentSpec.CONTENTSPECNODE_ANY_LOCAL || 2330 (contentSpec.type & 0x0f) == XMLContentSpec.CONTENTSPECNODE_ANY_OTHER) { 2331 2332 if (children.length == children.qname.length) { 2334 QName[] newQName = new QName[children.length * 2]; 2335 System.arraycopy(children.qname, 0, newQName, 0, children.length); 2336 children.qname = newQName; 2337 int[] newType = new int[children.length * 2]; 2338 System.arraycopy(children.type, 0, newType, 0, children.length); 2339 children.type = newType; 2340 } 2341 2342 children.qname[children.length] = new QName(null, (String )contentSpec.value, 2344 (String ) contentSpec.value, 2345 (String ) contentSpec.otherValue); 2346 children.type[children.length] = contentSpec.type; 2347 children.length++; 2348 return; 2349 } 2350 2351 final int leftNode = contentSpec.value != null 2356 ? ((int[])(contentSpec.value))[0] : -1; 2357 int rightNode = -1 ; 2358 if (contentSpec.otherValue != null ) 2359 rightNode = ((int[])(contentSpec.otherValue))[0]; 2360 else 2361 return; 2362 2363 if (contentSpec.type == XMLContentSpec.CONTENTSPECNODE_CHOICE || 2364 contentSpec.type == XMLContentSpec.CONTENTSPECNODE_SEQ) { 2365 contentSpecTree(leftNode, contentSpec, children); 2366 contentSpecTree(rightNode, contentSpec, children); 2367 return; 2368 } 2369 2370 if (contentSpec.type == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_ONE || 2371 contentSpec.type == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_MORE || 2372 contentSpec.type == XMLContentSpec.CONTENTSPECNODE_ONE_OR_MORE) { 2373 contentSpecTree(leftNode, contentSpec, children); 2374 return; 2375 } 2376 2377 throw new RuntimeException ("Invalid content spec type seen in contentSpecTree() method of AbstractDTDGrammar class : "+contentSpec.type); 2379 2380 } 2382 2384 private void ensureElementDeclCapacity(int chunk) { 2385 if (chunk >= fElementDeclName.length) { 2386 fElementDeclIsExternal = resize(fElementDeclIsExternal, 2387 fElementDeclIsExternal.length * 2); 2388 2389 fElementDeclName = resize(fElementDeclName, fElementDeclName.length * 2); 2390 fElementDeclType = resize(fElementDeclType, fElementDeclType.length * 2); 2391 fElementDeclContentModelValidator = resize(fElementDeclContentModelValidator, fElementDeclContentModelValidator.length * 2); 2392 fElementDeclContentSpecIndex = resize(fElementDeclContentSpecIndex,fElementDeclContentSpecIndex.length * 2); 2393 fElementDeclFirstAttributeDeclIndex = resize(fElementDeclFirstAttributeDeclIndex, fElementDeclFirstAttributeDeclIndex.length * 2); 2394 fElementDeclLastAttributeDeclIndex = resize(fElementDeclLastAttributeDeclIndex, fElementDeclLastAttributeDeclIndex.length * 2); 2395 } 2396 else if (fElementDeclName[chunk] != null) { 2397 return; 2398 } 2399 2400 fElementDeclIsExternal[chunk] = new int[CHUNK_SIZE]; 2401 fElementDeclName[chunk] = new QName[CHUNK_SIZE]; 2402 fElementDeclType[chunk] = new short[CHUNK_SIZE]; 2403 fElementDeclContentModelValidator[chunk] = new ContentModelValidator[CHUNK_SIZE]; 2404 fElementDeclContentSpecIndex[chunk] = new int[CHUNK_SIZE]; 2405 fElementDeclFirstAttributeDeclIndex[chunk] = new int[CHUNK_SIZE]; 2406 fElementDeclLastAttributeDeclIndex[chunk] = new int[CHUNK_SIZE]; 2407 return; 2408 } 2409 2410 private void ensureAttributeDeclCapacity(int chunk) { 2411 2412 if (chunk >= fAttributeDeclName.length) { 2413 fAttributeDeclIsExternal = resize(fAttributeDeclIsExternal, 2414 fAttributeDeclIsExternal.length * 2); 2415 fAttributeDeclName = resize(fAttributeDeclName, fAttributeDeclName.length * 2); 2416 fAttributeDeclType = resize(fAttributeDeclType, fAttributeDeclType.length * 2); 2417 fAttributeDeclEnumeration = resize(fAttributeDeclEnumeration, fAttributeDeclEnumeration.length * 2); 2418 fAttributeDeclDefaultType = resize(fAttributeDeclDefaultType, fAttributeDeclDefaultType.length * 2); 2419 fAttributeDeclDatatypeValidator = resize(fAttributeDeclDatatypeValidator, fAttributeDeclDatatypeValidator.length * 2); 2420 fAttributeDeclDefaultValue = resize(fAttributeDeclDefaultValue, fAttributeDeclDefaultValue.length * 2); 2421 fAttributeDeclNonNormalizedDefaultValue = resize(fAttributeDeclNonNormalizedDefaultValue, fAttributeDeclNonNormalizedDefaultValue.length * 2); 2422 fAttributeDeclNextAttributeDeclIndex = resize(fAttributeDeclNextAttributeDeclIndex, fAttributeDeclNextAttributeDeclIndex.length * 2); 2423 } 2424 else if (fAttributeDeclName[chunk] != null) { 2425 return; 2426 } 2427 2428 fAttributeDeclIsExternal[chunk] = new int[CHUNK_SIZE]; 2429 fAttributeDeclName[chunk] = new QName[CHUNK_SIZE]; 2430 fAttributeDeclType[chunk] = new short[CHUNK_SIZE]; 2431 fAttributeDeclEnumeration[chunk] = new String [CHUNK_SIZE][]; 2432 fAttributeDeclDefaultType[chunk] = new short[CHUNK_SIZE]; 2433 fAttributeDeclDatatypeValidator[chunk] = new DatatypeValidator[CHUNK_SIZE]; 2434 fAttributeDeclDefaultValue[chunk] = new String [CHUNK_SIZE]; 2435 fAttributeDeclNonNormalizedDefaultValue[chunk] = new String [CHUNK_SIZE]; 2436 fAttributeDeclNextAttributeDeclIndex[chunk] = new int[CHUNK_SIZE]; 2437 return; 2438 } 2439 2440 private void ensureEntityDeclCapacity(int chunk) { 2441 if (chunk >= fEntityName.length) { 2442 fEntityName = resize(fEntityName, fEntityName.length * 2); 2443 fEntityValue = resize(fEntityValue, fEntityValue.length * 2); 2444 fEntityPublicId = resize(fEntityPublicId, fEntityPublicId.length * 2); 2445 fEntitySystemId = resize(fEntitySystemId, fEntitySystemId.length * 2); 2446 fEntityBaseSystemId = resize(fEntityBaseSystemId, fEntityBaseSystemId.length * 2); 2447 fEntityNotation = resize(fEntityNotation, fEntityNotation.length * 2); 2448 fEntityIsPE = resize(fEntityIsPE, fEntityIsPE.length * 2); 2449 fEntityInExternal = resize(fEntityInExternal, fEntityInExternal.length * 2); 2450 } 2451 else if (fEntityName[chunk] != null) { 2452 return; 2453 } 2454 2455 fEntityName[chunk] = new String [CHUNK_SIZE]; 2456 fEntityValue[chunk] = new String [CHUNK_SIZE]; 2457 fEntityPublicId[chunk] = new String [CHUNK_SIZE]; 2458 fEntitySystemId[chunk] = new String [CHUNK_SIZE]; 2459 fEntityBaseSystemId[chunk] = new String [CHUNK_SIZE]; 2460 fEntityNotation[chunk] = new String [CHUNK_SIZE]; 2461 fEntityIsPE[chunk] = new byte[CHUNK_SIZE]; 2462 fEntityInExternal[chunk] = new byte[CHUNK_SIZE]; 2463 return; 2464 } 2465 2466 private void ensureNotationDeclCapacity(int chunk) { 2467 if (chunk >= fNotationName.length) { 2468 fNotationName = resize(fNotationName, fNotationName.length * 2); 2469 fNotationPublicId = resize(fNotationPublicId, fNotationPublicId.length * 2); 2470 fNotationSystemId = resize(fNotationSystemId, fNotationSystemId.length * 2); 2471 fNotationBaseSystemId = resize(fNotationBaseSystemId, fNotationBaseSystemId.length * 2); 2472 } 2473 else if (fNotationName[chunk] != null) { 2474 return; 2475 } 2476 2477 fNotationName[chunk] = new String [CHUNK_SIZE]; 2478 fNotationPublicId[chunk] = new String [CHUNK_SIZE]; 2479 fNotationSystemId[chunk] = new String [CHUNK_SIZE]; 2480 fNotationBaseSystemId[chunk] = new String [CHUNK_SIZE]; 2481 return; 2482 } 2483 2484 private void ensureContentSpecCapacity(int chunk) { 2485 if (chunk >= fContentSpecType.length) { 2486 fContentSpecType = resize(fContentSpecType, fContentSpecType.length * 2); 2487 fContentSpecValue = resize(fContentSpecValue, fContentSpecValue.length * 2); 2488 fContentSpecOtherValue = resize(fContentSpecOtherValue, fContentSpecOtherValue.length * 2); 2489 } 2490 else if (fContentSpecType[chunk] != null) { 2491 return; 2492 } 2493 2494 fContentSpecType[chunk] = new short[CHUNK_SIZE]; 2495 fContentSpecValue[chunk] = new Object [CHUNK_SIZE]; 2496 fContentSpecOtherValue[chunk] = new Object [CHUNK_SIZE]; 2497 return; 2498 } 2499 2500 2504 2506 private static byte[][] resize(byte array[][], int newsize) { 2507 byte newarray[][] = new byte[newsize][]; 2508 System.arraycopy(array, 0, newarray, 0, array.length); 2509 return newarray; 2510 } 2511 2512 private static short[][] resize(short array[][], int newsize) { 2513 short newarray[][] = new short[newsize][]; 2514 System.arraycopy(array, 0, newarray, 0, array.length); 2515 return newarray; 2516 } 2517 2518 private static int[][] resize(int array[][], int newsize) { 2519 int newarray[][] = new int[newsize][]; 2520 System.arraycopy(array, 0, newarray, 0, array.length); 2521 return newarray; 2522 } 2523 2524 private static DatatypeValidator[][] resize(DatatypeValidator array[][], int newsize) { 2525 DatatypeValidator newarray[][] = new DatatypeValidator[newsize][]; 2526 System.arraycopy(array, 0, newarray, 0, array.length); 2527 return newarray; 2528 } 2529 2530 private static ContentModelValidator[][] resize(ContentModelValidator array[][], int newsize) { 2531 ContentModelValidator newarray[][] = new ContentModelValidator[newsize][]; 2532 System.arraycopy(array, 0, newarray, 0, array.length); 2533 return newarray; 2534 } 2535 2536 private static Object [][] resize(Object array[][], int newsize) { 2537 Object newarray[][] = new Object [newsize][]; 2538 System.arraycopy(array, 0, newarray, 0, array.length); 2539 return newarray; 2540 } 2541 2542 private static QName[][] resize(QName array[][], int newsize) { 2543 QName newarray[][] = new QName[newsize][]; 2544 System.arraycopy(array, 0, newarray, 0, array.length); 2545 return newarray; 2546 } 2547 2548 private static String [][] resize(String array[][], int newsize) { 2549 String newarray[][] = new String [newsize][]; 2550 System.arraycopy(array, 0, newarray, 0, array.length); 2551 return newarray; 2552 } 2553 2554 private static String [][][] resize(String array[][][], int newsize) { 2555 String newarray[][][] = new String [newsize] [][]; 2556 System.arraycopy(array, 0, newarray, 0, array.length); 2557 return newarray; 2558 } 2559 2560 2564 2571 private static class ChildrenList { 2572 2573 2577 2578 public int length = 0; 2579 2580 2584 2585 public QName[] qname = new QName[2]; 2586 2587 2588 public int[] type = new int[2]; 2589 2590 2594 public ChildrenList () {} 2595 2596 } 2598 2602 2611 protected static final class QNameHashtable { 2612 2613 2617 2618 private static final int INITIAL_BUCKET_SIZE = 4; 2619 2620 2623 private static final int HASHTABLE_SIZE = 101; 2624 2625 private Object [][] fHashTable = new Object [HASHTABLE_SIZE][]; 2629 2630 2634 public void put(String key, int value) { 2635 2636 int hash = (key.hashCode() & 0x7FFFFFFF) % HASHTABLE_SIZE; 2637 Object [] bucket = fHashTable[hash]; 2638 2639 if (bucket == null) { 2640 bucket = new Object [1 + 2*INITIAL_BUCKET_SIZE]; 2641 bucket[0] = new int[]{1}; 2642 bucket[1] = key; 2643 bucket[2] = new int[]{value}; 2644 fHashTable[hash] = bucket; 2645 } else { 2646 int count = ((int[])bucket[0])[0]; 2647 int offset = 1 + 2*count; 2648 if (offset == bucket.length) { 2649 int newSize = count + INITIAL_BUCKET_SIZE; 2650 Object [] newBucket = new Object [1 + 2*newSize]; 2651 System.arraycopy(bucket, 0, newBucket, 0, offset); 2652 bucket = newBucket; 2653 fHashTable[hash] = bucket; 2654 } 2655 boolean found = false; 2656 int j=1; 2657 for (int i=0; i<count; i++){ 2658 if ((String )bucket[j] == key) { 2659 ((int[])bucket[j+1])[0] = value; 2660 found = true; 2661 break; 2662 } 2663 j += 2; 2664 } 2665 if (! found) { 2666 bucket[offset++] = key; 2667 bucket[offset]= new int[]{value}; 2668 ((int[])bucket[0])[0] = ++count; 2669 } 2670 2671 } 2672 2675 } 2677 2678 public int get(String key) { 2679 int hash = (key.hashCode() & 0x7FFFFFFF) % HASHTABLE_SIZE; 2680 Object [] bucket = fHashTable[hash]; 2681 2682 if (bucket == null) { 2683 return -1; 2684 } 2685 int count = ((int[])bucket[0])[0]; 2686 2687 int j=1; 2688 for (int i=0; i<count; i++){ 2689 if ((String )bucket[j] == key) { 2690 return ((int[])bucket[j+1])[0]; 2691 } 2692 j += 2; 2693 } 2694 return -1; 2695 2696 } 2698 } 2700 public boolean isEntityDeclared (String name){ 2704 return (getEntityDeclIndex(name)!=-1)?true:false; 2705 } 2706 2707 public boolean isEntityUnparsed (String name){ 2708 int entityIndex = getEntityDeclIndex(name); 2709 if (entityIndex >-1) { 2710 int chunk = entityIndex >> CHUNK_SHIFT; 2711 int index = entityIndex & CHUNK_MASK; 2712 return (fEntityNotation[chunk][index]!=null)?true:false; 2714 } 2715 return false; 2716 } 2717} | Popular Tags |