xmlschemafactory.java

来自「JAVA 所有包」· Java 代码 · 共 436 行 · 第 1/2 页

JAVA
436
字号
        // Clear reference to grammar pool.        fXMLGrammarPoolWrapper.setGrammarPool(null);                // Select Schema implementation based on grammar count.        final int grammarCount = pool.getGrammarCount();        if (grammarCount > 1) {            return new XMLSchema(new ReadOnlyGrammarPool(pool));        }        else if (grammarCount == 1) {            Grammar[] grammars = pool.retrieveInitialGrammarSet(XMLGrammarDescription.XML_SCHEMA);            return new SimpleXMLSchema(grammars[0]);        }        else {            return EmptyXMLSchema.getInstance();        }    }        public Schema newSchema() throws SAXException {        // Use a Schema that uses the system id as the equality source.        return new WeakReferenceXMLSchema();    }        public boolean getFeature(String name)         throws SAXNotRecognizedException, SAXNotSupportedException {        if (name == null) {            throw new NullPointerException(JAXPValidationMessageFormatter.formatMessage(Locale.getDefault(),                     "FeatureNameNull", null));        }        if (name.equals(XMLConstants.FEATURE_SECURE_PROCESSING)) {            return (fSecurityManager != null);        }        try {            return fXMLSchemaLoader.getFeature(name);        }        catch (XMLConfigurationException e) {            String identifier = e.getIdentifier();            if (e.getType() == XMLConfigurationException.NOT_RECOGNIZED) {                throw new SAXNotRecognizedException(                        SAXMessageFormatter.formatMessage(Locale.getDefault(),                         "feature-not-recognized", new Object [] {identifier}));            }            else {                throw new SAXNotSupportedException(                        SAXMessageFormatter.formatMessage(Locale.getDefault(),                         "feature-not-supported", new Object [] {identifier}));            }        }    }        public Object getProperty(String name)         throws SAXNotRecognizedException, SAXNotSupportedException {        if (name == null) {            throw new NullPointerException(JAXPValidationMessageFormatter.formatMessage(Locale.getDefault(),                     "ProperyNameNull", null));        }        if (name.equals(SECURITY_MANAGER)) {            return fSecurityManager;        }        else if (name.equals(XMLGRAMMAR_POOL)) {            throw new SAXNotSupportedException(                    SAXMessageFormatter.formatMessage(Locale.getDefault(),                     "property-not-supported", new Object [] {name}));        }        try {            return fXMLSchemaLoader.getProperty(name);        }        catch (XMLConfigurationException e) {            String identifier = e.getIdentifier();            if (e.getType() == XMLConfigurationException.NOT_RECOGNIZED) {                throw new SAXNotRecognizedException(                        SAXMessageFormatter.formatMessage(Locale.getDefault(),                         "property-not-recognized", new Object [] {identifier}));            }            else {                throw new SAXNotSupportedException(                        SAXMessageFormatter.formatMessage(Locale.getDefault(),                         "property-not-supported", new Object [] {identifier}));            }        }    }        public void setFeature(String name, boolean value)        throws SAXNotRecognizedException, SAXNotSupportedException {        if (name == null) {            throw new NullPointerException(JAXPValidationMessageFormatter.formatMessage(Locale.getDefault(),                     "FeatureNameNull", null));        }        if (name.equals(XMLConstants.FEATURE_SECURE_PROCESSING)) {            fSecurityManager = value ? new SecurityManager() : null;            fXMLSchemaLoader.setProperty(SECURITY_MANAGER, fSecurityManager);            return;        }        try {            fXMLSchemaLoader.setFeature(name, value);        }        catch (XMLConfigurationException e) {            String identifier = e.getIdentifier();            if (e.getType() == XMLConfigurationException.NOT_RECOGNIZED) {                throw new SAXNotRecognizedException(                        SAXMessageFormatter.formatMessage(Locale.getDefault(),                         "feature-not-recognized", new Object [] {identifier}));            }            else {                throw new SAXNotSupportedException(                        SAXMessageFormatter.formatMessage(Locale.getDefault(),                         "feature-not-supported", new Object [] {identifier}));            }        }    }        public void setProperty(String name, Object object)        throws SAXNotRecognizedException, SAXNotSupportedException {        if (name == null) {            throw new NullPointerException(JAXPValidationMessageFormatter.formatMessage(Locale.getDefault(),                     "ProperyNameNull", null));        }        if (name.equals(SECURITY_MANAGER)) {            fSecurityManager = (SecurityManager) object;            fXMLSchemaLoader.setProperty(SECURITY_MANAGER, fSecurityManager);            return;        }        else if (name.equals(XMLGRAMMAR_POOL)) {            throw new SAXNotSupportedException(                    SAXMessageFormatter.formatMessage(Locale.getDefault(),                     "property-not-supported", new Object [] {name}));        }        try {            fXMLSchemaLoader.setProperty(name, object);        }        catch (XMLConfigurationException e) {            String identifier = e.getIdentifier();            if (e.getType() == XMLConfigurationException.NOT_RECOGNIZED) {                throw new SAXNotRecognizedException(                        SAXMessageFormatter.formatMessage(Locale.getDefault(),                         "property-not-recognized", new Object [] {identifier}));            }            else {                throw new SAXNotSupportedException(                        SAXMessageFormatter.formatMessage(Locale.getDefault(),                         "property-not-supported", new Object [] {identifier}));            }        }    }        /**      * Extension of XMLGrammarPoolImpl which exposes the number of     * grammars stored in the grammar pool.     */    static class XMLGrammarPoolImplExtension extends XMLGrammarPoolImpl {                /** Constructs a grammar pool with a default number of buckets. */        public XMLGrammarPoolImplExtension() {            super();        }        /** Constructs a grammar pool with a specified number of buckets. */        public XMLGrammarPoolImplExtension(int initialCapacity) {            super(initialCapacity);        }                /** Returns the number of grammars contained in this pool. */        int getGrammarCount() {            return fGrammarCount;        }            } // XMLSchemaFactory.XMLGrammarPoolImplExtension        /**     * A grammar pool which wraps another.     */    static class XMLGrammarPoolWrapper implements XMLGrammarPool {        private XMLGrammarPool fGrammarPool;                /*         * XMLGrammarPool methods         */                public Grammar[] retrieveInitialGrammarSet(String grammarType) {            return fGrammarPool.retrieveInitialGrammarSet(grammarType);        }        public void cacheGrammars(String grammarType, Grammar[] grammars) {            fGrammarPool.cacheGrammars(grammarType, grammars);        }        public Grammar retrieveGrammar(XMLGrammarDescription desc) {            return fGrammarPool.retrieveGrammar(desc);        }        public void lockPool() {            fGrammarPool.lockPool();        }        public void unlockPool() {            fGrammarPool.unlockPool();        }        public void clear() {            fGrammarPool.clear();        }                /*         * Other methods         */                void setGrammarPool(XMLGrammarPool grammarPool) {            fGrammarPool = grammarPool;        }                XMLGrammarPool getGrammarPool() {            return fGrammarPool;        }            } // XMLSchemaFactory.XMLGrammarPoolWrapper    } // XMLSchemaFactory

⌨️ 快捷键说明

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