You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by an...@apache.org on 2001/10/01 10:54:50 UTC

cvs commit: xml-xerces/java/src/org/apache/xerces/util ParserConfigurationSettings.java

andyc       01/10/01 01:54:50

  Modified:    java/src/org/apache/xerces/impl XMLEntityManager.java
                        XMLNamespaceBinder.java
               java/src/org/apache/xerces/parsers
                        BasicParserConfiguration.java
                        StandardParserConfiguration.java
  Added:       java/src/org/apache/xerces/util
                        ParserConfigurationSettings.java
  Log:
  1) Added a parser configuration settings class to allow settings
     to be separated from a configuration and allow settings to be
     "chained".
  2) Modified xerces.parser configuration classes to descend from
     the new settings class and take advantage of the "chaining".
  3) Added constructors to the entity manager and namespace binder
     to allow them to share a common context.
  
  Revision  Changes    Path
  1.5       +48 -2     xml-xerces/java/src/org/apache/xerces/impl/XMLEntityManager.java
  
  Index: XMLEntityManager.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/XMLEntityManager.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- XMLEntityManager.java	2001/09/07 02:07:34	1.4
  +++ XMLEntityManager.java	2001/10/01 08:54:49	1.5
  @@ -114,7 +114,7 @@
    * @author Andy Clark, IBM
    * @author Arnaud  Le Hors, IBM
    *
  - * @version $Id: XMLEntityManager.java,v 1.4 2001/09/07 02:07:34 andyc Exp $
  + * @version $Id: XMLEntityManager.java,v 1.5 2001/10/01 08:54:49 andyc Exp $
    */
   public class XMLEntityManager
       implements XMLComponent {
  @@ -278,15 +278,39 @@
       /** Current entity. */
       protected ScannedEntity fCurrentEntity;
   
  +    // shared context
  +
  +    /** Shared declared entities. */
  +    protected Hashtable fDeclaredEntities;
  +
       //
       // Constructors
       //
   
       /** Default constructor. */
       public XMLEntityManager() {
  -        fEntityScanner = new EntityScanner();
  +        this(null);
       } // <init>()
   
  +    /** 
  +     * Constructs an entity manager that shares the specified entity 
  +     * declarations during each parse.
  +     * <p>
  +     * <strong>REVISIT:</strong> We might want to think about the "right"
  +     * way to expose the list of declared entities. For now, the knowledge
  +     * how to access the entity declarations is implicit.
  +     */
  +    public XMLEntityManager(XMLEntityManager entityManager) {
  +        
  +        // create scanner
  +        fEntityScanner = new EntityScanner();
  +
  +        // save shared entity declarations
  +        fDeclaredEntities = entityManager != null 
  +                          ? entityManager.getDeclaredEntities() : null;
  +
  +    } // <init>(XMLEntityManager)
  +
       //
       // Public methods
       //
  @@ -851,6 +875,16 @@
               addExternalEntity("two", null, "ent/two.ent", "test/ent/one.xml");
           }
   
  +        // copy declared entities
  +        if (fDeclaredEntities != null) {
  +            java.util.Enumeration keys = fDeclaredEntities.keys();
  +            while (keys.hasMoreElements()) {
  +                Object key = keys.nextElement();
  +                Object value = fDeclaredEntities.get(key);
  +                fEntities.put(key, value);
  +            }
  +        }
  +
       } // reset(XMLComponentManager)
   
       /**
  @@ -1263,6 +1297,18 @@
       //
       // Package visible methods
       //
  +
  +    /** 
  +     * Returns the hashtable of declared entities.
  +     * <p>
  +     * <strong>REVISIT:</strong>
  +     * This should be done the "right" way by designing a better way to
  +     * enumerate the declared entities. For now, this method is needed
  +     * by the constructor that takes an XMLEntityManager parameter.
  +     */
  +    Hashtable getDeclaredEntities() {
  +        return fEntities;
  +    } // getDeclaredEntities():Hashtable
   
       /** Prints the contents of the buffer. */
       final void print() {
  
  
  
  1.5       +47 -2     xml-xerces/java/src/org/apache/xerces/impl/XMLNamespaceBinder.java
  
  Index: XMLNamespaceBinder.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/XMLNamespaceBinder.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- XMLNamespaceBinder.java	2001/09/25 06:08:32	1.4
  +++ XMLNamespaceBinder.java	2001/10/01 08:54:49	1.5
  @@ -65,6 +65,7 @@
   import org.apache.xerces.util.NamespaceSupport;
   import org.apache.xerces.util.SymbolTable;
   
  +import org.apache.xerces.xni.NamespaceContext;
   import org.apache.xerces.xni.QName;
   import org.apache.xerces.xni.XMLAttributes;
   import org.apache.xerces.xni.XMLDocumentHandler;
  @@ -91,7 +92,7 @@
    *
    * @author Andy Clark, IBM
    *
  - * @version $Id: XMLNamespaceBinder.java,v 1.4 2001/09/25 06:08:32 andyc Exp $
  + * @version $Id: XMLNamespaceBinder.java,v 1.5 2001/10/01 08:54:49 andyc Exp $
    */
   public class XMLNamespaceBinder 
       implements XMLComponent, XMLDocumentHandler {
  @@ -161,8 +162,13 @@
       /** Only pass start and end prefix mapping events. */
       protected boolean fOnlyPassPrefixMappingEvents;
   
  -    // private data
  +    // shared context
   
  +    /** Namespace context. */
  +    private NamespaceContext fNamespaceContext;
  +
  +    // temp vars
  +
       /** Attribute QName. */
       private QName fAttributeQName = new QName();
   
  @@ -178,9 +184,34 @@
       private String fXmlnsSymbol;
   
       //
  +    // Constructors
  +    //
  +
  +    /** Default constructor. */
  +    public XMLNamespaceBinder() {
  +        this(null);
  +    } // <init>()
  +
  +    /** 
  +     * Constructs a namespace binder that shares the specified namespace
  +     * context during each parse.
  +     *
  +     * @param namespaceContext The shared context.
  +     */
  +    public XMLNamespaceBinder(NamespaceContext namespaceContext) {
  +        fNamespaceContext = namespaceContext;
  +    } // <init>(NamespaceContext)
  +    
  +
  +    //
       // Public methods
       //
   
  +    /** Returns the current namespace context. */
  +    public NamespaceContext getNamespaceContext() {
  +        return fNamespaceSupport;
  +    } // getNamespaceContext():NamespaceContext
  +
       // settings
   
       /**
  @@ -246,6 +277,20 @@
           fXmlSymbol = fSymbolTable.addSymbol("xml");
           fXmlnsSymbol = fSymbolTable.addSymbol("xmlns");
       
  +        // use shared context
  +        NamespaceContext context = fNamespaceContext;
  +        while (context != null) {
  +            int count = context.getDeclaredPrefixCount();
  +            for (int i = 0; i < count; i++) {
  +                String prefix = context.getDeclaredPrefixAt(i);
  +                if (fNamespaceSupport.getURI(prefix) == null) {
  +                    String uri = context.getURI(prefix);
  +                    fNamespaceSupport.declarePrefix(prefix, uri);
  +                }
  +            }
  +            context = context.getParentContext();
  +        }
  +
       } // reset(XMLComponentManager)
   
       /**
  
  
  
  1.4       +29 -196   xml-xerces/java/src/org/apache/xerces/parsers/BasicParserConfiguration.java
  
  Index: BasicParserConfiguration.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/parsers/BasicParserConfiguration.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- BasicParserConfiguration.java	2001/08/28 08:49:12	1.3
  +++ BasicParserConfiguration.java	2001/10/01 08:54:49	1.4
  @@ -66,6 +66,7 @@
   
   import org.apache.xerces.impl.Constants;
   import org.apache.xerces.impl.msg.XMLMessageFormatter;
  +import org.apache.xerces.util.ParserConfigurationSettings;
   import org.apache.xerces.util.SymbolTable;
   import org.apache.xerces.xni.XMLDocumentHandler;
   import org.apache.xerces.xni.XMLDTDHandler;
  @@ -129,9 +130,10 @@
    * @author Arnaud  Le Hors, IBM
    * @author Andy Clark, IBM
    *
  - * @version $Id: BasicParserConfiguration.java,v 1.3 2001/08/28 08:49:12 andyc Exp $
  + * @version $Id: BasicParserConfiguration.java,v 1.4 2001/10/01 08:54:49 andyc Exp $
    */
   public abstract class BasicParserConfiguration
  +    extends ParserConfigurationSettings
       implements XMLParserConfiguration {
   
       //
  @@ -188,18 +190,6 @@
       /** Locale. */
       protected Locale fLocale;
   
  -    /** Recognized properties. */
  -    protected Vector fRecognizedProperties;
  -
  -    /** Properties. */
  -    protected Hashtable fProperties;
  -
  -    /** Recognized features. */
  -    protected Vector fRecognizedFeatures;
  -
  -    /** Features. */
  -    protected Hashtable fFeatures;
  -
       /** Components. */
       protected Vector fComponents;
   
  @@ -220,15 +210,28 @@
   
       /** Default Constructor. */
       protected BasicParserConfiguration() {
  -        this(null);
  +        this(null, null);
       } // <init>()
   
  -    /**
  -     * Constructs a document parser using the specified symbol table
  -     * and a default grammar pool.
  +    /** 
  +     * Constructs a parser configuration using the specified symbol table. 
        *
  +     * @param symbolTable The symbol table to use.
        */
       protected BasicParserConfiguration(SymbolTable symbolTable) {
  +        this(null, null);
  +    } // <init>(SymbolTable)
  +
  +    /** 
  +     * Constructs a parser configuration using the specified symbol table
  +     * and parent settings.
  +     *
  +     * @param symbolTable    The symbol table to use.
  +     * @param parentSettings The parent settings.
  +     */
  +    protected BasicParserConfiguration(SymbolTable symbolTable,
  +                                       XMLComponentManager parentSettings) {
  +        super(parentSettings);
   
           // create a vector to hold all the components in use
           fComponents = new Vector();
  @@ -300,47 +303,10 @@
       } // addComponent(XMLComponent)
   
       //
  -    // Public methods
  +    // XMLParserConfiguration methods
       //
   
       /**
  -     * Parses the input source specified by the given system identifier.
  -     * <p>
  -     * This method is equivalent to the following:
  -     * <pre>
  -     *     parse(new InputSource(systemId));
  -     * </pre>
  -     *
  -     * @param source The input source.
  -     *
  -     * @exception org.xml.sax.SAXException Throws exception on SAX error.
  -     * @exception java.io.IOException Throws exception on i/o error.
  -     */
  -    /***
  -    public void parse(String systemId)
  -        throws XNIException, IOException {
  -
  -        InputSource source = new InputSource(systemId);
  -        parse(source);
  -        try {
  -            Reader reader = source.getCharacterStream();
  -            if (reader != null) {
  -                reader.close();
  -            }
  -            else {
  -                InputStream is = source.getByteStream();
  -                if (is != null) {
  -                    is.close();
  -                }
  -            }
  -        }
  -        catch (IOException e) {
  -            // ignore
  -        }
  -
  -    } // parse(String)
  -
  -    /**
        * parse
        *
        * @param inputSource
  @@ -420,26 +386,6 @@
       } // getErrorHandler():XMLErrorHandler
   
       /**
  -     * Allows a parser to add parser specific features to be recognized
  -     * and managed by the parser configuration.
  -     *
  -     * @param featureIds An array of the additional feature identifiers 
  -     *                   to be recognized.
  -     */
  -    public void addRecognizedFeatures(String[] featureIds) {
  -
  -        // add recognized features
  -        int featureIdsCount = featureIds != null ? featureIds.length : 0;
  -        for (int i = 0; i < featureIdsCount; i++) {
  -            String featureId = featureIds[i];
  -            if (!fRecognizedFeatures.contains(featureId)) {
  -                fRecognizedFeatures.addElement(featureId);
  -            }
  -        }
  -
  -    } // addRecognizedFeatures(String[])
  -
  -    /**
        * Set the state of a feature.
        *
        * Set the state of any feature in a SAX2 parser.  The parser
  @@ -460,38 +406,17 @@
       public void setFeature(String featureId, boolean state)
           throws XMLConfigurationException {
   
  -        checkFeature(featureId);
  -
           // forward to every component
           int count = fComponents.size();
           for (int i = 0; i < count; i++) {
               XMLComponent c = (XMLComponent) fComponents.elementAt(i);
               c.setFeature(featureId, state);
           }
  -        // then store the information
  -        fFeatures.put(featureId, state ? Boolean.TRUE : Boolean.FALSE);
   
  -    } // setFeature(String,boolean)
  -
  -    /**
  -     * Allows a parser to add parser specific properties to be recognized
  -     * and managed by the parser configuration.
  -     *
  -     * @param propertyIds An array of the additional property identifiers 
  -     *                    to be recognized.
  -     */
  -    public void addRecognizedProperties(String[] propertyIds) {
  +        // save state if noone "objects"
  +        super.setFeature(featureId, state);
   
  -        // add recognizedProperties
  -        int propertyIdsCount = propertyIds != null ? propertyIds.length : 0;
  -        for (int i = 0; i < propertyIdsCount; i++) {
  -            String propertyId = propertyIds[i];
  -            if (!fRecognizedProperties.contains(propertyId)) {
  -                fRecognizedProperties.addElement(propertyId);
  -            }
  -        }
  -
  -    } // addRecognizedProperties(String[])
  +    } // setFeature(String,boolean)
   
       /**
        * setProperty
  @@ -502,17 +427,16 @@
       public void setProperty(String propertyId, Object value)
           throws XMLConfigurationException {
   
  -        checkProperty(propertyId);
  -
           // forward to every component
           int count = fComponents.size();
           for (int i = 0; i < count; i++) {
               XMLComponent c = (XMLComponent) fComponents.elementAt(i);
               c.setProperty(propertyId, value);
           }
  -        // then store the information
  -        fProperties.put(propertyId, value);
   
  +        // store value if noone "objects"
  +        super.setProperty(propertyId, value);
  +
       } // setProperty(String,Object)
   
       /**
  @@ -528,69 +452,6 @@
       } // setLocale(Locale)
   
       //
  -    // XMLComponentManager methods
  -    //
  -
  -    /**
  -     * Returns the state of a feature.
  -     * 
  -     * @param featureId The feature identifier.
  -     * 
  -     * @throws XMLConfigurationException Thrown for configuration error.
  -     *                                   In general, components should
  -     *                                   only throw this exception if
  -     *                                   it is <strong>really</strong>
  -     *                                   a critical error.
  -     */
  -    public boolean getFeature(String featureId)
  -        throws XMLConfigurationException {
  -
  -        checkFeature(featureId);
  -
  -        Boolean state = (Boolean) fFeatures.get(featureId);
  -        return state != null ? state.booleanValue() : false;
  -
  -    } // getFeature(String):boolean
  -
  -    /**
  -     * Returns the value of a property.
  -     * 
  -     * @param propertyId The property identifier.
  -     * 
  -     * @throws XMLConfigurationException Thrown for configuration error.
  -     *                                   In general, components should
  -     *                                   only throw this exception if
  -     *                                   it is <strong>really</strong>
  -     *                                   a critical error.
  -     */
  -    public Object getProperty(String propertyId)
  -        throws XMLConfigurationException {
  -
  -        checkProperty(propertyId);
  -
  -        return fProperties.get(propertyId);
  -
  -    } // getProperty(String):Object
  -
  -    /*** These should be queried through the property mechanism. -Ac ***
  -    public Locator getLocator() {
  -        return fLocator;
  -    } // getLocator():Locator
  -
  -    public SymbolTable getSymbolTable() {
  -        return fSymbolTable;
  -    } // getSymbolTable():SymbolTable
  -
  -    public Hashtable getFeatureTable() {
  -        return fFeatures;
  -    }
  -
  -    public Hashtable getPropertyTable() {
  -        return fProperties;
  -    }
  -    /***/
  -
  -    //
       // Protected methods
       //
   
  @@ -605,33 +466,8 @@
               XMLComponent c = (XMLComponent) fComponents.elementAt(i);
               c.reset(this);
           }
  -
  -    } // reset(XMLParser)
  -
  -    /**
  -     * Check a feature. If feature is known and supported, this method simply
  -     * returns. Otherwise, the appropriate exception is thrown.
  -     *
  -     * @param featureId The unique identifier (URI) of the feature.
  -     *
  -     * @exception org.xml.sax.SAXNotRecognizedException If the
  -     *            requested feature is not known.
  -     * @exception org.xml.sax.SAXNotSupportedException If the
  -     *            requested feature is known, but the requested
  -     *            state is not supported.
  -     * @exception org.xml.sax.SAXException If there is any other
  -     *            problem fulfilling the request.
  -     */
  -    protected void checkFeature(String featureId)
  -        throws XMLConfigurationException {
  -
  -        // check feature
  -        if (!fRecognizedFeatures.contains(featureId)) {
  -            short type = XMLConfigurationException.NOT_RECOGNIZED;
  -            throw new XMLConfigurationException(type, featureId);
  -        }
   
  -    } // checkFeature(String)
  +    } // reset()
   
       /**
        * Check a property. If the property is known and supported, this method
  @@ -674,10 +510,7 @@
           }
   
           // check property
  -        if (!fRecognizedProperties.contains(propertyId)) {
  -            short type = XMLConfigurationException.NOT_RECOGNIZED;
  -            throw new XMLConfigurationException(type, propertyId);
  -        }
  +        super.checkProperty(propertyId);
   
       } // checkProperty(String)
   
  
  
  
  1.3       +49 -41    xml-xerces/java/src/org/apache/xerces/parsers/StandardParserConfiguration.java
  
  Index: StandardParserConfiguration.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/parsers/StandardParserConfiguration.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- StandardParserConfiguration.java	2001/08/23 00:35:31	1.2
  +++ StandardParserConfiguration.java	2001/10/01 08:54:49	1.3
  @@ -75,6 +75,7 @@
   import org.apache.xerces.xni.XMLLocator;
   import org.apache.xerces.xni.XNIException;
   import org.apache.xerces.xni.parser.XMLComponent;
  +import org.apache.xerces.xni.parser.XMLComponentManager;
   import org.apache.xerces.xni.parser.XMLConfigurationException;
   import org.apache.xerces.xni.parser.XMLDocumentScanner;
   import org.apache.xerces.xni.parser.XMLDTDScanner;
  @@ -116,7 +117,7 @@
    * @author Arnaud  Le Hors, IBM
    * @author Andy Clark, IBM
    *
  - * @version $Id: StandardParserConfiguration.java,v 1.2 2001/08/23 00:35:31 lehors Exp $
  + * @version $Id: StandardParserConfiguration.java,v 1.3 2001/10/01 08:54:49 andyc Exp $
    */
   public class StandardParserConfiguration
       extends BasicParserConfiguration 
  @@ -243,28 +244,50 @@
       // Constructors
       //
   
  -    /**
  -     * Constructs a document parser using the default symbol table and grammar
  -     * pool or the ones specified by the application (through the properties).
  -     */
  +    /** Default constructor. */
       public StandardParserConfiguration() {
  -        this(null, null);
  +        this(null, null, null);
       } // <init>()
   
  -    /**
  -     * Constructs a document parser using the specified symbol table.
  +    /** 
  +     * Constructs a parser configuration using the specified symbol table. 
  +     *
  +     * @param symbolTable The symbol table to use.
        */
       public StandardParserConfiguration(SymbolTable symbolTable) {
  -        this(symbolTable, null);
  +        this(symbolTable, null, null);
       } // <init>(SymbolTable)
   
       /**
  -     * Constructs a document parser using the specified symbol table and
  +     * Constructs a parser configuration using the specified symbol table and
        * grammar pool.
  +     * <p>
  +     * <strong>REVISIT:</strong> 
  +     * Grammar pool will be updated when the new validation engine is
  +     * implemented.
  +     *
  +     * @param symbolTable The symbol table to use.
  +     * @param grammarPool The grammar pool to use.
        */
       public StandardParserConfiguration(SymbolTable symbolTable,
                                          GrammarPool grammarPool) {
  -        super(symbolTable);
  +    } // <init>(SymbolTable,GrammarPool)
  +    /**
  +     * Constructs a parser configuration using the specified symbol table,
  +     * grammar pool, and parent settings.
  +     * <p>
  +     * <strong>REVISIT:</strong> 
  +     * Grammar pool will be updated when the new validation engine is
  +     * implemented.
  +     *
  +     * @param symbolTable    The symbol table to use.
  +     * @param grammarPool    The grammar pool to use.
  +     * @param parentSettings The parent settings.
  +     */
  +    public StandardParserConfiguration(SymbolTable symbolTable,
  +                                       GrammarPool grammarPool,
  +                                       XMLComponentManager parentSettings) {
  +        super(symbolTable, parentSettings);
   
           // add default recognized features
           final String[] recognizedFeatures = {
  @@ -288,6 +311,10 @@
           final String[] recognizedProperties = {
               ERROR_REPORTER,             
               ENTITY_MANAGER, 
  +            DOCUMENT_SCANNER,
  +            DTD_SCANNER,
  +            DTD_VALIDATOR,
  +            NAMESPACE_BINDER,
               GRAMMAR_POOL,   
               DATATYPE_VALIDATOR_FACTORY,
           };
  @@ -295,34 +322,29 @@
   
           // create and register missing components
           if (grammarPool == null) {
  -            if (fGrammarPool == null) {
  -                fGrammarPool = new GrammarPool();
  -                fProperties.put(GRAMMAR_POOL, fGrammarPool);
  -            }
  +            grammarPool = new GrammarPool();
           }
  -        else {
  -            fGrammarPool = grammarPool;
  -            fProperties.put(GRAMMAR_POOL, fGrammarPool);
  -        }
  +        fGrammarPool = grammarPool;
  +        setProperty(GRAMMAR_POOL, fGrammarPool);
   
           fEntityManager = createEntityManager();
  -        fProperties.put(ENTITY_MANAGER, fEntityManager);
  +        setProperty(ENTITY_MANAGER, fEntityManager);
           addComponent(fEntityManager);
   
           fErrorReporter = createErrorReporter();
           fErrorReporter.setDocumentLocator(fEntityManager.getEntityScanner());
  -        fProperties.put(ERROR_REPORTER, fErrorReporter);
  +        setProperty(ERROR_REPORTER, fErrorReporter);
           addComponent(fErrorReporter);
   
           fScanner = createDocumentScanner();
  -        fProperties.put(DOCUMENT_SCANNER, fScanner);
  +        setProperty(DOCUMENT_SCANNER, fScanner);
           if (fScanner instanceof XMLComponent) {
               addComponent((XMLComponent)fScanner);
           }
   
           fDTDScanner = createDTDScanner();
           if (fDTDScanner != null) {
  -            fProperties.put(DTD_SCANNER, fDTDScanner);
  +            setProperty(DTD_SCANNER, fDTDScanner);
               if (fDTDScanner instanceof XMLComponent) {
                   addComponent((XMLComponent)fDTDScanner);
               }
  @@ -330,20 +352,20 @@
   
           fDTDValidator = createDTDValidator();
           if (fDTDValidator != null) {
  -            fProperties.put(DTD_VALIDATOR, fDTDValidator);
  +            setProperty(DTD_VALIDATOR, fDTDValidator);
               addComponent(fDTDValidator);
           }
   
           fNamespaceBinder = createNamespaceBinder();
           if (fNamespaceBinder != null) {
  -            fProperties.put(NAMESPACE_BINDER, fNamespaceBinder);
  +            setProperty(NAMESPACE_BINDER, fNamespaceBinder);
               addComponent(fNamespaceBinder);
           }
           
           fDatatypeValidatorFactory = createDatatypeValidatorFactory();
           if (fDatatypeValidatorFactory != null) {
  -            fProperties.put(DATATYPE_VALIDATOR_FACTORY,
  -                            fDatatypeValidatorFactory);
  +            setProperty(DATATYPE_VALIDATOR_FACTORY,
  +                        fDatatypeValidatorFactory);
           }
   
           // add message formatters
  @@ -377,20 +399,6 @@
        *                         specified locale.
        */
       public void setLocale(Locale locale) throws XNIException {
  -        // REVISIT: Is this code needed? We're now creating
  -        //          these components in the constructor. -Ac
  -        if (fErrorReporter == null) {
  -            if (fEntityManager == null) {
  -                fEntityManager = createEntityManager();
  -                fProperties.put(ENTITY_MANAGER, fEntityManager);
  -                addComponent(fEntityManager);
  -                fLocator = (XMLLocator)fEntityManager.getEntityScanner();
  -            }
  -            fErrorReporter = createErrorReporter();
  -            fErrorReporter.setDocumentLocator(fEntityManager.getEntityScanner());
  -            fProperties.put(ERROR_REPORTER, fErrorReporter);
  -            addComponent(fErrorReporter);
  -        }
           fErrorReporter.setLocale(locale);
       } // setLocale(Locale)
   
  
  
  
  1.1                  xml-xerces/java/src/org/apache/xerces/util/ParserConfigurationSettings.java
  
  Index: ParserConfigurationSettings.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2001 The Apache Software Foundation.  
   * All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Xerces" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 1999, International
   * Business Machines, Inc., http://www.apache.org.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.xerces.util;
  
  import java.util.Hashtable;
  import java.util.Vector;
  
  import org.apache.xerces.xni.parser.XMLComponentManager;
  import org.apache.xerces.xni.parser.XMLConfigurationException;
  
  /**
   * This class implements the basic operations for managing parser
   * configuration features and properties. This utility class can
   * be used as a base class for parser configurations or separately
   * to encapsulate a number of parser settings as a component
   * manager.
   * <p>
   * This class can be constructed with a "parent" settings object
   * (in the form of an <code>XMLComponentManager</code>) that allows
   * parser configuration settings to be "chained" together.
   *
   * @author Andy Clark, IBM
   *
   * @version $Id: ParserConfigurationSettings.java,v 1.1 2001/10/01 08:54:49 andyc Exp $
   */
  public class ParserConfigurationSettings
      implements XMLComponentManager {
  
      //
      // Data
      //
  
      // data
  
      /** Recognized properties. */
      protected Vector fRecognizedProperties;
  
      /** Properties. */
      protected Hashtable fProperties;
  
      /** Recognized features. */
      protected Vector fRecognizedFeatures;
  
      /** Features. */
      protected Hashtable fFeatures;
  
      /** Parent parser configuration settings. */
      protected XMLComponentManager fParentSettings;
  
      //
      // Constructors
      //
  
      /** Default Constructor. */
      public ParserConfigurationSettings() {
          this(null);
      } // <init>()
  
      /**
       * Constructs a parser configuration settings object with a
       * parent settings object.
       */
      public ParserConfigurationSettings(XMLComponentManager parent) {
  
          // create storage for recognized features and properties
          fRecognizedFeatures = new Vector();
          fRecognizedProperties = new Vector();
  
          // create table for features and properties
          fFeatures = new Hashtable();
          fProperties = new Hashtable();
  
          // save parent
          fParentSettings = parent;
  
      } // <init>(XMLComponentManager)
  
      //
      // XMLParserConfiguration methods
      //
  
      /**
       * Allows a parser to add parser specific features to be recognized
       * and managed by the parser configuration.
       *
       * @param featureIds An array of the additional feature identifiers 
       *                   to be recognized.
       */
      public void addRecognizedFeatures(String[] featureIds) {
  
          // add recognized features
          int featureIdsCount = featureIds != null ? featureIds.length : 0;
          for (int i = 0; i < featureIdsCount; i++) {
              String featureId = featureIds[i];
              if (!fRecognizedFeatures.contains(featureId)) {
                  fRecognizedFeatures.addElement(featureId);
              }
          }
  
      } // addRecognizedFeatures(String[])
  
      /**
       * Set the state of a feature.
       *
       * Set the state of any feature in a SAX2 parser.  The parser
       * might not recognize the feature, and if it does recognize
       * it, it might not be able to fulfill the request.
       *
       * @param featureId The unique identifier (URI) of the feature.
       * @param state The requested state of the feature (true or false).
       *
       * @exception org.xml.sax.SAXNotRecognizedException If the
       *            requested feature is not known.
       * @exception org.xml.sax.SAXNotSupportedException If the
       *            requested feature is known, but the requested
       *            state is not supported.
       * @exception org.xml.sax.SAXException If there is any other
       *            problem fulfilling the request.
       */
      public void setFeature(String featureId, boolean state)
          throws XMLConfigurationException {
  
          // check and store
          checkFeature(featureId);
          fFeatures.put(featureId, state ? Boolean.TRUE : Boolean.FALSE);
  
      } // setFeature(String,boolean)
  
      /**
       * Allows a parser to add parser specific properties to be recognized
       * and managed by the parser configuration.
       *
       * @param propertyIds An array of the additional property identifiers 
       *                    to be recognized.
       */
      public void addRecognizedProperties(String[] propertyIds) {
  
          // add recognizedProperties
          int propertyIdsCount = propertyIds != null ? propertyIds.length : 0;
          for (int i = 0; i < propertyIdsCount; i++) {
              String propertyId = propertyIds[i];
              if (!fRecognizedProperties.contains(propertyId)) {
                  fRecognizedProperties.addElement(propertyId);
              }
          }
  
      } // addRecognizedProperties(String[])
  
      /**
       * setProperty
       * 
       * @param propertyId 
       * @param value 
       */
      public void setProperty(String propertyId, Object value)
          throws XMLConfigurationException {
  
          // check and store
          checkProperty(propertyId);
          fProperties.put(propertyId, value);
  
      } // setProperty(String,Object)
  
      //
      // XMLComponentManager methods
      //
  
      /**
       * Returns the state of a feature.
       * 
       * @param featureId The feature identifier.
       * 
       * @throws XMLConfigurationException Thrown for configuration error.
       *                                   In general, components should
       *                                   only throw this exception if
       *                                   it is <strong>really</strong>
       *                                   a critical error.
       */
      public boolean getFeature(String featureId)
          throws XMLConfigurationException {
  
          checkFeature(featureId);
  
          Boolean state = (Boolean) fFeatures.get(featureId);
          return state != null ? state.booleanValue() : false;
  
      } // getFeature(String):boolean
  
      /**
       * Returns the value of a property.
       * 
       * @param propertyId The property identifier.
       * 
       * @throws XMLConfigurationException Thrown for configuration error.
       *                                   In general, components should
       *                                   only throw this exception if
       *                                   it is <strong>really</strong>
       *                                   a critical error.
       */
      public Object getProperty(String propertyId)
          throws XMLConfigurationException {
  
          checkProperty(propertyId);
  
          return fProperties.get(propertyId);
  
      } // getProperty(String):Object
  
      //
      // Protected methods
      //
  
      /**
       * Check a feature. If feature is known and supported, this method simply
       * returns. Otherwise, the appropriate exception is thrown.
       *
       * @param featureId The unique identifier (URI) of the feature.
       *
       * @exception org.xml.sax.SAXNotRecognizedException If the
       *            requested feature is not known.
       * @exception org.xml.sax.SAXNotSupportedException If the
       *            requested feature is known, but the requested
       *            state is not supported.
       * @exception org.xml.sax.SAXException If there is any other
       *            problem fulfilling the request.
       */
      protected void checkFeature(String featureId)
          throws XMLConfigurationException {
  
          // check feature
          if (!fRecognizedFeatures.contains(featureId)) {
              if (fParentSettings != null) {
                  fParentSettings.getFeature(featureId);
              }
              else {
                  short type = XMLConfigurationException.NOT_RECOGNIZED;
                  throw new XMLConfigurationException(type, featureId);
              }
          }
  
      } // checkFeature(String)
  
      /**
       * Check a property. If the property is known and supported, this method
       * simply returns. Otherwise, the appropriate exception is thrown.
       *
       * @param propertyId The unique identifier (URI) of the property
       *                   being set.
       * @exception org.xml.sax.SAXNotRecognizedException If the
       *            requested property is not known.
       * @exception org.xml.sax.SAXNotSupportedException If the
       *            requested property is known, but the requested
       *            value is not supported.
       * @exception org.xml.sax.SAXException If there is any other
       *            problem fulfilling the request.
       */
      protected void checkProperty(String propertyId)
          throws XMLConfigurationException {
  
          // check property
          if (!fRecognizedProperties.contains(propertyId)) {
              if (fParentSettings != null) {
                  fParentSettings.getProperty(propertyId);
              }
              else {
                  short type = XMLConfigurationException.NOT_RECOGNIZED;
                  throw new XMLConfigurationException(type, propertyId);
              }
          }
  
      } // checkProperty(String)
  
  } // class XMLParser
  
  
  

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