xmlgrammarpreparser.java

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

JAVA
379
字号
        if(loader == null) { // none specified!            if(KNOWN_LOADERS.containsKey(grammarType)) {                // got one; just instantiate it...                String loaderName = (String)KNOWN_LOADERS.get(grammarType);                try {                    ClassLoader cl = ObjectFactory.findClassLoader();                    XMLGrammarLoader gl = (XMLGrammarLoader)(ObjectFactory.newInstance(loaderName, cl, true));                    fLoaders.put(grammarType, gl);                } catch (Exception e) {                    return false;                }                return true;            }            return false;        }        // were given one        fLoaders.put(grammarType, loader);        return true;    } // registerPreparser(String, XMLGrammarLoader):  boolean    /**     * 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 preparseGrammar(String type, XMLInputSource                is) throws XNIException, IOException {        if(fLoaders.containsKey(type)) {            XMLGrammarLoader gl = (XMLGrammarLoader)fLoaders.get(type);            // make sure gl's been set up with all the "basic" properties:            gl.setProperty(SYMBOL_TABLE, fSymbolTable);            gl.setProperty(ENTITY_RESOLVER, fEntityResolver);            gl.setProperty(ERROR_REPORTER, fErrorReporter);            // potentially, not all will support this one...            if(fGrammarPool != null) {                try {                    gl.setProperty(GRAMMAR_POOL, fGrammarPool);                } catch(Exception e) {                    // too bad...                }            }            return gl.loadGrammar(is);        }        return null;    } // preparseGrammar(String, XMLInputSource):  Grammar    /**     * Set the locale to use for messages.     *     * @param locale The locale object to use for localization of messages.     *     * @exception XNIException Thrown if the parser does not support the     *                         specified locale.     */    public void setLocale(Locale locale) {        fLocale = locale;    } // setLocale(Locale)    /** Return the Locale the XMLGrammarLoader is using. */    public Locale getLocale() {        return fLocale;    } // getLocale():  Locale    /**     * Sets the error handler.     *     * @param errorHandler The error handler.     */    public void setErrorHandler(XMLErrorHandler errorHandler) {        fErrorReporter.setProperty(ERROR_HANDLER, errorHandler);    } // setErrorHandler(XMLErrorHandler)    /** Returns the registered error handler.  */    public XMLErrorHandler getErrorHandler() {        return fErrorReporter.getErrorHandler();    } // getErrorHandler():  XMLErrorHandler    /**     * Sets the entity resolver.     *     * @param entityResolver The new entity resolver.     */    public void setEntityResolver(XMLEntityResolver entityResolver) {        fEntityResolver = entityResolver;    } // setEntityResolver(XMLEntityResolver)    /** Returns the registered entity resolver.  */    public XMLEntityResolver getEntityResolver() {        return fEntityResolver;    } // getEntityResolver():  XMLEntityResolver    /**     * Sets the grammar pool.     *     * @param grammarPool The new grammar pool.     */    public void setGrammarPool(XMLGrammarPool grammarPool) {        fGrammarPool = grammarPool;    } // setGrammarPool(XMLGrammarPool)    /** Returns the registered grammar pool.  */    public XMLGrammarPool getGrammarPool() {        return fGrammarPool;    } // getGrammarPool():  XMLGrammarPool    // it's possible the application may want access to a certain loader to do    // some custom work.    public XMLGrammarLoader getLoader(String type) {        return (XMLGrammarLoader)fLoaders.get(type);    } // getLoader(String):  XMLGrammarLoader    // set a feature.  This method tries to set it on all    // registered loaders; it eats any resulting exceptions.  If    // an app needs to know if a particular feature is supported    // by a grammar loader of a particular type, it will have    // to retrieve that loader and use the loader's setFeature method.    public void setFeature(String featureId, boolean value) {        Enumeration loaders = fLoaders.elements();        while(loaders.hasMoreElements()){            XMLGrammarLoader gl = (XMLGrammarLoader)loaders.nextElement();            try {                gl.setFeature(featureId, value);            } catch(Exception e) {                // eat it up...            }        }        // since our error reporter is a property we set later,        // make sure features it understands are also set.        if(featureId.equals(CONTINUE_AFTER_FATAL_ERROR)) {            fErrorReporter.setFeature(CONTINUE_AFTER_FATAL_ERROR, value);        }    } //setFeature(String, boolean)    // set a property.  This method tries to set it on all    // registered loaders; it eats any resulting exceptions.  If    // an app needs to know if a particular property is supported    // by a grammar loader of a particular type, it will have    // to retrieve that loader and use the loader's setProperty method.    // <p> <strong>An application should use the explicit method    // in this class to set "standard" properties like error handler etc.</strong>    public void setProperty(String propId, Object value) {        Enumeration loaders = fLoaders.elements();        while(loaders.hasMoreElements()){            XMLGrammarLoader gl = (XMLGrammarLoader)loaders.nextElement();            try {                gl.setProperty(propId, value);            } catch(Exception e) {                // eat it up...            }        }    } //setProperty(String, Object)    // get status of feature in a particular loader.  This    // catches no exceptions--including NPE's--so the application had    // better make sure the loader exists and knows about this feature.    // @param type type of grammar to look for the feature in.    // @param featureId the feature string to query.    // @return the value of the feature.    public boolean getFeature(String type, String featureId) {        XMLGrammarLoader gl = (XMLGrammarLoader)fLoaders.get(type);        return gl.getFeature(featureId);    } // getFeature (String, String):  boolean    // get status of property in a particular loader.  This    // catches no exceptions--including NPE's--so the application had    // better make sure the loader exists and knows about this property.    // <strong>For standard properties--that will be supported    // by all loaders--the specific methods should be queried!</strong>    // @param type type of grammar to look for the property in.    // @param propertyId the property string to query.    // @return the value of the property.    public Object getProperty(String type, String propertyId) {        XMLGrammarLoader gl = (XMLGrammarLoader)fLoaders.get(type);        return gl.getProperty(propertyId);    } // getProperty(String, String):  Object} // class XMLGrammarPreparser

⌨️ 快捷键说明

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