xmlschemavalidatorcomponentmanager.java
来自「JAVA 所有包」· Java 代码 · 共 420 行 · 第 1/2 页
JAVA
420 行
/* * Copyright 2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package com.sun.org.apache.xerces.internal.jaxp.validation;import java.util.HashMap;import javax.xml.XMLConstants;import com.sun.org.apache.xerces.internal.impl.Constants;import com.sun.org.apache.xerces.internal.impl.XMLEntityManager;import com.sun.org.apache.xerces.internal.impl.XMLErrorReporter;import com.sun.org.apache.xerces.internal.impl.validation.ValidationManager;import com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator;import com.sun.org.apache.xerces.internal.impl.xs.XSMessageFormatter;import com.sun.org.apache.xerces.internal.util.DOMEntityResolverWrapper;import com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper;import com.sun.org.apache.xerces.internal.util.NamespaceSupport;import com.sun.org.apache.xerces.internal.util.ParserConfigurationSettings;import com.sun.org.apache.xerces.internal.util.SecurityManager;import com.sun.org.apache.xerces.internal.util.SymbolTable;import com.sun.org.apache.xerces.internal.xni.NamespaceContext;import com.sun.org.apache.xerces.internal.xni.XNIException;import com.sun.org.apache.xerces.internal.xni.parser.XMLComponent;import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager;import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException;import org.w3c.dom.ls.LSResourceResolver;import org.xml.sax.ErrorHandler;/** * <p>An implementation of XMLComponentManager for a schema validator.</p> * * @author Michael Glavassevich, IBM * @version $Id: XMLSchemaValidatorComponentManager.java,v 1.1.4.1 2005/09/05 11:48:40 sunithareddy Exp $ */final class XMLSchemaValidatorComponentManager extends ParserConfigurationSettings implements XMLComponentManager { // feature identifiers /** Feature identifier: schema validation. */ private static final String SCHEMA_VALIDATION = Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_VALIDATION_FEATURE; /** Feature identifier: validation. */ private static final String VALIDATION = Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE; /** Feature identifier: use grammar pool only. */ private static final String USE_GRAMMAR_POOL_ONLY = Constants.XERCES_FEATURE_PREFIX + Constants.USE_GRAMMAR_POOL_ONLY_FEATURE; // property identifiers /** Property identifier: entity manager. */ private static final String ENTITY_MANAGER = Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_MANAGER_PROPERTY; /** Property identifier: entity resolver. */ private static final String ENTITY_RESOLVER = Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_RESOLVER_PROPERTY; /** Property identifier: error handler. */ private static final String ERROR_HANDLER = Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_HANDLER_PROPERTY; /** Property identifier: error reporter. */ private static final String ERROR_REPORTER = Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY; /** Property identifier: namespace context. */ private static final String NAMESPACE_CONTEXT = Constants.XERCES_PROPERTY_PREFIX + Constants.NAMESPACE_CONTEXT_PROPERTY; /** Property identifier: XML Schema validator. */ private static final String SCHEMA_VALIDATOR = Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_VALIDATOR_PROPERTY; /** Property identifier: security manager. */ private static final String SECURITY_MANAGER = Constants.XERCES_PROPERTY_PREFIX + Constants.SECURITY_MANAGER_PROPERTY; /** Property identifier: symbol table. */ private static final String SYMBOL_TABLE = Constants.XERCES_PROPERTY_PREFIX + Constants.SYMBOL_TABLE_PROPERTY; /** Property identifier: validation manager. */ private static final String VALIDATION_MANAGER = Constants.XERCES_PROPERTY_PREFIX + Constants.VALIDATION_MANAGER_PROPERTY; /** Property identifier: grammar pool. */ private static final String XMLGRAMMAR_POOL = Constants.XERCES_PROPERTY_PREFIX + Constants.XMLGRAMMAR_POOL_PROPERTY; // // Data // /** * fConfigUpdated is set to true if there has been any change to the configuration settings, * i.e a feature or a property was changed. */ private boolean fConfigUpdated = true; /** * Tracks whether the validator should use components from * the grammar pool to the exclusion of all others. */ private boolean fUseGrammarPoolOnly; /** Lookup map for components required for validation. **/ private final HashMap fComponents = new HashMap(); // // Components // /** Entity manager. */ private XMLEntityManager fEntityManager; /** Error reporter. */ private XMLErrorReporter fErrorReporter; /** Namespace context. */ private NamespaceContext fNamespaceContext; /** XML Schema validator. */ private XMLSchemaValidator fSchemaValidator; /** Validation manager. */ private ValidationManager fValidationManager; // // User Objects // /** Application's ErrorHandler. **/ private ErrorHandler fErrorHandler = null; /** Application's LSResourceResolver. */ private LSResourceResolver fResourceResolver = null; /** Constructs a component manager suitable for Xerces' schema validator. */ public XMLSchemaValidatorComponentManager(XSGrammarPoolContainer grammarContainer) { // setup components fEntityManager = new XMLEntityManager(); fComponents.put(ENTITY_MANAGER, fEntityManager); fErrorReporter = new XMLErrorReporter(); fComponents.put(ERROR_REPORTER, fErrorReporter); fNamespaceContext = new NamespaceSupport(); fComponents.put(NAMESPACE_CONTEXT, fNamespaceContext); fSchemaValidator = new XMLSchemaValidator(); fComponents.put(SCHEMA_VALIDATOR, fSchemaValidator); fValidationManager = new ValidationManager(); fComponents.put(VALIDATION_MANAGER, fValidationManager); // setup other properties fComponents.put(ENTITY_RESOLVER, null); fComponents.put(ERROR_HANDLER, null); fComponents.put(SECURITY_MANAGER, null); fComponents.put(SYMBOL_TABLE, new SymbolTable()); // setup grammar pool fComponents.put(XMLGRAMMAR_POOL, grammarContainer.getGrammarPool()); fUseGrammarPoolOnly = grammarContainer.isFullyComposed(); // add schema message formatter to error reporter fErrorReporter.putMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN, new XSMessageFormatter()); // add all recognized features and properties and apply their defaults addRecognizedParamsAndSetDefaults(fEntityManager); addRecognizedParamsAndSetDefaults(fErrorReporter); addRecognizedParamsAndSetDefaults(fSchemaValidator); } /** * Returns the state of a feature. * * @param featureId The feature identifier. * @return true if the feature is supported * * @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 { if (PARSER_SETTINGS.equals(featureId)) { return fConfigUpdated; } else if (VALIDATION.equals(featureId) || SCHEMA_VALIDATION.equals(featureId)) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?