1 57 58 package com.sun.org.apache.xerces.internal.impl.xs; 59 60 import java.util.Vector ; 61 62 import com.sun.org.apache.xerces.internal.impl.dv.SchemaDVFactory; 63 import com.sun.org.apache.xerces.internal.impl.dv.ValidatedInfo; 64 import com.sun.org.apache.xerces.internal.impl.dv.XSSimpleType; 65 import com.sun.org.apache.xerces.internal.impl.xs.identity.IdentityConstraint; 66 import com.sun.org.apache.xerces.internal.xs.StringList; 67 import com.sun.org.apache.xerces.internal.xs.XSAnnotation; 68 import com.sun.org.apache.xerces.internal.xs.XSAttributeDeclaration; 69 import com.sun.org.apache.xerces.internal.xs.XSAttributeGroupDefinition; 70 import com.sun.org.apache.xerces.internal.xs.XSConstants; 71 import com.sun.org.apache.xerces.internal.xs.XSElementDeclaration; 72 import com.sun.org.apache.xerces.internal.xs.XSModel; 73 import com.sun.org.apache.xerces.internal.xs.XSModelGroupDefinition; 74 import com.sun.org.apache.xerces.internal.xs.XSNamedMap; 75 import com.sun.org.apache.xerces.internal.xs.XSNamespaceItem; 76 import com.sun.org.apache.xerces.internal.xs.XSNotationDeclaration; 77 import com.sun.org.apache.xerces.internal.xs.XSObjectList; 78 import com.sun.org.apache.xerces.internal.xs.XSParticle; 79 import com.sun.org.apache.xerces.internal.xs.XSTypeDefinition; 80 import com.sun.org.apache.xerces.internal.xs.XSWildcard; 81 import com.sun.org.apache.xerces.internal.impl.xs.util.SimpleLocator; 82 import com.sun.org.apache.xerces.internal.impl.xs.util.StringListImpl; 83 import com.sun.org.apache.xerces.internal.impl.xs.util.XSNamedMap4Types; 84 import com.sun.org.apache.xerces.internal.impl.xs.util.XSNamedMapImpl; 85 import com.sun.org.apache.xerces.internal.impl.xs.util.XSObjectListImpl; 86 import com.sun.org.apache.xerces.internal.impl.Constants; 87 import com.sun.org.apache.xerces.internal.parsers.DOMParser; 88 import com.sun.org.apache.xerces.internal.parsers.SAXParser; 89 import com.sun.org.apache.xerces.internal.parsers.IntegratedParserConfiguration; 90 import com.sun.org.apache.xerces.internal.util.SymbolHash; 91 import com.sun.org.apache.xerces.internal.util.SymbolTable; 92 import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarDescription; 93 import com.sun.org.apache.xerces.internal.xni.grammars.XSGrammar; 94 95 109 110 public class SchemaGrammar implements XSGrammar, XSNamespaceItem { 111 112 String fTargetNamespace; 114 115 SymbolHash fGlobalAttrDecls; 117 SymbolHash fGlobalAttrGrpDecls; 118 SymbolHash fGlobalElemDecls; 119 SymbolHash fGlobalGroupDecls; 120 SymbolHash fGlobalNotationDecls; 121 SymbolHash fGlobalIDConstraintDecls; 122 SymbolHash fGlobalTypeDecls; 123 124 XSDDescription fGrammarDescription = null; 126 127 XSAnnotationImpl [] fAnnotations = null; 129 130 int fNumAnnotations; 132 133 private SymbolTable fSymbolTable = null; 135 private SAXParser fSAXParser = null; 137 private DOMParser fDOMParser = null; 138 139 143 private SchemaGrammar() {} 145 146 154 public SchemaGrammar(String targetNamespace, XSDDescription grammarDesc, 155 SymbolTable symbolTable) { 156 fTargetNamespace = targetNamespace; 157 fGrammarDescription = grammarDesc; 158 fSymbolTable = symbolTable; 159 160 fGlobalAttrDecls = new SymbolHash(); 164 fGlobalAttrGrpDecls = new SymbolHash(); 165 fGlobalElemDecls = new SymbolHash(); 166 fGlobalGroupDecls = new SymbolHash(); 167 fGlobalNotationDecls = new SymbolHash(); 168 fGlobalIDConstraintDecls = new SymbolHash(); 169 170 if (fTargetNamespace == SchemaSymbols.URI_SCHEMAFORSCHEMA) 174 fGlobalTypeDecls = SG_SchemaNS.fGlobalTypeDecls.makeClone(); 175 else 176 fGlobalTypeDecls = new SymbolHash(); 177 } 179 private static final int BASICSET_COUNT = 29; 182 private static final int FULLSET_COUNT = 46; 183 184 private static final int GRAMMAR_XS = 1; 185 private static final int GRAMMAR_XSI = 2; 186 187 public static class BuiltinSchemaGrammar extends SchemaGrammar { 190 195 public BuiltinSchemaGrammar(int grammar) { 196 SchemaDVFactory schemaFactory = SchemaDVFactory.getInstance(); 197 198 if (grammar == GRAMMAR_XS) { 199 fTargetNamespace = SchemaSymbols.URI_SCHEMAFORSCHEMA; 201 202 fGrammarDescription = new XSDDescription(); 204 fGrammarDescription.fContextType = XSDDescription.CONTEXT_PREPARSE; 205 fGrammarDescription.setNamespace(SchemaSymbols.URI_SCHEMAFORSCHEMA); 206 207 fGlobalAttrDecls = new SymbolHash(1); 209 fGlobalAttrGrpDecls = new SymbolHash(1); 210 fGlobalElemDecls = new SymbolHash(1); 211 fGlobalGroupDecls = new SymbolHash(1); 212 fGlobalNotationDecls = new SymbolHash(1); 213 fGlobalIDConstraintDecls = new SymbolHash(1); 214 215 fGlobalTypeDecls = schemaFactory.getBuiltInTypes(); 217 fGlobalTypeDecls.put(fAnyType.getName(), fAnyType); 219 } 220 else if (grammar == GRAMMAR_XSI) { 221 fTargetNamespace = SchemaSymbols.URI_XSI; 223 fGrammarDescription = new XSDDescription(); 225 fGrammarDescription.fContextType = XSDDescription.CONTEXT_PREPARSE; 226 fGrammarDescription.setNamespace(SchemaSymbols.URI_XSI); 227 228 fGlobalAttrGrpDecls = new SymbolHash(1); 230 fGlobalElemDecls = new SymbolHash(1); 231 fGlobalGroupDecls = new SymbolHash(1); 232 fGlobalNotationDecls = new SymbolHash(1); 233 fGlobalIDConstraintDecls = new SymbolHash(1); 234 fGlobalTypeDecls = new SymbolHash(1); 235 236 fGlobalAttrDecls = new SymbolHash(8); 238 String name = null; 239 String tns = null; 240 XSSimpleType type = null; 241 short scope = XSConstants.SCOPE_GLOBAL; 242 243 name = SchemaSymbols.XSI_TYPE; 245 tns = SchemaSymbols.URI_XSI; 246 type = schemaFactory.getBuiltInType(SchemaSymbols.ATTVAL_QNAME); 247 fGlobalAttrDecls.put(name, new BuiltinAttrDecl(name, tns, type, scope)); 248 249 name = SchemaSymbols.XSI_NIL; 251 tns = SchemaSymbols.URI_XSI; 252 type = schemaFactory.getBuiltInType(SchemaSymbols.ATTVAL_BOOLEAN); 253 fGlobalAttrDecls.put(name, new BuiltinAttrDecl(name, tns, type, scope)); 254 255 XSSimpleType anyURI = schemaFactory.getBuiltInType(SchemaSymbols.ATTVAL_ANYURI); 256 257 name = SchemaSymbols.XSI_SCHEMALOCATION; 259 tns = SchemaSymbols.URI_XSI; 260 type = schemaFactory.createTypeList(null, SchemaSymbols.URI_XSI, (short)0, anyURI, null); 261 fGlobalAttrDecls.put(name, new BuiltinAttrDecl(name, tns, type, scope)); 262 263 name = SchemaSymbols.XSI_NONAMESPACESCHEMALOCATION; 265 tns = SchemaSymbols.URI_XSI; 266 type = anyURI; 267 fGlobalAttrDecls.put(name, new BuiltinAttrDecl(name, tns, type, scope)); 268 } 269 } 271 public XMLGrammarDescription getGrammarDescription() { 274 return fGrammarDescription.makeClone(); 275 } 277 public void setImportedGrammars(Vector importedGrammars) { 280 } 282 public void addGlobalAttributeDecl(XSAttributeDecl decl) { 283 } 285 public void addGlobalAttributeGroupDecl(XSAttributeGroupDecl decl) { 286 } 288 public void addGlobalElementDecl(XSElementDecl decl) { 289 } 291 public void addGlobalGroupDecl(XSGroupDecl decl) { 292 } 294 public void addGlobalNotationDecl(XSNotationDecl decl) { 295 } 297 public void addGlobalTypeDecl(XSTypeDefinition decl) { 298 } 300 public void addComplexTypeDecl(XSComplexTypeDecl decl, SimpleLocator locator) { 301 } 303 public void addRedefinedGroupDecl(XSGroupDecl derived, XSGroupDecl base, SimpleLocator locator) { 304 } 306 public synchronized void addDocument(Object document, String location) { 307 } 309 310 synchronized DOMParser getDOMParser() { 312 return null; 313 } 314 synchronized SAXParser getSAXParser() { 315 return null; 316 } 317 } 318 319 321 public XMLGrammarDescription getGrammarDescription() { 324 return fGrammarDescription; 325 } 327 public boolean isNamespaceAware () { 329 return true; 330 } 332 Vector fImported = null; 333 334 public void setImportedGrammars(Vector importedGrammars) { 335 fImported = importedGrammars; 336 } 337 338 public Vector getImportedGrammars() { 339 return fImported; 340 } 341 342 345 public final String getTargetNamespace() { 346 return fTargetNamespace; 347 } 349 352 public void addGlobalAttributeDecl(XSAttributeDecl decl) { 353 fGlobalAttrDecls.put(decl.fName, decl); 354 } 355 356 359 public void addGlobalAttributeGroupDecl(XSAttributeGroupDecl decl) { 360 fGlobalAttrGrpDecls.put(decl.fName, decl); 361 } 362 363 366 public void addGlobalElementDecl(XSElementDecl decl) { 367 fGlobalElemDecls.put(decl.fName, decl); 368 369 if (decl.fSubGroup != null) { 372 if (fSubGroupCount == fSubGroups.length) 373 fSubGroups = resize(fSubGroups, fSubGroupCount+INC_SIZE); 374 fSubGroups[fSubGroupCount++] = decl; 375 } 376 } 377 378 381 public void addGlobalGroupDecl(XSGroupDecl decl) { 382 fGlobalGroupDecls.put(decl.fName, decl); 383 } 384 385 388 public void addGlobalNotationDecl(XSNotationDecl decl) { 389 fGlobalNotationDecls.put(decl.fName, decl); 390 } 391 392 395 public void addGlobalTypeDecl(XSTypeDefinition decl) { 396 fGlobalTypeDecls.put(decl.getName(), decl); 397 } 398 399 402 public final void addIDConstraintDecl(XSElementDecl elmDecl, IdentityConstraint decl) { 403 elmDecl.addIDConstraint(decl); 404 fGlobalIDConstraintDecls.put(decl.getIdentityConstraintName(), decl); 405 } 406 407 410 public final XSAttributeDecl getGlobalAttributeDecl(String declName) { 411 return(XSAttributeDecl)fGlobalAttrDecls.get(declName); 412 } 413 414 417 public final XSAttributeGroupDecl getGlobalAttributeGroupDecl(String declName) { 418 return(XSAttributeGroupDecl)fGlobalAttrGrpDecls.get(declName); 419 } 420 421 424 public final XSElementDecl getGlobalElementDecl(String declName) { 425 return(XSElementDecl)fGlobalElemDecls.get(declName); 426 } 427 428 431 public final XSGroupDecl getGlobalGroupDecl(String declName) { 432 return(XSGroupDecl)fGlobalGroupDecls.get(declName); 433 } 434 435 438 public final XSNotationDecl getGlobalNotationDecl(String declName) { 439 return(XSNotationDecl)fGlobalNotationDecls.get(declName); 440 } 441 442 445 public final XSTypeDefinition getGlobalTypeDecl(String declName) { 446 return(XSTypeDefinition)fGlobalTypeDecls.get(declName); 447 } 448 449 452 public final IdentityConstraint getIDConstraintDecl(String declName) { 453 return(IdentityConstraint)fGlobalIDConstraintDecls.get(declName); 454 } 455 456 459 public final boolean hasIDConstraints() { 460 return fGlobalIDConstraintDecls.getLength() > 0; 461 } 462 463 private static final int INITIAL_SIZE = 16; 465 private static final int INC_SIZE = 16; 466 467 private int fCTCount = 0; 468 private XSComplexTypeDecl[] fComplexTypeDecls = new XSComplexTypeDecl[INITIAL_SIZE]; 469 private SimpleLocator[] fCTLocators = new SimpleLocator[INITIAL_SIZE]; 470 471 private static final int REDEFINED_GROUP_INIT_SIZE = 2; 474 private int fRGCount = 0; 475 private XSGroupDecl[] fRedefinedGroupDecls = new XSGroupDecl[REDEFINED_GROUP_INIT_SIZE]; 476 private SimpleLocator[] fRGLocators = new SimpleLocator[REDEFINED_GROUP_INIT_SIZE/2]; 477 478 boolean fFullChecked = false; 481 482 485 public void addComplexTypeDecl(XSComplexTypeDecl decl, SimpleLocator locator) { 486 if (fCTCount == fComplexTypeDecls.length) { 487 fComplexTypeDecls = resize(fComplexTypeDecls, fCTCount+INC_SIZE); 488 fCTLocators = resize(fCTLocators, fCTCount+INC_SIZE); 489 } 490 fCTLocators[fCTCount] = locator; 491 fComplexTypeDecls[fCTCount++] = decl; 492 } 493 494 497 public void addRedefinedGroupDecl(XSGroupDecl derived, XSGroupDecl base, SimpleLocator locator) { 498 if (fRGCount == fRedefinedGroupDecls.length) { 499 fRedefinedGroupDecls = resize(fRedefinedGroupDecls, fRGCount << 1); 501 fRGLocators = resize(fRGLocators, fRGCount); 502 } 503 fRGLocators[fRGCount/2] = locator; 504 fRedefinedGroupDecls[fRGCount++] = derived; 505 fRedefinedGroupDecls[fRGCount++] = base; 506 } 507 508 511 final XSComplexTypeDecl[] getUncheckedComplexTypeDecls() { 512 if (fCTCount < fComplexTypeDecls.length) { 513 fComplexTypeDecls = resize(fComplexTypeDecls, fCTCount); 514 fCTLocators = resize(fCTLocators, fCTCount); 515 } 516 return fComplexTypeDecls; 517 } 518 519 522 final SimpleLocator[] getUncheckedCTLocators() { 523 if (fCTCount < fCTLocators.length) { 524 fComplexTypeDecls = resize(fComplexTypeDecls, fCTCount); 525 fCTLocators = resize(fCTLocators, fCTCount); 526 } 527 return fCTLocators; 528 } 529 530 533 final XSGroupDecl[] getRedefinedGroupDecls() { 534 if (fRGCount < fRedefinedGroupDecls.length) { 535 fRedefinedGroupDecls = resize(fRedefinedGroupDecls, fRGCount); 536 fRGLocators = resize(fRGLocators, fRGCount/2); 537 } 538 return fRedefinedGroupDecls; 539 } 540 541 544 final SimpleLocator[] getRGLocators() { 545 if (fRGCount < fRedefinedGroupDecls.length) { 546 fRedefinedGroupDecls = resize(fRedefinedGroupDecls, fRGCount); 547 fRGLocators = resize(fRGLocators, fRGCount/2); 548 } 549 return fRGLocators; 550 } 551 552 556 final void setUncheckedTypeNum(int newSize) { 557 fCTCount = newSize; 558 fComplexTypeDecls = resize(fComplexTypeDecls, fCTCount); 559 fCTLocators = resize(fCTLocators, fCTCount); 560 } 561 562 private int fSubGroupCount = 0; 565 private XSElementDecl[] fSubGroups = new XSElementDecl[INITIAL_SIZE]; 566 567 570 final XSElementDecl[] getSubstitutionGroups() { 571 if (fSubGroupCount < fSubGroups.length) 572 fSubGroups = resize(fSubGroups, fSubGroupCount); 573 return fSubGroups; 574 } 575 576 public final static XSComplexTypeDecl fAnyType = new XSAnyType(); 579 private static class XSAnyType extends XSComplexTypeDecl { 580 public XSAnyType () { 581 fName = SchemaSymbols.ATTVAL_ANYTYPE; 582 super.fTargetNamespace = SchemaSymbols.URI_SCHEMAFORSCHEMA; 583 fBaseType = this; 584 fDerivedBy = XSConstants.DERIVATION_RESTRICTION; 585 fContentType = XSComplexTypeDecl.CONTENTTYPE_MIXED; 586 587 fParticle = null; 588 fAttrGrp = null; 589 } 590 591 public void setValues(String name, String targetNamespace, 593 XSTypeDefinition baseType, short derivedBy, short schemaFinal, 594 short block, short contentType, 595 boolean isAbstract, XSAttributeGroupDecl attrGrp, 596 XSSimpleType simpleType, XSParticleDecl particle) { 597 } 599 600 public void setName(String name){ 601 } 603 604 public void setIsAbstractType() { 605 } 607 608 public void setContainsTypeID() { 609 } 611 612 public void setIsAnonymous() { 613 } 615 616 public void reset() { 617 } 619 620 public XSObjectList getAttributeUses() { 621 return new XSObjectListImpl(null, 0); 622 } 623 624 public XSAttributeGroupDecl getAttrGrp() { 625 XSWildcardDecl wildcard = new XSWildcardDecl(); 626 wildcard.fProcessContents = XSWildcardDecl.PC_LAX; 627 XSAttributeGroupDecl attrGrp = new XSAttributeGroupDecl(); 628 attrGrp.fAttributeWC = wildcard; 629 return attrGrp; 630 } 631 632 public XSWildcard getAttributeWildcard() { 633 XSWildcardDecl wildcard = new XSWildcardDecl(); 634 wildcard.fProcessContents = XSWildcardDecl.PC_LAX; 635 return wildcard; 636 } 637 638 public XSParticle getParticle() { 639 XSWildcardDecl wildcard = new XSWildcardDecl(); 642 wildcard.fProcessContents = XSWildcardDecl.PC_LAX; 643 XSParticleDecl particleW = new XSParticleDecl(); 645 particleW.fMinOccurs = 0; 646 particleW.fMaxOccurs = SchemaSymbols.OCCURRENCE_UNBOUNDED; 647 particleW.fType = XSParticleDecl.PARTICLE_WILDCARD; 648 particleW.fValue = wildcard; 649 XSModelGroupImpl group = new XSModelGroupImpl(); 651 group.fCompositor = XSModelGroupImpl.MODELGROUP_SEQUENCE; 652 group.fParticleCount = 1; 653 group.fParticles = new XSParticleDecl[1]; 654 group.fParticles[0] = particleW; 655 XSParticleDecl particleG = new XSParticleDecl(); 657 particleG.fType = XSParticleDecl.PARTICLE_MODELGROUP; 658 particleG.fValue = group; 659 660 return particleG; 661 } 662 663 public XSObjectList getAnnotations() { 664 return null; 665 } 666 } 667 private static class BuiltinAttrDecl extends XSAttributeDecl { 668 public BuiltinAttrDecl(String name, String tns, 669 XSSimpleType type, short scope) { 670 fName = name; 671 super.fTargetNamespace = tns; 672 fType = type; 673 fScope = scope; 674 } 675 676 public void setValues(String name, String targetNamespace, 677 XSSimpleType simpleType, short constraintType, short scope, 678 ValidatedInfo valInfo, XSComplexTypeDecl enclosingCT) { 679 } 681 682 public void reset () { 683 } 685 public XSAnnotation getAnnotation() { 686 return null; 687 } 688 } 690 public final static BuiltinSchemaGrammar SG_SchemaNS = new BuiltinSchemaGrammar(GRAMMAR_XS); 692 693 public final static XSSimpleType fAnySimpleType = (XSSimpleType)SG_SchemaNS.getGlobalTypeDecl(SchemaSymbols.ATTVAL_ANYSIMPLETYPE); 694 695 public final static BuiltinSchemaGrammar SG_XSI = new BuiltinSchemaGrammar(GRAMMAR_XSI); 697 698 static final XSComplexTypeDecl[] resize(XSComplexTypeDecl[] oldArray, int newSize) { 699 XSComplexTypeDecl[] newArray = new XSComplexTypeDecl[newSize]; 700 System.arraycopy(oldArray, 0, newArray, 0, Math.min(oldArray.length, newSize)); 701 return newArray; 702 } 703 704 static final XSGroupDecl[] resize(XSGroupDecl[] oldArray, int newSize) { 705 XSGroupDecl[] newArray = new XSGroupDecl[newSize]; 706 System.arraycopy(oldArray, 0, newArray, 0, Math.min(oldArray.length, newSize)); 707 return newArray; 708 } 709 710 static final XSElementDecl[] resize(XSElementDecl[] oldArray, int newSize) { 711 XSElementDecl[] newArray = new XSElementDecl[newSize]; 712 System.arraycopy(oldArray, 0, newArray, 0, Math.min(oldArray.length, newSize)); 713 return newArray; 714 } 715 716 static final SimpleLocator[] resize(SimpleLocator[] oldArray, int newSize) { 717 SimpleLocator[] newArray = new SimpleLocator[newSize]; 718 System.arraycopy(oldArray, 0, newArray, 0, Math.min(oldArray.length, newSize)); 719 return newArray; 720 } 721 722 724 private static final short MAX_COMP_IDX = XSTypeDefinition.SIMPLE_TYPE; 726 private static final boolean[] GLOBAL_COMP = {false, true, true, true, false, true, true, false, false, false, false, true, false, true, true }; 742 743 private XSNamedMap[] fComponents = null; 745 746 private Vector fDocuments = null; 749 private Vector fLocations = null; 750 751 public synchronized void addDocument(Object document, String location) { 752 if (fDocuments == null) { 753 fDocuments = new Vector (); 754 fLocations = new Vector (); 755 } 756 fDocuments.addElement(document); 757 fLocations.addElement(location); 758 } 759 760 765 public String getSchemaNamespace() { 766 return fTargetNamespace; 767 } 768 769 synchronized DOMParser getDOMParser() { 771 if (fDOMParser != null) return fDOMParser; 772 IntegratedParserConfiguration config = new IntegratedParserConfiguration(fSymbolTable); 775 config.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE, true); 779 config.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE, false); 780 fDOMParser = new DOMParser(config); 781 return fDOMParser; 782 } 783 784 synchronized SAXParser getSAXParser() { 785 if (fSAXParser != null) return fSAXParser; 786 IntegratedParserConfiguration config = new IntegratedParserConfiguration(fSymbolTable); 789 config.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE, true); 793 config.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE, false); 794 fSAXParser = new SAXParser(config); 795 return fSAXParser; 796 } 797 798 810 public synchronized XSNamedMap getComponents(short objectType) { 811 if (objectType <= 0 || objectType > MAX_COMP_IDX || 812 !GLOBAL_COMP[objectType]) { 813 return null; 814 } 815 816 if (fComponents == null) 817 fComponents = new XSNamedMap[MAX_COMP_IDX+1]; 818 819 if (fComponents[objectType] == null) { 821 SymbolHash table = null; 822 switch (objectType) { 823 case XSConstants.TYPE_DEFINITION: 824 case XSTypeDefinition.COMPLEX_TYPE: 825 case XSTypeDefinition.SIMPLE_TYPE: 826 table = fGlobalTypeDecls; 827 break; 828 case XSConstants.ATTRIBUTE_DECLARATION: 829 table = fGlobalAttrDecls; 830 break; 831 case XSConstants.ELEMENT_DECLARATION: 832 table = fGlobalElemDecls; 833 break; 834 case XSConstants.ATTRIBUTE_GROUP: 835 table = fGlobalAttrGrpDecls; 836 break; 837 case XSConstants.MODEL_GROUP_DEFINITION: 838 table = fGlobalGroupDecls; 839 break; 840 case XSConstants.NOTATION_DECLARATION: 841 table = fGlobalNotationDecls; 842 break; 843 } 844 845 if (objectType == XSTypeDefinition.COMPLEX_TYPE || 848 objectType == XSTypeDefinition.SIMPLE_TYPE) { 849 fComponents[objectType] = new XSNamedMap4Types(fTargetNamespace, table, objectType); 850 } 851 else { 852 fComponents[objectType] = new XSNamedMapImpl(fTargetNamespace, table); 853 } 854 } 855 856 return fComponents[objectType]; 857 } 858 859 866 public XSTypeDefinition getTypeDefinition(String name) { 867 return getGlobalTypeDecl(name); 868 } 869 870 876 public XSAttributeDeclaration getAttributeDeclaration(String name) { 877 return getGlobalAttributeDecl(name); 878 } 879 880 886 public XSElementDeclaration getElementDeclaration(String name) { 887 return getGlobalElementDecl(name); 888 } 889 890 896 public XSAttributeGroupDefinition getAttributeGroup(String name) { 897 return getGlobalAttributeGroupDecl(name); 898 } 899 900 907 public XSModelGroupDefinition getModelGroupDefinition(String name) { 908 return getGlobalGroupDecl(name); 909 } 910 911 918 public XSNotationDeclaration getNotationDeclaration(String name) { 919 return getGlobalNotationDecl(name); 920 } 921 922 923 928 public StringList getDocumentLocations() { 929 return new StringListImpl(fLocations); 930 } 931 932 938 public XSModel toXSModel() { 939 return new XSModelImpl(new SchemaGrammar[]{this}); 940 } 941 942 public XSModel toXSModel(XSGrammar[] grammars) { 943 if (grammars == null || grammars.length == 0) 944 return toXSModel(); 945 946 int len = grammars.length; 947 boolean hasSelf = false; 948 for (int i = 0; i < len; i++) { 949 if (grammars[i] == this) { 950 hasSelf = true; 951 break; 952 } 953 } 954 955 SchemaGrammar[] gs = new SchemaGrammar[hasSelf ? len : len+1]; 956 for (int i = 0; i < len; i++) 957 gs[i] = (SchemaGrammar)grammars[i]; 958 if (!hasSelf) 959 gs[len] = this; 960 return new XSModelImpl(gs); 961 } 962 963 966 public XSObjectList getAnnotations() { 967 return new XSObjectListImpl(fAnnotations, fNumAnnotations); 968 } 969 970 public void addAnnotation(XSAnnotationImpl annotation) { 971 if(annotation == null) 972 return; 973 if(fAnnotations == null) { 974 fAnnotations = new XSAnnotationImpl[2]; 975 } else if(fNumAnnotations == fAnnotations.length) { 976 XSAnnotationImpl[] newArray = new XSAnnotationImpl[fNumAnnotations << 1]; 977 System.arraycopy(fAnnotations, 0, newArray, 0, fNumAnnotations); 978 fAnnotations = newArray; 979 } 980 fAnnotations[fNumAnnotations++] = annotation; 981 } 982 983 } | Popular Tags |