1 16 17 package org.apache.xerces.impl.xs; 18 19 import java.util.Vector ; 20 21 import org.apache.xerces.impl.Constants; 22 import org.apache.xerces.impl.dv.SchemaDVFactory; 23 import org.apache.xerces.impl.dv.ValidatedInfo; 24 import org.apache.xerces.impl.dv.XSSimpleType; 25 import org.apache.xerces.impl.xs.identity.IdentityConstraint; 26 import org.apache.xerces.impl.xs.util.SimpleLocator; 27 import org.apache.xerces.impl.xs.util.StringListImpl; 28 import org.apache.xerces.impl.xs.util.XSNamedMap4Types; 29 import org.apache.xerces.impl.xs.util.XSNamedMapImpl; 30 import org.apache.xerces.impl.xs.util.XSObjectListImpl; 31 import org.apache.xerces.parsers.DOMParser; 32 import org.apache.xerces.parsers.IntegratedParserConfiguration; 33 import org.apache.xerces.parsers.SAXParser; 34 import org.apache.xerces.util.SymbolHash; 35 import org.apache.xerces.util.SymbolTable; 36 import org.apache.xerces.xni.NamespaceContext; 37 import org.apache.xerces.xni.grammars.XMLGrammarDescription; 38 import org.apache.xerces.xni.grammars.XSGrammar; 39 import org.apache.xerces.xs.StringList; 40 import org.apache.xerces.xs.XSAnnotation; 41 import org.apache.xerces.xs.XSAttributeDeclaration; 42 import org.apache.xerces.xs.XSAttributeGroupDefinition; 43 import org.apache.xerces.xs.XSConstants; 44 import org.apache.xerces.xs.XSElementDeclaration; 45 import org.apache.xerces.xs.XSModel; 46 import org.apache.xerces.xs.XSModelGroupDefinition; 47 import org.apache.xerces.xs.XSNamedMap; 48 import org.apache.xerces.xs.XSNamespaceItem; 49 import org.apache.xerces.xs.XSNotationDeclaration; 50 import org.apache.xerces.xs.XSObjectList; 51 import org.apache.xerces.xs.XSParticle; 52 import org.apache.xerces.xs.XSTypeDefinition; 53 import org.apache.xerces.xs.XSWildcard; 54 55 71 72 public class SchemaGrammar implements XSGrammar, XSNamespaceItem { 73 74 String fTargetNamespace; 76 77 SymbolHash fGlobalAttrDecls; 79 SymbolHash fGlobalAttrGrpDecls; 80 SymbolHash fGlobalElemDecls; 81 SymbolHash fGlobalGroupDecls; 82 SymbolHash fGlobalNotationDecls; 83 SymbolHash fGlobalIDConstraintDecls; 84 SymbolHash fGlobalTypeDecls; 85 86 XSDDescription fGrammarDescription = null; 88 89 XSAnnotationImpl [] fAnnotations = null; 91 92 int fNumAnnotations; 94 95 private SymbolTable fSymbolTable = null; 97 private SAXParser fSAXParser = null; 99 private DOMParser fDOMParser = null; 100 101 105 protected SchemaGrammar() {} 107 108 116 public SchemaGrammar(String targetNamespace, XSDDescription grammarDesc, 117 SymbolTable symbolTable) { 118 fTargetNamespace = targetNamespace; 119 fGrammarDescription = grammarDesc; 120 fSymbolTable = symbolTable; 121 122 fGlobalAttrDecls = new SymbolHash(); 126 fGlobalAttrGrpDecls = new SymbolHash(); 127 fGlobalElemDecls = new SymbolHash(); 128 fGlobalGroupDecls = new SymbolHash(); 129 fGlobalNotationDecls = new SymbolHash(); 130 fGlobalIDConstraintDecls = new SymbolHash(); 131 132 if (fTargetNamespace == SchemaSymbols.URI_SCHEMAFORSCHEMA) 136 fGlobalTypeDecls = SG_SchemaNS.fGlobalTypeDecls.makeClone(); 137 else 138 fGlobalTypeDecls = new SymbolHash(); 139 } 141 private static final int BASICSET_COUNT = 29; 144 private static final int FULLSET_COUNT = 46; 145 146 private static final int GRAMMAR_XS = 1; 147 private static final int GRAMMAR_XSI = 2; 148 149 public static class BuiltinSchemaGrammar extends SchemaGrammar { 152 157 public BuiltinSchemaGrammar(int grammar) { 158 SchemaDVFactory schemaFactory = SchemaDVFactory.getInstance(); 159 160 if (grammar == GRAMMAR_XS) { 161 fTargetNamespace = SchemaSymbols.URI_SCHEMAFORSCHEMA; 163 164 fGrammarDescription = new XSDDescription(); 166 fGrammarDescription.fContextType = XSDDescription.CONTEXT_PREPARSE; 167 fGrammarDescription.setNamespace(SchemaSymbols.URI_SCHEMAFORSCHEMA); 168 169 fGlobalAttrDecls = new SymbolHash(1); 171 fGlobalAttrGrpDecls = new SymbolHash(1); 172 fGlobalElemDecls = new SymbolHash(1); 173 fGlobalGroupDecls = new SymbolHash(1); 174 fGlobalNotationDecls = new SymbolHash(1); 175 fGlobalIDConstraintDecls = new SymbolHash(1); 176 177 fGlobalTypeDecls = schemaFactory.getBuiltInTypes(); 179 fGlobalTypeDecls.put(fAnyType.getName(), fAnyType); 181 } 182 else if (grammar == GRAMMAR_XSI) { 183 fTargetNamespace = SchemaSymbols.URI_XSI; 185 fGrammarDescription = new XSDDescription(); 187 fGrammarDescription.fContextType = XSDDescription.CONTEXT_PREPARSE; 188 fGrammarDescription.setNamespace(SchemaSymbols.URI_XSI); 189 190 fGlobalAttrGrpDecls = new SymbolHash(1); 192 fGlobalElemDecls = new SymbolHash(1); 193 fGlobalGroupDecls = new SymbolHash(1); 194 fGlobalNotationDecls = new SymbolHash(1); 195 fGlobalIDConstraintDecls = new SymbolHash(1); 196 fGlobalTypeDecls = new SymbolHash(1); 197 198 fGlobalAttrDecls = new SymbolHash(8); 200 String name = null; 201 String tns = null; 202 XSSimpleType type = null; 203 short scope = XSConstants.SCOPE_GLOBAL; 204 205 name = SchemaSymbols.XSI_TYPE; 207 tns = SchemaSymbols.URI_XSI; 208 type = schemaFactory.getBuiltInType(SchemaSymbols.ATTVAL_QNAME); 209 fGlobalAttrDecls.put(name, new BuiltinAttrDecl(name, tns, type, scope)); 210 211 name = SchemaSymbols.XSI_NIL; 213 tns = SchemaSymbols.URI_XSI; 214 type = schemaFactory.getBuiltInType(SchemaSymbols.ATTVAL_BOOLEAN); 215 fGlobalAttrDecls.put(name, new BuiltinAttrDecl(name, tns, type, scope)); 216 217 XSSimpleType anyURI = schemaFactory.getBuiltInType(SchemaSymbols.ATTVAL_ANYURI); 218 219 name = SchemaSymbols.XSI_SCHEMALOCATION; 221 tns = SchemaSymbols.URI_XSI; 222 type = schemaFactory.createTypeList(null, SchemaSymbols.URI_XSI, (short)0, anyURI, null); 223 fGlobalAttrDecls.put(name, new BuiltinAttrDecl(name, tns, type, scope)); 224 225 name = SchemaSymbols.XSI_NONAMESPACESCHEMALOCATION; 227 tns = SchemaSymbols.URI_XSI; 228 type = anyURI; 229 fGlobalAttrDecls.put(name, new BuiltinAttrDecl(name, tns, type, scope)); 230 } 231 } 233 public XMLGrammarDescription getGrammarDescription() { 236 return fGrammarDescription.makeClone(); 237 } 239 public void setImportedGrammars(Vector importedGrammars) { 242 } 244 public void addGlobalAttributeDecl(XSAttributeDecl decl) { 245 } 247 public void addGlobalAttributeGroupDecl(XSAttributeGroupDecl decl) { 248 } 250 public void addGlobalElementDecl(XSElementDecl decl) { 251 } 253 public void addGlobalGroupDecl(XSGroupDecl decl) { 254 } 256 public void addGlobalNotationDecl(XSNotationDecl decl) { 257 } 259 public void addGlobalTypeDecl(XSTypeDefinition decl) { 260 } 262 public void addComplexTypeDecl(XSComplexTypeDecl decl, SimpleLocator locator) { 263 } 265 public void addRedefinedGroupDecl(XSGroupDecl derived, XSGroupDecl base, SimpleLocator locator) { 266 } 268 public synchronized void addDocument(Object document, String location) { 269 } 271 272 synchronized DOMParser getDOMParser() { 274 return null; 275 } 276 synchronized SAXParser getSAXParser() { 277 return null; 278 } 279 } 280 281 288 public static final class Schema4Annotations extends SchemaGrammar { 289 290 294 public Schema4Annotations() { 295 296 fTargetNamespace = SchemaSymbols.URI_SCHEMAFORSCHEMA; 298 299 fGrammarDescription = new XSDDescription(); 301 fGrammarDescription.fContextType = XSDDescription.CONTEXT_PREPARSE; 302 fGrammarDescription.setNamespace(SchemaSymbols.URI_SCHEMAFORSCHEMA); 303 304 fGlobalAttrDecls = new SymbolHash(1); 307 fGlobalAttrGrpDecls = new SymbolHash(1); 308 fGlobalElemDecls = new SymbolHash(6); 309 fGlobalGroupDecls = new SymbolHash(1); 310 fGlobalNotationDecls = new SymbolHash(1); 311 fGlobalIDConstraintDecls = new SymbolHash(1); 312 313 fGlobalTypeDecls = SG_SchemaNS.fGlobalTypeDecls; 315 316 XSElementDecl annotationDecl = createAnnotationElementDecl(SchemaSymbols.ELT_ANNOTATION); 318 XSElementDecl documentationDecl = createAnnotationElementDecl(SchemaSymbols.ELT_DOCUMENTATION); 319 XSElementDecl appinfoDecl = createAnnotationElementDecl(SchemaSymbols.ELT_APPINFO); 320 321 fGlobalElemDecls.put(annotationDecl.fName, annotationDecl); 323 fGlobalElemDecls.put(documentationDecl.fName, documentationDecl); 324 fGlobalElemDecls.put(appinfoDecl.fName, appinfoDecl); 325 326 XSComplexTypeDecl annotationType = new XSComplexTypeDecl(); 328 XSComplexTypeDecl documentationType = new XSComplexTypeDecl(); 329 XSComplexTypeDecl appinfoType = new XSComplexTypeDecl(); 330 331 annotationDecl.fType = annotationType; 333 documentationDecl.fType = documentationType; 334 appinfoDecl.fType = appinfoType; 335 336 XSAttributeGroupDecl annotationAttrs = new XSAttributeGroupDecl(); 338 XSAttributeGroupDecl documentationAttrs = new XSAttributeGroupDecl(); 339 XSAttributeGroupDecl appinfoAttrs = new XSAttributeGroupDecl(); 340 341 { 343 XSAttributeUseImpl annotationIDAttr = new XSAttributeUseImpl(); 345 annotationIDAttr.fAttrDecl = new XSAttributeDecl(); 346 annotationIDAttr.fAttrDecl.setValues(SchemaSymbols.ATT_ID, null, (XSSimpleType) fGlobalTypeDecls.get(SchemaSymbols.ATTVAL_ID), 347 XSConstants.VC_NONE, XSConstants.SCOPE_LOCAL, null, annotationType, null); 348 annotationIDAttr.fUse = SchemaSymbols.USE_OPTIONAL; 349 annotationIDAttr.fConstraintType = XSConstants.VC_NONE; 350 351 XSAttributeUseImpl documentationSourceAttr = new XSAttributeUseImpl(); 352 documentationSourceAttr.fAttrDecl = new XSAttributeDecl(); 353 documentationSourceAttr.fAttrDecl.setValues(SchemaSymbols.ATT_SOURCE, null, (XSSimpleType) fGlobalTypeDecls.get(SchemaSymbols.ATTVAL_ANYURI), 354 XSConstants.VC_NONE, XSConstants.SCOPE_LOCAL, null, documentationType, null); 355 documentationSourceAttr.fUse = SchemaSymbols.USE_OPTIONAL; 356 documentationSourceAttr.fConstraintType = XSConstants.VC_NONE; 357 358 XSAttributeUseImpl documentationLangAttr = new XSAttributeUseImpl(); 359 documentationLangAttr.fAttrDecl = new XSAttributeDecl(); 360 documentationLangAttr.fAttrDecl.setValues("lang".intern(), NamespaceContext.XML_URI, (XSSimpleType) fGlobalTypeDecls.get(SchemaSymbols.ATTVAL_LANGUAGE), 361 XSConstants.VC_NONE, XSConstants.SCOPE_LOCAL, null, documentationType, null); 362 documentationLangAttr.fUse = SchemaSymbols.USE_OPTIONAL; 363 documentationLangAttr.fConstraintType = XSConstants.VC_NONE; 364 365 XSAttributeUseImpl appinfoSourceAttr = new XSAttributeUseImpl(); 366 appinfoSourceAttr.fAttrDecl = new XSAttributeDecl(); 367 appinfoSourceAttr.fAttrDecl.setValues(SchemaSymbols.ATT_SOURCE, null, (XSSimpleType) fGlobalTypeDecls.get(SchemaSymbols.ATTVAL_ANYURI), 368 XSConstants.VC_NONE, XSConstants.SCOPE_LOCAL, null, appinfoType, null); 369 appinfoSourceAttr.fUse = SchemaSymbols.USE_OPTIONAL; 370 appinfoSourceAttr.fConstraintType = XSConstants.VC_NONE; 371 372 XSWildcardDecl otherAttrs = new XSWildcardDecl(); 374 otherAttrs.fNamespaceList = new String [] {fTargetNamespace, null}; 375 otherAttrs.fType = XSWildcard.NSCONSTRAINT_NOT; 376 otherAttrs.fProcessContents = XSWildcard.PC_LAX; 377 378 annotationAttrs.addAttributeUse(annotationIDAttr); 380 annotationAttrs.fAttributeWC = otherAttrs; 381 382 documentationAttrs.addAttributeUse(documentationSourceAttr); 383 documentationAttrs.addAttributeUse(documentationLangAttr); 384 documentationAttrs.fAttributeWC = otherAttrs; 385 386 appinfoAttrs.addAttributeUse(appinfoSourceAttr); 387 appinfoAttrs.fAttributeWC = otherAttrs; 388 } 389 390 XSParticleDecl annotationParticle = createUnboundedModelGroupParticle(); 392 { 393 XSModelGroupImpl annotationChoice = new XSModelGroupImpl(); 394 annotationChoice.fCompositor = XSModelGroupImpl.MODELGROUP_CHOICE; 395 annotationChoice.fParticleCount = 2; 396 annotationChoice.fParticles = new XSParticleDecl[2]; 397 annotationChoice.fParticles[0] = createChoiceElementParticle(appinfoDecl); 398 annotationChoice.fParticles[1] = createChoiceElementParticle(documentationDecl); 399 annotationParticle.fValue = annotationChoice; 400 } 401 402 XSParticleDecl anyWCSequenceParticle = createUnboundedAnyWildcardSequenceParticle(); 404 405 annotationType.setValues("#AnonType_" + SchemaSymbols.ELT_ANNOTATION, fTargetNamespace, SchemaGrammar.fAnyType, 407 XSConstants.DERIVATION_RESTRICTION, XSConstants.DERIVATION_NONE, (short) (XSConstants.DERIVATION_EXTENSION | XSConstants.DERIVATION_RESTRICTION), 408 XSComplexTypeDecl.CONTENTTYPE_ELEMENT, false, annotationAttrs, null, annotationParticle, new XSObjectListImpl(null, 0)); 409 annotationType.setName("#AnonType_" + SchemaSymbols.ELT_ANNOTATION); 410 annotationType.setIsAnonymous(); 411 412 documentationType.setValues("#AnonType_" + SchemaSymbols.ELT_DOCUMENTATION, fTargetNamespace, SchemaGrammar.fAnyType, 413 XSConstants.DERIVATION_RESTRICTION, XSConstants.DERIVATION_NONE, (short) (XSConstants.DERIVATION_EXTENSION | XSConstants.DERIVATION_RESTRICTION), 414 XSComplexTypeDecl.CONTENTTYPE_MIXED, false, documentationAttrs, null, anyWCSequenceParticle, new XSObjectListImpl(null, 0)); 415 documentationType.setName("#AnonType_" + SchemaSymbols.ELT_DOCUMENTATION); 416 documentationType.setIsAnonymous(); 417 418 appinfoType.setValues("#AnonType_" + SchemaSymbols.ELT_APPINFO, fTargetNamespace, SchemaGrammar.fAnyType, 419 XSConstants.DERIVATION_RESTRICTION, XSConstants.DERIVATION_NONE, (short) (XSConstants.DERIVATION_EXTENSION | XSConstants.DERIVATION_RESTRICTION), 420 XSComplexTypeDecl.CONTENTTYPE_MIXED, false, appinfoAttrs, null, anyWCSequenceParticle, new XSObjectListImpl(null, 0)); 421 appinfoType.setName("#AnonType_" + SchemaSymbols.ELT_APPINFO); 422 appinfoType.setIsAnonymous(); 423 424 } 426 public XMLGrammarDescription getGrammarDescription() { 429 return fGrammarDescription.makeClone(); 430 } 432 public void setImportedGrammars(Vector importedGrammars) { 435 } 437 public void addGlobalAttributeDecl(XSAttributeDecl decl) { 438 } 440 public void addGlobalAttributeGroupDecl(XSAttributeGroupDecl decl) { 441 } 443 public void addGlobalElementDecl(XSElementDecl decl) { 444 } 446 public void addGlobalGroupDecl(XSGroupDecl decl) { 447 } 449 public void addGlobalNotationDecl(XSNotationDecl decl) { 450 } 452 public void addGlobalTypeDecl(XSTypeDefinition decl) { 453 } 455 public void addComplexTypeDecl(XSComplexTypeDecl decl, SimpleLocator locator) { 456 } 458 public void addRedefinedGroupDecl(XSGroupDecl derived, XSGroupDecl base, SimpleLocator locator) { 459 } 461 public synchronized void addDocument(Object document, String location) { 462 } 464 465 synchronized DOMParser getDOMParser() { 467 return null; 468 } 469 synchronized SAXParser getSAXParser() { 470 return null; 471 } 472 473 477 private XSElementDecl createAnnotationElementDecl(String localName) { 478 XSElementDecl eDecl = new XSElementDecl(); 479 eDecl.fName = localName; 480 eDecl.fTargetNamespace = fTargetNamespace; 481 eDecl.setIsGlobal(); 482 eDecl.fBlock = (XSConstants.DERIVATION_EXTENSION | 483 XSConstants.DERIVATION_RESTRICTION | XSConstants.DERIVATION_SUBSTITUTION); 484 eDecl.setConstraintType(XSConstants.VC_NONE); 485 return eDecl; 486 } 487 488 private XSParticleDecl createUnboundedModelGroupParticle() { 489 XSParticleDecl particle = new XSParticleDecl(); 490 particle.fMinOccurs = 0; 491 particle.fMaxOccurs = SchemaSymbols.OCCURRENCE_UNBOUNDED; 492 particle.fType = XSParticleDecl.PARTICLE_MODELGROUP; 493 return particle; 494 } 495 496 private XSParticleDecl createChoiceElementParticle(XSElementDecl ref) { 497 XSParticleDecl particle = new XSParticleDecl(); 498 particle.fMinOccurs = 1; 499 particle.fMaxOccurs = 1; 500 particle.fType = XSParticleDecl.PARTICLE_ELEMENT; 501 particle.fValue = ref; 502 return particle; 503 } 504 505 private XSParticleDecl createUnboundedAnyWildcardSequenceParticle() { 506 XSParticleDecl particle = createUnboundedModelGroupParticle(); 507 XSModelGroupImpl sequence = new XSModelGroupImpl(); 508 sequence.fCompositor = XSModelGroupImpl.MODELGROUP_SEQUENCE; 509 sequence.fParticleCount = 1; 510 sequence.fParticles = new XSParticleDecl[1]; 511 sequence.fParticles[0] = createAnyLaxWildcardParticle(); 512 particle.fValue = sequence; 513 return particle; 514 } 515 516 private XSParticleDecl createAnyLaxWildcardParticle() { 517 XSParticleDecl particle = new XSParticleDecl(); 518 particle.fMinOccurs = 1; 519 particle.fMaxOccurs = 1; 520 particle.fType = XSParticleDecl.PARTICLE_WILDCARD; 521 522 XSWildcardDecl anyWC = new XSWildcardDecl(); 523 anyWC.fNamespaceList = null; 524 anyWC.fType = XSWildcard.NSCONSTRAINT_ANY; 525 anyWC.fProcessContents = XSWildcard.PC_LAX; 526 527 particle.fValue = anyWC; 528 return particle; 529 } 530 } 531 532 534 public XMLGrammarDescription getGrammarDescription() { 537 return fGrammarDescription; 538 } 540 public boolean isNamespaceAware () { 542 return true; 543 } 545 Vector fImported = null; 546 547 public void setImportedGrammars(Vector importedGrammars) { 548 fImported = importedGrammars; 549 } 550 551 public Vector getImportedGrammars() { 552 return fImported; 553 } 554 555 558 public final String getTargetNamespace() { 559 return fTargetNamespace; 560 } 562 565 public void addGlobalAttributeDecl(XSAttributeDecl decl) { 566 fGlobalAttrDecls.put(decl.fName, decl); 567 } 568 569 572 public void addGlobalAttributeGroupDecl(XSAttributeGroupDecl decl) { 573 fGlobalAttrGrpDecls.put(decl.fName, decl); 574 } 575 576 579 public void addGlobalElementDecl(XSElementDecl decl) { 580 fGlobalElemDecls.put(decl.fName, decl); 581 582 if (decl.fSubGroup != null) { 585 if (fSubGroupCount == fSubGroups.length) 586 fSubGroups = resize(fSubGroups, fSubGroupCount+INC_SIZE); 587 fSubGroups[fSubGroupCount++] = decl; 588 } 589 } 590 591 594 public void addGlobalGroupDecl(XSGroupDecl decl) { 595 fGlobalGroupDecls.put(decl.fName, decl); 596 } 597 598 601 public void addGlobalNotationDecl(XSNotationDecl decl) { 602 fGlobalNotationDecls.put(decl.fName, decl); 603 } 604 605 608 public void addGlobalTypeDecl(XSTypeDefinition decl) { 609 fGlobalTypeDecls.put(decl.getName(), decl); 610 } 611 612 615 public final void addIDConstraintDecl(XSElementDecl elmDecl, IdentityConstraint decl) { 616 elmDecl.addIDConstraint(decl); 617 fGlobalIDConstraintDecls.put(decl.getIdentityConstraintName(), decl); 618 } 619 620 623 public final XSAttributeDecl getGlobalAttributeDecl(String declName) { 624 return(XSAttributeDecl)fGlobalAttrDecls.get(declName); 625 } 626 627 630 public final XSAttributeGroupDecl getGlobalAttributeGroupDecl(String declName) { 631 return(XSAttributeGroupDecl)fGlobalAttrGrpDecls.get(declName); 632 } 633 634 637 public final XSElementDecl getGlobalElementDecl(String declName) { 638 return(XSElementDecl)fGlobalElemDecls.get(declName); 639 } 640 641 644 public final XSGroupDecl getGlobalGroupDecl(String declName) { 645 return(XSGroupDecl)fGlobalGroupDecls.get(declName); 646 } 647 648 651 public final XSNotationDecl getGlobalNotationDecl(String declName) { 652 return(XSNotationDecl)fGlobalNotationDecls.get(declName); 653 } 654 655 658 public final XSTypeDefinition getGlobalTypeDecl(String declName) { 659 return(XSTypeDefinition)fGlobalTypeDecls.get(declName); 660 } 661 662 665 public final IdentityConstraint getIDConstraintDecl(String declName) { 666 return(IdentityConstraint)fGlobalIDConstraintDecls.get(declName); 667 } 668 669 672 public final boolean hasIDConstraints() { 673 return fGlobalIDConstraintDecls.getLength() > 0; 674 } 675 676 private static final int INITIAL_SIZE = 16; 678 private static final int INC_SIZE = 16; 679 680 private int fCTCount = 0; 681 private XSComplexTypeDecl[] fComplexTypeDecls = new XSComplexTypeDecl[INITIAL_SIZE]; 682 private SimpleLocator[] fCTLocators = new SimpleLocator[INITIAL_SIZE]; 683 684 private static final int REDEFINED_GROUP_INIT_SIZE = 2; 687 private int fRGCount = 0; 688 private XSGroupDecl[] fRedefinedGroupDecls = new XSGroupDecl[REDEFINED_GROUP_INIT_SIZE]; 689 private SimpleLocator[] fRGLocators = new SimpleLocator[REDEFINED_GROUP_INIT_SIZE/2]; 690 691 boolean fFullChecked = false; 694 695 698 public void addComplexTypeDecl(XSComplexTypeDecl decl, SimpleLocator locator) { 699 if (fCTCount == fComplexTypeDecls.length) { 700 fComplexTypeDecls = resize(fComplexTypeDecls, fCTCount+INC_SIZE); 701 fCTLocators = resize(fCTLocators, fCTCount+INC_SIZE); 702 } 703 fCTLocators[fCTCount] = locator; 704 fComplexTypeDecls[fCTCount++] = decl; 705 } 706 707 710 public void addRedefinedGroupDecl(XSGroupDecl derived, XSGroupDecl base, SimpleLocator locator) { 711 if (fRGCount == fRedefinedGroupDecls.length) { 712 fRedefinedGroupDecls = resize(fRedefinedGroupDecls, fRGCount << 1); 714 fRGLocators = resize(fRGLocators, fRGCount); 715 } 716 fRGLocators[fRGCount/2] = locator; 717 fRedefinedGroupDecls[fRGCount++] = derived; 718 fRedefinedGroupDecls[fRGCount++] = base; 719 } 720 721 724 final XSComplexTypeDecl[] getUncheckedComplexTypeDecls() { 725 if (fCTCount < fComplexTypeDecls.length) { 726 fComplexTypeDecls = resize(fComplexTypeDecls, fCTCount); 727 fCTLocators = resize(fCTLocators, fCTCount); 728 } 729 return fComplexTypeDecls; 730 } 731 732 735 final SimpleLocator[] getUncheckedCTLocators() { 736 if (fCTCount < fCTLocators.length) { 737 fComplexTypeDecls = resize(fComplexTypeDecls, fCTCount); 738 fCTLocators = resize(fCTLocators, fCTCount); 739 } 740 return fCTLocators; 741 } 742 743 746 final XSGroupDecl[] getRedefinedGroupDecls() { 747 if (fRGCount < fRedefinedGroupDecls.length) { 748 fRedefinedGroupDecls = resize(fRedefinedGroupDecls, fRGCount); 749 fRGLocators = resize(fRGLocators, fRGCount/2); 750 } 751 return fRedefinedGroupDecls; 752 } 753 754 757 final SimpleLocator[] getRGLocators() { 758 if (fRGCount < fRedefinedGroupDecls.length) { 759 fRedefinedGroupDecls = resize(fRedefinedGroupDecls, fRGCount); 760 fRGLocators = resize(fRGLocators, fRGCount/2); 761 } 762 return fRGLocators; 763 } 764 765 769 final void setUncheckedTypeNum(int newSize) { 770 fCTCount = newSize; 771 fComplexTypeDecls = resize(fComplexTypeDecls, fCTCount); 772 fCTLocators = resize(fCTLocators, fCTCount); 773 } 774 775 private int fSubGroupCount = 0; 778 private XSElementDecl[] fSubGroups = new XSElementDecl[INITIAL_SIZE]; 779 780 783 final XSElementDecl[] getSubstitutionGroups() { 784 if (fSubGroupCount < fSubGroups.length) 785 fSubGroups = resize(fSubGroups, fSubGroupCount); 786 return fSubGroups; 787 } 788 789 public final static XSComplexTypeDecl fAnyType = new XSAnyType(); 792 private static class XSAnyType extends XSComplexTypeDecl { 793 public XSAnyType () { 794 fName = SchemaSymbols.ATTVAL_ANYTYPE; 795 super.fTargetNamespace = SchemaSymbols.URI_SCHEMAFORSCHEMA; 796 fBaseType = this; 797 fDerivedBy = XSConstants.DERIVATION_RESTRICTION; 798 fContentType = XSComplexTypeDecl.CONTENTTYPE_MIXED; 799 800 fParticle = null; 801 fAttrGrp = null; 802 } 803 804 public void setValues(String name, String targetNamespace, 806 XSTypeDefinition baseType, short derivedBy, short schemaFinal, 807 short block, short contentType, 808 boolean isAbstract, XSAttributeGroupDecl attrGrp, 809 XSSimpleType simpleType, XSParticleDecl particle) { 810 } 812 813 public void setName(String name){ 814 } 816 817 public void setIsAbstractType() { 818 } 820 821 public void setContainsTypeID() { 822 } 824 825 public void setIsAnonymous() { 826 } 828 829 public void reset() { 830 } 832 833 public XSObjectList getAttributeUses() { 834 return new XSObjectListImpl(null, 0); 835 } 836 837 public XSAttributeGroupDecl getAttrGrp() { 838 XSWildcardDecl wildcard = new XSWildcardDecl(); 839 wildcard.fProcessContents = XSWildcardDecl.PC_LAX; 840 XSAttributeGroupDecl attrGrp = new XSAttributeGroupDecl(); 841 attrGrp.fAttributeWC = wildcard; 842 return attrGrp; 843 } 844 845 public XSWildcard getAttributeWildcard() { 846 XSWildcardDecl wildcard = new XSWildcardDecl(); 847 wildcard.fProcessContents = XSWildcardDecl.PC_LAX; 848 return wildcard; 849 } 850 851 public XSParticle getParticle() { 852 XSWildcardDecl wildcard = new XSWildcardDecl(); 855 wildcard.fProcessContents = XSWildcardDecl.PC_LAX; 856 XSParticleDecl particleW = new XSParticleDecl(); 858 particleW.fMinOccurs = 0; 859 particleW.fMaxOccurs = SchemaSymbols.OCCURRENCE_UNBOUNDED; 860 particleW.fType = XSParticleDecl.PARTICLE_WILDCARD; 861 particleW.fValue = wildcard; 862 XSModelGroupImpl group = new XSModelGroupImpl(); 864 group.fCompositor = XSModelGroupImpl.MODELGROUP_SEQUENCE; 865 group.fParticleCount = 1; 866 group.fParticles = new XSParticleDecl[1]; 867 group.fParticles[0] = particleW; 868 XSParticleDecl particleG = new XSParticleDecl(); 870 particleG.fType = XSParticleDecl.PARTICLE_MODELGROUP; 871 particleG.fValue = group; 872 873 return particleG; 874 } 875 876 public XSObjectList getAnnotations() { 877 return null; 878 } 879 } 880 private static class BuiltinAttrDecl extends XSAttributeDecl { 881 public BuiltinAttrDecl(String name, String tns, 882 XSSimpleType type, short scope) { 883 fName = name; 884 super.fTargetNamespace = tns; 885 fType = type; 886 fScope = scope; 887 } 888 889 public void setValues(String name, String targetNamespace, 890 XSSimpleType simpleType, short constraintType, short scope, 891 ValidatedInfo valInfo, XSComplexTypeDecl enclosingCT) { 892 } 894 895 public void reset () { 896 } 898 public XSAnnotation getAnnotation() { 899 return null; 900 } 901 } 903 public final static BuiltinSchemaGrammar SG_SchemaNS = new BuiltinSchemaGrammar(GRAMMAR_XS); 905 906 public final static Schema4Annotations SG_Schema4Annotations = new Schema4Annotations(); 907 908 public final static XSSimpleType fAnySimpleType = (XSSimpleType)SG_SchemaNS.getGlobalTypeDecl(SchemaSymbols.ATTVAL_ANYSIMPLETYPE); 909 910 public final static BuiltinSchemaGrammar SG_XSI = new BuiltinSchemaGrammar(GRAMMAR_XSI); 912 913 static final XSComplexTypeDecl[] resize(XSComplexTypeDecl[] oldArray, int newSize) { 914 XSComplexTypeDecl[] newArray = new XSComplexTypeDecl[newSize]; 915 System.arraycopy(oldArray, 0, newArray, 0, Math.min(oldArray.length, newSize)); 916 return newArray; 917 } 918 919 static final XSGroupDecl[] resize(XSGroupDecl[] oldArray, int newSize) { 920 XSGroupDecl[] newArray = new XSGroupDecl[newSize]; 921 System.arraycopy(oldArray, 0, newArray, 0, Math.min(oldArray.length, newSize)); 922 return newArray; 923 } 924 925 static final XSElementDecl[] resize(XSElementDecl[] oldArray, int newSize) { 926 XSElementDecl[] newArray = new XSElementDecl[newSize]; 927 System.arraycopy(oldArray, 0, newArray, 0, Math.min(oldArray.length, newSize)); 928 return newArray; 929 } 930 931 static final SimpleLocator[] resize(SimpleLocator[] oldArray, int newSize) { 932 SimpleLocator[] newArray = new SimpleLocator[newSize]; 933 System.arraycopy(oldArray, 0, newArray, 0, Math.min(oldArray.length, newSize)); 934 return newArray; 935 } 936 937 939 private static final short MAX_COMP_IDX = XSTypeDefinition.SIMPLE_TYPE; 941 private static final boolean[] GLOBAL_COMP = {false, true, true, true, false, true, true, false, false, false, false, true, false, false, false, true, true }; 959 960 private XSNamedMap[] fComponents = null; 962 963 private Vector fDocuments = null; 966 private Vector fLocations = null; 967 968 public synchronized void addDocument(Object document, String location) { 969 if (fDocuments == null) { 970 fDocuments = new Vector (); 971 fLocations = new Vector (); 972 } 973 fDocuments.addElement(document); 974 fLocations.addElement(location); 975 } 976 977 982 public String getSchemaNamespace() { 983 return fTargetNamespace; 984 } 985 986 synchronized DOMParser getDOMParser() { 988 if (fDOMParser != null) return fDOMParser; 989 IntegratedParserConfiguration config = new IntegratedParserConfiguration(fSymbolTable); 992 config.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE, true); 996 config.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE, false); 997 fDOMParser = new DOMParser(config); 998 return fDOMParser; 999 } 1000 1001 synchronized SAXParser getSAXParser() { 1002 if (fSAXParser != null) return fSAXParser; 1003 IntegratedParserConfiguration config = new IntegratedParserConfiguration(fSymbolTable); 1006 config.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE, true); 1010 config.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE, false); 1011 fSAXParser = new SAXParser(config); 1012 return fSAXParser; 1013 } 1014 1015 1028 public synchronized XSNamedMap getComponents(short objectType) { 1029 if (objectType <= 0 || objectType > MAX_COMP_IDX || 1030 !GLOBAL_COMP[objectType]) { 1031 return XSNamedMapImpl.EMPTY_MAP; 1032 } 1033 1034 if (fComponents == null) 1035 fComponents = new XSNamedMap[MAX_COMP_IDX+1]; 1036 1037 if (fComponents[objectType] == null) { 1039 SymbolHash table = null; 1040 switch (objectType) { 1041 case XSConstants.TYPE_DEFINITION: 1042 case XSTypeDefinition.COMPLEX_TYPE: 1043 case XSTypeDefinition.SIMPLE_TYPE: 1044 table = fGlobalTypeDecls; 1045 break; 1046 case XSConstants.ATTRIBUTE_DECLARATION: 1047 table = fGlobalAttrDecls; 1048 break; 1049 case XSConstants.ELEMENT_DECLARATION: 1050 table = fGlobalElemDecls; 1051 break; 1052 case XSConstants.ATTRIBUTE_GROUP: 1053 table = fGlobalAttrGrpDecls; 1054 break; 1055 case XSConstants.MODEL_GROUP_DEFINITION: 1056 table = fGlobalGroupDecls; 1057 break; 1058 case XSConstants.NOTATION_DECLARATION: 1059 table = fGlobalNotationDecls; 1060 break; 1061 } 1062 1063 if (objectType == XSTypeDefinition.COMPLEX_TYPE || 1066 objectType == XSTypeDefinition.SIMPLE_TYPE) { 1067 fComponents[objectType] = new XSNamedMap4Types(fTargetNamespace, table, objectType); 1068 } 1069 else { 1070 fComponents[objectType] = new XSNamedMapImpl(fTargetNamespace, table); 1071 } 1072 } 1073 1074 return fComponents[objectType]; 1075 } 1076 1077 1084 public XSTypeDefinition getTypeDefinition(String name) { 1085 return getGlobalTypeDecl(name); 1086 } 1087 1088 1094 public XSAttributeDeclaration getAttributeDeclaration(String name) { 1095 return getGlobalAttributeDecl(name); 1096 } 1097 1098 1104 public XSElementDeclaration getElementDeclaration(String name) { 1105 return getGlobalElementDecl(name); 1106 } 1107 1108 1114 public XSAttributeGroupDefinition getAttributeGroup(String name) { 1115 return getGlobalAttributeGroupDecl(name); 1116 } 1117 1118 1125 public XSModelGroupDefinition getModelGroupDefinition(String name) { 1126 return getGlobalGroupDecl(name); 1127 } 1128 1129 1136 public XSNotationDeclaration getNotationDeclaration(String name) { 1137 return getGlobalNotationDecl(name); 1138 } 1139 1140 1141 1146 public StringList getDocumentLocations() { 1147 return new StringListImpl(fLocations); 1148 } 1149 1150 1156 public XSModel toXSModel() { 1157 return new XSModelImpl(new SchemaGrammar[]{this}); 1158 } 1159 1160 public XSModel toXSModel(XSGrammar[] grammars) { 1161 if (grammars == null || grammars.length == 0) 1162 return toXSModel(); 1163 1164 int len = grammars.length; 1165 boolean hasSelf = false; 1166 for (int i = 0; i < len; i++) { 1167 if (grammars[i] == this) { 1168 hasSelf = true; 1169 break; 1170 } 1171 } 1172 1173 SchemaGrammar[] gs = new SchemaGrammar[hasSelf ? len : len+1]; 1174 for (int i = 0; i < len; i++) 1175 gs[i] = (SchemaGrammar)grammars[i]; 1176 if (!hasSelf) 1177 gs[len] = this; 1178 return new XSModelImpl(gs); 1179 } 1180 1181 1184 public XSObjectList getAnnotations() { 1185 return new XSObjectListImpl(fAnnotations, fNumAnnotations); 1186 } 1187 1188 public void addAnnotation(XSAnnotationImpl annotation) { 1189 if(annotation == null) 1190 return; 1191 if(fAnnotations == null) { 1192 fAnnotations = new XSAnnotationImpl[2]; 1193 } else if(fNumAnnotations == fAnnotations.length) { 1194 XSAnnotationImpl[] newArray = new XSAnnotationImpl[fNumAnnotations << 1]; 1195 System.arraycopy(fAnnotations, 0, newArray, 0, fNumAnnotations); 1196 fAnnotations = newArray; 1197 } 1198 fAnnotations[fNumAnnotations++] = annotation; 1199 } 1200 1201} | Popular Tags |