KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xerces > parsers > IntegratedParserConfiguration


1 /*
2  * Copyright 2001, 2002,2004 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.parsers;
18
19 import org.apache.xerces.impl.XMLDocumentScannerImpl;
20 import org.apache.xerces.impl.XMLNSDocumentScannerImpl;
21 import org.apache.xerces.impl.dtd.XMLDTDValidator;
22 import org.apache.xerces.impl.dtd.XMLNSDTDValidator;
23 import org.apache.xerces.impl.xs.XMLSchemaValidator;
24 import org.apache.xerces.impl.xs.XSMessageFormatter;
25 import org.apache.xerces.util.SymbolTable;
26 import org.apache.xerces.xni.grammars.XMLGrammarPool;
27 import org.apache.xerces.xni.parser.XMLComponent;
28 import org.apache.xerces.xni.parser.XMLComponentManager;
29 import org.apache.xerces.xni.parser.XMLDocumentScanner;
30
31 /**
32  * This is configuration uses a scanner that integrates both scanning of the document
33  * and binding namespaces.
34  *
35  * If namespace feature is turned on, the pipeline is constructured with the
36  * following components:
37  * XMLNSDocumentScannerImpl -> XMLNSDTDValidator -> (optional) XMLSchemaValidator
38  *
39  * If the namespace feature is turned off the default document scanner implementation
40  * is used (XMLDocumentScannerImpl).
41  * <p>
42  * In addition to the features and properties recognized by the base
43  * parser configuration, this class recognizes these additional
44  * features and properties:
45  * <ul>
46  * <li>Features
47  * <ul>
48  * <li>http://apache.org/xml/features/validation/schema</li>
49  * <li>http://apache.org/xml/features/validation/schema-full-checking</li>
50  * <li>http://apache.org/xml/features/validation/schema/normalized-value</li>
51  * <li>http://apache.org/xml/features/validation/schema/element-default</li>
52  * </ul>
53  * <li>Properties
54  * <ul>
55  * <li>http://apache.org/xml/properties/internal/error-reporter</li>
56  * <li>http://apache.org/xml/properties/internal/entity-manager</li>
57  * <li>http://apache.org/xml/properties/internal/document-scanner</li>
58  * <li>http://apache.org/xml/properties/internal/dtd-scanner</li>
59  * <li>http://apache.org/xml/properties/internal/grammar-pool</li>
60  * <li>http://apache.org/xml/properties/internal/validator/dtd</li>
61  * <li>http://apache.org/xml/properties/internal/datatype-validator-factory</li>
62  * </ul>
63  * </ul>
64  *
65  * @author Elena Litani, IBM
66  *
67  * @version $Id: IntegratedParserConfiguration.java,v 1.13 2004/02/24 23:15:57 mrglavas Exp $
68  */

69 public class IntegratedParserConfiguration
70 extends StandardParserConfiguration {
71
72  
73     //
74
// REVISIT: should this configuration depend on the others
75
// like DTD/Standard one?
76
//
77

78     /** Document scanner that does namespace binding. */
79     protected XMLNSDocumentScannerImpl fNamespaceScanner;
80
81     /** Default Xerces implementation of scanner */
82     protected XMLDocumentScannerImpl fNonNSScanner;
83
84     /** DTD Validator that does not bind namespaces */
85     protected XMLDTDValidator fNonNSDTDValidator;
86     
87     //
88
// Constructors
89
//
90

91     /** Default constructor. */
92     public IntegratedParserConfiguration() {
93         this(null, null, null);
94     } // <init>()
95

96     /**
97      * Constructs a parser configuration using the specified symbol table.
98      *
99      * @param symbolTable The symbol table to use.
100      */

101     public IntegratedParserConfiguration(SymbolTable symbolTable) {
102         this(symbolTable, null, null);
103     } // <init>(SymbolTable)
104

105     /**
106      * Constructs a parser configuration using the specified symbol table and
107      * grammar pool.
108      * <p>
109      * <strong>REVISIT:</strong>
110      * Grammar pool will be updated when the new validation engine is
111      * implemented.
112      *
113      * @param symbolTable The symbol table to use.
114      * @param grammarPool The grammar pool to use.
115      */

116     public IntegratedParserConfiguration(SymbolTable symbolTable,
117                                          XMLGrammarPool grammarPool) {
118         this(symbolTable, grammarPool, null);
119     } // <init>(SymbolTable,XMLGrammarPool)
120

121     /**
122      * Constructs a parser configuration using the specified symbol table,
123      * grammar pool, and parent settings.
124      * <p>
125      * <strong>REVISIT:</strong>
126      * Grammar pool will be updated when the new validation engine is
127      * implemented.
128      *
129      * @param symbolTable The symbol table to use.
130      * @param grammarPool The grammar pool to use.
131      * @param parentSettings The parent settings.
132      */

133     public IntegratedParserConfiguration(SymbolTable symbolTable,
134                                          XMLGrammarPool grammarPool,
135                                          XMLComponentManager parentSettings) {
136         super(symbolTable, grammarPool, parentSettings);
137         
138         // create components
139
fNonNSScanner = new XMLDocumentScannerImpl();
140         fNonNSDTDValidator = new XMLDTDValidator();
141
142         // add components
143
addComponent((XMLComponent)fNonNSScanner);
144         addComponent((XMLComponent)fNonNSDTDValidator);
145
146     } // <init>(SymbolTable,XMLGrammarPool)
147

148     
149     /** Configures the pipeline. */
150     protected void configurePipeline() {
151
152         // use XML 1.0 datatype library
153
setProperty(DATATYPE_VALIDATOR_FACTORY, fDatatypeValidatorFactory);
154
155         // setup DTD pipeline
156
configureDTDPipeline();
157
158         // setup document pipeline
159
if (fFeatures.get(NAMESPACES) == Boolean.TRUE) {
160             fProperties.put(NAMESPACE_BINDER, fNamespaceBinder);
161             fScanner = fNamespaceScanner;
162             fProperties.put(DOCUMENT_SCANNER, fNamespaceScanner);
163             if (fDTDValidator != null) {
164                 fProperties.put(DTD_VALIDATOR, fDTDValidator);
165                 fNamespaceScanner.setDTDValidator(fDTDValidator);
166                 fNamespaceScanner.setDocumentHandler(fDTDValidator);
167                 fDTDValidator.setDocumentSource(fNamespaceScanner);
168                 fDTDValidator.setDocumentHandler(fDocumentHandler);
169                 if (fDocumentHandler != null) {
170                     fDocumentHandler.setDocumentSource(fDTDValidator);
171                 }
172                 fLastComponent = fDTDValidator;
173             }
174             else {
175                 fNamespaceScanner.setDocumentHandler(fDocumentHandler);
176                 fNamespaceScanner.setDTDValidator(null);
177                 if (fDocumentHandler != null) {
178                     fDocumentHandler.setDocumentSource(fNamespaceScanner);
179                 }
180                 fLastComponent = fNamespaceScanner;
181             }
182         }
183         else {
184             fScanner = fNonNSScanner;
185             fProperties.put(DOCUMENT_SCANNER, fNonNSScanner);
186             if (fNonNSDTDValidator != null) {
187                 fProperties.put(DTD_VALIDATOR, fNonNSDTDValidator);
188                 fNonNSScanner.setDocumentHandler(fNonNSDTDValidator);
189                 fNonNSDTDValidator.setDocumentSource(fNonNSScanner);
190                 fNonNSDTDValidator.setDocumentHandler(fDocumentHandler);
191                 if (fDocumentHandler != null) {
192                     fDocumentHandler.setDocumentSource(fNonNSDTDValidator);
193                 }
194                 fLastComponent = fNonNSDTDValidator;
195             }
196             else {
197                 fScanner.setDocumentHandler(fDocumentHandler);
198                 if (fDocumentHandler != null) {
199                     fDocumentHandler.setDocumentSource(fScanner);
200                 }
201                 fLastComponent = fScanner;
202             }
203         }
204
205         // setup document pipeline
206
if (fFeatures.get(XMLSCHEMA_VALIDATION) == Boolean.TRUE) {
207             // If schema validator was not in the pipeline insert it.
208
if (fSchemaValidator == null) {
209                 fSchemaValidator = new XMLSchemaValidator();
210
211                 // add schema component
212
fProperties.put(SCHEMA_VALIDATOR, fSchemaValidator);
213                 addComponent(fSchemaValidator);
214                 // add schema message formatter
215
if (fErrorReporter.getMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN) == null) {
216                     XSMessageFormatter xmft = new XSMessageFormatter();
217                     fErrorReporter.putMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN, xmft);
218                 }
219
220             }
221
222             fLastComponent.setDocumentHandler(fSchemaValidator);
223             fSchemaValidator.setDocumentSource(fLastComponent);
224             fSchemaValidator.setDocumentHandler(fDocumentHandler);
225             if (fDocumentHandler != null) {
226                 fDocumentHandler.setDocumentSource(fSchemaValidator);
227             }
228             fLastComponent = fSchemaValidator;
229         }
230     } // configurePipeline()
231

232
233
234     /** Create a document scanner: this scanner performs namespace binding
235       */

236     protected XMLDocumentScanner createDocumentScanner() {
237         fNamespaceScanner = new XMLNSDocumentScannerImpl();
238         return fNamespaceScanner;
239     } // createDocumentScanner():XMLDocumentScanner
240

241
242     /** Create a DTD validator: this validator performs namespace binding.
243       */

244     protected XMLDTDValidator createDTDValidator() {
245         return new XMLNSDTDValidator();
246     } // createDTDValidator():XMLDTDValidator
247

248 } // class IntegratedParserConfiguration
249

250
Popular Tags