1 57 58 package com.sun.org.apache.xerces.internal.impl.xs.traversers; 59 60 import java.io.IOException ; 61 import java.util.Hashtable ; 62 import java.util.Stack ; 63 import java.util.Vector ; 64 65 import javax.xml.transform.Source ; 66 import javax.xml.transform.Transformer ; 67 import javax.xml.transform.TransformerException ; 68 import javax.xml.transform.TransformerFactory ; 69 import javax.xml.transform.dom.DOMSource ; 70 import javax.xml.transform.sax.SAXSource ; 71 import javax.xml.transform.sax.SAXResult ; 72 import javax.xml.transform.stream.StreamSource ; 73 74 import com.sun.org.apache.xerces.internal.impl.Constants; 75 import com.sun.org.apache.xerces.internal.impl.XMLEntityManager; 76 import com.sun.org.apache.xerces.internal.impl.XMLErrorReporter; 77 import com.sun.org.apache.xerces.internal.impl.xs.SchemaGrammar; 78 import com.sun.org.apache.xerces.internal.impl.xs.SchemaNamespaceSupport; 79 import com.sun.org.apache.xerces.internal.impl.xs.SchemaSymbols; 80 import com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaException; 81 import com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader; 82 import com.sun.org.apache.xerces.internal.impl.xs.XSComplexTypeDecl; 83 import com.sun.org.apache.xerces.internal.impl.xs.XSDDescription; 84 import com.sun.org.apache.xerces.internal.impl.xs.XSDeclarationPool; 85 import com.sun.org.apache.xerces.internal.impl.xs.XSElementDecl; 86 import com.sun.org.apache.xerces.internal.impl.xs.XSGrammarBucket; 87 import com.sun.org.apache.xerces.internal.impl.xs.XSGroupDecl; 88 import com.sun.org.apache.xerces.internal.impl.xs.XSMessageFormatter; 89 import com.sun.org.apache.xerces.internal.impl.xs.XSModelGroupImpl; 90 import com.sun.org.apache.xerces.internal.impl.xs.XSParticleDecl; 91 import com.sun.org.apache.xerces.internal.impl.xs.opti.ElementImpl; 92 import com.sun.org.apache.xerces.internal.impl.xs.opti.SchemaDOM; 93 import com.sun.org.apache.xerces.internal.impl.xs.opti.SchemaDOMParser; 94 import com.sun.org.apache.xerces.internal.impl.xs.opti.SchemaParsingConfig; 95 import com.sun.org.apache.xerces.internal.impl.xs.util.SimpleLocator; 96 import com.sun.org.apache.xerces.internal.parsers.SAXParser; 97 import com.sun.org.apache.xerces.internal.util.DOMUtil; 98 import com.sun.org.apache.xerces.internal.util.SecurityManager; 99 import com.sun.org.apache.xerces.internal.util.SAX2XNI; 100 import com.sun.org.apache.xerces.internal.util.SymbolTable; 101 import com.sun.org.apache.xerces.internal.util.XMLInputSourceAdaptor; 102 import com.sun.org.apache.xerces.internal.util.XMLSymbols; 103 import com.sun.org.apache.xerces.internal.xni.QName; 104 import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool; 105 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager; 106 import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException; 107 import com.sun.org.apache.xerces.internal.xni.parser.XMLEntityResolver; 108 import com.sun.org.apache.xerces.internal.xni.parser.XMLErrorHandler; 109 import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource; 110 import com.sun.org.apache.xerces.internal.xs.XSObject; 111 import org.w3c.dom.Document ; 112 import org.w3c.dom.Element ; 113 import org.w3c.dom.Node ; 114 import org.xml.sax.XMLReader ; 115 import org.xml.sax.SAXException ; 116 117 129 public class XSDHandler { 130 131 132 protected static final String ALLOW_JAVA_ENCODINGS = 133 Constants.XERCES_FEATURE_PREFIX + Constants.ALLOW_JAVA_ENCODINGS_FEATURE; 134 135 136 protected static final String CONTINUE_AFTER_FATAL_ERROR = 137 Constants.XERCES_FEATURE_PREFIX + Constants.CONTINUE_AFTER_FATAL_ERROR_FEATURE; 138 139 140 protected static final String STANDARD_URI_CONFORMANT_FEATURE = 141 Constants.XERCES_FEATURE_PREFIX + Constants.STANDARD_URI_CONFORMANT_FEATURE; 142 143 144 protected static final String DISALLOW_DOCTYPE = 145 Constants.XERCES_FEATURE_PREFIX + Constants.DISALLOW_DOCTYPE_DECL_FEATURE; 146 147 148 protected static final String ERROR_HANDLER = 149 Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_HANDLER_PROPERTY; 150 151 152 protected static final String JAXP_SCHEMA_SOURCE = 153 Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE; 154 155 156 public static final String ENTITY_RESOLVER = 157 Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_RESOLVER_PROPERTY; 158 159 private static final String SECURE_PROCESSING = 160 Constants.XERCES_PROPERTY_PREFIX + Constants.SECURITY_MANAGER_PROPERTY; 161 162 163 protected static final String ENTITY_MANAGER = 164 Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_MANAGER_PROPERTY; 165 166 167 public static final String ERROR_REPORTER = 168 Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY; 169 170 171 public static final String XMLGRAMMAR_POOL = 172 Constants.XERCES_PROPERTY_PREFIX + Constants.XMLGRAMMAR_POOL_PROPERTY; 173 174 175 public static final String SYMBOL_TABLE = 176 Constants.XERCES_PROPERTY_PREFIX + Constants.SYMBOL_TABLE_PROPERTY; 177 178 protected static final String SECURITY_MANAGER = 179 Constants.XERCES_PROPERTY_PREFIX + Constants.SECURITY_MANAGER_PROPERTY; 180 181 184 protected static final boolean DEBUG_NODE_POOL = false; 185 186 188 final static int ATTRIBUTE_TYPE = 1; 191 final static int ATTRIBUTEGROUP_TYPE = 2; 192 final static int ELEMENT_TYPE = 3; 193 final static int GROUP_TYPE = 4; 194 final static int IDENTITYCONSTRAINT_TYPE = 5; 195 final static int NOTATION_TYPE = 6; 196 final static int TYPEDECL_TYPE = 7; 197 198 public final static String REDEF_IDENTIFIER = "_fn3dktizrknc9pi"; 201 202 protected Hashtable fNotationRegistry = new Hashtable (); 206 207 protected XSDeclarationPool fDeclPool = null; 208 209 private boolean fAllowJavaEncodings = false; 211 212 private boolean fStrictURI = false; 214 215 220 protected SecurityManager fSecureProcessing = null; 221 222 private Hashtable fUnparsedAttributeRegistry = new Hashtable (); 230 private Hashtable fUnparsedAttributeGroupRegistry = new Hashtable (); 231 private Hashtable fUnparsedElementRegistry = new Hashtable (); 232 private Hashtable fUnparsedGroupRegistry = new Hashtable (); 233 private Hashtable fUnparsedIdentityConstraintRegistry = new Hashtable (); 234 private Hashtable fUnparsedNotationRegistry = new Hashtable (); 235 private Hashtable fUnparsedTypeRegistry = new Hashtable (); 236 private Hashtable fXSDocumentInfoRegistry = new Hashtable (); 243 244 private Hashtable fDependencyMap = new Hashtable (); 248 249 private Hashtable fImportMap = new Hashtable (); 254 private Vector fAllTNSs = new Vector (); 258 private Hashtable fLocationPairs = null; 260 261 private String null2EmptyString(String ns) { 263 return ns == null ? XMLSymbols.EMPTY_STRING : ns; 264 } 265 private String emptyString2Null(String ns) { 266 return ns == XMLSymbols.EMPTY_STRING ? null : ns; 267 } 268 269 private Hashtable fTraversed = new Hashtable (); 275 276 private Hashtable fDoc2SystemId = new Hashtable (); 279 280 private XSDocumentInfo fRoot = null; 282 283 private Hashtable fDoc2XSDocumentMap = new Hashtable (); 287 288 private Hashtable fRedefine2XSDMap = new Hashtable (); 291 292 private Hashtable fRedefine2NSSupport = new Hashtable (); 294 295 private Hashtable fRedefinedRestrictedAttributeGroupRegistry = new Hashtable (); 301 private Hashtable fRedefinedRestrictedGroupRegistry = new Hashtable (); 302 303 private boolean fLastSchemaWasDuplicate; 306 307 private XMLErrorReporter fErrorReporter; 309 private XMLEntityResolver fEntityResolver; 310 311 private XSAttributeChecker fAttributeChecker; 313 314 private SymbolTable fSymbolTable; 316 317 private XSGrammarBucket fGrammarBucket; 319 320 private XSDDescription fSchemaGrammarDescription; 322 323 private XMLGrammarPool fGrammarPool; 325 326 XSDAttributeGroupTraverser fAttributeGroupTraverser; 328 XSDAttributeTraverser fAttributeTraverser; 329 XSDComplexTypeTraverser fComplexTypeTraverser; 330 XSDElementTraverser fElementTraverser; 331 XSDGroupTraverser fGroupTraverser; 332 XSDKeyrefTraverser fKeyrefTraverser; 333 XSDNotationTraverser fNotationTraverser; 334 XSDSimpleTypeTraverser fSimpleTypeTraverser; 335 XSDUniqueOrKeyTraverser fUniqueOrKeyTraverser; 336 XSDWildcardTraverser fWildCardTraverser; 337 338 SchemaParsingConfig fSchemaParser; 340 341 344 private static final int INIT_STACK_SIZE = 30; 346 private static final int INC_STACK_SIZE = 10; 348 private int fLocalElemStackPos = 0; 350 351 private XSParticleDecl[] fParticle = new XSParticleDecl[INIT_STACK_SIZE]; 352 private Element [] fLocalElementDecl = new Element [INIT_STACK_SIZE]; 353 private int[] fAllContext = new int[INIT_STACK_SIZE]; 354 private XSObject[] fParent = new XSObject[INIT_STACK_SIZE]; 355 private String [][] fLocalElemNamespaceContext = new String [INIT_STACK_SIZE][1]; 356 357 360 private static final int INIT_KEYREF_STACK = 2; 362 private static final int INC_KEYREF_STACK_AMOUNT = 2; 364 private int fKeyrefStackPos = 0; 366 367 private Element [] fKeyrefs = new Element [INIT_KEYREF_STACK]; 368 private XSElementDecl [] fKeyrefElems = new XSElementDecl [INIT_KEYREF_STACK]; 369 private String [][] fKeyrefNamespaceContext = new String [INIT_KEYREF_STACK][1]; 370 371 public XSDHandler(){ 373 fSchemaParser = new SchemaParsingConfig(); 374 } 375 376 public XSDHandler (XSGrammarBucket gBucket) { 380 this(); 381 fGrammarBucket = gBucket; 382 383 fSchemaGrammarDescription = new XSDDescription(); 387 } 389 390 391 392 403 public SchemaGrammar parseSchema(Source source, XSDDescription desc, 404 Hashtable locationPairs) 405 throws IOException { 406 fLocationPairs = locationPairs; 407 408 if (fSchemaParser != null) { 409 fSchemaParser.resetNodePool(); 410 } 411 412 SchemaGrammar grammar = null; 413 String schemaNamespace = null; 414 short referType = desc.getContextType(); 415 if (referType != XSDDescription.CONTEXT_PREPARSE){ 422 grammar = findGrammar(desc); 424 if (grammar != null) 425 return grammar; 426 schemaNamespace = desc.getTargetNamespace(); 427 if (schemaNamespace != null) { 429 schemaNamespace = fSymbolTable.addSymbol(schemaNamespace); 430 } 431 } 432 433 prepareForParse(); 436 437 Document schemaRoot = getSchema(schemaNamespace, source, 439 referType == XSDDescription.CONTEXT_PREPARSE, 440 referType, null); 441 if (schemaRoot == null) { 442 return null; 444 } 445 if ( referType == XSDDescription.CONTEXT_PREPARSE) { 446 Element schemaElem = DOMUtil.getRoot(schemaRoot); 447 schemaNamespace = DOMUtil.getAttrValue(schemaElem, SchemaSymbols.ATT_TARGETNAMESPACE); 448 if(schemaNamespace != null && schemaNamespace.length() > 0) { 449 schemaNamespace = fSymbolTable.addSymbol(schemaNamespace); 452 desc.setTargetNamespace(schemaNamespace); 453 } 454 else { 455 schemaNamespace = null; 456 } 457 grammar = findGrammar(desc); 458 if (grammar != null) 459 return grammar; 460 String schemaId = source.getSystemId(); 461 XSDKey key = new XSDKey(schemaId, referType, schemaNamespace); 462 fTraversed.put(key, schemaRoot ); 463 if (schemaId != null) { 464 fDoc2SystemId.put(schemaRoot, schemaId ); 465 } 466 } 467 468 prepareForTraverse(); 471 472 fRoot = constructTrees(schemaRoot, source.getSystemId(), desc); 473 if (fRoot == null) { 474 return null; 475 } 476 477 buildGlobalNameRegistries(); 479 480 traverseSchemas(); 482 483 traverseLocalElements(); 485 486 resolveKeyRefs(); 488 489 493 for (int i = fAllTNSs.size() - 1; i >= 0; i--) { 496 String tns = (String )fAllTNSs.elementAt(i); 498 Vector ins = (Vector )fImportMap.get(tns); 500 SchemaGrammar sg = fGrammarBucket.getGrammar(emptyString2Null(tns)); 502 if (sg == null) 503 continue; 504 SchemaGrammar isg; 505 int count = 0; 507 for (int j = 0; j < ins.size(); j++) { 508 isg = fGrammarBucket.getGrammar((String )ins.elementAt(j)); 510 if (isg != null) 512 ins.setElementAt(isg, count++); 513 } 514 ins.setSize(count); 515 sg.setImportedGrammars(ins); 517 } 518 519 return fGrammarBucket.getGrammar(fRoot.fTargetNamespace); 521 } 523 527 SchemaGrammar getGrammar(String tns) { 528 return fGrammarBucket.getGrammar(tns); 529 } 530 531 536 protected SchemaGrammar findGrammar(XSDDescription desc) { 537 SchemaGrammar sg = fGrammarBucket.getGrammar(desc.getTargetNamespace()); 538 if (sg == null) { 539 if (fGrammarPool != null) { 540 sg = (SchemaGrammar)fGrammarPool.retrieveGrammar(desc); 541 if (sg != null) { 542 if (!fGrammarBucket.putGrammar(sg, true)) { 545 reportSchemaWarning("GrammarConflict", null, null); 548 sg = null; 549 } 550 } 551 } 552 } 553 return sg; 554 } 555 556 559 private static final String [][] NS_ERROR_CODES = { 560 {"src-include.2.1", "src-include.2.1"}, 561 {"src-redefine.3.1", "src-redefine.3.1"}, 562 {"src-import.3.1", "src-import.3.2"}, 563 null, 564 {"TargetNamespace.1", "TargetNamespace.2"}, 565 {"TargetNamespace.1", "TargetNamespace.2"}, 566 {"TargetNamespace.1", "TargetNamespace.2"}, 567 {"TargetNamespace.1", "TargetNamespace.2"} 568 }; 569 570 private static final String [] ELE_ERROR_CODES = { 571 "src-include.1", "src-redefine.2", "src-import.2", "schema_reference.4", 572 "schema_reference.4", "schema_reference.4", "schema_reference.4", "schema_reference.4" 573 }; 574 575 protected XSDocumentInfo constructTrees(Document schemaRoot, String locationHint, XSDDescription desc) { 586 if (schemaRoot == null) return null; 587 String callerTNS = desc.getTargetNamespace(); 588 short referType = desc.getContextType(); 589 590 XSDocumentInfo currSchemaInfo = null; 591 try { 592 currSchemaInfo = new XSDocumentInfo(schemaRoot, fAttributeChecker, fSymbolTable); 594 } catch (XMLSchemaException se) { 595 reportSchemaError(ELE_ERROR_CODES[referType], 596 new Object []{locationHint}, 597 DOMUtil.getRoot(schemaRoot)); 598 return null; 599 } 600 if (currSchemaInfo.fTargetNamespace != null && 602 currSchemaInfo.fTargetNamespace.length() == 0) { 603 reportSchemaWarning("EmptyTargetNamespace", 604 new Object []{locationHint}, 605 DOMUtil.getRoot(schemaRoot)); 606 currSchemaInfo.fTargetNamespace = null; 607 } 608 609 if (callerTNS != null) { 610 int secondIdx = 0; 613 if (referType == XSDDescription.CONTEXT_INCLUDE || 615 referType == XSDDescription.CONTEXT_REDEFINE) { 616 if (currSchemaInfo.fTargetNamespace == null) { 619 currSchemaInfo.fTargetNamespace = callerTNS; 620 currSchemaInfo.fIsChameleonSchema = true; 621 } 622 else if (callerTNS != currSchemaInfo.fTargetNamespace) { 625 reportSchemaError(NS_ERROR_CODES[referType][secondIdx], 626 new Object [] {callerTNS, currSchemaInfo.fTargetNamespace}, 627 DOMUtil.getRoot(schemaRoot)); 628 return null; 629 } 630 } 631 else if (referType != XSDDescription.CONTEXT_PREPARSE && callerTNS != currSchemaInfo.fTargetNamespace) { 633 reportSchemaError(NS_ERROR_CODES[referType][secondIdx], 634 new Object [] {callerTNS, currSchemaInfo.fTargetNamespace}, 635 DOMUtil.getRoot(schemaRoot)); 636 return null; 637 } 638 } 639 else if (currSchemaInfo.fTargetNamespace != null) { 642 if (referType == XSDDescription.CONTEXT_PREPARSE) { 644 desc.setTargetNamespace(currSchemaInfo.fTargetNamespace); 645 callerTNS = currSchemaInfo.fTargetNamespace; 646 } 647 else { 648 int secondIdx = 1; 651 reportSchemaError(NS_ERROR_CODES[referType][secondIdx], 652 new Object [] {callerTNS, currSchemaInfo.fTargetNamespace}, 653 DOMUtil.getRoot(schemaRoot)); 654 return null; 655 } 656 } 657 660 currSchemaInfo.addAllowedNS(currSchemaInfo.fTargetNamespace); 662 663 SchemaGrammar sg = null; 664 665 if (referType == XSDDescription.CONTEXT_INCLUDE || 666 referType == XSDDescription.CONTEXT_REDEFINE) { 667 sg = fGrammarBucket.getGrammar(currSchemaInfo.fTargetNamespace); 668 } 669 else { 670 sg = new SchemaGrammar(currSchemaInfo.fTargetNamespace, desc.makeClone(), fSymbolTable); 671 fGrammarBucket.putGrammar(sg); 672 } 673 674 sg.addDocument(null, (String )fDoc2SystemId.get(currSchemaInfo.fSchemaDoc)); 678 679 fDoc2XSDocumentMap.put(schemaRoot, currSchemaInfo); 680 681 Vector dependencies = new Vector (); 682 Element rootNode = DOMUtil.getRoot(schemaRoot); 683 684 Document newSchemaRoot = null; 685 for (Element child = DOMUtil.getFirstChildElement(rootNode); 686 child != null; 687 child = DOMUtil.getNextSiblingElement(child)) { 688 String schemaNamespace=null; 689 String schemaHint=null; 690 String localName = DOMUtil.getLocalName(child); 691 692 short refType = -1; 693 694 if (localName.equals(SchemaSymbols.ELT_ANNOTATION)) 695 continue; 696 else if (localName.equals(SchemaSymbols.ELT_IMPORT)) { 697 refType = XSDDescription.CONTEXT_IMPORT; 698 Object [] importAttrs = fAttributeChecker.checkAttributes(child, true, currSchemaInfo); 701 schemaHint = (String )importAttrs[XSAttributeChecker.ATTIDX_SCHEMALOCATION]; 702 schemaNamespace = (String )importAttrs[XSAttributeChecker.ATTIDX_NAMESPACE]; 703 if (schemaNamespace != null) 704 schemaNamespace = fSymbolTable.addSymbol(schemaNamespace); 705 if (schemaNamespace == currSchemaInfo.fTargetNamespace) { 707 reportSchemaError("src-import.1.1", new Object [] {schemaNamespace}, child); 708 } 709 710 Element importChild = DOMUtil.getFirstChildElement(child); 712 if(importChild != null ) { 713 String importComponentType = DOMUtil.getLocalName(importChild); 714 if (importComponentType.equals(SchemaSymbols.ELT_ANNOTATION)) { 715 sg.addAnnotation( 717 fElementTraverser.traverseAnnotationDecl(importChild, importAttrs, true, currSchemaInfo)); 718 } else { 719 reportSchemaError("s4s-elt-must-match.1", new Object [] {localName, "annotation?", importComponentType}, child); 720 } 721 if(DOMUtil.getNextSiblingElement(importChild) != null) { 722 reportSchemaError("s4s-elt-must-match.1", new Object [] {localName, "annotation?", DOMUtil.getLocalName(DOMUtil.getNextSiblingElement(importChild))}, child); 723 } 724 } 725 fAttributeChecker.returnAttrArray(importAttrs, currSchemaInfo); 726 727 if (currSchemaInfo.isAllowedNS(schemaNamespace)) 730 continue; 731 732 currSchemaInfo.addAllowedNS(schemaNamespace); 734 735 String tns = null2EmptyString(currSchemaInfo.fTargetNamespace); 738 Vector ins = (Vector )fImportMap.get(tns); 740 if (ins == null) { 742 fAllTNSs.addElement(tns); 744 ins = new Vector (); 745 fImportMap.put(tns, ins); 746 ins.addElement(schemaNamespace); 747 } 748 else if (!ins.contains(schemaNamespace)){ 749 ins.addElement(schemaNamespace); 750 } 751 752 fSchemaGrammarDescription.reset(); 753 fSchemaGrammarDescription.setContextType(XSDDescription.CONTEXT_IMPORT); 754 fSchemaGrammarDescription.setBaseSystemId((String )fDoc2SystemId.get(schemaRoot)); 755 fSchemaGrammarDescription.setLocationHints(new String []{schemaHint}); 756 fSchemaGrammarDescription.setTargetNamespace(schemaNamespace); 757 758 if (findGrammar(fSchemaGrammarDescription) != null) 761 continue; 762 newSchemaRoot = resolveSchema(fSchemaGrammarDescription, false, child); 763 } 764 else if ((localName.equals(SchemaSymbols.ELT_INCLUDE)) || 765 (localName.equals(SchemaSymbols.ELT_REDEFINE))) { 766 Object [] includeAttrs = fAttributeChecker.checkAttributes(child, true, currSchemaInfo); 770 schemaHint = (String )includeAttrs[XSAttributeChecker.ATTIDX_SCHEMALOCATION]; 771 if (localName.equals(SchemaSymbols.ELT_REDEFINE)) { 773 fRedefine2NSSupport.put(child, new SchemaNamespaceSupport(currSchemaInfo.fNamespaceSupport)); 774 } 775 776 if(localName.equals(SchemaSymbols.ELT_INCLUDE)) { 779 Element includeChild = DOMUtil.getFirstChildElement(child); 780 if(includeChild != null ) { 781 String includeComponentType = DOMUtil.getLocalName(includeChild); 782 if (includeComponentType.equals(SchemaSymbols.ELT_ANNOTATION)) { 783 sg.addAnnotation( 785 fElementTraverser.traverseAnnotationDecl(includeChild, includeAttrs, true, currSchemaInfo)); 786 } else { 787 reportSchemaError("s4s-elt-must-match.1", new Object [] {localName, "annotation?", includeComponentType}, child); 788 } 789 if(DOMUtil.getNextSiblingElement(includeChild) != null) { 790 reportSchemaError("s4s-elt-must-match.1", new Object [] {localName, "annotation?", DOMUtil.getLocalName(DOMUtil.getNextSiblingElement(includeChild))}, child); 791 } 792 } 793 } 794 else { 795 for (Element redefinedChild = DOMUtil.getFirstChildElement(child); 796 redefinedChild != null; 797 redefinedChild = DOMUtil.getNextSiblingElement(redefinedChild)) { 798 String redefinedComponentType = DOMUtil.getLocalName(redefinedChild); 799 if (redefinedComponentType.equals(SchemaSymbols.ELT_ANNOTATION)) { 800 sg.addAnnotation( 802 fElementTraverser.traverseAnnotationDecl(redefinedChild, includeAttrs, true, currSchemaInfo)); 803 DOMUtil.setHidden(redefinedChild); 804 } 805 } 807 } 808 fAttributeChecker.returnAttrArray(includeAttrs, currSchemaInfo); 809 if (schemaHint == null) { 811 reportSchemaError("s4s-att-must-appear", new Object [] { 812 "<include> or <redefine>", "schemaLocation"}, 813 child); 814 } 815 boolean mustResolve = false; 817 refType = XSDDescription.CONTEXT_INCLUDE; 818 if(localName.equals(SchemaSymbols.ELT_REDEFINE)) { 819 mustResolve = nonAnnotationContent(child); 820 refType = XSDDescription.CONTEXT_REDEFINE; 821 } 822 fSchemaGrammarDescription.reset(); 823 fSchemaGrammarDescription.setContextType(refType); 824 fSchemaGrammarDescription.setBaseSystemId((String )fDoc2SystemId.get(schemaRoot)); 825 fSchemaGrammarDescription.setLocationHints(new String []{schemaHint}); 826 fSchemaGrammarDescription.setTargetNamespace(callerTNS); 827 newSchemaRoot = resolveSchema(fSchemaGrammarDescription, mustResolve, child); 828 schemaNamespace = currSchemaInfo.fTargetNamespace; 829 } 830 else { 831 break; 834 } 835 836 XSDocumentInfo newSchemaInfo = null; 839 if (fLastSchemaWasDuplicate) { 840 newSchemaInfo = (XSDocumentInfo)fDoc2XSDocumentMap.get(newSchemaRoot); 841 } 842 else { 843 newSchemaInfo = constructTrees(newSchemaRoot, schemaHint, fSchemaGrammarDescription); 844 } 845 846 if (localName.equals(SchemaSymbols.ELT_REDEFINE) && 847 newSchemaInfo != null) { 848 fRedefine2XSDMap.put(child, newSchemaInfo); 851 } 852 if (newSchemaRoot != null) { 853 if (newSchemaInfo != null) 854 dependencies.addElement(newSchemaInfo); 855 newSchemaRoot = null; 856 } 857 } 858 859 fDependencyMap.put(currSchemaInfo, dependencies); 860 return currSchemaInfo; 861 } 863 protected void buildGlobalNameRegistries() { 869 879 Stack schemasToProcess = new Stack (); 880 schemasToProcess.push(fRoot); 881 while (!schemasToProcess.empty()) { 882 XSDocumentInfo currSchemaDoc = 883 (XSDocumentInfo)schemasToProcess.pop(); 884 Document currDoc = currSchemaDoc.fSchemaDoc; 885 if (DOMUtil.isHidden(currDoc)) { 886 continue; 888 } 889 Element currRoot = DOMUtil.getRoot(currDoc); 890 891 boolean dependenciesCanOccur = true; 893 for (Element globalComp = 894 DOMUtil.getFirstChildElement(currRoot); 895 globalComp != null; 896 globalComp = DOMUtil.getNextSiblingElement(globalComp)) { 897 if (DOMUtil.getLocalName(globalComp).equals(SchemaSymbols.ELT_ANNOTATION)) { 900 continue; 902 } 903 else if (DOMUtil.getLocalName(globalComp).equals(SchemaSymbols.ELT_INCLUDE) || 904 DOMUtil.getLocalName(globalComp).equals(SchemaSymbols.ELT_IMPORT)) { 905 if (!dependenciesCanOccur) { 906 reportSchemaError("s4s-elt-invalid-content.3", new Object [] {DOMUtil.getLocalName(globalComp)}, globalComp); 907 } 908 DOMUtil.setHidden(globalComp); 910 } 911 else if (DOMUtil.getLocalName(globalComp).equals(SchemaSymbols.ELT_REDEFINE)) { 912 if (!dependenciesCanOccur) { 913 reportSchemaError("s4s-elt-invalid-content.3", new Object [] {DOMUtil.getLocalName(globalComp)}, globalComp); 914 } 915 for (Element redefineComp = DOMUtil.getFirstChildElement(globalComp); 916 redefineComp != null; 917 redefineComp = DOMUtil.getNextSiblingElement(redefineComp)) { 918 String lName = DOMUtil.getAttrValue(redefineComp, SchemaSymbols.ATT_NAME); 919 if (lName.length() == 0) continue; 921 String qName = currSchemaDoc.fTargetNamespace == null ? 922 ","+lName: 923 currSchemaDoc.fTargetNamespace +","+lName; 924 String componentType = DOMUtil.getLocalName(redefineComp); 925 if (componentType.equals(SchemaSymbols.ELT_ATTRIBUTEGROUP)) { 926 checkForDuplicateNames(qName, fUnparsedAttributeGroupRegistry, redefineComp, currSchemaDoc); 927 String targetLName = DOMUtil.getAttrValue(redefineComp, SchemaSymbols.ATT_NAME)+REDEF_IDENTIFIER; 929 renameRedefiningComponents(currSchemaDoc, redefineComp, SchemaSymbols.ELT_ATTRIBUTEGROUP, 931 lName, targetLName); 932 } 933 else if ((componentType.equals(SchemaSymbols.ELT_COMPLEXTYPE)) || 934 (componentType.equals(SchemaSymbols.ELT_SIMPLETYPE))) { 935 checkForDuplicateNames(qName, fUnparsedTypeRegistry, redefineComp, currSchemaDoc); 936 String targetLName = DOMUtil.getAttrValue(redefineComp, SchemaSymbols.ATT_NAME) + REDEF_IDENTIFIER; 938 if (componentType.equals(SchemaSymbols.ELT_COMPLEXTYPE)) { 940 renameRedefiningComponents(currSchemaDoc, redefineComp, SchemaSymbols.ELT_COMPLEXTYPE, 941 lName, targetLName); 942 } 943 else { renameRedefiningComponents(currSchemaDoc, redefineComp, SchemaSymbols.ELT_SIMPLETYPE, 945 lName, targetLName); 946 } 947 } 948 else if (componentType.equals(SchemaSymbols.ELT_GROUP)) { 949 checkForDuplicateNames(qName, fUnparsedGroupRegistry, redefineComp, currSchemaDoc); 950 String targetLName = DOMUtil.getAttrValue(redefineComp, SchemaSymbols.ATT_NAME)+REDEF_IDENTIFIER; 952 renameRedefiningComponents(currSchemaDoc, redefineComp, SchemaSymbols.ELT_GROUP, 954 lName, targetLName); 955 } 956 } } 960 else { 961 dependenciesCanOccur = false; 962 String lName = DOMUtil.getAttrValue(globalComp, SchemaSymbols.ATT_NAME); 963 if (lName.length() == 0) continue; 965 String qName = currSchemaDoc.fTargetNamespace == null? 966 ","+lName: 967 currSchemaDoc.fTargetNamespace +","+lName; 968 String componentType = DOMUtil.getLocalName(globalComp); 969 if (componentType.equals(SchemaSymbols.ELT_ATTRIBUTE)) { 970 checkForDuplicateNames(qName, fUnparsedAttributeRegistry, globalComp, currSchemaDoc); 971 } 972 else if (componentType.equals(SchemaSymbols.ELT_ATTRIBUTEGROUP)) { 973 checkForDuplicateNames(qName, fUnparsedAttributeGroupRegistry, globalComp, currSchemaDoc); 974 } 975 else if ((componentType.equals(SchemaSymbols.ELT_COMPLEXTYPE)) || 976 (componentType.equals(SchemaSymbols.ELT_SIMPLETYPE))) { 977 checkForDuplicateNames(qName, fUnparsedTypeRegistry, globalComp, currSchemaDoc); 978 } 979 else if (componentType.equals(SchemaSymbols.ELT_ELEMENT)) { 980 checkForDuplicateNames(qName, fUnparsedElementRegistry, globalComp, currSchemaDoc); 981 } 982 else if (componentType.equals(SchemaSymbols.ELT_GROUP)) { 983 checkForDuplicateNames(qName, fUnparsedGroupRegistry, globalComp, currSchemaDoc); 984 } 985 else if (componentType.equals(SchemaSymbols.ELT_NOTATION)) { 986 checkForDuplicateNames(qName, fUnparsedNotationRegistry, globalComp, currSchemaDoc); 987 } 988 } 989 } 991 DOMUtil.setHidden(currDoc); 993 Vector currSchemaDepends = (Vector )fDependencyMap.get(currSchemaDoc); 995 for (int i = 0; i < currSchemaDepends.size(); i++) { 996 schemasToProcess.push(currSchemaDepends.elementAt(i)); 997 } 998 } } 1001 protected void traverseSchemas() { 1013 setSchemasVisible(fRoot); 1018 Stack schemasToProcess = new Stack (); 1019 schemasToProcess.push(fRoot); 1020 while (!schemasToProcess.empty()) { 1021 XSDocumentInfo currSchemaDoc = 1022 (XSDocumentInfo)schemasToProcess.pop(); 1023 Document currDoc = currSchemaDoc.fSchemaDoc; 1024 SchemaGrammar currSG = fGrammarBucket.getGrammar(currSchemaDoc.fTargetNamespace); 1025 if (DOMUtil.isHidden(currDoc)) { 1026 continue; 1028 } 1029 Element currRoot = DOMUtil.getRoot(currDoc); 1030 1031 for (Element globalComp = 1033 DOMUtil.getFirstVisibleChildElement(currRoot); 1034 globalComp != null; 1035 globalComp = DOMUtil.getNextVisibleSiblingElement(globalComp)) { 1036 DOMUtil.setHidden(globalComp); 1038 String componentType = DOMUtil.getLocalName(globalComp); 1039 if (DOMUtil.getLocalName(globalComp).equals(SchemaSymbols.ELT_REDEFINE)) { 1041 currSchemaDoc.backupNSSupport((SchemaNamespaceSupport)fRedefine2NSSupport.get(globalComp)); 1043 for (Element redefinedComp = DOMUtil.getFirstVisibleChildElement(globalComp); 1044 redefinedComp != null; 1045 redefinedComp = DOMUtil.getNextVisibleSiblingElement(redefinedComp)) { 1046 String redefinedComponentType = DOMUtil.getLocalName(redefinedComp); 1047 DOMUtil.setHidden(redefinedComp); 1048 if (redefinedComponentType.equals(SchemaSymbols.ELT_ATTRIBUTEGROUP)) { 1049 fAttributeGroupTraverser.traverseGlobal(redefinedComp, currSchemaDoc, currSG); 1050 } 1051 else if (redefinedComponentType.equals(SchemaSymbols.ELT_COMPLEXTYPE)) { 1052 fComplexTypeTraverser.traverseGlobal(redefinedComp, currSchemaDoc, currSG); 1053 } 1054 else if (redefinedComponentType.equals(SchemaSymbols.ELT_GROUP)) { 1055 fGroupTraverser.traverseGlobal(redefinedComp, currSchemaDoc, currSG); 1056 } 1057 else if (redefinedComponentType.equals(SchemaSymbols.ELT_SIMPLETYPE)) { 1058 fSimpleTypeTraverser.traverseGlobal(redefinedComp, currSchemaDoc, currSG); 1059 } 1060 else { 1066 reportSchemaError("s4s-elt-must-match.1", new Object [] {DOMUtil.getLocalName(globalComp), "(annotation | (simpleType | complexType | group | attributeGroup))*", redefinedComponentType}, redefinedComp); 1067 } 1068 } currSchemaDoc.restoreNSSupport(); 1070 } 1071 else if (componentType.equals(SchemaSymbols.ELT_ATTRIBUTE)) { 1072 fAttributeTraverser.traverseGlobal(globalComp, currSchemaDoc, currSG); 1073 } 1074 else if (componentType.equals(SchemaSymbols.ELT_ATTRIBUTEGROUP)) { 1075 fAttributeGroupTraverser.traverseGlobal(globalComp, currSchemaDoc, currSG); 1076 } 1077 else if (componentType.equals(SchemaSymbols.ELT_COMPLEXTYPE)) { 1078 fComplexTypeTraverser.traverseGlobal(globalComp, currSchemaDoc, currSG); 1079 } 1080 else if (componentType.equals(SchemaSymbols.ELT_ELEMENT)) { 1081 fElementTraverser.traverseGlobal(globalComp, currSchemaDoc, currSG); 1082 } 1083 else if (componentType.equals(SchemaSymbols.ELT_GROUP)) { 1084 fGroupTraverser.traverseGlobal(globalComp, currSchemaDoc, currSG); 1085 } 1086 else if (componentType.equals(SchemaSymbols.ELT_NOTATION)) { 1087 fNotationTraverser.traverse(globalComp, currSchemaDoc, currSG); 1088 } 1089 else if (componentType.equals(SchemaSymbols.ELT_SIMPLETYPE)) { 1090 fSimpleTypeTraverser.traverseGlobal(globalComp, currSchemaDoc, currSG); 1091 } 1092 else if (componentType.equals(SchemaSymbols.ELT_ANNOTATION)) { 1093 currSG.addAnnotation(fElementTraverser.traverseAnnotationDecl(globalComp, currSchemaDoc.getSchemaAttrs(), true, currSchemaDoc)); 1094 } 1095 else { 1096 reportSchemaError("s4s-elt-invalid-content.1", new Object [] {SchemaSymbols.ELT_SCHEMA, DOMUtil.getLocalName(globalComp)}, globalComp); 1097 } 1098 } 1100 currSchemaDoc.returnSchemaAttrs(); 1102 DOMUtil.setHidden(currDoc); 1103 Vector currSchemaDepends = (Vector )fDependencyMap.get(currSchemaDoc); 1105 for (int i = 0; i < currSchemaDepends.size(); i++) { 1106 schemasToProcess.push(currSchemaDepends.elementAt(i)); 1107 } 1108 } } 1111 private Vector fReportedTNS = null; 1114 private final boolean needReportTNSError(String uri) { 1118 if (fReportedTNS == null) 1119 fReportedTNS = new Vector (); 1120 else if (fReportedTNS.contains(uri)) 1121 return false; 1122 fReportedTNS.addElement(uri); 1123 return true; 1124 } 1125 1126 private static final String [] COMP_TYPE = { 1127 null, "attribute declaration", 1129 "attribute group", 1130 "element declaration", 1131 "group", 1132 "identity constraint", 1133 "notation", 1134 "type definition", 1135 }; 1136 1137 private static final String [] CIRCULAR_CODES = { 1138 "Internal-Error", 1139 "Internal-Error", 1140 "src-attribute_group.3", 1141 "e-props-correct.6", 1142 "mg-props-correct.2", 1143 "Internal-Error", 1144 "Internal-Error", 1145 "st-props-correct.2", }; 1147 1148 protected Object getGlobalDecl(XSDocumentInfo currSchema, 1166 int declType, 1167 QName declToTraverse, 1168 Element elmNode) { 1169 1170 if (DEBUG_NODE_POOL) { 1171 System.out.println("TRAVERSE_GL: "+declToTraverse.toString()); 1172 } 1173 if (declToTraverse.uri != null && 1179 declToTraverse.uri == SchemaSymbols.URI_SCHEMAFORSCHEMA) { 1180 if (declType == TYPEDECL_TYPE) { 1181 Object retObj = SchemaGrammar.SG_SchemaNS.getGlobalTypeDecl(declToTraverse.localpart); 1182 if (retObj != null) 1183 return retObj; 1184 } 1185 } 1186 1187 if (!currSchema.isAllowedNS(declToTraverse.uri)) { 1189 if (currSchema.needReportTNSError(declToTraverse.uri)) { 1191 String code = declToTraverse.uri == null ? "src-resolve.4.1" : "src-resolve.4.2"; 1192 reportSchemaError(code, new Object []{fDoc2SystemId.get(currSchema.fSchemaDoc), declToTraverse.uri, declToTraverse.rawname}, elmNode); 1193 } 1194 return null; 1195 } 1196 1197 SchemaGrammar sGrammar = fGrammarBucket.getGrammar(declToTraverse.uri); 1199 if (sGrammar == null) { 1200 if (needReportTNSError(declToTraverse.uri)) 1201 reportSchemaError("src-resolve", new Object []{declToTraverse.rawname, COMP_TYPE[declType]}, elmNode); 1202 return null; 1203 } 1204 1205 Object retObj = null; 1207 switch (declType) { 1208 case ATTRIBUTE_TYPE : 1209 retObj = sGrammar.getGlobalAttributeDecl(declToTraverse.localpart); 1210 break; 1211 case ATTRIBUTEGROUP_TYPE : 1212 retObj = sGrammar.getGlobalAttributeGroupDecl(declToTraverse.localpart); 1213 break; 1214 case ELEMENT_TYPE : 1215 retObj = sGrammar.getGlobalElementDecl(declToTraverse.localpart); 1216 break; 1217 case GROUP_TYPE : 1218 retObj = sGrammar.getGlobalGroupDecl(declToTraverse.localpart); 1219 break; 1220 case IDENTITYCONSTRAINT_TYPE : 1221 retObj = sGrammar.getIDConstraintDecl(declToTraverse.localpart); 1222 break; 1223 case NOTATION_TYPE : 1224 retObj = sGrammar.getGlobalNotationDecl(declToTraverse.localpart); 1225 break; 1226 case TYPEDECL_TYPE : 1227 retObj = sGrammar.getGlobalTypeDecl(declToTraverse.localpart); 1228 break; 1229 } 1230 1231 if (retObj != null) 1233 return retObj; 1234 1235 XSDocumentInfo schemaWithDecl = null; 1236 Element decl = null; 1237 1238 String declKey = declToTraverse.uri == null? ","+declToTraverse.localpart: 1240 declToTraverse.uri+","+declToTraverse.localpart; 1241 switch (declType) { 1242 case ATTRIBUTE_TYPE : 1243 decl = (Element )fUnparsedAttributeRegistry.get(declKey); 1244 break; 1245 case ATTRIBUTEGROUP_TYPE : 1246 decl = (Element )fUnparsedAttributeGroupRegistry.get(declKey); 1247 break; 1248 case ELEMENT_TYPE : 1249 decl = (Element )fUnparsedElementRegistry.get(declKey); 1250 break; 1251 case GROUP_TYPE : 1252 decl = (Element )fUnparsedGroupRegistry.get(declKey); 1253 break; 1254 case IDENTITYCONSTRAINT_TYPE : 1255 decl = (Element )fUnparsedIdentityConstraintRegistry.get(declKey); 1256 break; 1257 case NOTATION_TYPE : 1258 decl = (Element )fUnparsedNotationRegistry.get(declKey); 1259 break; 1260 case TYPEDECL_TYPE : 1261 decl = (Element )fUnparsedTypeRegistry.get(declKey); 1262 break; 1263 default: 1264 reportSchemaError("Internal-Error", new Object [] {"XSDHandler asked to locate component of type " + declType + "; it does not recognize this type!"}, elmNode); 1265 } 1266 1267 if (decl == null) { 1269 reportSchemaError("src-resolve", new Object []{declToTraverse.rawname, COMP_TYPE[declType]}, elmNode); 1270 return null; 1271 } 1272 1273 schemaWithDecl = findXSDocumentForDecl(currSchema, decl); 1277 if (schemaWithDecl == null) { 1278 String code = declToTraverse.uri == null ? "src-resolve.4.1" : "src-resolve.4.2"; 1280 reportSchemaError(code, new Object []{fDoc2SystemId.get(currSchema.fSchemaDoc), declToTraverse.uri, declToTraverse.rawname}, elmNode); 1281 return null; 1282 } 1283 if (DOMUtil.isHidden(decl)) { 1287 String code = CIRCULAR_CODES[declType]; 1288 if (declType == TYPEDECL_TYPE) { 1289 if (SchemaSymbols.ELT_COMPLEXTYPE.equals(DOMUtil.getLocalName(decl))) 1290 code = "ct-props-correct.3"; 1291 } 1292 reportSchemaError(code, new Object [] {declToTraverse.prefix+":"+declToTraverse.localpart}, elmNode); 1294 return null; 1295 } 1296 1297 DOMUtil.setHidden(decl); 1299 1300 SchemaNamespaceSupport nsSupport = null; 1301 Element parent = DOMUtil.getParent(decl); 1303 if (DOMUtil.getLocalName(parent).equals(SchemaSymbols.ELT_REDEFINE)) 1304 nsSupport = (SchemaNamespaceSupport)fRedefine2NSSupport.get(parent); 1305 schemaWithDecl.backupNSSupport(nsSupport); 1308 1309 switch (declType) { 1311 case ATTRIBUTE_TYPE : 1312 retObj = fAttributeTraverser.traverseGlobal(decl, schemaWithDecl, sGrammar); 1313 break; 1314 case ATTRIBUTEGROUP_TYPE : 1315 retObj = fAttributeGroupTraverser.traverseGlobal(decl, schemaWithDecl, sGrammar); 1316 break; 1317 case ELEMENT_TYPE : 1318 retObj = fElementTraverser.traverseGlobal(decl, schemaWithDecl, sGrammar); 1319 break; 1320 case GROUP_TYPE : 1321 retObj = fGroupTraverser.traverseGlobal(decl, schemaWithDecl, sGrammar); 1322 break; 1323 case IDENTITYCONSTRAINT_TYPE : 1324 retObj = null; 1327 break; 1328 case NOTATION_TYPE : 1329 retObj = fNotationTraverser.traverse(decl, schemaWithDecl, sGrammar); 1330 break; 1331 case TYPEDECL_TYPE : 1332 if (DOMUtil.getLocalName(decl).equals(SchemaSymbols.ELT_COMPLEXTYPE)) 1333 retObj = fComplexTypeTraverser.traverseGlobal(decl, schemaWithDecl, sGrammar); 1334 else 1335 retObj = fSimpleTypeTraverser.traverseGlobal(decl, schemaWithDecl, sGrammar); 1336 } 1337 1338 schemaWithDecl.restoreNSSupport(); 1341 1342 return retObj; 1343 } 1345 Object getGrpOrAttrGrpRedefinedByRestriction(int type, QName name, XSDocumentInfo currSchema, Element elmNode) { 1355 String realName = name.uri != null?name.uri+","+name.localpart: 1356 ","+name.localpart; 1357 String nameToFind = null; 1358 switch (type) { 1359 case ATTRIBUTEGROUP_TYPE: 1360 nameToFind = (String )fRedefinedRestrictedAttributeGroupRegistry.get(realName); 1361 break; 1362 case GROUP_TYPE: 1363 nameToFind = (String )fRedefinedRestrictedGroupRegistry.get(realName); 1364 break; 1365 default: 1366 return null; 1367 } 1368 if (nameToFind == null) return null; 1369 int commaPos = nameToFind.indexOf(","); 1370 QName qNameToFind = new QName(XMLSymbols.EMPTY_STRING, nameToFind.substring(commaPos+1), 1371 nameToFind.substring(commaPos), (commaPos == 0)? null : nameToFind.substring(0, commaPos)); 1372 Object retObj = getGlobalDecl(currSchema, type, qNameToFind, elmNode); 1373 if(retObj == null) { 1374 switch (type) { 1375 case ATTRIBUTEGROUP_TYPE: 1376 reportSchemaError("src-redefine.7.2.1", new Object []{name.localpart}, elmNode); 1377 break; 1378 case GROUP_TYPE: 1379 reportSchemaError("src-redefine.6.2.1", new Object []{name.localpart}, elmNode); 1380 break; 1381 } 1382 return null; 1383 } 1384 return retObj; 1385 } 1387 protected void resolveKeyRefs() { 1397 for (int i=0; i<fKeyrefStackPos; i++) { 1398 Document keyrefDoc = DOMUtil.getDocument(fKeyrefs[i]); 1399 XSDocumentInfo keyrefSchemaDoc = (XSDocumentInfo)fDoc2XSDocumentMap.get(keyrefDoc); 1400 keyrefSchemaDoc.fNamespaceSupport.makeGlobal(); 1401 keyrefSchemaDoc.fNamespaceSupport.setEffectiveContext( fKeyrefNamespaceContext[i] ); 1402 SchemaGrammar keyrefGrammar = fGrammarBucket.getGrammar(keyrefSchemaDoc.fTargetNamespace); 1403 DOMUtil.setHidden(fKeyrefs[i]); 1406 fKeyrefTraverser.traverse(fKeyrefs[i], fKeyrefElems[i], keyrefSchemaDoc, keyrefGrammar); 1407 } 1408 } 1410 protected Hashtable getIDRegistry() { 1413 return fUnparsedIdentityConstraintRegistry; 1414 } 1415 1416 protected void storeKeyRef (Element keyrefToStore, XSDocumentInfo schemaDoc, 1419 XSElementDecl currElemDecl) { 1420 String keyrefName = DOMUtil.getAttrValue(keyrefToStore, SchemaSymbols.ATT_NAME); 1421 if (keyrefName.length() != 0) { 1422 String keyrefQName = schemaDoc.fTargetNamespace == null? 1423 "," + keyrefName: schemaDoc.fTargetNamespace+","+keyrefName; 1424 checkForDuplicateNames(keyrefQName, fUnparsedIdentityConstraintRegistry, keyrefToStore, schemaDoc); 1425 } 1426 1428 if (fKeyrefStackPos == fKeyrefs.length) { 1430 Element [] elemArray = new Element [fKeyrefStackPos + INC_KEYREF_STACK_AMOUNT]; 1431 System.arraycopy(fKeyrefs, 0, elemArray, 0, fKeyrefStackPos); 1432 fKeyrefs = elemArray; 1433 XSElementDecl [] declArray = new XSElementDecl [fKeyrefStackPos + INC_KEYREF_STACK_AMOUNT]; 1434 System.arraycopy(fKeyrefElems, 0, declArray, 0, fKeyrefStackPos); 1435 fKeyrefElems = declArray; 1436 String [][] stringArray = new String [fKeyrefStackPos + INC_KEYREF_STACK_AMOUNT][]; 1437 System.arraycopy(fKeyrefNamespaceContext, 0, stringArray, 0, fKeyrefStackPos); 1438 fKeyrefNamespaceContext = stringArray; 1439 } 1440 fKeyrefs[fKeyrefStackPos] = keyrefToStore; 1441 fKeyrefElems[fKeyrefStackPos] = currElemDecl; 1442 fKeyrefNamespaceContext[fKeyrefStackPos++] = schemaDoc.fNamespaceSupport.getEffectiveLocalContext(); 1443 } 1445 1446 1454 private Document resolveSchema(XSDDescription desc, 1455 boolean mustResolve, Element referElement) { 1456 XMLInputSource schemaSource=null; 1457 try { 1458 schemaSource = XMLSchemaLoader.resolveDocument(desc, fLocationPairs, fEntityResolver); 1459 } 1460 catch (IOException ex) { 1461 if (mustResolve) { 1462 reportSchemaError("schema_reference.4", 1463 new Object []{desc.getLocationHints()[0]}, 1464 referElement); 1465 } 1466 else { 1467 reportSchemaWarning("schema_reference.4", 1468 new Object []{desc.getLocationHints()[0]}, 1469 referElement); 1470 } 1471 } 1472 return getSchema(desc.getTargetNamespace(), 1473 schemaSource.toSource(), mustResolve, desc.getContextType(), referElement); 1474 } 1476 1485 private Document getSchema(String schemaNamespace, Source schemaSource, 1486 boolean mustResolve, short referType, Element referElement) { 1487 1488 boolean hasInput = true; 1489 Document schemaDoc = null; 1491 try { 1492 if (schemaSource != null ) { 1499 1500 XSDKey key = null; 1505 String schemaId = null; 1506 if (referType != XSDDescription.CONTEXT_PREPARSE){ 1507 schemaId = schemaSource.getSystemId(); 1508 key = new XSDKey(schemaId, referType, schemaNamespace); 1509 if ((schemaDoc = (Document )fTraversed.get(key)) != null) { 1510 fLastSchemaWasDuplicate = true; 1511 return schemaDoc; 1512 } 1513 } 1514 if( schemaSource instanceof XMLInputSourceAdaptor ) { 1515 fSchemaParser.parse(((XMLInputSourceAdaptor)schemaSource).fSource); 1518 schemaDoc = fSchemaParser.getDocument(); 1519 } else 1520 if( schemaSource instanceof DOMSource ) { 1521 try { 1529 Transformer t = TransformerFactory.newInstance().newTransformer(); 1530 SchemaDOMParser p = new SchemaDOMParser(fErrorReporter); 1531 t.transform( schemaSource, new SAXResult (new SAX2XNI(p)) ); 1532 schemaDoc = p.getDocument(); 1533 } catch( TransformerException e ) { 1534 e.printStackTrace(); 1536 throw new InternalError (); 1537 } 1538 } else 1539 if( schemaSource instanceof StreamSource ) { 1540 fSchemaParser.parse(new XMLInputSource((StreamSource )schemaSource)); 1541 schemaDoc = fSchemaParser.getDocument(); 1542 } else 1543 if( schemaSource instanceof SAXSource ) { 1544 SAXSource ss = (SAXSource )schemaSource; 1545 XMLReader reader = ss.getXMLReader(); 1546 if(reader==null) { 1547 reader = new SAXParser(); 1548 try { 1549 reader.setFeature("http://xml.org/sax/features/namespaces",true); 1550 reader.setFeature("http://xml.org/sax/features/namespace-prefixes",true); 1551 } catch( SAXException e ) { 1552 e.printStackTrace(); 1554 throw new InternalError (); 1555 } 1556 } 1557 SchemaDOMParser p = new SchemaDOMParser(fErrorReporter); 1558 reader.setContentHandler(new SAX2XNI(p)); 1559 reader.setErrorHandler(fErrorReporter.getSAXErrorHandler()); 1560 try { 1561 reader.parse(ss.getInputSource()); 1562 schemaDoc = p.getDocument(); 1563 } catch( SAXException e ) { 1564 ; } 1566 } else { 1567 throw new IllegalArgumentException (schemaSource.getClass().getName()); 1568 } 1569 1570 if (key != null) 1573 fTraversed.put(key, schemaDoc ); 1574 if (schemaId != null) 1575 fDoc2SystemId.put(schemaDoc, schemaId ); 1576 fLastSchemaWasDuplicate = false; 1577 return schemaDoc; 1578 } 1579 else { 1580 hasInput = false; 1581 } 1582 } 1583 catch (IOException ex) { 1584 } 1585 1586 if (mustResolve) { 1589 if (hasInput) { 1590 reportSchemaError("schema_reference.4", 1591 new Object []{schemaSource.getSystemId()}, 1592 referElement); 1593 } 1594 else { 1595 reportSchemaError("schema_reference.4", 1596 new Object []{schemaSource == null ? "" : schemaSource.getSystemId()}, 1597 referElement); 1598 } 1599 } 1600 1601 fLastSchemaWasDuplicate = false; 1602 return null; 1603 } 1605 1609 private void createTraversers() { 1611 fAttributeChecker = new XSAttributeChecker(this); 1612 fAttributeGroupTraverser = new XSDAttributeGroupTraverser(this, fAttributeChecker); 1613 fAttributeTraverser = new XSDAttributeTraverser(this, fAttributeChecker); 1614 fComplexTypeTraverser = new XSDComplexTypeTraverser(this, fAttributeChecker); 1615 fElementTraverser = new XSDElementTraverser(this, fAttributeChecker); 1616 fGroupTraverser = new XSDGroupTraverser(this, fAttributeChecker); 1617 fKeyrefTraverser = new XSDKeyrefTraverser(this, fAttributeChecker); 1618 fNotationTraverser = new XSDNotationTraverser(this, fAttributeChecker); 1619 fSimpleTypeTraverser = new XSDSimpleTypeTraverser(this, fAttributeChecker); 1620 fUniqueOrKeyTraverser = new XSDUniqueOrKeyTraverser(this, fAttributeChecker); 1621 fWildCardTraverser = new XSDWildcardTraverser(this, fAttributeChecker); 1622 } 1624 void prepareForParse() { 1627 fTraversed.clear(); 1628 fDoc2SystemId.clear(); 1629 fLastSchemaWasDuplicate = false; 1630 } 1631 1632 void prepareForTraverse() { 1635 fUnparsedAttributeRegistry.clear(); 1636 fUnparsedAttributeGroupRegistry.clear(); 1637 fUnparsedElementRegistry.clear(); 1638 fUnparsedGroupRegistry.clear(); 1639 fUnparsedIdentityConstraintRegistry.clear(); 1640 fUnparsedNotationRegistry.clear(); 1641 fUnparsedTypeRegistry.clear(); 1642 1643 fXSDocumentInfoRegistry.clear(); 1644 fDependencyMap.clear(); 1645 fDoc2XSDocumentMap.clear(); 1646 fRedefine2XSDMap.clear(); 1647 fRedefine2NSSupport.clear(); 1648 fAllTNSs.removeAllElements(); 1649 fImportMap.clear(); 1650 fRoot = null; 1651 1652 for (int i = 0; i < fLocalElemStackPos; i++) { 1654 fParticle[i] = null; 1655 fLocalElementDecl[i] = null; 1656 fLocalElemNamespaceContext[i] = null; 1657 } 1658 fLocalElemStackPos = 0; 1659 1660 for (int i = 0; i < fKeyrefStackPos; i++) { 1662 fKeyrefs[i] = null; 1663 fKeyrefElems[i] = null; 1664 fKeyrefNamespaceContext[i] = null; 1665 } 1666 fKeyrefStackPos = 0; 1667 1668 if (fAttributeChecker == null) { 1670 createTraversers(); 1671 } 1672 1673 fAttributeChecker.reset(fSymbolTable); 1675 fAttributeGroupTraverser.reset(fSymbolTable); 1676 fAttributeTraverser.reset(fSymbolTable); 1677 fComplexTypeTraverser.reset(fSymbolTable); 1678 fElementTraverser.reset(fSymbolTable); 1679 fGroupTraverser.reset(fSymbolTable); 1680 fKeyrefTraverser.reset(fSymbolTable); 1681 fNotationTraverser.reset(fSymbolTable); 1682 fSimpleTypeTraverser.reset(fSymbolTable); 1683 fUniqueOrKeyTraverser.reset(fSymbolTable); 1684 fWildCardTraverser.reset(fSymbolTable); 1685 1686 fRedefinedRestrictedAttributeGroupRegistry.clear(); 1687 fRedefinedRestrictedGroupRegistry.clear(); 1688 } 1689 public void setDeclPool (XSDeclarationPool declPool){ 1690 fDeclPool = declPool; 1691 } 1692 1693 public void reset(XMLComponentManager componentManager) { 1694 1695 fSymbolTable = (SymbolTable) componentManager.getProperty(SYMBOL_TABLE); 1697 1698 fSecureProcessing = null; 1699 if( componentManager!=null ) { 1700 try { 1701 fSecureProcessing = (SecurityManager ) componentManager.getProperty(SECURE_PROCESSING); 1702 } catch (XMLConfigurationException xmlConfigurationException) { 1703 ; 1704 } 1705 } 1706 1707 fEntityResolver = (XMLEntityResolver) componentManager.getProperty(ENTITY_MANAGER); 1709 XMLEntityResolver er = (XMLEntityResolver)componentManager.getProperty(ENTITY_RESOLVER); 1710 if (er != null) 1711 fSchemaParser.setEntityResolver(er); 1712 1713 fErrorReporter = 1715 (XMLErrorReporter) componentManager.getProperty(ERROR_REPORTER); 1716 try { 1717 XMLErrorHandler currErrorHandler = fErrorReporter.getErrorHandler(); 1718 if (currErrorHandler != fSchemaParser.getProperty(ERROR_HANDLER)) { 1722 fSchemaParser.setProperty(ERROR_HANDLER, currErrorHandler); 1723 } 1724 } catch (XMLConfigurationException e) { 1725 } 1726 1727 try { 1728 fSchemaParser.setFeature( 1729 CONTINUE_AFTER_FATAL_ERROR, 1730 fErrorReporter.getFeature(CONTINUE_AFTER_FATAL_ERROR)); 1731 } catch (XMLConfigurationException e) { 1732 } 1733 1734 try { 1735 fSchemaParser.setFeature( 1736 ALLOW_JAVA_ENCODINGS, 1737 componentManager.getFeature(ALLOW_JAVA_ENCODINGS)); 1738 } catch (XMLConfigurationException e) { 1739 } 1740 try { 1741 fSchemaParser.setFeature( 1742 STANDARD_URI_CONFORMANT_FEATURE, 1743 componentManager.getFeature(STANDARD_URI_CONFORMANT_FEATURE)); 1744 } catch (XMLConfigurationException e) { 1745 } 1746 1747 try { 1748 fGrammarPool = 1749 (XMLGrammarPool) componentManager.getProperty(XMLGRAMMAR_POOL); 1750 } catch (XMLConfigurationException e) { 1751 fGrammarPool = null; 1752 } 1753 try { 1755 fSchemaParser.setFeature( DISALLOW_DOCTYPE, 1756 componentManager.getFeature(DISALLOW_DOCTYPE)); 1757 } catch (XMLConfigurationException e) { 1758 } 1759 try { 1760 Object security = componentManager.getProperty(SECURITY_MANAGER); 1761 if (security != null){ 1762 fSchemaParser.setProperty(SECURITY_MANAGER, security); 1763 } 1764 } catch (XMLConfigurationException e) { 1765 } 1766 1767 } 1769 1770 1774 void traverseLocalElements() { 1775 fElementTraverser.fDeferTraversingLocalElements = false; 1776 1777 for (int i = 0; i < fLocalElemStackPos; i++) { 1778 Element currElem = fLocalElementDecl[i]; 1779 XSDocumentInfo currSchema = (XSDocumentInfo)fDoc2XSDocumentMap.get(DOMUtil.getDocument(currElem)); 1780 SchemaGrammar currGrammar = fGrammarBucket.getGrammar(currSchema.fTargetNamespace); 1781 fElementTraverser.traverseLocal (fParticle[i], currElem, currSchema, currGrammar, fAllContext[i], fParent[i]); 1782 if (fParticle[i].fType == XSParticleDecl.PARTICLE_EMPTY) { 1784 XSModelGroupImpl group; 1785 if (fParent[i] instanceof XSComplexTypeDecl) 1786 group = (XSModelGroupImpl)((XSComplexTypeDecl)fParent[i]).getParticle().getTerm(); 1787 else 1788 group = ((XSGroupDecl)fParent[i]).fModelGroup; 1789 removeParticle(group, fParticle[i]); 1790 } 1791 } 1792 } 1793 1794 private boolean removeParticle(XSModelGroupImpl group, XSParticleDecl particle) { 1795 XSParticleDecl member; 1796 for (int i = 0; i < group.fParticleCount; i++) { 1797 member = group.fParticles[i]; 1798 if (member == particle) { 1799 for (int j = i; j < group.fParticleCount-1; j++) 1800 group.fParticles[j] = group.fParticles[j+1]; 1801 group.fParticleCount--; 1802 return true; 1803 } 1804 if (member.fType == XSParticleDecl.PARTICLE_MODELGROUP) { 1805 if (removeParticle((XSModelGroupImpl)member.fValue, particle)) 1806 return true; 1807 } 1808 } 1809 return false; 1810 } 1811 1812 void fillInLocalElemInfo(Element elmDecl, 1815 XSDocumentInfo schemaDoc, 1816 int allContextFlags, 1817 XSObject parent, 1818 XSParticleDecl particle) { 1819 1820 if (fParticle.length == fLocalElemStackPos) { 1822 XSParticleDecl[] newStackP = new XSParticleDecl[fLocalElemStackPos+INC_STACK_SIZE]; 1824 System.arraycopy(fParticle, 0, newStackP, 0, fLocalElemStackPos); 1825 fParticle = newStackP; 1826 Element [] newStackE = new Element [fLocalElemStackPos+INC_STACK_SIZE]; 1827 System.arraycopy(fLocalElementDecl, 0, newStackE, 0, fLocalElemStackPos); 1828 fLocalElementDecl = newStackE; 1829 int[] newStackI = new int[fLocalElemStackPos+INC_STACK_SIZE]; 1830 System.arraycopy(fAllContext, 0, newStackI, 0, fLocalElemStackPos); 1831 fAllContext = newStackI; 1832 XSObject[] newStackC = new XSObject[fLocalElemStackPos+INC_STACK_SIZE]; 1833 System.arraycopy(fParent, 0, newStackC, 0, fLocalElemStackPos); 1834 fParent = newStackC; 1835 String [][] newStackN = new String [fLocalElemStackPos+INC_STACK_SIZE][]; 1836 System.arraycopy(fLocalElemNamespaceContext, 0, newStackN, 0, fLocalElemStackPos); 1837 fLocalElemNamespaceContext = newStackN; 1838 } 1839 1840 fParticle[fLocalElemStackPos] = particle; 1841 fLocalElementDecl[fLocalElemStackPos] = elmDecl; 1842 fAllContext[fLocalElemStackPos] = allContextFlags; 1843 fParent[fLocalElemStackPos] = parent; 1844 fLocalElemNamespaceContext[fLocalElemStackPos++] = schemaDoc.fNamespaceSupport.getEffectiveLocalContext(); 1845 } 1847 1855 void checkForDuplicateNames(String qName, 1856 Hashtable registry, Element currComp, 1857 XSDocumentInfo currSchema) { 1858 Object objElem = null; 1859 if ((objElem = registry.get(qName)) == null) { 1862 registry.put(qName, currComp); 1864 } 1865 else { 1866 Element collidingElem = (Element )objElem; 1867 if (collidingElem == currComp) return; 1868 Element elemParent = null; 1869 XSDocumentInfo redefinedSchema = null; 1870 boolean collidedWithRedefine = true; 1873 if ((DOMUtil.getLocalName((elemParent = DOMUtil.getParent(collidingElem))).equals(SchemaSymbols.ELT_REDEFINE))) { 1874 redefinedSchema = (XSDocumentInfo)(fRedefine2XSDMap.get(elemParent)); 1875 } 1877 else if ((DOMUtil.getLocalName(DOMUtil.getParent(currComp)).equals(SchemaSymbols.ELT_REDEFINE))) { 1878 redefinedSchema = (XSDocumentInfo)(fDoc2XSDocumentMap.get(DOMUtil.getDocument(collidingElem))); 1879 collidedWithRedefine = false; 1880 } 1881 if (redefinedSchema != null) { if (fDoc2XSDocumentMap.get(DOMUtil.getDocument(collidingElem)) == currSchema) { 1885 reportSchemaError("sch-props-correct.2", new Object []{qName}, currComp); 1886 return; 1887 } 1888 1889 String newName = qName.substring(qName.lastIndexOf(',')+1)+REDEF_IDENTIFIER; 1890 if (redefinedSchema == currSchema) { currComp.setAttribute(SchemaSymbols.ATT_NAME, newName); 1893 if (currSchema.fTargetNamespace == null) 1894 registry.put(","+newName, currComp); 1895 else 1896 registry.put(currSchema.fTargetNamespace+","+newName, currComp); 1897 if (currSchema.fTargetNamespace == null) 1899 checkForDuplicateNames(","+newName, registry, currComp, currSchema); 1900 else 1901 checkForDuplicateNames(currSchema.fTargetNamespace+","+newName, registry, currComp, currSchema); 1902 } 1903 else { if (collidedWithRedefine) { 1905 if (currSchema.fTargetNamespace == null) 1906 checkForDuplicateNames(","+newName, registry, currComp, currSchema); 1907 else 1908 checkForDuplicateNames(currSchema.fTargetNamespace+","+newName, registry, currComp, currSchema); 1909 } 1910 else { 1911 reportSchemaError("sch-props-correct.2", new Object [] {qName}, currComp); 1913 } 1914 } 1915 } 1916 else { 1917 reportSchemaError("sch-props-correct.2", new Object []{qName}, currComp); 1919 } 1920 } 1921 } 1923 private void renameRedefiningComponents(XSDocumentInfo currSchema, 1930 Element child, String componentType, 1931 String oldName, String newName) { 1932 if (componentType.equals(SchemaSymbols.ELT_SIMPLETYPE)) { 1933 Element grandKid = DOMUtil.getFirstChildElement(child); 1934 if (grandKid == null) { 1935 reportSchemaError("src-redefine.5.a.a", null, child); 1936 } 1937 else { 1938 String grandKidName = DOMUtil.getLocalName(grandKid); 1939 if (grandKidName.equals(SchemaSymbols.ELT_ANNOTATION)) { 1940 grandKid = DOMUtil.getNextSiblingElement(grandKid); 1941 } 1942 if (grandKid == null) { 1943 reportSchemaError("src-redefine.5.a.a", null, child); 1944 } 1945 else { 1946 grandKidName = DOMUtil.getLocalName(grandKid); 1947 if (!grandKidName.equals(SchemaSymbols.ELT_RESTRICTION)) { 1948 reportSchemaError("src-redefine.5.a.b", new Object []{grandKidName}, child); 1949 } 1950 else { 1951 Object [] attrs = fAttributeChecker.checkAttributes(grandKid, false, currSchema); 1952 QName derivedBase = (QName)attrs[XSAttributeChecker.ATTIDX_BASE]; 1953 if (derivedBase == null || 1954 derivedBase.uri != currSchema.fTargetNamespace || 1955 !derivedBase.localpart.equals(oldName)) { 1956 reportSchemaError("src-redefine.5.a.c", 1957 new Object []{grandKidName, 1958 (currSchema.fTargetNamespace==null?"":currSchema.fTargetNamespace) 1959 + "," + oldName}, 1960 child); 1961 } 1962 else { 1963 if (derivedBase.prefix != null && derivedBase.prefix.length() > 0) 1965 grandKid.setAttribute( SchemaSymbols.ATT_BASE, 1966 derivedBase.prefix + ":" + newName ); 1967 else 1968 grandKid.setAttribute( SchemaSymbols.ATT_BASE, newName ); 1969 } 1971 fAttributeChecker.returnAttrArray(attrs, currSchema); 1972 } 1973 } 1974 } 1975 } 1976 else if (componentType.equals(SchemaSymbols.ELT_COMPLEXTYPE)) { 1977 Element grandKid = DOMUtil.getFirstChildElement(child); 1978 if (grandKid == null) { 1979 reportSchemaError("src-redefine.5.b.a", null, child); 1980 } 1981 else { 1982 if (DOMUtil.getLocalName(grandKid).equals(SchemaSymbols.ELT_ANNOTATION)) { 1983 grandKid = DOMUtil.getNextSiblingElement(grandKid); 1984 } 1985 if (grandKid == null) { 1986 reportSchemaError("src-redefine.5.b.a", null, child); 1987 } 1988 else { 1989 Element greatGrandKid = DOMUtil.getFirstChildElement(grandKid); 1991 if (greatGrandKid == null) { 1992 reportSchemaError("src-redefine.5.b.b", null, grandKid); 1993 } 1994 else { 1995 String greatGrandKidName = DOMUtil.getLocalName(greatGrandKid); 1996 if (greatGrandKidName.equals(SchemaSymbols.ELT_ANNOTATION)) { 1997 greatGrandKid = DOMUtil.getNextSiblingElement(greatGrandKid); 1998 } 1999 if (greatGrandKid == null) { 2000 reportSchemaError("src-redefine.5.b.b", null, grandKid); 2001 } 2002 else { 2003 greatGrandKidName = DOMUtil.getLocalName(greatGrandKid); 2004 if (!greatGrandKidName.equals(SchemaSymbols.ELT_RESTRICTION) && 2005 !greatGrandKidName.equals(SchemaSymbols.ELT_EXTENSION)) { 2006 reportSchemaError("src-redefine.5.b.c", new Object []{greatGrandKidName}, greatGrandKid); 2007 } 2008 else { 2009 Object [] attrs = fAttributeChecker.checkAttributes(greatGrandKid, false, currSchema); 2010 QName derivedBase = (QName)attrs[XSAttributeChecker.ATTIDX_BASE]; 2011 if (derivedBase == null || 2012 derivedBase.uri != currSchema.fTargetNamespace || 2013 !derivedBase.localpart.equals(oldName)) { 2014 reportSchemaError("src-redefine.5.b.d", 2015 new Object []{greatGrandKidName, 2016 (currSchema.fTargetNamespace==null?"":currSchema.fTargetNamespace) 2017 + "," + oldName}, 2018 greatGrandKid); 2019 } 2020 else { 2021 if (derivedBase.prefix != null && derivedBase.prefix.length() > 0) 2023 greatGrandKid.setAttribute( SchemaSymbols.ATT_BASE, 2024 derivedBase.prefix + ":" + newName ); 2025 else 2026 greatGrandKid.setAttribute( SchemaSymbols.ATT_BASE, 2027 newName ); 2028 } 2030 } 2031 } 2032 } 2033 } 2034 } 2035 } 2036 else if (componentType.equals(SchemaSymbols.ELT_ATTRIBUTEGROUP)) { 2037 String processedBaseName = (currSchema.fTargetNamespace == null)? 2038 ","+oldName:currSchema.fTargetNamespace+","+oldName; 2039 int attGroupRefsCount = changeRedefineGroup(processedBaseName, componentType, newName, child, currSchema); 2040 if (attGroupRefsCount > 1) { 2041 reportSchemaError("src-redefine.7.1", new Object []{new Integer (attGroupRefsCount)}, child); 2042 } 2043 else if (attGroupRefsCount == 1) { 2044 } 2046 else 2047 if (currSchema.fTargetNamespace == null) 2048 fRedefinedRestrictedAttributeGroupRegistry.put(processedBaseName, ","+newName); 2049 else 2050 fRedefinedRestrictedAttributeGroupRegistry.put(processedBaseName, currSchema.fTargetNamespace+","+newName); 2051 } 2052 else if (componentType.equals(SchemaSymbols.ELT_GROUP)) { 2053 String processedBaseName = (currSchema.fTargetNamespace == null)? 2054 ","+oldName:currSchema.fTargetNamespace+","+oldName; 2055 int groupRefsCount = changeRedefineGroup(processedBaseName, componentType, newName, child, currSchema); 2056 if (groupRefsCount > 1) { 2057 reportSchemaError("src-redefine.6.1.1", new Object []{new Integer (groupRefsCount)}, child); 2058 } 2059 else if (groupRefsCount == 1) { 2060 } 2062 else { 2063 if (currSchema.fTargetNamespace == null) 2064 fRedefinedRestrictedGroupRegistry.put(processedBaseName, ","+newName); 2065 else 2066 fRedefinedRestrictedGroupRegistry.put(processedBaseName, currSchema.fTargetNamespace+","+newName); 2067 } 2068 } 2069 else { 2070 reportSchemaError("Internal-Error", new Object [] {"could not handle this particular <redefine>; please submit your schemas and instance document in a bug report!"}, child); 2071 } 2072 } 2076 private String findQName(String name, XSDocumentInfo schemaDoc) { 2088 SchemaNamespaceSupport currNSMap = schemaDoc.fNamespaceSupport; 2089 int colonPtr = name.indexOf(':'); 2090 String prefix = XMLSymbols.EMPTY_STRING; 2091 if (colonPtr > 0) 2092 prefix = name.substring(0, colonPtr); 2093 String uri = currNSMap.getURI(fSymbolTable.addSymbol(prefix)); 2094 String localpart = (colonPtr == 0)?name:name.substring(colonPtr+1); 2095 if (prefix == XMLSymbols.EMPTY_STRING && uri == null && schemaDoc.fIsChameleonSchema) 2096 uri = schemaDoc.fTargetNamespace; 2097 if (uri == null) 2098 return ","+localpart; 2099 return uri+","+localpart; 2100 } 2102 private int changeRedefineGroup(String originalQName, String elementSought, 2110 String newName, Element curr, XSDocumentInfo schemaDoc) { 2111 int result = 0; 2112 for (Element child = DOMUtil.getFirstChildElement(curr); 2113 child != null; child = DOMUtil.getNextSiblingElement(child)) { 2114 String name = DOMUtil.getLocalName(child); 2115 if (!name.equals(elementSought)) 2116 result += changeRedefineGroup(originalQName, elementSought, newName, child, schemaDoc); 2117 else { 2118 String ref = child.getAttribute( SchemaSymbols.ATT_REF ); 2119 if (ref.length() != 0) { 2120 String processedRef = findQName(ref, schemaDoc); 2121 if (originalQName.equals(processedRef)) { 2122 String prefix = XMLSymbols.EMPTY_STRING; 2123 int colonptr = ref.indexOf(":"); 2124 if (colonptr > 0) { 2125 prefix = ref.substring(0,colonptr); 2126 child.setAttribute(SchemaSymbols.ATT_REF, prefix + ":" + newName); 2127 } 2128 else 2129 child.setAttribute(SchemaSymbols.ATT_REF, newName); 2130 result++; 2131 if (elementSought.equals(SchemaSymbols.ELT_GROUP)) { 2132 String minOccurs = child.getAttribute( SchemaSymbols.ATT_MINOCCURS ); 2133 String maxOccurs = child.getAttribute( SchemaSymbols.ATT_MAXOCCURS ); 2134 if (!((maxOccurs.length() == 0 || maxOccurs.equals("1")) 2135 && (minOccurs.length() == 0 || minOccurs.equals("1")))) { 2136 reportSchemaError("src-redefine.6.1.2", new Object [] {ref}, child); 2137 } 2138 } 2139 } 2140 } } 2142 } 2143 return result; 2144 } 2146 private XSDocumentInfo findXSDocumentForDecl(XSDocumentInfo currSchema, 2154 Element decl) { 2155 2156 if (DEBUG_NODE_POOL) { 2157 System.out.println("DOCUMENT NS:"+ currSchema.fTargetNamespace+" hashcode:"+ ((Object )currSchema.fSchemaDoc).hashCode()); 2158 } 2159 Document declDoc = DOMUtil.getDocument(decl); 2160 Object temp = fDoc2XSDocumentMap.get(declDoc); 2161 if (temp == null) { 2162 return null; 2164 } 2165 XSDocumentInfo declDocInfo = (XSDocumentInfo)temp; 2166 return declDocInfo; 2167 2180 } 2182 private boolean nonAnnotationContent(Element elem) { 2184 for(Element child = DOMUtil.getFirstChildElement(elem); child != null; child = DOMUtil.getNextSiblingElement(child)) { 2185 if(!(DOMUtil.getLocalName(child).equals(SchemaSymbols.ELT_ANNOTATION))) return true; 2186 } 2187 return false; 2188 } 2190 private void setSchemasVisible(XSDocumentInfo startSchema) { 2191 if (DOMUtil.isHidden(startSchema.fSchemaDoc)) { 2192 DOMUtil.setVisible(startSchema.fSchemaDoc); 2194 Vector dependingSchemas = (Vector )fDependencyMap.get(startSchema); 2195 for (int i = 0; i < dependingSchemas.size(); i++) { 2196 setSchemasVisible((XSDocumentInfo)dependingSchemas.elementAt(i)); 2197 } 2198 } 2199 } 2202 private SimpleLocator xl = new SimpleLocator(); 2203 2204 2209 public SimpleLocator element2Locator(Element e) { 2210 if (!( e instanceof ElementImpl)) 2211 return null; 2212 2213 SimpleLocator l = new SimpleLocator(); 2214 return element2Locator(e, l) ? l : null; 2215 } 2216 2217 2222 public boolean element2Locator(Element e, SimpleLocator l) { 2223 if (l == null) 2224 return false; 2225 if (e instanceof ElementImpl) { 2226 ElementImpl ele = (ElementImpl)e; 2227 Document doc = ele.getOwnerDocument(); 2229 String sid = (String )fDoc2SystemId.get(doc); 2230 int line = ele.getLineNumber(); 2232 int column = ele.getColumnNumber(); 2233 l.setValues(sid, sid, line, column); 2234 return true; 2235 } 2236 return false; 2237 } 2238 2239 void reportSchemaError(String key, Object [] args, Element ele) { 2240 if (element2Locator(ele, xl)) { 2241 fErrorReporter.reportError(xl, XSMessageFormatter.SCHEMA_DOMAIN, 2242 key, args, XMLErrorReporter.SEVERITY_ERROR); 2243 } 2244 else { 2245 fErrorReporter.reportError(XSMessageFormatter.SCHEMA_DOMAIN, 2246 key, args, XMLErrorReporter.SEVERITY_ERROR); 2247 } 2248 } 2249 2250 void reportSchemaWarning(String key, Object [] args, Element ele) { 2251 if (element2Locator(ele, xl)) { 2252 fErrorReporter.reportError(xl, XSMessageFormatter.SCHEMA_DOMAIN, 2253 key, args, XMLErrorReporter.SEVERITY_WARNING); 2254 } 2255 else { 2256 fErrorReporter.reportError(XSMessageFormatter.SCHEMA_DOMAIN, 2257 key, args, XMLErrorReporter.SEVERITY_WARNING); 2258 } 2259 } 2260 2261 2298 private static class XSDKey { 2299 String systemId; 2300 short referType; 2301 String referNS; 2304 2305 XSDKey(String systemId, short referType, String referNS) { 2306 this.systemId = systemId; 2307 this.referType = referType; 2308 this.referNS = referNS; 2309 } 2310 2311 public int hashCode() { 2312 return referNS == null ? 0 : referNS.hashCode(); 2315 } 2316 2317 public boolean equals(Object obj) { 2318 if (!(obj instanceof XSDKey)) { 2319 return false; 2320 } 2321 XSDKey key = (XSDKey)obj; 2322 2323 if (referType == XSDDescription.CONTEXT_REDEFINE || 2325 key.referType == XSDDescription.CONTEXT_REDEFINE) { 2326 if (referType != key.referType) 2327 return false; 2328 } 2329 2330 if (referNS != key.referNS) 2332 return false; 2333 2334 if (systemId == null || !systemId.equals(key.systemId)) { 2336 return false; 2337 } 2338 2339 return true; 2340 } 2341 } 2342 2343} | Popular Tags |