mrglavas 2003/10/02 12:45:42 Modified: java/src/org/apache/xerces/parsers XML11Configuration.java Log: Adding specialized document scanner and DTD validator to the configuration for improving performance of namespace processing. When namespace processing is enabled, these components are added to the pipeline. They are responsible for binding namespaces; replacing the role of the NamespaceBinder. The regular scanner and DTD validator are used in the pipeline when namespace processing is off. Also, we weren't setting the source on most of the pipeline components. This has now been fixed. Revision Changes Path 1.5 +148 -111 xml-xerces/java/src/org/apache/xerces/parsers/XML11Configuration.java Index: XML11Configuration.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/parsers/XML11Configuration.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- XML11Configuration.java 3 Mar 2003 22:17:17 -0000 1.4 +++ XML11Configuration.java 2 Oct 2003 19:45:42 -0000 1.5 @@ -2,7 +2,7 @@ * The Apache Software License, Version 1.1 * * - * Copyright (c) 2001 - 2003 The Apache Software Foundation. + * Copyright (c) 2001-2003 The Apache Software Foundation. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -63,17 +63,23 @@ import org.apache.xerces.impl.XML11DTDScannerImpl; import org.apache.xerces.impl.XML11DocumentScannerImpl; import org.apache.xerces.impl.XML11NamespaceBinder; +import org.apache.xerces.impl.XML11NSDocumentScannerImpl; import org.apache.xerces.impl.XMLEntityHandler; import org.apache.xerces.impl.XMLVersionDetector; + import org.apache.xerces.impl.dtd.XML11DTDProcessor; import org.apache.xerces.impl.dtd.XML11DTDValidator; +import org.apache.xerces.impl.dtd.XML11NSDTDValidator; + import org.apache.xerces.impl.dv.DTDDVFactory; + import org.apache.xerces.impl.xs.XMLSchemaValidator; import org.apache.xerces.impl.xs.XSMessageFormatter; + import org.apache.xerces.util.SymbolTable; + 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.XMLComponentManager; /** @@ -84,42 +90,48 @@ * scanners optimal for the document being scanned. * * @author Neil Graham, IBM + * @author Michael Glavassevich, IBM * * @version $Id$ */ -public class XML11Configuration - extends IntegratedParserConfiguration { +public class XML11Configuration extends IntegratedParserConfiguration { // // Constants // - protected final static String XML11_DATATYPE_VALIDATOR_FACTORY = "org.apache.xerces.impl.dv.dtd.XML11DTDDVFactoryImpl"; + protected final static String XML11_DATATYPE_VALIDATOR_FACTORY = + "org.apache.xerces.impl.dv.dtd.XML11DTDDVFactoryImpl"; // // Data // protected XMLVersionDetector fVersionDetector = new XMLVersionDetector(); - - // the XML 1.1 document scanner + + /** The XML 1.1 document scanner that does namespace binding. **/ + protected XML11NSDocumentScannerImpl fXML11NSDocScanner = null; + + /** The XML 1.1 document scanner that does not do namespace binding. **/ protected XML11DocumentScannerImpl fXML11DocScanner = null; - - // the XML 1.1 DTD scanner + + /** The XML 1.1 DTD scanner. **/ protected XML11DTDScannerImpl fXML11DTDScanner = null; - // the XML 1.1 DTD validator + /** The XML 1.1 DTD validator that does namespace binding. **/ + protected XML11NSDTDValidator fXML11NSDTDValidator = null; + + /** The XML 1.1 DTD validator that does not do namespace binding. **/ protected XML11DTDValidator fXML11DTDValidator = null; - - // the XML 1.1 DTD processor + + /** The XML 1.1 DTD processor. **/ protected XML11DTDProcessor fXML11DTDProcessor = null; - - // the XML 1.1 namespace binder + + /** The XML 1.1 namespace binder. **/ protected XML11NamespaceBinder fXML11NamespaceBinder = null; - - // the XML 1.1. datatype factory - protected DTDDVFactory fXML11DatatypeFactory = null; - - + + /** The XML 1.1 datatype factory. **/ + protected DTDDVFactory fXML11DatatypeFactory = null; + // // Constructors // @@ -149,8 +161,8 @@ * @param symbolTable The symbol table to use. * @param grammarPool The grammar pool to use. */ - public XML11Configuration(SymbolTable symbolTable, - XMLGrammarPool grammarPool) { + public XML11Configuration(SymbolTable symbolTable, + XMLGrammarPool grammarPool) { this(symbolTable, grammarPool, null); } // <init>(SymbolTable,XMLGrammarPool) @@ -166,50 +178,45 @@ * @param grammarPool The grammar pool to use. * @param parentSettings The parent settings. */ - public XML11Configuration(SymbolTable symbolTable, - XMLGrammarPool grammarPool, - XMLComponentManager parentSettings) { + public XML11Configuration(SymbolTable symbolTable, + XMLGrammarPool grammarPool, + XMLComponentManager parentSettings) { super(symbolTable, grammarPool, parentSettings); - } // <init>(SymbolTable,XMLGrammarPool) // // Public methods // public boolean parse(boolean complete) throws XNIException, IOException { - + // // reset and configure pipeline and set InputSource. - if (fInputSource !=null) { + if (fInputSource != null) { try { fVersionDetector.reset(this); reset(); short version = fVersionDetector.determineDocVersion(fInputSource); - if (version == Constants.XML_VERSION_1_1){ + if (version == Constants.XML_VERSION_1_1) { // XML 1.1 pipeline configureXML11Pipeline(); } // resets and sets the pipeline. - fVersionDetector.startDocumentParsing((XMLEntityHandler)fScanner, version); + fVersionDetector.startDocumentParsing((XMLEntityHandler) fScanner, version); fInputSource = null; - } - catch (XNIException ex) { + } catch (XNIException ex) { if (PRINT_EXCEPTION_STACK_TRACE) ex.printStackTrace(); throw ex; - } - catch (IOException ex) { + } catch (IOException ex) { if (PRINT_EXCEPTION_STACK_TRACE) ex.printStackTrace(); throw ex; - } - catch (RuntimeException ex) { + } catch (RuntimeException ex) { if (PRINT_EXCEPTION_STACK_TRACE) ex.printStackTrace(); throw ex; - } - catch (Exception ex) { + } catch (Exception ex) { if (PRINT_EXCEPTION_STACK_TRACE) ex.printStackTrace(); throw new XNIException(ex); @@ -218,23 +225,19 @@ try { return fScanner.scanDocument(complete); - } - catch (XNIException ex) { + } catch (XNIException ex) { if (PRINT_EXCEPTION_STACK_TRACE) ex.printStackTrace(); throw ex; - } - catch (IOException ex) { + } catch (IOException ex) { if (PRINT_EXCEPTION_STACK_TRACE) ex.printStackTrace(); throw ex; - } - catch (RuntimeException ex) { + } catch (RuntimeException ex) { if (PRINT_EXCEPTION_STACK_TRACE) ex.printStackTrace(); throw ex; - } - catch (Exception ex) { + } catch (Exception ex) { if (PRINT_EXCEPTION_STACK_TRACE) ex.printStackTrace(); throw new XNIException(ex); @@ -242,77 +245,111 @@ } // parse(boolean):boolean - /** Configures the XML 1.1 pipeline. - * Note: this method also resets the new XML11 components + /** + * Configures the XML 1.1 pipeline. + * Note: this method also resets the new XML11 components. */ - protected void configureXML11Pipeline() { - + protected void configureXML11Pipeline() { + // create datatype factory if (fXML11DatatypeFactory == null) { - fXML11DatatypeFactory= DTDDVFactory.getInstance(XML11_DATATYPE_VALIDATOR_FACTORY); + fXML11DatatypeFactory = DTDDVFactory.getInstance(XML11_DATATYPE_VALIDATOR_FACTORY); } setProperty(DATATYPE_VALIDATOR_FACTORY, fXML11DatatypeFactory); - - if (fXML11DTDScanner == null) { - fXML11DTDScanner = new XML11DTDScannerImpl(); - } - // setup dtd pipeline - if (fXML11DTDProcessor == null) { - fXML11DTDProcessor = new XML11DTDProcessor(); - } - fProperties.put(DTD_SCANNER, fXML11DTDScanner); - fProperties.put(DTD_PROCESSOR, fXML11DTDProcessor); - - fXML11DTDScanner.setDTDHandler(fXML11DTDProcessor); - fXML11DTDProcessor.setDTDHandler(fDTDHandler); - fXML11DTDScanner.setDTDContentModelHandler(fXML11DTDProcessor); - fXML11DTDProcessor.setDTDContentModelHandler(fDTDContentModelHandler); - - if (fXML11DocScanner == null) { - fXML11DocScanner = new XML11DocumentScannerImpl(); - } - - if(fXML11DTDValidator == null) { - fXML11DTDValidator = new XML11DTDValidator(); + // setup XML 1.1 DTD pipeline + if (fXML11DTDScanner == null) { + fXML11DTDScanner = new XML11DTDScannerImpl(); + } + if (fXML11DTDProcessor == null) { + fXML11DTDProcessor = new XML11DTDProcessor(); } - - fScanner = fXML11DocScanner; - ((XMLComponent)fScanner).reset(this); - fProperties.put(DOCUMENT_SCANNER, fXML11DocScanner); - fProperties.put(DTD_VALIDATOR, fXML11DTDValidator); - if (fFeatures.get(NAMESPACES) == Boolean.TRUE) { - if (fXML11NamespaceBinder == null) { - fXML11NamespaceBinder = new XML11NamespaceBinder(); - } - fProperties.put(NAMESPACE_BINDER, fXML11NamespaceBinder); - - fScanner.setDocumentHandler(fXML11DTDValidator); - fXML11DTDValidator.setDocumentSource(fScanner); - - fXML11DTDValidator.setDocumentHandler(fXML11NamespaceBinder); - fXML11NamespaceBinder.setDocumentSource(fXML11DTDValidator); - - fXML11NamespaceBinder.setDocumentHandler(fDocumentHandler); - fDocumentHandler.setDocumentSource(fXML11NamespaceBinder); - fLastComponent = fXML11NamespaceBinder; + fProperties.put(DTD_SCANNER, fXML11DTDScanner); + fProperties.put(DTD_PROCESSOR, fXML11DTDProcessor); + + fXML11DTDScanner.setDTDHandler(fXML11DTDProcessor); + fXML11DTDProcessor.setDTDSource(fXML11DTDScanner); + fXML11DTDProcessor.setDTDHandler(fDTDHandler); + if (fDTDHandler != null) { + fDTDHandler.setDTDSource(fXML11DTDProcessor); + } + + fXML11DTDScanner.setDTDContentModelHandler(fXML11DTDProcessor); + fXML11DTDProcessor.setDTDContentModelSource(fXML11DTDScanner); + fXML11DTDProcessor.setDTDContentModelHandler(fDTDContentModelHandler); + if (fDTDContentModelHandler != null) { + fDTDContentModelHandler.setDTDContentModelSource(fXML11DTDProcessor); + } + + // setup XML 1.1 document pipeline + if (fFeatures.get(NAMESPACES) == Boolean.TRUE) { + // REVISIT: Do we still need the namespace binder in the + // configuration? It doesn't appear that any other + // component uses it. - mrglavas + if (fXML11NamespaceBinder == null) { + fXML11NamespaceBinder = new XML11NamespaceBinder(); + } + fProperties.put(NAMESPACE_BINDER, fXML11NamespaceBinder); + + if (fXML11NSDocScanner == null) { + fXML11NSDocScanner = new XML11NSDocumentScannerImpl(); + } + fScanner = fXML11NSDocScanner; + fProperties.put(DOCUMENT_SCANNER, fXML11NSDocScanner); + + if (fXML11NSDTDValidator == null) { + fXML11NSDTDValidator = new XML11NSDTDValidator(); + } + fProperties.put(DTD_VALIDATOR, fXML11NSDTDValidator); + + fXML11NSDocScanner.setDTDValidator(fXML11NSDTDValidator); + fXML11NSDocScanner.setDocumentHandler(fXML11NSDTDValidator); + + fXML11NSDTDValidator.setDocumentSource(fXML11NSDocScanner); + fXML11NSDTDValidator.setDocumentHandler(fDocumentHandler); + + if (fDocumentHandler != null) { + fDocumentHandler.setDocumentSource(fXML11NSDTDValidator); + } + fLastComponent = fXML11NSDTDValidator; + + // Reset namespace pipeline components. + fXML11NSDocScanner.reset(this); + fXML11NSDTDValidator.reset(this); fXML11NamespaceBinder.reset(this); - } - else { - fScanner.setDocumentHandler(fXML11DTDValidator); - fXML11DTDValidator.setDocumentSource(fScanner); - fXML11DTDValidator.setDocumentHandler(fDocumentHandler); - fDocumentHandler.setDocumentSource(fXML11DTDValidator); - fLastComponent = fXML11DTDValidator; - } - // reset all 1.1 components - - fXML11DTDProcessor.reset(this); - fXML11DTDScanner.reset(this); - fXML11DTDValidator.reset(this); + + } else { + if (fXML11DocScanner == null) { + fXML11DocScanner = new XML11DocumentScannerImpl(); + } + fScanner = fXML11DocScanner; + fProperties.put(DOCUMENT_SCANNER, fXML11DocScanner); + if (fXML11DTDValidator == null) { + fXML11DTDValidator = new XML11DTDValidator(); + } + fProperties.put(DTD_VALIDATOR, fXML11DTDValidator); + + fXML11DocScanner.setDocumentHandler(fXML11DTDValidator); + + fXML11DTDValidator.setDocumentSource(fXML11DocScanner); + fXML11DTDValidator.setDocumentHandler(fDocumentHandler); + + if (fDocumentHandler != null) { + fDocumentHandler.setDocumentSource(fXML11DTDValidator); + } + fLastComponent = fXML11DTDValidator; + + // Reset no namespace pipeline components. + fXML11DocScanner.reset(this); + fXML11DTDValidator.reset(this); + } - // setup document pipeline + // Reset DTD pipeline components. + fXML11DTDScanner.reset(this); + fXML11DTDProcessor.reset(this); + + // setup document pipeline if (fFeatures.get(XMLSCHEMA_VALIDATION) == Boolean.TRUE) { // If schema validator was not in the pipeline insert it. if (fSchemaValidator == null) { @@ -326,17 +363,17 @@ XSMessageFormatter xmft = new XSMessageFormatter(); fErrorReporter.putMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN, xmft); } - } fLastComponent.setDocumentHandler(fSchemaValidator); fSchemaValidator.setDocumentSource(fLastComponent); fSchemaValidator.setDocumentHandler(fDocumentHandler); + if (fDocumentHandler != null) { + fDocumentHandler.setDocumentSource(fSchemaValidator); + } fLastComponent = fSchemaValidator; } - } // configurePipeline() - - + } // configurePipeline() } // class XML11Configuration
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]