KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xerces > internal > jaxp > SchemaValidatorConfiguration


1 /*
2  * Copyright 2005 The Apache Software Foundation.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */

16
17 package com.sun.org.apache.xerces.internal.jaxp;
18
19 import com.sun.org.apache.xerces.internal.impl.Constants;
20 import com.sun.org.apache.xerces.internal.impl.XMLErrorReporter;
21 import com.sun.org.apache.xerces.internal.impl.validation.ValidationManager;
22 import com.sun.org.apache.xerces.internal.impl.xs.XSMessageFormatter;
23 import com.sun.org.apache.xerces.internal.jaxp.validation.XSGrammarPoolContainer;
24 import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool;
25 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager;
26 import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException;
27
28 /**
29  * <p>Parser configuration for Xerces' XMLSchemaValidator.</p>
30  *
31  * @version $Id: SchemaValidatorConfiguration.java,v 1.1.4.1 2005/09/08 05:48:45 sunithareddy Exp $
32  */

33 final class SchemaValidatorConfiguration implements XMLComponentManager {
34     
35     // feature identifiers
36

37     /** Feature identifier: schema validation. */
38     private static final String JavaDoc SCHEMA_VALIDATION =
39         Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_VALIDATION_FEATURE;
40     
41     /** Feature identifier: validation. */
42     private static final String JavaDoc VALIDATION =
43         Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE;
44     
45     /** Feature identifier: use grammar pool only. */
46     private static final String JavaDoc USE_GRAMMAR_POOL_ONLY =
47         Constants.XERCES_FEATURE_PREFIX + Constants.USE_GRAMMAR_POOL_ONLY_FEATURE;
48     
49     /** Feature identifier: parser settings. */
50     private static final String JavaDoc PARSER_SETTINGS =
51         Constants.XERCES_FEATURE_PREFIX + Constants.PARSER_SETTINGS;
52     
53     // property identifiers
54

55     /** Property identifier: error reporter. */
56     private static final String JavaDoc ERROR_REPORTER =
57         Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY;
58     
59     /** Property identifier: validation manager. */
60     private static final String JavaDoc VALIDATION_MANAGER =
61         Constants.XERCES_PROPERTY_PREFIX + Constants.VALIDATION_MANAGER_PROPERTY;
62     
63     /** Property identifier: grammar pool. */
64     private static final String JavaDoc XMLGRAMMAR_POOL =
65         Constants.XERCES_PROPERTY_PREFIX + Constants.XMLGRAMMAR_POOL_PROPERTY;
66     
67     //
68
// Data
69
//
70

71     /** Parent component manager. **/
72     private final XMLComponentManager fParentComponentManager;
73     
74     /** The Schema's grammar pool. **/
75     private final XMLGrammarPool fGrammarPool;
76
77     /**
78      * Tracks whether the validator should use components from
79      * the grammar pool to the exclusion of all others.
80      */

81     private final boolean fUseGrammarPoolOnly;
82     
83     /** Validation manager. */
84     private final ValidationManager fValidationManager;
85     
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
93
try {
94             XMLErrorReporter errorReporter = (XMLErrorReporter) fParentComponentManager.getProperty(ERROR_REPORTER);
95             if (errorReporter != null) {
96                 errorReporter.putMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN, new XSMessageFormatter());
97             }
98         }
99         // Ignore exception.
100
catch (XMLConfigurationException exc) {}
101     }
102     
103     /**
104      * Returns the state of a feature.
105      *
106      * @param featureId The feature identifier.
107      * @return true if the feature is supported
108      *
109      * @throws XMLConfigurationException Thrown for configuration error.
110      * In general, components should
111      * only throw this exception if
112      * it is <strong>really</strong>
113      * a critical error.
114      */

115     public boolean getFeature(String JavaDoc featureId)
116             throws XMLConfigurationException {
117         if (PARSER_SETTINGS.equals(featureId)) {
118             return fParentComponentManager.getFeature(featureId);
119         }
120         else if (VALIDATION.equals(featureId) || SCHEMA_VALIDATION.equals(featureId)) {
121             return true;
122         }
123         else if (USE_GRAMMAR_POOL_ONLY.equals(featureId)) {
124             return fUseGrammarPoolOnly;
125         }
126         return fParentComponentManager.getFeature(featureId);
127     }
128
129     /**
130      * Returns the value of a property.
131      *
132      * @param propertyId The property identifier.
133      * @return the value of the property
134      *
135      * @throws XMLConfigurationException Thrown for configuration error.
136      * In general, components should
137      * only throw this exception if
138      * it is <strong>really</strong>
139      * a critical error.
140      */

141     public Object JavaDoc getProperty(String JavaDoc propertyId)
142             throws XMLConfigurationException {
143         if (XMLGRAMMAR_POOL.equals(propertyId)) {
144             return fGrammarPool;
145         }
146         else if (VALIDATION_MANAGER.equals(propertyId)) {
147             return fValidationManager;
148         }
149         return fParentComponentManager.getProperty(propertyId);
150     }
151 }
152
Popular Tags