~ubuntu-branches/ubuntu/karmic/libxerces2-java/karmic

« back to all changes in this revision

Viewing changes to src/org/apache/xerces/jaxp/SchemaValidatorConfiguration.java

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2006-12-04 17:37:55 UTC
  • mfrom: (2.1.2 etch)
  • Revision ID: james.westby@ubuntu.com-20061204173755-hb6ybrrrk097zhx7
Tags: 2.8.1-1ubuntu1
* Merge with Debian unstable; remaining changes:
  - Build -gcj package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 org.apache.xerces.jaxp;
 
18
 
 
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;
 
27
 
 
28
/**
 
29
 * <p>Parser configuration for Xerces' XMLSchemaValidator.</p>
 
30
 * 
 
31
 * @version $Id: SchemaValidatorConfiguration.java 320517 2005-06-22 02:03:40Z mrglavas $
 
32
 */
 
33
final class SchemaValidatorConfiguration implements XMLComponentManager {
 
34
    
 
35
    // feature identifiers
 
36
    
 
37
    /** Feature identifier: schema validation. */
 
38
    private static final String SCHEMA_VALIDATION =
 
39
        Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_VALIDATION_FEATURE;
 
40
    
 
41
    /** Feature identifier: validation. */
 
42
    private static final String VALIDATION =
 
43
        Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE;
 
44
    
 
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;
 
48
    
 
49
    /** Feature identifier: parser settings. */
 
50
    private static final String 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 ERROR_REPORTER =
 
57
        Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY;
 
58
    
 
59
    /** Property identifier: validation manager. */
 
60
    private static final String VALIDATION_MANAGER =
 
61
        Constants.XERCES_PROPERTY_PREFIX + Constants.VALIDATION_MANAGER_PROPERTY;
 
62
    
 
63
    /** Property identifier: grammar pool. */
 
64
    private static final String 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 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 getProperty(String 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
}