2
* Copyright 2005 The Apache Software Foundation.
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
17
package org.apache.xerces.jaxp;
19
import org.apache.xerces.impl.Constants;
20
import org.apache.xerces.impl.XMLErrorReporter;
21
import org.apache.xerces.impl.validation.ValidationManager;
22
import org.apache.xerces.impl.xs.XSMessageFormatter;
23
import org.apache.xerces.jaxp.validation.XSGrammarPoolContainer;
24
import org.apache.xerces.xni.grammars.XMLGrammarPool;
25
import org.apache.xerces.xni.parser.XMLComponentManager;
26
import org.apache.xerces.xni.parser.XMLConfigurationException;
29
* <p>Parser configuration for Xerces' XMLSchemaValidator.</p>
31
* @version $Id: SchemaValidatorConfiguration.java 320517 2005-06-22 02:03:40Z mrglavas $
33
final class SchemaValidatorConfiguration implements XMLComponentManager {
35
// feature identifiers
37
/** Feature identifier: schema validation. */
38
private static final String SCHEMA_VALIDATION =
39
Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_VALIDATION_FEATURE;
41
/** Feature identifier: validation. */
42
private static final String VALIDATION =
43
Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE;
45
/** Feature identifier: use grammar pool only. */
46
private static final String USE_GRAMMAR_POOL_ONLY =
47
Constants.XERCES_FEATURE_PREFIX + Constants.USE_GRAMMAR_POOL_ONLY_FEATURE;
49
/** Feature identifier: parser settings. */
50
private static final String PARSER_SETTINGS =
51
Constants.XERCES_FEATURE_PREFIX + Constants.PARSER_SETTINGS;
53
// property identifiers
55
/** Property identifier: error reporter. */
56
private static final String ERROR_REPORTER =
57
Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY;
59
/** Property identifier: validation manager. */
60
private static final String VALIDATION_MANAGER =
61
Constants.XERCES_PROPERTY_PREFIX + Constants.VALIDATION_MANAGER_PROPERTY;
63
/** Property identifier: grammar pool. */
64
private static final String XMLGRAMMAR_POOL =
65
Constants.XERCES_PROPERTY_PREFIX + Constants.XMLGRAMMAR_POOL_PROPERTY;
71
/** Parent component manager. **/
72
private final XMLComponentManager fParentComponentManager;
74
/** The Schema's grammar pool. **/
75
private final XMLGrammarPool fGrammarPool;
78
* Tracks whether the validator should use components from
79
* the grammar pool to the exclusion of all others.
81
private final boolean fUseGrammarPoolOnly;
83
/** Validation manager. */
84
private final ValidationManager fValidationManager;
86
public SchemaValidatorConfiguration(XMLComponentManager parentManager,
87
XSGrammarPoolContainer grammarContainer, ValidationManager validationManager) {
88
fParentComponentManager = parentManager;
89
fGrammarPool = grammarContainer.getGrammarPool();
90
fUseGrammarPoolOnly = grammarContainer.isFullyComposed();
91
fValidationManager = validationManager;
92
// add schema message formatter to error reporter
94
XMLErrorReporter errorReporter = (XMLErrorReporter) fParentComponentManager.getProperty(ERROR_REPORTER);
95
if (errorReporter != null) {
96
errorReporter.putMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN, new XSMessageFormatter());
100
catch (XMLConfigurationException exc) {}
104
* Returns the state of a feature.
106
* @param featureId The feature identifier.
107
* @return true if the feature is supported
109
* @throws XMLConfigurationException Thrown for configuration error.
110
* In general, components should
111
* only throw this exception if
112
* it is <strong>really</strong>
115
public boolean getFeature(String featureId)
116
throws XMLConfigurationException {
117
if (PARSER_SETTINGS.equals(featureId)) {
118
return fParentComponentManager.getFeature(featureId);
120
else if (VALIDATION.equals(featureId) || SCHEMA_VALIDATION.equals(featureId)) {
123
else if (USE_GRAMMAR_POOL_ONLY.equals(featureId)) {
124
return fUseGrammarPoolOnly;
126
return fParentComponentManager.getFeature(featureId);
130
* Returns the value of a property.
132
* @param propertyId The property identifier.
133
* @return the value of the property
135
* @throws XMLConfigurationException Thrown for configuration error.
136
* In general, components should
137
* only throw this exception if
138
* it is <strong>really</strong>
141
public Object getProperty(String propertyId)
142
throws XMLConfigurationException {
143
if (XMLGRAMMAR_POOL.equals(propertyId)) {
146
else if (VALIDATION_MANAGER.equals(propertyId)) {
147
return fValidationManager;
149
return fParentComponentManager.getProperty(propertyId);