85 import com.sun.org.apache.xerces.internal.xs.XSModelGroup;
86 import com.sun.org.apache.xerces.internal.xs.XSModelGroupDefinition;
87 import com.sun.org.apache.xerces.internal.xs.XSNamedMap;
88 import com.sun.org.apache.xerces.internal.xs.XSObject;
89 import com.sun.org.apache.xerces.internal.xs.XSObjectList;
90 import com.sun.org.apache.xerces.internal.xs.XSParticle;
91 import com.sun.org.apache.xerces.internal.xs.XSSimpleTypeDefinition;
92 import com.sun.org.apache.xerces.internal.xs.XSTerm;
93 import com.sun.org.apache.xerces.internal.xs.XSTypeDefinition;
94 import com.sun.org.apache.xerces.internal.xs.datatypes.ObjectList;
95 import java.io.IOException;
96 import java.io.StringReader;
97 import java.util.ArrayList;
98 import java.util.Collections;
99 import java.util.HashMap;
100 import java.util.Locale;
101 import java.util.Map;
102 import java.util.Stack;
103 import java.util.Vector;
104 import javax.xml.XMLConstants;
105 import javax.xml.stream.XMLEventReader;
106 import javax.xml.stream.XMLStreamException;
107 import javax.xml.stream.XMLStreamReader;
108 import org.w3c.dom.Document;
109 import org.w3c.dom.Element;
110 import org.w3c.dom.Node;
111 import org.xml.sax.InputSource;
112 import org.xml.sax.SAXException;
113 import org.xml.sax.SAXNotRecognizedException;
114 import org.xml.sax.SAXParseException;
115 import org.xml.sax.XMLReader;
116 import org.xml.sax.helpers.XMLReaderFactory;
117
118 /**
119 * The purpose of this class is to co-ordinate the construction of a
120 * grammar object corresponding to a schema. To do this, it must be
121 * prepared to parse several schema documents (for instance if the
122 * schema document originally referred to contains <include> or
123 * <redefined> information items). If any of the schemas imports a
124 * schema, other grammars may be constructed as a side-effect.
125 *
126 * @xerces.internal
127 *
374
375 //handle multiple import feature
376 private boolean fHonourAllSchemaLocations = false;
377
378 //handle namespace growth feature
379 boolean fNamespaceGrowth = false;
380
381 // handle tolerate duplicates feature
382 boolean fTolerateDuplicates = false;
383
384 // the XMLErrorReporter
385 private XMLErrorReporter fErrorReporter;
386
387 // the XMLErrorHandler
388 private XMLErrorHandler fErrorHandler;
389
390 // the Locale
391 private Locale fLocale;
392
393 // the XMLEntityManager
394 private XMLEntityResolver fEntityManager;
395
396 // the XSAttributeChecker
397 private XSAttributeChecker fAttributeChecker;
398
399 // the symbol table
400 private SymbolTable fSymbolTable;
401
402 // the GrammarResolver
403 private XSGrammarBucket fGrammarBucket;
404
405 // the Grammar description
406 private XSDDescription fSchemaGrammarDescription;
407
408 // the Grammar Pool
409 private XMLGrammarPool fGrammarPool;
410
411 // the security property manager
412 private XMLSecurityPropertyManager fSecurityPropertyMgr = null;
413
414 //************ Traversers **********
415 XSDAttributeGroupTraverser fAttributeGroupTraverser;
416 XSDAttributeTraverser fAttributeTraverser;
417 XSDComplexTypeTraverser fComplexTypeTraverser;
418 XSDElementTraverser fElementTraverser;
419 XSDGroupTraverser fGroupTraverser;
420 XSDKeyrefTraverser fKeyrefTraverser;
421 XSDNotationTraverser fNotationTraverser;
422 XSDSimpleTypeTraverser fSimpleTypeTraverser;
423 XSDUniqueOrKeyTraverser fUniqueOrKeyTraverser;
424 XSDWildcardTraverser fWildCardTraverser;
425
426 SchemaDVFactory fDVFactory;
427 SchemaDOMParser fSchemaParser;
428 SchemaContentHandler fXSContentHandler;
429 StAXSchemaParser fStAXSchemaParser;
430 XML11Configuration fAnnotationValidator;
431 XSAnnotationGrammarPool fGrammarBucketAdapter;
432
433 // these data members are needed for the deferred traversal
693 }
694 catch (IOException exc) {}
695 annotation = annotation.next;
696 }
697 }
698 }
699
700 private void createAnnotationValidator() {
701 fAnnotationValidator = new XML11Configuration();
702 fGrammarBucketAdapter = new XSAnnotationGrammarPool();
703 fAnnotationValidator.setFeature(VALIDATION, true);
704 fAnnotationValidator.setFeature(XMLSCHEMA_VALIDATION, true);
705 fAnnotationValidator.setProperty(XMLGRAMMAR_POOL, fGrammarBucketAdapter);
706 /** set security manager and XML Security Property Manager **/
707 fAnnotationValidator.setProperty(SECURITY_MANAGER, (fSecurityManager != null) ? fSecurityManager : new XMLSecurityManager(true));
708 fAnnotationValidator.setProperty(XML_SECURITY_PROPERTY_MANAGER, fSecurityPropertyMgr);
709 /** Set error handler. **/
710 fAnnotationValidator.setProperty(ERROR_HANDLER, (fErrorHandler != null) ? fErrorHandler : new DefaultErrorHandler());
711 /** Set locale. **/
712 fAnnotationValidator.setProperty(LOCALE, fLocale);
713 }
714
715 /**
716 * Pull the grammar out of the bucket simply using
717 * its TNS as a key
718 */
719 SchemaGrammar getGrammar(String tns) {
720 return fGrammarBucket.getGrammar(tns);
721 }
722
723 /**
724 * First try to find a grammar in the bucket, if failed, consult the
725 * grammar pool. If a grammar is found in the pool, then add it (and all
726 * imported ones) into the bucket.
727 */
728 protected SchemaGrammar findGrammar(XSDDescription desc, boolean ignoreConflict) {
729 SchemaGrammar sg = fGrammarBucket.getGrammar(desc.getTargetNamespace());
730 if (sg == null) {
731 if (fGrammarPool != null) {
732 sg = (SchemaGrammar)fGrammarPool.retrieveGrammar(desc);
3497 }
3498 public void setDeclPool (XSDeclarationPool declPool){
3499 fDeclPool = declPool;
3500 }
3501 public void setDVFactory(SchemaDVFactory dvFactory){
3502 fDVFactory = dvFactory;
3503 }
3504 public SchemaDVFactory getDVFactory(){
3505 return fDVFactory;
3506 }
3507
3508 public void reset(XMLComponentManager componentManager) {
3509
3510 // set symbol table
3511 fSymbolTable = (SymbolTable) componentManager.getProperty(SYMBOL_TABLE);
3512
3513 // set security manager
3514 fSecurityManager = (XMLSecurityManager) componentManager.getProperty(SECURITY_MANAGER, null);
3515
3516 //set entity manager
3517 fEntityManager = (XMLEntityResolver) componentManager.getProperty(ENTITY_MANAGER);
3518
3519 //set entity resolver
3520 XMLEntityResolver er = (XMLEntityResolver)componentManager.getProperty(ENTITY_RESOLVER);
3521 if (er != null)
3522 fSchemaParser.setEntityResolver(er);
3523
3524 // set error reporter
3525 fErrorReporter = (XMLErrorReporter) componentManager.getProperty(ERROR_REPORTER);
3526 fErrorHandler = fErrorReporter.getErrorHandler();
3527 fLocale = fErrorReporter.getLocale();
3528
3529 fValidateAnnotations = componentManager.getFeature(VALIDATE_ANNOTATIONS, false);
3530 fHonourAllSchemaLocations = componentManager.getFeature(HONOUR_ALL_SCHEMALOCATIONS, false);
3531 fNamespaceGrowth = componentManager.getFeature(NAMESPACE_GROWTH, false);
3532 fTolerateDuplicates = componentManager.getFeature(TOLERATE_DUPLICATES, false);
3533
3534 try {
3535 // Setting a parser property can be much more expensive
3536 // than checking its value. Don't set the ERROR_HANDLER
3537 // or LOCALE properties unless they've actually changed.
3576 try {
3577 if (componentManager.getFeature(DISALLOW_DOCTYPE, false)) {
3578 fSchemaParser.setFeature(DISALLOW_DOCTYPE, true);
3579 }
3580 } catch (XMLConfigurationException e) {}
3581
3582 try {
3583 if (fSecurityManager != null) {
3584 fSchemaParser.setProperty(SECURITY_MANAGER, fSecurityManager);
3585 }
3586 } catch (XMLConfigurationException e) {}
3587
3588 fSecurityPropertyMgr = (XMLSecurityPropertyManager) componentManager.getProperty(XML_SECURITY_PROPERTY_MANAGER);
3589
3590 //Passing on the setting to the parser
3591 fSchemaParser.setProperty(XML_SECURITY_PROPERTY_MANAGER, fSecurityPropertyMgr);
3592
3593 fAccessExternalDTD = fSecurityPropertyMgr.getValue(XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_DTD);
3594 fAccessExternalSchema = fSecurityPropertyMgr.getValue(XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_SCHEMA);
3595
3596 } // reset(XMLComponentManager)
3597
3598
3599 /**
3600 * Traverse all the deferred local elements. This method should be called
3601 * by traverseSchemas after we've done with all the global declarations.
3602 */
3603 void traverseLocalElements() {
3604 fElementTraverser.fDeferTraversingLocalElements = false;
3605
3606 for (int i = 0; i < fLocalElemStackPos; i++) {
3607 Element currElem = fLocalElementDecl[i];
3608 //XSDocumentInfo currSchema = (XSDocumentInfo)fDoc2XSDocumentMap.get(DOMUtil.getDocument(currElem));
3609 //XSDocumentInfo currSchema = (XSDocumentInfo)fDoc2XSDocumentMap.get(DOMUtil.getRoot(DOMUtil.getDocument(currElem)));
3610 XSDocumentInfo currSchema = fLocalElementDecl_schema[i];
3611 SchemaGrammar currGrammar = fGrammarBucket.getGrammar(currSchema.fTargetNamespace);
3612 fElementTraverser.traverseLocal (fParticle[i], currElem, currSchema, currGrammar, fAllContext[i], fParent[i], fLocalElemNamespaceContext[i]);
3613 // If it's an empty particle, remove it from the containing component.
3614 if (fParticle[i].fType == XSParticleDecl.PARTICLE_EMPTY) {
3615 XSModelGroupImpl group = null;
|
85 import com.sun.org.apache.xerces.internal.xs.XSModelGroup;
86 import com.sun.org.apache.xerces.internal.xs.XSModelGroupDefinition;
87 import com.sun.org.apache.xerces.internal.xs.XSNamedMap;
88 import com.sun.org.apache.xerces.internal.xs.XSObject;
89 import com.sun.org.apache.xerces.internal.xs.XSObjectList;
90 import com.sun.org.apache.xerces.internal.xs.XSParticle;
91 import com.sun.org.apache.xerces.internal.xs.XSSimpleTypeDefinition;
92 import com.sun.org.apache.xerces.internal.xs.XSTerm;
93 import com.sun.org.apache.xerces.internal.xs.XSTypeDefinition;
94 import com.sun.org.apache.xerces.internal.xs.datatypes.ObjectList;
95 import java.io.IOException;
96 import java.io.StringReader;
97 import java.util.ArrayList;
98 import java.util.Collections;
99 import java.util.HashMap;
100 import java.util.Locale;
101 import java.util.Map;
102 import java.util.Stack;
103 import java.util.Vector;
104 import javax.xml.XMLConstants;
105 import javax.xml.catalog.CatalogFeatures;
106 import javax.xml.stream.XMLEventReader;
107 import javax.xml.stream.XMLStreamException;
108 import javax.xml.stream.XMLStreamReader;
109 import jdk.xml.internal.JdkXmlUtils;
110 import org.w3c.dom.Document;
111 import org.w3c.dom.Element;
112 import org.w3c.dom.Node;
113 import org.xml.sax.InputSource;
114 import org.xml.sax.SAXException;
115 import org.xml.sax.SAXNotRecognizedException;
116 import org.xml.sax.SAXParseException;
117 import org.xml.sax.XMLReader;
118 import org.xml.sax.helpers.XMLReaderFactory;
119
120 /**
121 * The purpose of this class is to co-ordinate the construction of a
122 * grammar object corresponding to a schema. To do this, it must be
123 * prepared to parse several schema documents (for instance if the
124 * schema document originally referred to contains <include> or
125 * <redefined> information items). If any of the schemas imports a
126 * schema, other grammars may be constructed as a side-effect.
127 *
128 * @xerces.internal
129 *
376
377 //handle multiple import feature
378 private boolean fHonourAllSchemaLocations = false;
379
380 //handle namespace growth feature
381 boolean fNamespaceGrowth = false;
382
383 // handle tolerate duplicates feature
384 boolean fTolerateDuplicates = false;
385
386 // the XMLErrorReporter
387 private XMLErrorReporter fErrorReporter;
388
389 // the XMLErrorHandler
390 private XMLErrorHandler fErrorHandler;
391
392 // the Locale
393 private Locale fLocale;
394
395 // the XMLEntityManager
396 private XMLEntityManager fEntityManager;
397
398 // the XSAttributeChecker
399 private XSAttributeChecker fAttributeChecker;
400
401 // the symbol table
402 private SymbolTable fSymbolTable;
403
404 // the GrammarResolver
405 private XSGrammarBucket fGrammarBucket;
406
407 // the Grammar description
408 private XSDDescription fSchemaGrammarDescription;
409
410 // the Grammar Pool
411 private XMLGrammarPool fGrammarPool;
412
413 // the security property manager
414 private XMLSecurityPropertyManager fSecurityPropertyMgr = null;
415
416 /** indicate whether Catalog should be used for resolving external resources */
417 private boolean fUseCatalog = true;
418 private String fCatalogFile;
419 private String fDefer;
420 private String fPrefer;
421 private String fResolve;
422
423 //************ Traversers **********
424 XSDAttributeGroupTraverser fAttributeGroupTraverser;
425 XSDAttributeTraverser fAttributeTraverser;
426 XSDComplexTypeTraverser fComplexTypeTraverser;
427 XSDElementTraverser fElementTraverser;
428 XSDGroupTraverser fGroupTraverser;
429 XSDKeyrefTraverser fKeyrefTraverser;
430 XSDNotationTraverser fNotationTraverser;
431 XSDSimpleTypeTraverser fSimpleTypeTraverser;
432 XSDUniqueOrKeyTraverser fUniqueOrKeyTraverser;
433 XSDWildcardTraverser fWildCardTraverser;
434
435 SchemaDVFactory fDVFactory;
436 SchemaDOMParser fSchemaParser;
437 SchemaContentHandler fXSContentHandler;
438 StAXSchemaParser fStAXSchemaParser;
439 XML11Configuration fAnnotationValidator;
440 XSAnnotationGrammarPool fGrammarBucketAdapter;
441
442 // these data members are needed for the deferred traversal
702 }
703 catch (IOException exc) {}
704 annotation = annotation.next;
705 }
706 }
707 }
708
709 private void createAnnotationValidator() {
710 fAnnotationValidator = new XML11Configuration();
711 fGrammarBucketAdapter = new XSAnnotationGrammarPool();
712 fAnnotationValidator.setFeature(VALIDATION, true);
713 fAnnotationValidator.setFeature(XMLSCHEMA_VALIDATION, true);
714 fAnnotationValidator.setProperty(XMLGRAMMAR_POOL, fGrammarBucketAdapter);
715 /** set security manager and XML Security Property Manager **/
716 fAnnotationValidator.setProperty(SECURITY_MANAGER, (fSecurityManager != null) ? fSecurityManager : new XMLSecurityManager(true));
717 fAnnotationValidator.setProperty(XML_SECURITY_PROPERTY_MANAGER, fSecurityPropertyMgr);
718 /** Set error handler. **/
719 fAnnotationValidator.setProperty(ERROR_HANDLER, (fErrorHandler != null) ? fErrorHandler : new DefaultErrorHandler());
720 /** Set locale. **/
721 fAnnotationValidator.setProperty(LOCALE, fLocale);
722
723 // Passing on the Catalog settings
724 fAnnotationValidator.setFeature(XMLConstants.USE_CATALOG, fUseCatalog);
725 fAnnotationValidator.setProperty(JdkXmlUtils.CATALOG_FILES, fCatalogFile);
726 fAnnotationValidator.setProperty(JdkXmlUtils.CATALOG_DEFER, fDefer);
727 fAnnotationValidator.setProperty(JdkXmlUtils.CATALOG_PREFER, fPrefer);
728 fAnnotationValidator.setProperty(JdkXmlUtils.CATALOG_RESOLVE, fResolve);
729 }
730
731 /**
732 * Pull the grammar out of the bucket simply using
733 * its TNS as a key
734 */
735 SchemaGrammar getGrammar(String tns) {
736 return fGrammarBucket.getGrammar(tns);
737 }
738
739 /**
740 * First try to find a grammar in the bucket, if failed, consult the
741 * grammar pool. If a grammar is found in the pool, then add it (and all
742 * imported ones) into the bucket.
743 */
744 protected SchemaGrammar findGrammar(XSDDescription desc, boolean ignoreConflict) {
745 SchemaGrammar sg = fGrammarBucket.getGrammar(desc.getTargetNamespace());
746 if (sg == null) {
747 if (fGrammarPool != null) {
748 sg = (SchemaGrammar)fGrammarPool.retrieveGrammar(desc);
3513 }
3514 public void setDeclPool (XSDeclarationPool declPool){
3515 fDeclPool = declPool;
3516 }
3517 public void setDVFactory(SchemaDVFactory dvFactory){
3518 fDVFactory = dvFactory;
3519 }
3520 public SchemaDVFactory getDVFactory(){
3521 return fDVFactory;
3522 }
3523
3524 public void reset(XMLComponentManager componentManager) {
3525
3526 // set symbol table
3527 fSymbolTable = (SymbolTable) componentManager.getProperty(SYMBOL_TABLE);
3528
3529 // set security manager
3530 fSecurityManager = (XMLSecurityManager) componentManager.getProperty(SECURITY_MANAGER, null);
3531
3532 //set entity manager
3533 fEntityManager = (XMLEntityManager) componentManager.getProperty(ENTITY_MANAGER);
3534
3535 //set entity resolver
3536 XMLEntityResolver er = (XMLEntityResolver)componentManager.getProperty(ENTITY_RESOLVER);
3537 if (er != null)
3538 fSchemaParser.setEntityResolver(er);
3539
3540 // set error reporter
3541 fErrorReporter = (XMLErrorReporter) componentManager.getProperty(ERROR_REPORTER);
3542 fErrorHandler = fErrorReporter.getErrorHandler();
3543 fLocale = fErrorReporter.getLocale();
3544
3545 fValidateAnnotations = componentManager.getFeature(VALIDATE_ANNOTATIONS, false);
3546 fHonourAllSchemaLocations = componentManager.getFeature(HONOUR_ALL_SCHEMALOCATIONS, false);
3547 fNamespaceGrowth = componentManager.getFeature(NAMESPACE_GROWTH, false);
3548 fTolerateDuplicates = componentManager.getFeature(TOLERATE_DUPLICATES, false);
3549
3550 try {
3551 // Setting a parser property can be much more expensive
3552 // than checking its value. Don't set the ERROR_HANDLER
3553 // or LOCALE properties unless they've actually changed.
3592 try {
3593 if (componentManager.getFeature(DISALLOW_DOCTYPE, false)) {
3594 fSchemaParser.setFeature(DISALLOW_DOCTYPE, true);
3595 }
3596 } catch (XMLConfigurationException e) {}
3597
3598 try {
3599 if (fSecurityManager != null) {
3600 fSchemaParser.setProperty(SECURITY_MANAGER, fSecurityManager);
3601 }
3602 } catch (XMLConfigurationException e) {}
3603
3604 fSecurityPropertyMgr = (XMLSecurityPropertyManager) componentManager.getProperty(XML_SECURITY_PROPERTY_MANAGER);
3605
3606 //Passing on the setting to the parser
3607 fSchemaParser.setProperty(XML_SECURITY_PROPERTY_MANAGER, fSecurityPropertyMgr);
3608
3609 fAccessExternalDTD = fSecurityPropertyMgr.getValue(XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_DTD);
3610 fAccessExternalSchema = fSecurityPropertyMgr.getValue(XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_SCHEMA);
3611
3612 // Passing the Catalog settings to the parser
3613 fUseCatalog = componentManager.getFeature(XMLConstants.USE_CATALOG);
3614 fSchemaParser.setFeature(XMLConstants.USE_CATALOG, fUseCatalog);
3615 fEntityManager.setFeature(XMLConstants.USE_CATALOG, fUseCatalog);
3616
3617 fCatalogFile = (String)componentManager.getProperty(JdkXmlUtils.CATALOG_FILES);
3618 fDefer = (String)componentManager.getProperty(JdkXmlUtils.CATALOG_DEFER);
3619 fPrefer = (String)componentManager.getProperty(JdkXmlUtils.CATALOG_PREFER);
3620 fResolve = (String)componentManager.getProperty(JdkXmlUtils.CATALOG_RESOLVE);
3621
3622 for( CatalogFeatures.Feature f : CatalogFeatures.Feature.values()) {
3623 fSchemaParser.setProperty(f.getPropertyName(), componentManager.getProperty(f.getPropertyName()));
3624 fEntityManager.setProperty(f.getPropertyName(), componentManager.getProperty(f.getPropertyName()));
3625 }
3626 } // reset(XMLComponentManager)
3627
3628
3629 /**
3630 * Traverse all the deferred local elements. This method should be called
3631 * by traverseSchemas after we've done with all the global declarations.
3632 */
3633 void traverseLocalElements() {
3634 fElementTraverser.fDeferTraversingLocalElements = false;
3635
3636 for (int i = 0; i < fLocalElemStackPos; i++) {
3637 Element currElem = fLocalElementDecl[i];
3638 //XSDocumentInfo currSchema = (XSDocumentInfo)fDoc2XSDocumentMap.get(DOMUtil.getDocument(currElem));
3639 //XSDocumentInfo currSchema = (XSDocumentInfo)fDoc2XSDocumentMap.get(DOMUtil.getRoot(DOMUtil.getDocument(currElem)));
3640 XSDocumentInfo currSchema = fLocalElementDecl_schema[i];
3641 SchemaGrammar currGrammar = fGrammarBucket.getGrammar(currSchema.fTargetNamespace);
3642 fElementTraverser.traverseLocal (fParticle[i], currElem, currSchema, currGrammar, fAllContext[i], fParent[i], fLocalElemNamespaceContext[i]);
3643 // If it's an empty particle, remove it from the containing component.
3644 if (fParticle[i].fType == XSParticleDecl.PARTICLE_EMPTY) {
3645 XSModelGroupImpl group = null;
|