FileDocCategorySizeDatePackage
XMLSchemaValidatorComponentManager.javaAPI DocJava SE 6 API17685Tue Jun 10 00:22:48 BST 2008com.sun.org.apache.xerces.internal.jaxp.validation

XMLSchemaValidatorComponentManager

public final class XMLSchemaValidatorComponentManager extends ParserConfigurationSettings implements XMLComponentManager

An implementation of XMLComponentManager for a schema validator.

author
Michael Glavassevich, IBM
version
$Id: XMLSchemaValidatorComponentManager.java,v 1.1.4.1 2005/09/05 11:48:40 sunithareddy Exp $

Fields Summary
private static final String
SCHEMA_VALIDATION
Feature identifier: schema validation.
private static final String
VALIDATION
Feature identifier: validation.
private static final String
USE_GRAMMAR_POOL_ONLY
Feature identifier: use grammar pool only.
private static final String
ENTITY_MANAGER
Property identifier: entity manager.
private static final String
ENTITY_RESOLVER
Property identifier: entity resolver.
private static final String
ERROR_HANDLER
Property identifier: error handler.
private static final String
ERROR_REPORTER
Property identifier: error reporter.
private static final String
NAMESPACE_CONTEXT
Property identifier: namespace context.
private static final String
SCHEMA_VALIDATOR
Property identifier: XML Schema validator.
private static final String
SECURITY_MANAGER
Property identifier: security manager.
private static final String
SYMBOL_TABLE
Property identifier: symbol table.
private static final String
VALIDATION_MANAGER
Property identifier: validation manager.
private static final String
XMLGRAMMAR_POOL
Property identifier: grammar pool.
private boolean
fConfigUpdated
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
fUseGrammarPoolOnly
Tracks whether the validator should use components from the grammar pool to the exclusion of all others.
private final HashMap
fComponents
Lookup map for components required for validation.
private XMLEntityManager
fEntityManager
Entity manager.
private XMLErrorReporter
fErrorReporter
Error reporter.
private NamespaceContext
fNamespaceContext
Namespace context.
private XMLSchemaValidator
fSchemaValidator
XML Schema validator.
private ValidationManager
fValidationManager
Validation manager.
private ErrorHandler
fErrorHandler
Application's ErrorHandler.
private LSResourceResolver
fResourceResolver
Application's LSResourceResolver.
Constructors Summary
public XMLSchemaValidatorComponentManager(XSGrammarPoolContainer grammarContainer)
Constructs a component manager suitable for Xerces' schema validator.

    
              
       
        // 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); 
    
Methods Summary
public voidaddRecognizedParamsAndSetDefaults(com.sun.org.apache.xerces.internal.xni.parser.XMLComponent component)
Adds all of the component's recognized features and properties to the list of default recognized features and properties, and sets default values on the configuration for features and properties which were previously absent from the configuration.

param
component The component whose recognized features and properties will be added to the configuration

        
        // register component's recognized features
        final String[] recognizedFeatures = component.getRecognizedFeatures();
        addRecognizedFeatures(recognizedFeatures);
        
        // register component's recognized properties
        final String[] recognizedProperties = component.getRecognizedProperties();
        addRecognizedProperties(recognizedProperties);

        // set default values
        setFeatureDefaults(component, recognizedFeatures);
        setPropertyDefaults(component, recognizedProperties);
    
org.xml.sax.ErrorHandlergetErrorHandler()

        return fErrorHandler;
    
public booleangetFeature(java.lang.String featureId)
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 really a critical error.

        if (PARSER_SETTINGS.equals(featureId)) {
            return fConfigUpdated;
        }
        else if (VALIDATION.equals(featureId) || SCHEMA_VALIDATION.equals(featureId)) {
            return true;
        }
        else if (USE_GRAMMAR_POOL_ONLY.equals(featureId)) {
            return fUseGrammarPoolOnly;
        }
        else if (XMLConstants.FEATURE_SECURE_PROCESSING.equals(featureId)) {
            return getProperty(SECURITY_MANAGER) != null;
        }
        return super.getFeature(featureId);
    
public java.lang.ObjectgetProperty(java.lang.String propertyId)
Returns the value of a property.

param
propertyId The property identifier.
return
the value of the property
throws
XMLConfigurationException Thrown for configuration error. In general, components should only throw this exception if it is really a critical error.

        final Object component = fComponents.get(propertyId);
        if (component != null) {
            return component;
        }
        else if (fComponents.containsKey(propertyId)) {
            return null;
        }
        return super.getProperty(propertyId);
    
public org.w3c.dom.ls.LSResourceResolvergetResourceResolver()

        return fResourceResolver;
    
public voidreset()
Calls reset on each of the components owned by this component manager.

        fNamespaceContext.reset();
        fValidationManager.reset();
        fEntityManager.reset(this);
        fErrorReporter.reset(this);
        fSchemaValidator.reset(this);
        // Mark configuration as fixed.
        fConfigUpdated = false;
    
voidrestoreInitialState()
Cleans out configuration, restoring it to its initial state.

        fConfigUpdated = true;
        
        // Clear feature and property tables.
        fFeatures.clear();
        fProperties.clear();
        
        // Remove error resolver and error handler
        fComponents.put(ENTITY_RESOLVER, null);
        fComponents.put(ERROR_HANDLER, null);
        
        // Restore component defaults.
        setFeatureDefaults(fEntityManager, fEntityManager.getRecognizedFeatures());
        setPropertyDefaults(fEntityManager, fEntityManager.getRecognizedProperties());
        setFeatureDefaults(fErrorReporter, fErrorReporter.getRecognizedFeatures());
        setPropertyDefaults(fErrorReporter, fErrorReporter.getRecognizedProperties());
        setFeatureDefaults(fSchemaValidator, fSchemaValidator.getRecognizedFeatures());
        setPropertyDefaults(fSchemaValidator, fSchemaValidator.getRecognizedProperties());
    
voidsetErrorHandler(org.xml.sax.ErrorHandler errorHandler)

        fErrorHandler = errorHandler;
        setProperty(ERROR_HANDLER, (errorHandler != null) ? new ErrorHandlerWrapper(errorHandler) : 
                new ErrorHandlerWrapper(DraconianErrorHandler.getInstance()));
    
public voidsetFeature(java.lang.String featureId, boolean value)
Set the state of a feature.

param
featureId The unique identifier (URI) of the feature.
param
state The requested state of the feature (true or false).
exception
XMLConfigurationException If the requested feature is not known.

        if (PARSER_SETTINGS.equals(featureId)) {
            throw new XMLConfigurationException(XMLConfigurationException.NOT_SUPPORTED, featureId);
        }
        else if (value == false && (VALIDATION.equals(featureId) || SCHEMA_VALIDATION.equals(featureId))) {
            throw new XMLConfigurationException(XMLConfigurationException.NOT_SUPPORTED, featureId);
        }
        else if (USE_GRAMMAR_POOL_ONLY.equals(featureId) && value != fUseGrammarPoolOnly) {
            throw new XMLConfigurationException(XMLConfigurationException.NOT_SUPPORTED, featureId);
        }
        fConfigUpdated = true;
        if (XMLConstants.FEATURE_SECURE_PROCESSING.equals(featureId)) {
            setProperty(SECURITY_MANAGER, value ? new SecurityManager() : null);
            return;
        }
        fEntityManager.setFeature(featureId, value);
        fErrorReporter.setFeature(featureId, value);
        fSchemaValidator.setFeature(featureId, value);
        super.setFeature(featureId, value);
    
private voidsetFeatureDefaults(com.sun.org.apache.xerces.internal.xni.parser.XMLComponent component, java.lang.String[] recognizedFeatures)
Sets feature defaults for the given component on this configuration.

        if (recognizedFeatures != null) {
            for (int i = 0; i < recognizedFeatures.length; ++i) {
                String featureId = recognizedFeatures[i];
                Boolean state = component.getFeatureDefault(featureId);
                if (state != null) {
                    // Do not overwrite values already set on the configuration.
                    if (!fFeatures.containsKey(featureId)) {
                        fFeatures.put(featureId, state);
                        // For newly added components who recognize this feature
                        // but did not offer a default value, we need to make
                        // sure these components will get an opportunity to read
                        // the value before parsing begins.
                        fConfigUpdated = true;
                    }
                }
            }
        }
    
public voidsetProperty(java.lang.String propertyId, java.lang.Object value)
Sets the state of a property.

param
propertyId The unique identifier (URI) of the property.
param
value The requested state of the property.
exception
XMLConfigurationException If the requested property is not known.

        if ( ENTITY_MANAGER.equals(propertyId) || ERROR_REPORTER.equals(propertyId) ||
             NAMESPACE_CONTEXT.equals(propertyId) || SCHEMA_VALIDATOR.equals(propertyId) ||
             SYMBOL_TABLE.equals(propertyId) || VALIDATION_MANAGER.equals(propertyId) ||
             XMLGRAMMAR_POOL.equals(propertyId)) {
            throw new XMLConfigurationException(XMLConfigurationException.NOT_SUPPORTED, propertyId);
        }
        fConfigUpdated = true;
        fEntityManager.setProperty(propertyId, value);
        fErrorReporter.setProperty(propertyId, value);
        fSchemaValidator.setProperty(propertyId, value);
        if (ENTITY_RESOLVER.equals(propertyId) || ERROR_HANDLER.equals(propertyId) || 
                SECURITY_MANAGER.equals(propertyId)) {
            fComponents.put(propertyId, value);
            return;
        }
        super.setProperty(propertyId, value);
    
private voidsetPropertyDefaults(com.sun.org.apache.xerces.internal.xni.parser.XMLComponent component, java.lang.String[] recognizedProperties)
Sets property defaults for the given component on this configuration.

        if (recognizedProperties != null) {
            for (int i = 0; i < recognizedProperties.length; ++i) {
                String propertyId = recognizedProperties[i];
                Object value = component.getPropertyDefault(propertyId);
                if (value != null) {
                    // Do not overwrite values already set on the configuration.
                    if (!fProperties.containsKey(propertyId)) {
                        fProperties.put(propertyId, value);
                        // For newly added components who recognize this property
                        // but did not offer a default value, we need to make
                        // sure these components will get an opportunity to read
                        // the value before parsing begins.
                        fConfigUpdated = true;
                    }
                }
            }
        }
    
voidsetResourceResolver(org.w3c.dom.ls.LSResourceResolver resourceResolver)

        fResourceResolver = resourceResolver;
        setProperty(ENTITY_RESOLVER, new DOMEntityResolverWrapper(resourceResolver));