You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by el...@apache.org on 2003/11/07 20:47:56 UTC

cvs commit: xml-xerces/java/src/org/apache/xerces/impl/xs/opti SchemaParsingConfig.java SchemaDOMParser.java

elena       2003/11/07 11:47:56

  Modified:    java/src/org/apache/xerces/impl/xs/opti
                        SchemaParsingConfig.java SchemaDOMParser.java
  Log:
  Re-use schema parser.
  
  Revision  Changes    Path
  1.3       +50 -119   xml-xerces/java/src/org/apache/xerces/impl/xs/opti/SchemaParsingConfig.java
  
  Index: SchemaParsingConfig.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/opti/SchemaParsingConfig.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SchemaParsingConfig.java	13 Dec 2002 17:23:24 -0000	1.2
  +++ SchemaParsingConfig.java	7 Nov 2003 19:47:56 -0000	1.3
  @@ -57,40 +57,31 @@
   
   package org.apache.xerces.impl.xs.opti;
   
  -import java.util.Locale;
   import java.io.IOException;
  -
  -import org.w3c.dom.Document;
  +import java.util.Locale;
   
   import org.apache.xerces.impl.Constants;
  -import org.apache.xerces.impl.XMLErrorReporter;
  -import org.apache.xerces.impl.XMLEntityManager;
   import org.apache.xerces.impl.XMLDTDScannerImpl;
  -import org.apache.xerces.impl.XMLNamespaceBinder;
  -import org.apache.xerces.impl.XMLDocumentScannerImpl;
  -
  +import org.apache.xerces.impl.XMLEntityManager;
  +import org.apache.xerces.impl.XMLErrorReporter;
  +import org.apache.xerces.impl.XMLNSDocumentScannerImpl;
   import org.apache.xerces.impl.dv.DTDDVFactory;
  -
   import org.apache.xerces.impl.msg.XMLMessageFormatter;
  -
   import org.apache.xerces.impl.validation.ValidationManager;
  -
  +import org.apache.xerces.impl.xs.XSMessageFormatter;
  +import org.apache.xerces.parsers.BasicParserConfiguration;
   import org.apache.xerces.util.SymbolTable;
  -
   import org.apache.xerces.xni.XMLLocator;
   import org.apache.xerces.xni.XNIException;
  -
  +import org.apache.xerces.xni.grammars.XMLGrammarPool;
   import org.apache.xerces.xni.parser.XMLComponent;
  -import org.apache.xerces.xni.parser.XMLDTDScanner;
  -import org.apache.xerces.xni.parser.XMLInputSource;
  -import org.apache.xerces.xni.parser.XMLDocumentScanner;
   import org.apache.xerces.xni.parser.XMLComponentManager;
   import org.apache.xerces.xni.parser.XMLConfigurationException;
  +import org.apache.xerces.xni.parser.XMLDTDScanner;
  +import org.apache.xerces.xni.parser.XMLDocumentScanner;
  +import org.apache.xerces.xni.parser.XMLInputSource;
   import org.apache.xerces.xni.parser.XMLPullParserConfiguration;
  -
  -import org.apache.xerces.xni.grammars.XMLGrammarPool;
  -
  -import org.apache.xerces.parsers.BasicParserConfiguration;
  +import org.w3c.dom.Document;
   
   
   /**
  @@ -147,6 +138,7 @@
       /** Feature identifier: send element default value via characters() */
       protected static final String SCHEMA_ELEMENT_DEFAULT =
       Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_ELEMENT_DEFAULT;
  +    	
   
       // property identifiers
   
  @@ -224,8 +216,6 @@
       /** DTD scanner. */
       protected XMLDTDScanner fDTDScanner;
   
  -    /** Namespace binder. */
  -    protected XMLNamespaceBinder fNamespaceBinder;
       
       protected SchemaDOMParser fSchemaDOMParser;
   
  @@ -295,22 +285,22 @@
   
           // add default recognized features
           final String[] recognizedFeatures = {
  -            WARN_ON_DUPLICATE_ATTDEF,   WARN_ON_UNDECLARED_ELEMDEF,
  +			PARSER_SETTINGS, WARN_ON_DUPLICATE_ATTDEF,   WARN_ON_UNDECLARED_ELEMDEF,
               ALLOW_JAVA_ENCODINGS,       CONTINUE_AFTER_FATAL_ERROR,
               LOAD_EXTERNAL_DTD,          NOTIFY_BUILTIN_REFS,
               NOTIFY_CHAR_REFS
           };
           addRecognizedFeatures(recognizedFeatures);
  -
  +		fFeatures.put(PARSER_SETTINGS, Boolean.TRUE);
           // set state for default features
  -        setFeature(WARN_ON_DUPLICATE_ATTDEF, false);
  +		fFeatures.put(WARN_ON_DUPLICATE_ATTDEF, Boolean.FALSE);
           //setFeature(WARN_ON_DUPLICATE_ENTITYDEF, false);
  -        setFeature(WARN_ON_UNDECLARED_ELEMDEF, false);
  -        setFeature(ALLOW_JAVA_ENCODINGS, false);
  -        setFeature(CONTINUE_AFTER_FATAL_ERROR, false);
  -        setFeature(LOAD_EXTERNAL_DTD, true);
  -        setFeature(NOTIFY_BUILTIN_REFS, false);
  -        setFeature(NOTIFY_CHAR_REFS, false);
  +		fFeatures.put(WARN_ON_UNDECLARED_ELEMDEF, Boolean.FALSE);
  +		fFeatures.put(ALLOW_JAVA_ENCODINGS, Boolean.FALSE);
  +		fFeatures.put(CONTINUE_AFTER_FATAL_ERROR, Boolean.FALSE);
  +		fFeatures.put(LOAD_EXTERNAL_DTD, Boolean.TRUE);
  +		fFeatures.put(NOTIFY_BUILTIN_REFS, Boolean.FALSE);
  +		fFeatures.put(NOTIFY_CHAR_REFS, Boolean.FALSE);
   
           // add default recognized properties
           final String[] recognizedProperties = {
  @@ -331,46 +321,30 @@
           	setProperty(XMLGRAMMAR_POOL, fGrammarPool);
           }
   
  -        fEntityManager = createEntityManager();
  -        setProperty(ENTITY_MANAGER, fEntityManager);
  +        fEntityManager = new XMLEntityManager();
  +        fProperties.put(ENTITY_MANAGER, fEntityManager);
           addComponent(fEntityManager);
   
  -        fErrorReporter = createErrorReporter();
  +        fErrorReporter = new XMLErrorReporter();
           fErrorReporter.setDocumentLocator(fEntityManager.getEntityScanner());
  -        setProperty(ERROR_REPORTER, fErrorReporter);
  +		fProperties.put(ERROR_REPORTER, fErrorReporter);
           addComponent(fErrorReporter);
   
  -        fScanner = createDocumentScanner();
  -        setProperty(DOCUMENT_SCANNER, fScanner);
  -        if (fScanner instanceof XMLComponent) {
  -            addComponent((XMLComponent)fScanner);
  -        }
  +        fScanner = new XMLNSDocumentScannerImpl();
  +		fProperties.put(DOCUMENT_SCANNER, fScanner);
  +		addComponent((XMLComponent)fScanner);
  +
  +        fDTDScanner = new XMLDTDScannerImpl();
  +		fProperties.put(DTD_SCANNER, fDTDScanner);
  +        addComponent((XMLComponent)fDTDScanner);
   
  -        fDTDScanner = createDTDScanner();
  -        if (fDTDScanner != null) {
  -            setProperty(DTD_SCANNER, fDTDScanner);
  -            if (fDTDScanner instanceof XMLComponent) {
  -                addComponent((XMLComponent)fDTDScanner);
  -            }
  -        }
  -
  -        fNamespaceBinder = createNamespaceBinder();
  -        if (fNamespaceBinder != null) {
  -            setProperty(NAMESPACE_BINDER, fNamespaceBinder);
  -            addComponent(fNamespaceBinder);
  -        }
  -
  -
  -        fDatatypeValidatorFactory = createDatatypeValidatorFactory();
  -        if (fDatatypeValidatorFactory != null) {
  -            setProperty(DATATYPE_VALIDATOR_FACTORY,
  +        
  +        fDatatypeValidatorFactory = DTDDVFactory.getInstance();;
  +		fProperties.put(DATATYPE_VALIDATOR_FACTORY,
                           fDatatypeValidatorFactory);
  -        }
  -        fValidationManager = createValidationManager();
  -
  -        if (fValidationManager != null) {
  -            setProperty (VALIDATION_MANAGER, fValidationManager);
  -        }
  +        
  +        fValidationManager = new ValidationManager();
  +		fProperties.put(VALIDATION_MANAGER, fValidationManager);
   
           // add message formatters
           if (fErrorReporter.getMessageFormatter(XMLMessageFormatter.XML_DOMAIN) == null) {
  @@ -378,10 +352,15 @@
               fErrorReporter.putMessageFormatter(XMLMessageFormatter.XML_DOMAIN, xmft);
               fErrorReporter.putMessageFormatter(XMLMessageFormatter.XMLNS_DOMAIN, xmft);
           }
  +        
  +		if (fErrorReporter.getMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN) == null) {
  +			XSMessageFormatter xmft = new XSMessageFormatter();
  +			fErrorReporter.putMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN, xmft);
  +		}
   
           // set locale
           try {
  -            setLocale(Locale.getDefault());
  +            setLocale(Locale.getDefault()); 
           }
           catch (XNIException e) {
               // do nothing
  @@ -584,7 +563,8 @@
       public void reset() throws XNIException {
   
           // set handlers
  -        fSchemaDOMParser = createSchemaDOMParser();
  +        if (fSchemaDOMParser == null)
  +        	fSchemaDOMParser = new SchemaDOMParser(this);
           fDocumentHandler = fSchemaDOMParser;
           fDTDHandler = fSchemaDOMParser;
           fDTDContentModelHandler = fSchemaDOMParser;
  @@ -598,21 +578,12 @@
       /** Configures the pipeline. */
       protected void configurePipeline() {
   
  -        // REVISIT: This should be better designed. In other words, we
  -        //          need to figure out what is the best way for people to
  -        //          re-use *most* of the standard configuration but do 
  -        //          things common things such as remove a component (e.g.
  -        //          the validator), insert a new component (e.g. XInclude), 
  -        //          etc... -Ac
  -
           // setup document pipeline
  -        fScanner.setDocumentHandler(fNamespaceBinder);
  -        fNamespaceBinder.setDocumentHandler(fDocumentHandler);
  -
  -        fLastComponent = fNamespaceBinder;
  +        fScanner.setDocumentHandler(fDocumentHandler);
  +        fDocumentHandler.setDocumentSource(fScanner);
  +        fLastComponent = fScanner;
   
           // setup dtd pipeline
  -
           if (fDTDScanner != null) {
                   fDTDScanner.setDTDHandler(fDTDHandler);
                   fDTDScanner.setDTDContentModelHandler(fDTDContentModelHandler);
  @@ -742,46 +713,6 @@
   
       } // checkProperty(String)
   
  -    // factory methods
  -
  -    /** Creates an entity manager. */
  -    protected XMLEntityManager createEntityManager() {
  -        return new XMLEntityManager();
  -    } // createEntityManager():XMLEntityManager
  -
  -    /** Creates an error reporter. */
  -    protected XMLErrorReporter createErrorReporter() {
  -        return new XMLErrorReporter();
  -    } // createErrorReporter():XMLErrorReporter
  -
  -    /** Create a document scanner. */
  -    protected XMLDocumentScanner createDocumentScanner() {
  -        return new XMLDocumentScannerImpl();
  -    } // createDocumentScanner():XMLDocumentScanner
  -
  -    /** Create a DTD scanner. */
  -    protected XMLDTDScanner createDTDScanner() {
  -        return new XMLDTDScannerImpl();
  -    } // createDTDScanner():XMLDTDScanner
  -
  -
  -    /** Create a namespace binder. */
  -    protected XMLNamespaceBinder createNamespaceBinder() {
  -        return new XMLNamespaceBinder();
  -    } // createNamespaceBinder():XMLNamespaceBinder
  -    
  -    /** Create a readonly DOM parser for loading schema. */
  -    protected SchemaDOMParser createSchemaDOMParser() {
  -        return new SchemaDOMParser(this);
  -    }
  -
  -    /** Create a datatype validator factory. */
  -    protected DTDDVFactory createDatatypeValidatorFactory() {
  -        return DTDDVFactory.getInstance();
  -    } // createDatatypeValidatorFactory():DatatypeValidatorFactory
  -    protected ValidationManager createValidationManager(){
  -        return new ValidationManager();
  -    }
       
       
       //
  
  
  
  1.6       +6 -14     xml-xerces/java/src/org/apache/xerces/impl/xs/opti/SchemaDOMParser.java
  
  Index: SchemaDOMParser.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/opti/SchemaDOMParser.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- SchemaDOMParser.java	20 Aug 2003 13:52:57 -0000	1.5
  +++ SchemaDOMParser.java	7 Nov 2003 19:47:56 -0000	1.6
  @@ -106,7 +106,6 @@
   
       /** Default constructor. */
       public SchemaDOMParser(XMLParserConfiguration config) {
  -        schemaDOM = new SchemaDOM();
           this.config = config;
       }
   
  @@ -129,6 +128,11 @@
       public void startDocument(XMLLocator locator, String encoding, 
                                 NamespaceContext namespaceContext, Augmentations augs)
           throws XNIException {
  +		fErrorReporter = (XMLErrorReporter)config.getProperty(ERROR_REPORTER);
  +		schemaDOM = new SchemaDOM(); 
  +		fAnnotationDepth = -1;
  +        fInnerAnnotationDepth = -1;
  +        fDepth = -1;
           fLocator = locator;
           fNamespaceContext = namespaceContext;
       } // startDocument(XMLLocator,String,NamespaceContext, Augmentations)
  @@ -200,18 +204,6 @@
               for (int i=text.offset; i<text.offset+text.length; i++) {
                   // and there is a non-whitespace character
                   if (!XMLChar.isSpace(text.ch[i])) {
  -                    // only get the error reporter when reporting an error
  -                    if (fErrorReporter == null) {
  -                        try {
  -                            fErrorReporter = (XMLErrorReporter)config.getProperty(ERROR_REPORTER);
  -                        } catch (Exception e) {
  -                            //ignore the excpetion
  -                        }
  -                        if (fErrorReporter.getMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN) == null) {
  -                            XSMessageFormatter xmft = new XSMessageFormatter();
  -                            fErrorReporter.putMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN, xmft);
  -                        }
  -                    }
                       // the string we saw: starting from the first non-whitespace character.
                       String txt = new String(text.ch, i, text.length+text.offset-i);
                       // report an error
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org