KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xerces > internal > parsers > IntegratedParserConfiguration


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 2001, 2002 The Apache Software Foundation.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Apache Software Foundation (http://www.apache.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Xerces" and "Apache Software Foundation" must
28  * not be used to endorse or promote products derived from this
29  * software without prior written permission. For written
30  * permission, please contact apache@apache.org.
31  *
32  * 5. Products derived from this software may not be called "Apache",
33  * nor may "Apache" appear in their name, without prior written
34  * permission of the Apache Software Foundation.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  * ====================================================================
49  *
50  * This software consists of voluntary contributions made by many
51  * individuals on behalf of the Apache Software Foundation and was
52  * originally based on software copyright (c) 2002, International
53  * Business Machines, Inc., http://www.apache.org. For more
54  * information on the Apache Software Foundation, please see
55  * <http://www.apache.org/>.
56  */

57
58 package com.sun.org.apache.xerces.internal.parsers;
59
60 import com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl;
61 import com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl;
62 import com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator;
63 import com.sun.org.apache.xerces.internal.impl.dtd.XMLNSDTDValidator;
64 import com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator;
65 import com.sun.org.apache.xerces.internal.impl.xs.XSMessageFormatter;
66 import com.sun.org.apache.xerces.internal.util.SymbolTable;
67 import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool;
68 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponent;
69 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager;
70 import com.sun.org.apache.xerces.internal.xni.parser.XMLDocumentScanner;
71
72 /**
73  * This is configuration uses a scanner that integrates both scanning of the document
74  * and binding namespaces.
75  *
76  * If namespace feature is turned on, the pipeline is constructured with the
77  * following components:
78  * XMLNSDocumentScannerImpl -> XMLNSDTDValidator -> (optional) XMLSchemaValidator
79  *
80  * If the namespace feature is turned off the default document scanner implementation
81  * is used (XMLDocumentScannerImpl).
82  * <p>
83  * In addition to the features and properties recognized by the base
84  * parser configuration, this class recognizes these additional
85  * features and properties:
86  * <ul>
87  * <li>Features
88  * <ul>
89  * <li>http://apache.org/xml/features/validation/schema</li>
90  * <li>http://apache.org/xml/features/validation/schema-full-checking</li>
91  * <li>http://apache.org/xml/features/validation/schema/normalized-value</li>
92  * <li>http://apache.org/xml/features/validation/schema/element-default</li>
93  * </ul>
94  * <li>Properties
95  * <ul>
96  * <li>http://apache.org/xml/properties/internal/error-reporter</li>
97  * <li>http://apache.org/xml/properties/internal/entity-manager</li>
98  * <li>http://apache.org/xml/properties/internal/document-scanner</li>
99  * <li>http://apache.org/xml/properties/internal/dtd-scanner</li>
100  * <li>http://apache.org/xml/properties/internal/grammar-pool</li>
101  * <li>http://apache.org/xml/properties/internal/validator/dtd</li>
102  * <li>http://apache.org/xml/properties/internal/datatype-validator-factory</li>
103  * </ul>
104  * </ul>
105  *
106  * @author Elena Litani, IBM
107  *
108  * @version $Id: IntegratedParserConfiguration.java,v 1.12 2003/07/25 18:57:23 elena Exp $
109  */

110 public class IntegratedParserConfiguration
111 extends StandardParserConfiguration {
112
113  
114     //
115
// REVISIT: should this configuration depend on the others
116
// like DTD/Standard one?
117
//
118

119     /** Document scanner that does namespace binding. */
120     protected XMLNSDocumentScannerImpl fNamespaceScanner;
121
122     /** Default Xerces implementation of scanner */
123     protected XMLDocumentScannerImpl fNonNSScanner;
124
125     /** DTD Validator that does not bind namespaces */
126     protected XMLDTDValidator fNonNSDTDValidator;
127     
128     //
129
// Constructors
130
//
131

132     /** Default constructor. */
133     public IntegratedParserConfiguration() {
134         this(null, null, null);
135     } // <init>()
136

137     /**
138      * Constructs a parser configuration using the specified symbol table.
139      *
140      * @param symbolTable The symbol table to use.
141      */

142     public IntegratedParserConfiguration(SymbolTable symbolTable) {
143         this(symbolTable, null, null);
144     } // <init>(SymbolTable)
145

146     /**
147      * Constructs a parser configuration using the specified symbol table and
148      * grammar pool.
149      * <p>
150      * <strong>REVISIT:</strong>
151      * Grammar pool will be updated when the new validation engine is
152      * implemented.
153      *
154      * @param symbolTable The symbol table to use.
155      * @param grammarPool The grammar pool to use.
156      */

157     public IntegratedParserConfiguration(SymbolTable symbolTable,
158                                          XMLGrammarPool grammarPool) {
159         this(symbolTable, grammarPool, null);
160     } // <init>(SymbolTable,XMLGrammarPool)
161

162     /**
163      * Constructs a parser configuration using the specified symbol table,
164      * grammar pool, and parent settings.
165      * <p>
166      * <strong>REVISIT:</strong>
167      * Grammar pool will be updated when the new validation engine is
168      * implemented.
169      *
170      * @param symbolTable The symbol table to use.
171      * @param grammarPool The grammar pool to use.
172      * @param parentSettings The parent settings.
173      */

174     public IntegratedParserConfiguration(SymbolTable symbolTable,
175                                          XMLGrammarPool grammarPool,
176                                          XMLComponentManager parentSettings) {
177         super(symbolTable, grammarPool, parentSettings);
178         
179         // create components
180
fNonNSScanner = new XMLDocumentScannerImpl();
181         fNonNSDTDValidator = new XMLDTDValidator();
182
183         // add components
184
addComponent((XMLComponent)fNonNSScanner);
185         addComponent((XMLComponent)fNonNSDTDValidator);
186
187     } // <init>(SymbolTable,XMLGrammarPool)
188

189     
190     /** Configures the pipeline. */
191     protected void configurePipeline() {
192
193         // use XML 1.0 datatype library
194
setProperty(DATATYPE_VALIDATOR_FACTORY, fDatatypeValidatorFactory);
195
196         // setup DTD pipeline
197
configureDTDPipeline();
198
199         // setup document pipeline
200
if (fFeatures.get(NAMESPACES) == Boolean.TRUE) {
201             fProperties.put(NAMESPACE_BINDER, fNamespaceBinder);
202             fScanner = fNamespaceScanner;
203             fProperties.put(DOCUMENT_SCANNER, fNamespaceScanner);
204             if (fDTDValidator != null) {
205                 fProperties.put(DTD_VALIDATOR, fDTDValidator);
206                 fNamespaceScanner.setDTDValidator(fDTDValidator);
207                 fNamespaceScanner.setDocumentHandler(fDTDValidator);
208                 fDTDValidator.setDocumentSource(fNamespaceScanner);
209                 fDTDValidator.setDocumentHandler(fDocumentHandler);
210                 if (fDocumentHandler != null) {
211                     fDocumentHandler.setDocumentSource(fDTDValidator);
212                 }
213                 fLastComponent = fDTDValidator;
214             }
215             else {
216                 fNamespaceScanner.setDocumentHandler(fDocumentHandler);
217                 fNamespaceScanner.setDTDValidator(null);
218                 if (fDocumentHandler != null) {
219                     fDocumentHandler.setDocumentSource(fNamespaceScanner);
220                 }
221                 fLastComponent = fNamespaceScanner;
222             }
223         }
224         else {
225             fScanner = fNonNSScanner;
226             fProperties.put(DOCUMENT_SCANNER, fNonNSScanner);
227             if (fNonNSDTDValidator != null) {
228                 fProperties.put(DTD_VALIDATOR, fNonNSDTDValidator);
229                 fNonNSScanner.setDocumentHandler(fNonNSDTDValidator);
230                 fNonNSDTDValidator.setDocumentSource(fNonNSScanner);
231                 fNonNSDTDValidator.setDocumentHandler(fDocumentHandler);
232                 if (fDocumentHandler != null) {
233                     fDocumentHandler.setDocumentSource(fNonNSDTDValidator);
234                 }
235                 fLastComponent = fNonNSDTDValidator;
236             }
237             else {
238                 fScanner.setDocumentHandler(fDocumentHandler);
239                 if (fDocumentHandler != null) {
240                     fDocumentHandler.setDocumentSource(fScanner);
241                 }
242                 fLastComponent = fScanner;
243             }
244         }
245
246         // setup document pipeline
247
if (fFeatures.get(XMLSCHEMA_VALIDATION) == Boolean.TRUE) {
248             // If schema validator was not in the pipeline insert it.
249
if (fSchemaValidator == null) {
250                 fSchemaValidator = new XMLSchemaValidator();
251
252                 // add schema component
253
fProperties.put(SCHEMA_VALIDATOR, fSchemaValidator);
254                 addComponent(fSchemaValidator);
255                 // add schema message formatter
256
if (fErrorReporter.getMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN) == null) {
257                     XSMessageFormatter xmft = new XSMessageFormatter();
258                     fErrorReporter.putMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN, xmft);
259                 }
260
261             }
262
263             fLastComponent.setDocumentHandler(fSchemaValidator);
264             fSchemaValidator.setDocumentSource(fLastComponent);
265             fSchemaValidator.setDocumentHandler(fDocumentHandler);
266             if (fDocumentHandler != null) {
267                 fDocumentHandler.setDocumentSource(fSchemaValidator);
268             }
269             fLastComponent = fSchemaValidator;
270         }
271     } // configurePipeline()
272

273
274
275     /** Create a document scanner: this scanner performs namespace binding
276       */

277     protected XMLDocumentScanner createDocumentScanner() {
278         fNamespaceScanner = new XMLNSDocumentScannerImpl();
279         return fNamespaceScanner;
280     } // createDocumentScanner():XMLDocumentScanner
281

282
283     /** Create a DTD validator: this validator performs namespace binding.
284       */

285     protected XMLDTDValidator createDTDValidator() {
286         return new XMLNSDTDValidator();
287     } // createDTDValidator():XMLDTDValidator
288

289 } // class IntegratedParserConfiguration
290

291
Popular Tags