001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.xerces.jaxp;
019:
020: import org.apache.xerces.impl.Constants;
021: import org.apache.xerces.impl.XMLErrorReporter;
022: import org.apache.xerces.impl.validation.ValidationManager;
023: import org.apache.xerces.impl.xs.XSMessageFormatter;
024: import org.apache.xerces.jaxp.validation.XSGrammarPoolContainer;
025: import org.apache.xerces.xni.grammars.XMLGrammarPool;
026: import org.apache.xerces.xni.parser.XMLComponentManager;
027: import org.apache.xerces.xni.parser.XMLConfigurationException;
028:
029: /**
030: * <p>Parser configuration for Xerces' XMLSchemaValidator.</p>
031: *
032: * @version $Id: SchemaValidatorConfiguration.java 447237 2006-09-18 05:03:10Z mrglavas $
033: */
034: final class SchemaValidatorConfiguration implements XMLComponentManager {
035:
036: // feature identifiers
037:
038: /** Feature identifier: schema validation. */
039: private static final String SCHEMA_VALIDATION = Constants.XERCES_FEATURE_PREFIX
040: + Constants.SCHEMA_VALIDATION_FEATURE;
041:
042: /** Feature identifier: validation. */
043: private static final String VALIDATION = Constants.SAX_FEATURE_PREFIX
044: + Constants.VALIDATION_FEATURE;
045:
046: /** Feature identifier: use grammar pool only. */
047: private static final String USE_GRAMMAR_POOL_ONLY = Constants.XERCES_FEATURE_PREFIX
048: + Constants.USE_GRAMMAR_POOL_ONLY_FEATURE;
049:
050: /** Feature identifier: parser settings. */
051: private static final String PARSER_SETTINGS = Constants.XERCES_FEATURE_PREFIX
052: + Constants.PARSER_SETTINGS;
053:
054: // property identifiers
055:
056: /** Property identifier: error reporter. */
057: private static final String ERROR_REPORTER = Constants.XERCES_PROPERTY_PREFIX
058: + Constants.ERROR_REPORTER_PROPERTY;
059:
060: /** Property identifier: validation manager. */
061: private static final String VALIDATION_MANAGER = Constants.XERCES_PROPERTY_PREFIX
062: + Constants.VALIDATION_MANAGER_PROPERTY;
063:
064: /** Property identifier: grammar pool. */
065: private static final String XMLGRAMMAR_POOL = Constants.XERCES_PROPERTY_PREFIX
066: + Constants.XMLGRAMMAR_POOL_PROPERTY;
067:
068: //
069: // Data
070: //
071:
072: /** Parent component manager. **/
073: private final XMLComponentManager fParentComponentManager;
074:
075: /** The Schema's grammar pool. **/
076: private final XMLGrammarPool fGrammarPool;
077:
078: /**
079: * Tracks whether the validator should use components from
080: * the grammar pool to the exclusion of all others.
081: */
082: private final boolean fUseGrammarPoolOnly;
083:
084: /** Validation manager. */
085: private final ValidationManager fValidationManager;
086:
087: public SchemaValidatorConfiguration(
088: XMLComponentManager parentManager,
089: XSGrammarPoolContainer grammarContainer,
090: ValidationManager validationManager) {
091: fParentComponentManager = parentManager;
092: fGrammarPool = grammarContainer.getGrammarPool();
093: fUseGrammarPoolOnly = grammarContainer.isFullyComposed();
094: fValidationManager = validationManager;
095: // add schema message formatter to error reporter
096: try {
097: XMLErrorReporter errorReporter = (XMLErrorReporter) fParentComponentManager
098: .getProperty(ERROR_REPORTER);
099: if (errorReporter != null) {
100: errorReporter.putMessageFormatter(
101: XSMessageFormatter.SCHEMA_DOMAIN,
102: new XSMessageFormatter());
103: }
104: }
105: // Ignore exception.
106: catch (XMLConfigurationException exc) {
107: }
108: }
109:
110: /**
111: * Returns the state of a feature.
112: *
113: * @param featureId The feature identifier.
114: * @return true if the feature is supported
115: *
116: * @throws XMLConfigurationException Thrown for configuration error.
117: * In general, components should
118: * only throw this exception if
119: * it is <strong>really</strong>
120: * a critical error.
121: */
122: public boolean getFeature(String featureId)
123: throws XMLConfigurationException {
124: if (PARSER_SETTINGS.equals(featureId)) {
125: return fParentComponentManager.getFeature(featureId);
126: } else if (VALIDATION.equals(featureId)
127: || SCHEMA_VALIDATION.equals(featureId)) {
128: return true;
129: } else if (USE_GRAMMAR_POOL_ONLY.equals(featureId)) {
130: return fUseGrammarPoolOnly;
131: }
132: return fParentComponentManager.getFeature(featureId);
133: }
134:
135: /**
136: * Returns the value of a property.
137: *
138: * @param propertyId The property identifier.
139: * @return the value of the property
140: *
141: * @throws XMLConfigurationException Thrown for configuration error.
142: * In general, components should
143: * only throw this exception if
144: * it is <strong>really</strong>
145: * a critical error.
146: */
147: public Object getProperty(String propertyId)
148: throws XMLConfigurationException {
149: if (XMLGRAMMAR_POOL.equals(propertyId)) {
150: return fGrammarPool;
151: } else if (VALIDATION_MANAGER.equals(propertyId)) {
152: return fValidationManager;
153: }
154: return fParentComponentManager.getProperty(propertyId);
155: }
156: }
|