XMLSchemaValidatorComponentManagerpublic final class XMLSchemaValidatorComponentManager extends ParserConfigurationSettings implements XMLComponentManagerAn implementation of XMLComponentManager for a schema validator. |
Fields Summary |
---|
private static final String | SCHEMA_VALIDATIONFeature identifier: schema validation. | private static final String | VALIDATIONFeature identifier: validation. | private static final String | USE_GRAMMAR_POOL_ONLYFeature identifier: use grammar pool only. | private static final String | ENTITY_MANAGERProperty identifier: entity manager. | private static final String | ENTITY_RESOLVERProperty identifier: entity resolver. | private static final String | ERROR_HANDLERProperty identifier: error handler. | private static final String | ERROR_REPORTERProperty identifier: error reporter. | private static final String | NAMESPACE_CONTEXTProperty identifier: namespace context. | private static final String | SCHEMA_VALIDATORProperty identifier: XML Schema validator. | private static final String | SECURITY_MANAGERProperty identifier: security manager. | private static final String | SYMBOL_TABLEProperty identifier: symbol table. | private static final String | VALIDATION_MANAGERProperty identifier: validation manager. | private static final String | XMLGRAMMAR_POOLProperty identifier: grammar pool. | private boolean | fConfigUpdatedfConfigUpdated 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 | fUseGrammarPoolOnlyTracks whether the validator should use components from
the grammar pool to the exclusion of all others. | private final HashMap | fComponentsLookup map for components required for validation. | private XMLEntityManager | fEntityManagerEntity manager. | private XMLErrorReporter | fErrorReporterError reporter. | private NamespaceContext | fNamespaceContextNamespace context. | private XMLSchemaValidator | fSchemaValidatorXML Schema validator. | private ValidationManager | fValidationManagerValidation manager. | private ErrorHandler | fErrorHandlerApplication's ErrorHandler. | private LSResourceResolver | fResourceResolverApplication'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 void | addRecognizedParamsAndSetDefaults(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.
// 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.ErrorHandler | getErrorHandler()
return fErrorHandler;
| public boolean | getFeature(java.lang.String featureId)Returns the state of a feature.
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.Object | getProperty(java.lang.String propertyId)Returns the value of a property.
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.LSResourceResolver | getResourceResolver()
return fResourceResolver;
| public void | reset()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;
| void | restoreInitialState()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());
| void | setErrorHandler(org.xml.sax.ErrorHandler errorHandler)
fErrorHandler = errorHandler;
setProperty(ERROR_HANDLER, (errorHandler != null) ? new ErrorHandlerWrapper(errorHandler) :
new ErrorHandlerWrapper(DraconianErrorHandler.getInstance()));
| public void | setFeature(java.lang.String featureId, boolean value)Set the state of a feature.
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 void | setFeatureDefaults(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 void | setProperty(java.lang.String propertyId, java.lang.Object value)Sets the state of a property.
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 void | setPropertyDefaults(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;
}
}
}
}
| void | setResourceResolver(org.w3c.dom.ls.LSResourceResolver resourceResolver)
fResourceResolver = resourceResolver;
setProperty(ENTITY_RESOLVER, new DOMEntityResolverWrapper(resourceResolver));
|
|