xmlgrammarcachingconfiguration.java

来自「JAVA的一些源码 JAVA2 STANDARD EDITION DEVELO」· Java 代码 · 共 390 行 · 第 1/2 页

JAVA
390
字号
        fSchemaLoader.setProperty(XMLGRAMMAR_POOL, fGrammarPool);        // and set up the DTD loader too:        fDTDLoader = new XMLDTDLoader(fSymbolTable, fGrammarPool);    } // <init>(SymbolTable,XMLGrammarPool, XMLComponentManager)    //    // Public methods    //    /*     * lock the XMLGrammarPoolImpl object so that it does not     * accept any more grammars from the validators.       */    public void lockGrammarPool() {        fGrammarPool.lockPool();    } // lockGrammarPool()    /*     * clear the XMLGrammarPoolImpl object so that it does not     * contain any more grammars.       */    public void clearGrammarPool() {        fGrammarPool.clear();    } // clearGrammarPool()    /*     * unlock the XMLGrammarPoolImpl object so that it       * accepts more grammars from the validators.       */    public void unlockGrammarPool() {        fGrammarPool.unlockPool();    } // unlockGrammarPool()    /**     * Parse a grammar from a location identified by an URI.     * This method also adds this grammar to the XMLGrammarPool     *     * @param type The type of the grammar to be constructed     * @param uri The location of the grammar to be constructed.     * <strong>The parser will not expand this URI or make it     * available to the EntityResolver</strong>     * @return The newly created <code>Grammar</code>.     * @exception XNIException thrown on an error in grammar     * construction     * @exception IOException thrown if an error is encountered     * in reading the file     */    public Grammar parseGrammar(String type, String uri)                              throws XNIException, IOException {        XMLInputSource source = new XMLInputSource(null, uri, null);        return parseGrammar(type, source);    }    /**     * Parse a grammar from a location identified by an     * XMLInputSource.       * This method also adds this grammar to the XMLGrammarPool     *     * @param type The type of the grammar to be constructed     * @param source The XMLInputSource containing this grammar's     * information     * <strong>If a URI is included in the systemId field, the parser will not expand this URI or make it     * available to the EntityResolver</strong>     * @return The newly created <code>Grammar</code>.     * @exception XNIException thrown on an error in grammar     * construction     * @exception IOException thrown if an error is encountered     * in reading the file     */    public Grammar parseGrammar(String type, XMLInputSource                is) throws XNIException, IOException {        if(type.equals(XMLGrammarDescription.XML_SCHEMA)) {            // by default, make all XMLGrammarPoolImpl's schema grammars available to fSchemaHandler            return parseXMLSchema(is);        } else if(type.equals(XMLGrammarDescription.XML_DTD)) {            return parseDTD(is);        }        // don't know this grammar...        return null;    } // parseGrammar(String, XMLInputSource):  Grammar    //    // Protected methods    //        // features and properties    /**     * 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.     *     * @throws XMLConfigurationException Thrown for configuration error.     *                                   In general, components should     *                                   only throw this exception if     *                                   it is <strong>really</strong>     *                                   a critical error.     */    protected void checkFeature(String featureId)        throws XMLConfigurationException {        super.checkFeature(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.     *     * @throws XMLConfigurationException Thrown for configuration error.     *                                   In general, components should     *                                   only throw this exception if     *                                   it is <strong>really</strong>     *                                   a critical error.     */    protected void checkProperty(String propertyId)        throws XMLConfigurationException {        super.checkProperty(propertyId);    } // checkProperty(String)    // package-protected methods    /* This method parses an XML Schema document.       * It requires a GrammarBucket parameter so that DOMASBuilder can     * extract the info it needs.     * Therefore, bucket must not be null!     */    SchemaGrammar parseXMLSchema(XMLInputSource is)                 throws IOException {        XMLEntityResolver resolver = getEntityResolver();        if(resolver != null) {            fSchemaLoader.setEntityResolver(resolver);        }        if (fErrorReporter.getMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN) == null) {            fErrorReporter.putMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN, new XSMessageFormatter());        }         fSchemaLoader.setProperty(ERROR_REPORTER, fErrorReporter);        String propPrefix = Constants.XERCES_PROPERTY_PREFIX;        String propName = propPrefix + Constants.SCHEMA_LOCATION;        fSchemaLoader.setProperty(propName, getProperty(propName));        propName = propPrefix + Constants.SCHEMA_NONS_LOCATION;        fSchemaLoader.setProperty(propName, getProperty(propName));        propName = Constants.JAXP_PROPERTY_PREFIX+Constants.SCHEMA_SOURCE;        fSchemaLoader.setProperty(propName, getProperty(propName));        fSchemaLoader.setFeature(SCHEMA_FULL_CHECKING, getFeature(SCHEMA_FULL_CHECKING));        // Should check whether the grammar with this namespace is already in        // the grammar resolver. But since we don't know the target namespace        // of the document here, we leave such check to XSDHandler        SchemaGrammar grammar = (SchemaGrammar)fSchemaLoader.loadGrammar(is);        // by default, hand it off to the grammar pool        if (grammar != null) {            fGrammarPool.cacheGrammars(XMLGrammarDescription.XML_SCHEMA,                                      new Grammar[]{grammar});        }                return grammar;    } // parseXMLSchema(XMLInputSource) :  SchemaGrammar    /* This method parses an external DTD entity.     */    DTDGrammar parseDTD(XMLInputSource is)                 throws IOException {        XMLEntityResolver resolver = getEntityResolver();        if(resolver != null) {            fDTDLoader.setEntityResolver(resolver);        }        fDTDLoader.setProperty(ERROR_REPORTER, fErrorReporter);        // Should check whether the grammar with this namespace is already in        // the grammar resolver. But since we don't know the target namespace        // of the document here, we leave such check to the application...        DTDGrammar grammar = (DTDGrammar)fDTDLoader.loadGrammar(is);        // by default, hand it off to the grammar pool        if (grammar != null) {            fGrammarPool.cacheGrammars(XMLGrammarDescription.XML_DTD,                                      new Grammar[]{grammar});        }                return grammar;    } // parseXMLDTD(XMLInputSource) :  DTDGrammar} // class XMLGrammarCachingConfiguration

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?