~vcs-imports/xena/trunk

« back to all changes in this revision

Viewing changes to ext/src/xerces-2_9_1/src/org/apache/xerces/parsers/IntegratedParserConfiguration.java

  • Committer: matthewoliver
  • Date: 2009-12-10 03:18:07 UTC
  • Revision ID: vcs-imports@canonical.com-20091210031807-l086qguzdlljtkl9
Merged Xena Testing into Xena Stable for the Xena 5 release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
 
3
 * contributor license agreements.  See the NOTICE file distributed with
 
4
 * this work for additional information regarding copyright ownership.
 
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
 
6
 * (the "License"); you may not use this file except in compliance with
 
7
 * the License.  You may obtain a copy of the License at
 
8
 * 
 
9
 *      http://www.apache.org/licenses/LICENSE-2.0
 
10
 * 
 
11
 * Unless required by applicable law or agreed to in writing, software
 
12
 * distributed under the License is distributed on an "AS IS" BASIS,
 
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
14
 * See the License for the specific language governing permissions and
 
15
 * limitations under the License.
 
16
 */
 
17
 
 
18
package org.apache.xerces.parsers;
 
19
 
 
20
import org.apache.xerces.impl.XMLDocumentScannerImpl;
 
21
import org.apache.xerces.impl.XMLNSDocumentScannerImpl;
 
22
import org.apache.xerces.impl.dtd.XMLDTDValidator;
 
23
import org.apache.xerces.impl.dtd.XMLNSDTDValidator;
 
24
import org.apache.xerces.impl.xs.XMLSchemaValidator;
 
25
import org.apache.xerces.impl.xs.XSMessageFormatter;
 
26
import org.apache.xerces.util.SymbolTable;
 
27
import org.apache.xerces.xni.grammars.XMLGrammarPool;
 
28
import org.apache.xerces.xni.parser.XMLComponent;
 
29
import org.apache.xerces.xni.parser.XMLComponentManager;
 
30
import org.apache.xerces.xni.parser.XMLDocumentScanner;
 
31
 
 
32
/**
 
33
 * This is configuration uses a scanner that integrates both scanning of the document
 
34
 * and binding namespaces.
 
35
 *
 
36
 * If namespace feature is turned on, the pipeline is constructured with the 
 
37
 * following components:
 
38
 * XMLNSDocumentScannerImpl -> XMLNSDTDValidator -> (optional) XMLSchemaValidator
 
39
 * 
 
40
 * If the namespace feature is turned off the default document scanner implementation
 
41
 * is used (XMLDocumentScannerImpl).
 
42
 * <p>
 
43
 * In addition to the features and properties recognized by the base
 
44
 * parser configuration, this class recognizes these additional 
 
45
 * features and properties:
 
46
 * <ul>
 
47
 * <li>Features
 
48
 *  <ul>
 
49
 *  <li>http://apache.org/xml/features/validation/schema</li>
 
50
 *  <li>http://apache.org/xml/features/validation/schema-full-checking</li>
 
51
 *  <li>http://apache.org/xml/features/validation/schema/normalized-value</li>
 
52
 *  <li>http://apache.org/xml/features/validation/schema/element-default</li>
 
53
 *  </ul>
 
54
 * <li>Properties
 
55
 *  <ul>
 
56
 *   <li>http://apache.org/xml/properties/internal/error-reporter</li>
 
57
 *   <li>http://apache.org/xml/properties/internal/entity-manager</li>
 
58
 *   <li>http://apache.org/xml/properties/internal/document-scanner</li>
 
59
 *   <li>http://apache.org/xml/properties/internal/dtd-scanner</li>
 
60
 *   <li>http://apache.org/xml/properties/internal/grammar-pool</li>
 
61
 *   <li>http://apache.org/xml/properties/internal/validator/dtd</li>
 
62
 *   <li>http://apache.org/xml/properties/internal/datatype-validator-factory</li>
 
63
 *  </ul>
 
64
 * </ul>
 
65
 *
 
66
 * @author Elena Litani, IBM
 
67
 *
 
68
 * @version $Id: IntegratedParserConfiguration.java,v 1.2 2009/12/10 03:18:31 matthewoliver Exp $
 
69
 */
 
70
public class IntegratedParserConfiguration
 
71
extends StandardParserConfiguration {
 
72
 
 
73
 
 
74
    //
 
75
    // REVISIT: should this configuration depend on the others
 
76
    //          like DTD/Standard one?
 
77
    //
 
78
 
 
79
    /** Document scanner that does namespace binding. */
 
80
    protected XMLNSDocumentScannerImpl fNamespaceScanner;
 
81
 
 
82
    /** Default Xerces implementation of scanner */
 
83
    protected XMLDocumentScannerImpl fNonNSScanner;
 
84
 
 
85
    /** DTD Validator that does not bind namespaces */
 
86
    protected XMLDTDValidator fNonNSDTDValidator;
 
87
    
 
88
    //
 
89
    // Constructors
 
90
    //
 
91
 
 
92
    /** Default constructor. */
 
93
    public IntegratedParserConfiguration() {
 
94
        this(null, null, null);
 
95
    } // <init>()
 
96
 
 
97
    /** 
 
98
     * Constructs a parser configuration using the specified symbol table. 
 
99
     *
 
100
     * @param symbolTable The symbol table to use.
 
101
     */
 
102
    public IntegratedParserConfiguration(SymbolTable symbolTable) {
 
103
        this(symbolTable, null, null);
 
104
    } // <init>(SymbolTable)
 
105
 
 
106
    /**
 
107
     * Constructs a parser configuration using the specified symbol table and
 
108
     * grammar pool.
 
109
     * <p>
 
110
     * <strong>REVISIT:</strong> 
 
111
     * Grammar pool will be updated when the new validation engine is
 
112
     * implemented.
 
113
     *
 
114
     * @param symbolTable The symbol table to use.
 
115
     * @param grammarPool The grammar pool to use.
 
116
     */
 
117
    public IntegratedParserConfiguration(SymbolTable symbolTable,
 
118
                                         XMLGrammarPool grammarPool) {
 
119
        this(symbolTable, grammarPool, null);
 
120
    } // <init>(SymbolTable,XMLGrammarPool)
 
121
 
 
122
    /**
 
123
     * Constructs a parser configuration using the specified symbol table,
 
124
     * grammar pool, and parent settings.
 
125
     * <p>
 
126
     * <strong>REVISIT:</strong> 
 
127
     * Grammar pool will be updated when the new validation engine is
 
128
     * implemented.
 
129
     *
 
130
     * @param symbolTable    The symbol table to use.
 
131
     * @param grammarPool    The grammar pool to use.
 
132
     * @param parentSettings The parent settings.
 
133
     */
 
134
    public IntegratedParserConfiguration(SymbolTable symbolTable,
 
135
                                         XMLGrammarPool grammarPool,
 
136
                                         XMLComponentManager parentSettings) {
 
137
        super(symbolTable, grammarPool, parentSettings);
 
138
        
 
139
        // create components
 
140
        fNonNSScanner = new XMLDocumentScannerImpl();
 
141
        fNonNSDTDValidator = new XMLDTDValidator();
 
142
 
 
143
        // add components
 
144
        addComponent((XMLComponent)fNonNSScanner);
 
145
        addComponent((XMLComponent)fNonNSDTDValidator);
 
146
 
 
147
    } // <init>(SymbolTable,XMLGrammarPool)
 
148
 
 
149
    
 
150
    /** Configures the pipeline. */
 
151
        protected void configurePipeline() {
 
152
 
 
153
                // use XML 1.0 datatype library
 
154
                setProperty(DATATYPE_VALIDATOR_FACTORY, fDatatypeValidatorFactory);
 
155
 
 
156
                // setup DTD pipeline
 
157
                configureDTDPipeline();
 
158
 
 
159
                // setup document pipeline
 
160
                if (fFeatures.get(NAMESPACES) == Boolean.TRUE) {
 
161
            fProperties.put(NAMESPACE_BINDER, fNamespaceBinder);
 
162
                        fScanner = fNamespaceScanner;
 
163
                        fProperties.put(DOCUMENT_SCANNER, fNamespaceScanner);
 
164
                        if (fDTDValidator != null) {
 
165
                                fProperties.put(DTD_VALIDATOR, fDTDValidator);
 
166
                                fNamespaceScanner.setDTDValidator(fDTDValidator);
 
167
                                fNamespaceScanner.setDocumentHandler(fDTDValidator);
 
168
                                fDTDValidator.setDocumentSource(fNamespaceScanner);
 
169
                                fDTDValidator.setDocumentHandler(fDocumentHandler);
 
170
                                if (fDocumentHandler != null) {
 
171
                                        fDocumentHandler.setDocumentSource(fDTDValidator);
 
172
                                }
 
173
                                fLastComponent = fDTDValidator;
 
174
                        }
 
175
                        else {
 
176
                                fNamespaceScanner.setDocumentHandler(fDocumentHandler);
 
177
                fNamespaceScanner.setDTDValidator(null);
 
178
                                if (fDocumentHandler != null) {
 
179
                                        fDocumentHandler.setDocumentSource(fNamespaceScanner);
 
180
                                }
 
181
                                fLastComponent = fNamespaceScanner;
 
182
                        }
 
183
                }
 
184
                else {
 
185
                        fScanner = fNonNSScanner;
 
186
                        fProperties.put(DOCUMENT_SCANNER, fNonNSScanner);
 
187
                        if (fNonNSDTDValidator != null) {
 
188
                                fProperties.put(DTD_VALIDATOR, fNonNSDTDValidator);
 
189
                                fNonNSScanner.setDocumentHandler(fNonNSDTDValidator);
 
190
                                fNonNSDTDValidator.setDocumentSource(fNonNSScanner);
 
191
                                fNonNSDTDValidator.setDocumentHandler(fDocumentHandler);
 
192
                                if (fDocumentHandler != null) {
 
193
                                        fDocumentHandler.setDocumentSource(fNonNSDTDValidator);
 
194
                                }
 
195
                                fLastComponent = fNonNSDTDValidator;
 
196
                        }
 
197
                        else {
 
198
                                fScanner.setDocumentHandler(fDocumentHandler);
 
199
                                if (fDocumentHandler != null) {
 
200
                                        fDocumentHandler.setDocumentSource(fScanner);
 
201
                                }
 
202
                                fLastComponent = fScanner;
 
203
                        }
 
204
                }
 
205
 
 
206
                // setup document pipeline
 
207
                if (fFeatures.get(XMLSCHEMA_VALIDATION) == Boolean.TRUE) {
 
208
                        // If schema validator was not in the pipeline insert it.
 
209
                        if (fSchemaValidator == null) {
 
210
                                fSchemaValidator = new XMLSchemaValidator();
 
211
 
 
212
                                // add schema component
 
213
                                fProperties.put(SCHEMA_VALIDATOR, fSchemaValidator);
 
214
                                addComponent(fSchemaValidator);
 
215
                                // add schema message formatter
 
216
                                if (fErrorReporter.getMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN) == null) {
 
217
                                        XSMessageFormatter xmft = new XSMessageFormatter();
 
218
                                        fErrorReporter.putMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN, xmft);
 
219
                                }
 
220
 
 
221
                        }
 
222
 
 
223
                        fLastComponent.setDocumentHandler(fSchemaValidator);
 
224
                        fSchemaValidator.setDocumentSource(fLastComponent);
 
225
                        fSchemaValidator.setDocumentHandler(fDocumentHandler);
 
226
                        if (fDocumentHandler != null) {
 
227
                                fDocumentHandler.setDocumentSource(fSchemaValidator);
 
228
                        }
 
229
                        fLastComponent = fSchemaValidator;
 
230
                }
 
231
        } // configurePipeline()
 
232
 
 
233
 
 
234
 
 
235
    /** Create a document scanner: this scanner performs namespace binding 
 
236
      */
 
237
    protected XMLDocumentScanner createDocumentScanner() {
 
238
        fNamespaceScanner = new XMLNSDocumentScannerImpl();
 
239
        return fNamespaceScanner;
 
240
    } // createDocumentScanner():XMLDocumentScanner
 
241
 
 
242
 
 
243
    /** Create a DTD validator: this validator performs namespace binding.
 
244
      */
 
245
    protected XMLDTDValidator createDTDValidator() {
 
246
        return new XMLNSDTDValidator();
 
247
    } // createDTDValidator():XMLDTDValidator
 
248
 
 
249
} // class IntegratedParserConfiguration
 
250