KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright 2001-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.parsers;
18
19 import java.io.IOException JavaDoc;
20 import java.util.ArrayList JavaDoc;
21 import java.util.HashMap JavaDoc;
22 import java.util.Locale JavaDoc;
23
24 import org.apache.xerces.impl.Constants;
25 import org.apache.xerces.impl.XML11DTDScannerImpl;
26 import org.apache.xerces.impl.XML11DocumentScannerImpl;
27 import org.apache.xerces.impl.XML11NSDocumentScannerImpl;
28 import org.apache.xerces.impl.XMLDTDScannerImpl;
29 import org.apache.xerces.impl.XMLDocumentScannerImpl;
30 import org.apache.xerces.impl.XMLEntityHandler;
31 import org.apache.xerces.impl.XMLEntityManager;
32 import org.apache.xerces.impl.XMLErrorReporter;
33 import org.apache.xerces.impl.XMLNSDocumentScannerImpl;
34 import org.apache.xerces.impl.XMLVersionDetector;
35 import org.apache.xerces.impl.dtd.XML11DTDProcessor;
36 import org.apache.xerces.impl.dtd.XML11DTDValidator;
37 import org.apache.xerces.impl.dtd.XML11NSDTDValidator;
38 import org.apache.xerces.impl.dtd.XMLDTDProcessor;
39 import org.apache.xerces.impl.dtd.XMLDTDValidator;
40 import org.apache.xerces.impl.dtd.XMLNSDTDValidator;
41 import org.apache.xerces.impl.dv.DTDDVFactory;
42 import org.apache.xerces.impl.msg.XMLMessageFormatter;
43 import org.apache.xerces.impl.validation.ValidationManager;
44 import org.apache.xerces.impl.xs.XMLSchemaValidator;
45 import org.apache.xerces.impl.xs.XSMessageFormatter;
46 import org.apache.xerces.util.ParserConfigurationSettings;
47 import org.apache.xerces.util.SymbolTable;
48 import org.apache.xerces.xni.XMLDTDContentModelHandler;
49 import org.apache.xerces.xni.XMLDTDHandler;
50 import org.apache.xerces.xni.XMLDocumentHandler;
51 import org.apache.xerces.xni.XMLLocator;
52 import org.apache.xerces.xni.XNIException;
53 import org.apache.xerces.xni.grammars.XMLGrammarPool;
54 import org.apache.xerces.xni.parser.XMLComponent;
55 import org.apache.xerces.xni.parser.XMLComponentManager;
56 import org.apache.xerces.xni.parser.XMLConfigurationException;
57 import org.apache.xerces.xni.parser.XMLDTDScanner;
58 import org.apache.xerces.xni.parser.XMLDocumentScanner;
59 import org.apache.xerces.xni.parser.XMLDocumentSource;
60 import org.apache.xerces.xni.parser.XMLEntityResolver;
61 import org.apache.xerces.xni.parser.XMLErrorHandler;
62 import org.apache.xerces.xni.parser.XMLInputSource;
63 import org.apache.xerces.xni.parser.XMLPullParserConfiguration;
64
65 /**
66  * This class is the configuration used to parse XML 1.0 and XML 1.1 documents.
67  *
68  * @author Elena Litani, IBM
69  * @author Neil Graham, IBM
70  * @author Michael Glavassevich, IBM
71  *
72  * @version $Id: XML11Configuration.java,v 1.25 2005/06/13 22:18:32 mrglavas Exp $
73  */

74 public class XML11Configuration extends ParserConfigurationSettings
75     implements XMLPullParserConfiguration, XML11Configurable {
76
77     //
78
// Constants
79
//
80
protected final static String JavaDoc XML11_DATATYPE_VALIDATOR_FACTORY =
81         "org.apache.xerces.impl.dv.dtd.XML11DTDDVFactoryImpl";
82
83     // feature identifiers
84

85     /** Feature identifier: warn on duplicate attribute definition. */
86     protected static final String JavaDoc WARN_ON_DUPLICATE_ATTDEF =
87         Constants.XERCES_FEATURE_PREFIX + Constants.WARN_ON_DUPLICATE_ATTDEF_FEATURE;
88
89     /** Feature identifier: warn on duplicate entity definition. */
90     protected static final String JavaDoc WARN_ON_DUPLICATE_ENTITYDEF =
91         Constants.XERCES_FEATURE_PREFIX + Constants.WARN_ON_DUPLICATE_ENTITYDEF_FEATURE;
92
93     /** Feature identifier: warn on undeclared element definition. */
94     protected static final String JavaDoc WARN_ON_UNDECLARED_ELEMDEF =
95         Constants.XERCES_FEATURE_PREFIX + Constants.WARN_ON_UNDECLARED_ELEMDEF_FEATURE;
96
97     /** Feature identifier: allow Java encodings. */
98     protected static final String JavaDoc ALLOW_JAVA_ENCODINGS =
99         Constants.XERCES_FEATURE_PREFIX + Constants.ALLOW_JAVA_ENCODINGS_FEATURE;
100
101     /** Feature identifier: continue after fatal error. */
102     protected static final String JavaDoc CONTINUE_AFTER_FATAL_ERROR =
103         Constants.XERCES_FEATURE_PREFIX + Constants.CONTINUE_AFTER_FATAL_ERROR_FEATURE;
104
105     /** Feature identifier: load external DTD. */
106     protected static final String JavaDoc LOAD_EXTERNAL_DTD =
107         Constants.XERCES_FEATURE_PREFIX + Constants.LOAD_EXTERNAL_DTD_FEATURE;
108
109     /** Feature identifier: notify built-in refereces. */
110     protected static final String JavaDoc NOTIFY_BUILTIN_REFS =
111         Constants.XERCES_FEATURE_PREFIX + Constants.NOTIFY_BUILTIN_REFS_FEATURE;
112
113     /** Feature identifier: notify character refereces. */
114     protected static final String JavaDoc NOTIFY_CHAR_REFS =
115         Constants.XERCES_FEATURE_PREFIX + Constants.NOTIFY_CHAR_REFS_FEATURE;
116
117     /** Feature identifier: expose schema normalized value */
118     protected static final String JavaDoc NORMALIZE_DATA =
119         Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_NORMALIZED_VALUE;
120
121     /** Feature identifier: send element default value via characters() */
122     protected static final String JavaDoc SCHEMA_ELEMENT_DEFAULT =
123         Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_ELEMENT_DEFAULT;
124
125     /** Feature identifier: augment PSVI */
126     protected static final String JavaDoc SCHEMA_AUGMENT_PSVI =
127         Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_AUGMENT_PSVI;
128
129     /** feature identifier: XML Schema validation */
130     protected static final String JavaDoc XMLSCHEMA_VALIDATION =
131         Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_VALIDATION_FEATURE;
132
133     /** feature identifier: XML Schema validation -- full checking */
134     protected static final String JavaDoc XMLSCHEMA_FULL_CHECKING =
135         Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_FULL_CHECKING;
136     
137     /** Feature: generate synthetic annotations */
138     protected static final String JavaDoc GENERATE_SYNTHETIC_ANNOTATIONS =
139         Constants.XERCES_FEATURE_PREFIX + Constants.GENERATE_SYNTHETIC_ANNOTATIONS_FEATURE;
140     
141     /** Feature identifier: validate annotations */
142     protected static final String JavaDoc VALIDATE_ANNOTATIONS =
143         Constants.XERCES_FEATURE_PREFIX + Constants.VALIDATE_ANNOTATIONS_FEATURE;
144     
145     /** Feature identifier: honour all schemaLocations */
146     protected static final String JavaDoc HONOUR_ALL_SCHEMALOCATIONS =
147         Constants.XERCES_FEATURE_PREFIX + Constants.HONOUR_ALL_SCHEMALOCATIONS_FEATURE;
148     
149     /** Feature identifier: use grammar pool only */
150     protected static final String JavaDoc USE_GRAMMAR_POOL_ONLY =
151         Constants.XERCES_FEATURE_PREFIX + Constants.USE_GRAMMAR_POOL_ONLY_FEATURE;
152         
153     // feature identifiers
154

155     /** Feature identifier: validation. */
156     protected static final String JavaDoc VALIDATION =
157         Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE;
158     
159     /** Feature identifier: namespaces. */
160     protected static final String JavaDoc NAMESPACES =
161         Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE;
162     
163     /** Feature identifier: external general entities. */
164     protected static final String JavaDoc EXTERNAL_GENERAL_ENTITIES =
165         Constants.SAX_FEATURE_PREFIX + Constants.EXTERNAL_GENERAL_ENTITIES_FEATURE;
166     
167     /** Feature identifier: external parameter entities. */
168     protected static final String JavaDoc EXTERNAL_PARAMETER_ENTITIES =
169         Constants.SAX_FEATURE_PREFIX + Constants.EXTERNAL_PARAMETER_ENTITIES_FEATURE;
170         
171     
172
173     // property identifiers
174

175
176     /** Property identifier: xml string. */
177     protected static final String JavaDoc XML_STRING =
178         Constants.SAX_PROPERTY_PREFIX + Constants.XML_STRING_PROPERTY;
179
180     /** Property identifier: symbol table. */
181     protected static final String JavaDoc SYMBOL_TABLE =
182         Constants.XERCES_PROPERTY_PREFIX + Constants.SYMBOL_TABLE_PROPERTY;
183
184     /** Property identifier: error handler. */
185     protected static final String JavaDoc ERROR_HANDLER =
186         Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_HANDLER_PROPERTY;
187
188     /** Property identifier: entity resolver. */
189     protected static final String JavaDoc ENTITY_RESOLVER =
190         Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_RESOLVER_PROPERTY;
191
192
193     /** Property identifier: XML Schema validator. */
194     protected static final String JavaDoc SCHEMA_VALIDATOR =
195         Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_VALIDATOR_PROPERTY;
196
197     /** Property identifier: schema location. */
198     protected static final String JavaDoc SCHEMA_LOCATION =
199         Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_LOCATION;
200
201     /** Property identifier: no namespace schema location. */
202     protected static final String JavaDoc SCHEMA_NONS_LOCATION =
203         Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_NONS_LOCATION;
204
205     // property identifiers
206

207     /** Property identifier: error reporter. */
208     protected static final String JavaDoc ERROR_REPORTER =
209         Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY;
210
211     /** Property identifier: entity manager. */
212     protected static final String JavaDoc ENTITY_MANAGER =
213         Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_MANAGER_PROPERTY;
214
215     /** Property identifier document scanner: */
216     protected static final String JavaDoc DOCUMENT_SCANNER =
217         Constants.XERCES_PROPERTY_PREFIX + Constants.DOCUMENT_SCANNER_PROPERTY;
218
219     /** Property identifier: DTD scanner. */
220     protected static final String JavaDoc DTD_SCANNER =
221         Constants.XERCES_PROPERTY_PREFIX + Constants.DTD_SCANNER_PROPERTY;
222
223     /** Property identifier: grammar pool. */
224     protected static final String JavaDoc XMLGRAMMAR_POOL =
225         Constants.XERCES_PROPERTY_PREFIX + Constants.XMLGRAMMAR_POOL_PROPERTY;
226
227     /** Property identifier: DTD loader. */
228     protected static final String JavaDoc DTD_PROCESSOR =
229         Constants.XERCES_PROPERTY_PREFIX + Constants.DTD_PROCESSOR_PROPERTY;
230
231     /** Property identifier: DTD validator. */
232     protected static final String JavaDoc DTD_VALIDATOR =
233         Constants.XERCES_PROPERTY_PREFIX + Constants.DTD_VALIDATOR_PROPERTY;
234
235     /** Property identifier: namespace binder. */
236     protected static final String JavaDoc NAMESPACE_BINDER =
237         Constants.XERCES_PROPERTY_PREFIX + Constants.NAMESPACE_BINDER_PROPERTY;
238
239     /** Property identifier: datatype validator factory. */
240     protected static final String JavaDoc DATATYPE_VALIDATOR_FACTORY =
241         Constants.XERCES_PROPERTY_PREFIX + Constants.DATATYPE_VALIDATOR_FACTORY_PROPERTY;
242
243     protected static final String JavaDoc VALIDATION_MANAGER =
244         Constants.XERCES_PROPERTY_PREFIX + Constants.VALIDATION_MANAGER_PROPERTY;
245
246     /** Property identifier: JAXP schema language / DOM schema-type. */
247     protected static final String JavaDoc JAXP_SCHEMA_LANGUAGE =
248         Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE;
249
250     /** Property identifier: JAXP schema source/ DOM schema-location. */
251     protected static final String JavaDoc JAXP_SCHEMA_SOURCE =
252         Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE;
253
254     // debugging
255

256     /** Set to true and recompile to print exception stack trace. */
257     protected static final boolean PRINT_EXCEPTION_STACK_TRACE = false;
258
259     //
260
// Data
261
//
262

263     protected SymbolTable fSymbolTable;
264     protected XMLInputSource fInputSource;
265     protected ValidationManager fValidationManager;
266     protected XMLVersionDetector fVersionDetector;
267     protected XMLLocator fLocator;
268     protected Locale JavaDoc fLocale;
269
270     /** XML 1.0 Components. */
271     protected ArrayList JavaDoc fComponents;
272     
273     /** XML 1.1. Components. */
274     protected ArrayList JavaDoc fXML11Components = null;
275     
276     /** Common components: XMLEntityManager, XMLErrorReporter, XMLSchemaValidator */
277     protected ArrayList JavaDoc fCommonComponents = null;
278
279     /** The document handler. */
280     protected XMLDocumentHandler fDocumentHandler;
281
282     /** The DTD handler. */
283     protected XMLDTDHandler fDTDHandler;
284
285     /** The DTD content model handler. */
286     protected XMLDTDContentModelHandler fDTDContentModelHandler;
287
288     /** Last component in the document pipeline */
289     protected XMLDocumentSource fLastComponent;
290
291     /**
292      * True if a parse is in progress. This state is needed because
293      * some features/properties cannot be set while parsing (e.g.
294      * validation and namespaces).
295      */

296     protected boolean fParseInProgress = false;
297     
298     /** fConfigUpdated is set to true if there has been any change to the configuration settings,
299      * i.e a feature or a property was changed.
300      */

301     protected boolean fConfigUpdated = false;
302
303     //
304
// XML 1.0 components
305
//
306

307     /** The XML 1.0 Datatype validator factory. */
308     protected DTDDVFactory fDatatypeValidatorFactory;
309
310     /** The XML 1.0 Document scanner that does namespace binding. */
311     protected XMLNSDocumentScannerImpl fNamespaceScanner;
312     /** The XML 1.0 Non-namespace implementation of scanner */
313     protected XMLDocumentScannerImpl fNonNSScanner;
314     /** The XML 1.0 DTD Validator: binds namespaces */
315     protected XMLDTDValidator fDTDValidator;
316     /** The XML 1.0 DTD Validator that does not bind namespaces */
317     protected XMLDTDValidator fNonNSDTDValidator;
318     /** The XML 1.0 DTD scanner. */
319     protected XMLDTDScanner fDTDScanner;
320     /** The XML 1.0 DTD Processor . */
321     protected XMLDTDProcessor fDTDProcessor;
322
323     //
324
// XML 1.1 components
325
//
326

327     /** The XML 1.1 datatype factory. **/
328     protected DTDDVFactory fXML11DatatypeFactory = null;
329
330     /** The XML 1.1 document scanner that does namespace binding. **/
331     protected XML11NSDocumentScannerImpl fXML11NSDocScanner = null;
332
333     /** The XML 1.1 document scanner that does not do namespace binding. **/
334     protected XML11DocumentScannerImpl fXML11DocScanner = null;
335
336     /** The XML 1.1 DTD validator that does namespace binding. **/
337     protected XML11NSDTDValidator fXML11NSDTDValidator = null;
338
339     /** The XML 1.1 DTD validator that does not do namespace binding. **/
340     protected XML11DTDValidator fXML11DTDValidator = null;
341
342     /** The XML 1.1 DTD scanner. **/
343     protected XML11DTDScannerImpl fXML11DTDScanner = null;
344     /** The XML 1.1 DTD processor. **/
345     protected XML11DTDProcessor fXML11DTDProcessor = null;
346
347     //
348
// Common components
349
//
350

351     /** Grammar pool. */
352     protected XMLGrammarPool fGrammarPool;
353
354     /** Error reporter. */
355     protected XMLErrorReporter fErrorReporter;
356
357     /** Entity manager. */
358     protected XMLEntityManager fEntityManager;
359
360     /** XML Schema Validator. */
361     protected XMLSchemaValidator fSchemaValidator;
362
363     /** Current scanner */
364     protected XMLDocumentScanner fCurrentScanner;
365     /** Current Datatype validator factory. */
366     protected DTDDVFactory fCurrentDVFactory;
367     /** Current DTD scanner. */
368     protected XMLDTDScanner fCurrentDTDScanner;
369
370     /** Flag indiciating whether XML11 components have been initialized. */
371     private boolean f11Initialized = false;
372
373     //
374
// Constructors
375
//
376

377     /** Default constructor. */
378     public XML11Configuration() {
379         this(null, null, null);
380     } // <init>()
381

382     /**
383      * Constructs a parser configuration using the specified symbol table.
384      *
385      * @param symbolTable The symbol table to use.
386      */

387     public XML11Configuration(SymbolTable symbolTable) {
388         this(symbolTable, null, null);
389     } // <init>(SymbolTable)
390

391     /**
392      * Constructs a parser configuration using the specified symbol table and
393      * grammar pool.
394      * <p>
395      * <strong>REVISIT:</strong>
396      * Grammar pool will be updated when the new validation engine is
397      * implemented.
398      *
399      * @param symbolTable The symbol table to use.
400      * @param grammarPool The grammar pool to use.
401      */

402     public XML11Configuration(SymbolTable symbolTable, XMLGrammarPool grammarPool) {
403         this(symbolTable, grammarPool, null);
404     } // <init>(SymbolTable,XMLGrammarPool)
405

406     /**
407      * Constructs a parser configuration using the specified symbol table,
408      * grammar pool, and parent settings.
409      * <p>
410      * <strong>REVISIT:</strong>
411      * Grammar pool will be updated when the new validation engine is
412      * implemented.
413      *
414      * @param symbolTable The symbol table to use.
415      * @param grammarPool The grammar pool to use.
416      * @param parentSettings The parent settings.
417      */

418     public XML11Configuration(
419         SymbolTable symbolTable,
420         XMLGrammarPool grammarPool,
421         XMLComponentManager parentSettings) {
422         
423         super(parentSettings);
424
425         // create a vector to hold all the components in use
426
// XML 1.0 specialized components
427
fComponents = new ArrayList JavaDoc();
428         // XML 1.1 specialized components
429
fXML11Components = new ArrayList JavaDoc();
430         // Common components for XML 1.1. and XML 1.0
431
fCommonComponents = new ArrayList JavaDoc();
432
433         // create storage for recognized features and properties
434
fRecognizedFeatures = new ArrayList JavaDoc();
435         fRecognizedProperties = new ArrayList JavaDoc();
436
437         // create table for features and properties
438
fFeatures = new HashMap JavaDoc();
439         fProperties = new HashMap JavaDoc();
440
441         // add default recognized features
442
final String JavaDoc[] recognizedFeatures =
443             {
444                 CONTINUE_AFTER_FATAL_ERROR, LOAD_EXTERNAL_DTD, // from XMLDTDScannerImpl
445
VALIDATION,
446                 NAMESPACES,
447                 NORMALIZE_DATA, SCHEMA_ELEMENT_DEFAULT, SCHEMA_AUGMENT_PSVI,
448                 GENERATE_SYNTHETIC_ANNOTATIONS, VALIDATE_ANNOTATIONS,
449                 HONOUR_ALL_SCHEMALOCATIONS, USE_GRAMMAR_POOL_ONLY,
450                 // NOTE: These shouldn't really be here but since the XML Schema
451
// validator is constructed dynamically, its recognized
452
// features might not have been set and it would cause a
453
// not-recognized exception to be thrown. -Ac
454
XMLSCHEMA_VALIDATION, XMLSCHEMA_FULL_CHECKING,
455                 EXTERNAL_GENERAL_ENTITIES,
456                 EXTERNAL_PARAMETER_ENTITIES,
457                 PARSER_SETTINGS
458             };
459         addRecognizedFeatures(recognizedFeatures);
460         // set state for default features
461
fFeatures.put(VALIDATION, Boolean.FALSE);
462         fFeatures.put(NAMESPACES, Boolean.TRUE);
463         fFeatures.put(EXTERNAL_GENERAL_ENTITIES, Boolean.TRUE);
464         fFeatures.put(EXTERNAL_PARAMETER_ENTITIES, Boolean.TRUE);
465         fFeatures.put(CONTINUE_AFTER_FATAL_ERROR, Boolean.FALSE);
466         fFeatures.put(LOAD_EXTERNAL_DTD, Boolean.TRUE);
467         fFeatures.put(SCHEMA_ELEMENT_DEFAULT, Boolean.TRUE);
468         fFeatures.put(NORMALIZE_DATA, Boolean.TRUE);
469         fFeatures.put(SCHEMA_AUGMENT_PSVI, Boolean.TRUE);
470         fFeatures.put(GENERATE_SYNTHETIC_ANNOTATIONS, Boolean.FALSE);
471         fFeatures.put(VALIDATE_ANNOTATIONS, Boolean.FALSE);
472         fFeatures.put(HONOUR_ALL_SCHEMALOCATIONS, Boolean.FALSE);
473         fFeatures.put(USE_GRAMMAR_POOL_ONLY, Boolean.FALSE);
474         fFeatures.put(PARSER_SETTINGS, Boolean.TRUE);
475
476         // add default recognized properties
477
final String JavaDoc[] recognizedProperties =
478             {
479                 SYMBOL_TABLE,
480                 ERROR_HANDLER,
481                 ENTITY_RESOLVER,
482                 ERROR_REPORTER,
483                 ENTITY_MANAGER,
484                 DOCUMENT_SCANNER,
485                 DTD_SCANNER,
486                 DTD_PROCESSOR,
487                 DTD_VALIDATOR,
488                 DATATYPE_VALIDATOR_FACTORY,
489                 VALIDATION_MANAGER,
490                 SCHEMA_VALIDATOR,
491                 XML_STRING,
492                 XMLGRAMMAR_POOL,
493                 JAXP_SCHEMA_SOURCE,
494                 JAXP_SCHEMA_LANGUAGE,
495                 // NOTE: These shouldn't really be here but since the XML Schema
496
// validator is constructed dynamically, its recognized
497
// properties might not have been set and it would cause a
498
// not-recognized exception to be thrown. -Ac
499
SCHEMA_LOCATION, SCHEMA_NONS_LOCATION, };
500         addRecognizedProperties(recognizedProperties);
501         
502         if (symbolTable == null) {
503             symbolTable = new SymbolTable();
504         }
505         fSymbolTable = symbolTable;
506         fProperties.put(SYMBOL_TABLE, fSymbolTable);
507         
508         fGrammarPool = grammarPool;
509         if (fGrammarPool != null) {
510             fProperties.put(XMLGRAMMAR_POOL, fGrammarPool);
511         }
512
513         fEntityManager = new XMLEntityManager();
514         fProperties.put(ENTITY_MANAGER, fEntityManager);
515         addCommonComponent(fEntityManager);
516
517         fErrorReporter = new XMLErrorReporter();
518         fErrorReporter.setDocumentLocator(fEntityManager.getEntityScanner());
519         fProperties.put(ERROR_REPORTER, fErrorReporter);
520         addCommonComponent(fErrorReporter);
521
522         fNamespaceScanner = new XMLNSDocumentScannerImpl();
523         fProperties.put(DOCUMENT_SCANNER, fNamespaceScanner);
524         addComponent((XMLComponent) fNamespaceScanner);
525
526         fDTDScanner = new XMLDTDScannerImpl();
527         fProperties.put(DTD_SCANNER, fDTDScanner);
528         addComponent((XMLComponent) fDTDScanner);
529
530         fDTDProcessor = new XMLDTDProcessor();
531         fProperties.put(DTD_PROCESSOR, fDTDProcessor);
532         addComponent((XMLComponent) fDTDProcessor);
533
534         fDTDValidator = new XMLNSDTDValidator();
535         fProperties.put(DTD_VALIDATOR, fDTDValidator);
536         addComponent(fDTDValidator);
537
538         fDatatypeValidatorFactory = DTDDVFactory.getInstance();
539         fProperties.put(DATATYPE_VALIDATOR_FACTORY, fDatatypeValidatorFactory);
540
541         fValidationManager = new ValidationManager();
542         fProperties.put(VALIDATION_MANAGER, fValidationManager);
543         
544         fVersionDetector = new XMLVersionDetector();
545         
546         // add message formatters
547
if (fErrorReporter.getMessageFormatter(XMLMessageFormatter.XML_DOMAIN) == null) {
548             XMLMessageFormatter xmft = new XMLMessageFormatter();
549             fErrorReporter.putMessageFormatter(XMLMessageFormatter.XML_DOMAIN, xmft);
550             fErrorReporter.putMessageFormatter(XMLMessageFormatter.XMLNS_DOMAIN, xmft);
551         }
552
553         // set locale
554
try {
555             setLocale(Locale.getDefault());
556         } catch (XNIException e) {
557             // do nothing
558
// REVISIT: What is the right thing to do? -Ac
559
}
560         
561         fConfigUpdated = false;
562
563     } // <init>(SymbolTable,XMLGrammarPool)
564

565     //
566
// Public methods
567
//
568
/**
569      * Sets the input source for the document to parse.
570      *
571      * @param inputSource The document's input source.
572      *
573      * @exception XMLConfigurationException Thrown if there is a
574      * configuration error when initializing the
575      * parser.
576      * @exception IOException Thrown on I/O error.
577      *
578      * @see #parse(boolean)
579      */

580     public void setInputSource(XMLInputSource inputSource)
581         throws XMLConfigurationException, IOException JavaDoc {
582
583         // REVISIT: this method used to reset all the components and
584
// construct the pipeline. Now reset() is called
585
// in parse (boolean) just before we parse the document
586
// Should this method still throw exceptions..?
587

588         fInputSource = inputSource;
589
590     } // setInputSource(XMLInputSource)
591

592     /**
593      * Set the locale to use for messages.
594      *
595      * @param locale The locale object to use for localization of messages.
596      *
597      * @exception XNIException Thrown if the parser does not support the
598      * specified locale.
599      */

600     public void setLocale(Locale JavaDoc locale) throws XNIException {
601         fLocale = locale;
602         fErrorReporter.setLocale(locale);
603     } // setLocale(Locale)
604
/**
605      * Sets the document handler on the last component in the pipeline
606      * to receive information about the document.
607      *
608      * @param documentHandler The document handler.
609      */

610     public void setDocumentHandler(XMLDocumentHandler documentHandler) {
611         fDocumentHandler = documentHandler;
612         if (fLastComponent != null) {
613             fLastComponent.setDocumentHandler(fDocumentHandler);
614             if (fDocumentHandler !=null){
615                 fDocumentHandler.setDocumentSource(fLastComponent);
616             }
617         }
618     } // setDocumentHandler(XMLDocumentHandler)
619

620     /** Returns the registered document handler. */
621     public XMLDocumentHandler getDocumentHandler() {
622         return fDocumentHandler;
623     } // getDocumentHandler():XMLDocumentHandler
624

625     /**
626      * Sets the DTD handler.
627      *
628      * @param dtdHandler The DTD handler.
629      */

630     public void setDTDHandler(XMLDTDHandler dtdHandler) {
631         fDTDHandler = dtdHandler;
632     } // setDTDHandler(XMLDTDHandler)
633

634     /** Returns the registered DTD handler. */
635     public XMLDTDHandler getDTDHandler() {
636         return fDTDHandler;
637     } // getDTDHandler():XMLDTDHandler
638

639     /**
640      * Sets the DTD content model handler.
641      *
642      * @param handler The DTD content model handler.
643      */

644     public void setDTDContentModelHandler(XMLDTDContentModelHandler handler) {
645         fDTDContentModelHandler = handler;
646     } // setDTDContentModelHandler(XMLDTDContentModelHandler)
647

648     /** Returns the registered DTD content model handler. */
649     public XMLDTDContentModelHandler getDTDContentModelHandler() {
650         return fDTDContentModelHandler;
651     } // getDTDContentModelHandler():XMLDTDContentModelHandler
652

653     /**
654      * Sets the resolver used to resolve external entities. The EntityResolver
655      * interface supports resolution of public and system identifiers.
656      *
657      * @param resolver The new entity resolver. Passing a null value will
658      * uninstall the currently installed resolver.
659      */

660     public void setEntityResolver(XMLEntityResolver resolver) {
661         fProperties.put(ENTITY_RESOLVER, resolver);
662     } // setEntityResolver(XMLEntityResolver)
663

664     /**
665      * Return the current entity resolver.
666      *
667      * @return The current entity resolver, or null if none
668      * has been registered.
669      * @see #setEntityResolver
670      */

671     public XMLEntityResolver getEntityResolver() {
672         return (XMLEntityResolver)fProperties.get(ENTITY_RESOLVER);
673     } // getEntityResolver():XMLEntityResolver
674

675     /**
676      * Allow an application to register an error event handler.
677      *
678      * <p>If the application does not register an error handler, all
679      * error events reported by the SAX parser will be silently
680      * ignored; however, normal processing may not continue. It is
681      * highly recommended that all SAX applications implement an
682      * error handler to avoid unexpected bugs.</p>
683      *
684      * <p>Applications may register a new or different handler in the
685      * middle of a parse, and the SAX parser must begin using the new
686      * handler immediately.</p>
687      *
688      * @param errorHandler The error handler.
689      * @exception java.lang.NullPointerException If the handler
690      * argument is null.
691      * @see #getErrorHandler
692      */

693     public void setErrorHandler(XMLErrorHandler errorHandler) {
694         fProperties.put(ERROR_HANDLER, errorHandler);
695     } // setErrorHandler(XMLErrorHandler)
696

697     /**
698      * Return the current error handler.
699      *
700      * @return The current error handler, or null if none
701      * has been registered.
702      * @see #setErrorHandler
703      */

704     public XMLErrorHandler getErrorHandler() {
705         // REVISIT: Should this be a property?
706
return (XMLErrorHandler)fProperties.get(ERROR_HANDLER);
707     } // getErrorHandler():XMLErrorHandler
708

709
710     /**
711      * If the application decides to terminate parsing before the xml document
712      * is fully parsed, the application should call this method to free any
713      * resource allocated during parsing. For example, close all opened streams.
714      */

715     public void cleanup() {
716         fEntityManager.closeReaders();
717     }
718
719     /**
720      * Parses the specified input source.
721      *
722      * @param source The input source.
723      *
724      * @exception XNIException Throws exception on XNI error.
725      * @exception java.io.IOException Throws exception on i/o error.
726      */

727     public void parse(XMLInputSource source) throws XNIException, IOException JavaDoc {
728
729         if (fParseInProgress) {
730             // REVISIT - need to add new error message
731
throw new XNIException("FWK005 parse may not be called while parsing.");
732         }
733         fParseInProgress = true;
734
735         try {
736             setInputSource(source);
737             parse(true);
738         } catch (XNIException ex) {
739             if (PRINT_EXCEPTION_STACK_TRACE)
740                 ex.printStackTrace();
741             throw ex;
742         } catch (IOException JavaDoc ex) {
743             if (PRINT_EXCEPTION_STACK_TRACE)
744                 ex.printStackTrace();
745             throw ex;
746         } catch (RuntimeException JavaDoc ex) {
747             if (PRINT_EXCEPTION_STACK_TRACE)
748                 ex.printStackTrace();
749             throw ex;
750         } catch (Exception JavaDoc ex) {
751             if (PRINT_EXCEPTION_STACK_TRACE)
752                 ex.printStackTrace();
753             throw new XNIException(ex);
754         } finally {
755             fParseInProgress = false;
756             // close all streams opened by xerces
757
this.cleanup();
758         }
759
760     } // parse(InputSource)
761

762     public boolean parse(boolean complete) throws XNIException, IOException JavaDoc {
763         //
764
// reset and configure pipeline and set InputSource.
765
if (fInputSource != null) {
766             try {
767                 fValidationManager.reset();
768                 fVersionDetector.reset(this);
769                 resetCommon();
770
771                 short version = fVersionDetector.determineDocVersion(fInputSource);
772                 if (version == Constants.XML_VERSION_1_1) {
773                     initXML11Components();
774                     configureXML11Pipeline();
775                     resetXML11();
776                 } else {
777                     configurePipeline();
778                     reset();
779                 }
780                 
781                 // mark configuration as fixed
782
fConfigUpdated = false;
783
784                 // resets and sets the pipeline.
785
fVersionDetector.startDocumentParsing((XMLEntityHandler) fCurrentScanner, version);
786                 fInputSource = null;
787             } catch (XNIException ex) {
788                 if (PRINT_EXCEPTION_STACK_TRACE)
789                     ex.printStackTrace();
790                 throw ex;
791             } catch (IOException JavaDoc ex) {
792                 if (PRINT_EXCEPTION_STACK_TRACE)
793                     ex.printStackTrace();
794                 throw ex;
795             } catch (RuntimeException JavaDoc ex) {
796                 if (PRINT_EXCEPTION_STACK_TRACE)
797                     ex.printStackTrace();
798                 throw ex;
799             } catch (Exception JavaDoc ex) {
800                 if (PRINT_EXCEPTION_STACK_TRACE)
801                     ex.printStackTrace();
802                 throw new XNIException(ex);
803             }
804         }
805
806         try {
807             return fCurrentScanner.scanDocument(complete);
808         } catch (XNIException ex) {
809             if (PRINT_EXCEPTION_STACK_TRACE)
810                 ex.printStackTrace();
811             throw ex;
812         } catch (IOException JavaDoc ex) {
813             if (PRINT_EXCEPTION_STACK_TRACE)
814                 ex.printStackTrace();
815             throw ex;
816         } catch (RuntimeException JavaDoc ex) {
817             if (PRINT_EXCEPTION_STACK_TRACE)
818                 ex.printStackTrace();
819             throw ex;
820         } catch (Exception JavaDoc ex) {
821             if (PRINT_EXCEPTION_STACK_TRACE)
822                 ex.printStackTrace();
823             throw new XNIException(ex);
824         }
825
826     } // parse(boolean):boolean
827

828     /**
829      * Returns the state of a feature.
830      *
831      * @param featureId The feature identifier.
832          * @return true if the feature is supported
833      *
834      * @throws XMLConfigurationException Thrown for configuration error.
835      * In general, components should
836      * only throw this exception if
837      * it is <strong>really</strong>
838      * a critical error.
839      */

840     public boolean getFeature(String JavaDoc featureId)
841         throws XMLConfigurationException {
842             // make this feature special
843
if (featureId.equals(PARSER_SETTINGS)){
844             return fConfigUpdated;
845         }
846         return super.getFeature(featureId);
847
848     } // getFeature(String):boolean
849

850     /**
851      * Set the state of a feature.
852      *
853      * Set the state of any feature in a SAX2 parser. The parser
854      * might not recognize the feature, and if it does recognize
855      * it, it might not be able to fulfill the request.
856      *
857      * @param featureId The unique identifier (URI) of the feature.
858      * @param state The requested state of the feature (true or false).
859      *
860      * @exception org.apache.xerces.xni.parser.XMLConfigurationException If the
861      * requested feature is not known.
862      */

863     public void setFeature(String JavaDoc featureId, boolean state)
864         throws XMLConfigurationException {
865         fConfigUpdated = true;
866         // forward to every XML 1.0 component
867
int count = fComponents.size();
868         for (int i = 0; i < count; i++) {
869             XMLComponent c = (XMLComponent) fComponents.get(i);
870             c.setFeature(featureId, state);
871         }
872         // forward it to common components
873
count = fCommonComponents.size();
874         for (int i = 0; i < count; i++) {
875             XMLComponent c = (XMLComponent) fCommonComponents.get(i);
876             c.setFeature(featureId, state);
877         }
878                 
879         // forward to every XML 1.1 component
880
count = fXML11Components.size();
881         for (int i = 0; i < count; i++) {
882             XMLComponent c = (XMLComponent) fXML11Components.get(i);
883             try{
884                 c.setFeature(featureId, state);
885             }
886             catch (Exception JavaDoc e){
887                 // no op
888
}
889         }
890         // save state if noone "objects"
891
super.setFeature(featureId, state);
892
893     } // setFeature(String,boolean)
894

895     /**
896      * setProperty
897      *
898      * @param propertyId
899      * @param value
900      */

901     public void setProperty(String JavaDoc propertyId, Object JavaDoc value)
902         throws XMLConfigurationException {
903         fConfigUpdated = true;
904         // forward to every XML 1.0 component
905
int count = fComponents.size();
906         for (int i = 0; i < count; i++) {
907             XMLComponent c = (XMLComponent) fComponents.get(i);
908             c.setProperty(propertyId, value);
909         }
910         // forward it to every common Component
911
count = fCommonComponents.size();
912         for (int i = 0; i < count; i++) {
913             XMLComponent c = (XMLComponent) fCommonComponents.get(i);
914             c.setProperty(propertyId, value);
915         }
916         // forward it to every XML 1.1 component
917
count = fXML11Components.size();
918         for (int i = 0; i < count; i++) {
919             XMLComponent c = (XMLComponent) fXML11Components.get(i);
920             try{
921                 c.setProperty(propertyId, value);
922             }
923             catch (Exception JavaDoc e){
924                 // ignore it
925
}
926         }
927
928         // store value if noone "objects"
929
super.setProperty(propertyId, value);
930
931     } // setProperty(String,Object)
932

933
934     /** Returns the locale. */
935     public Locale JavaDoc getLocale() {
936         return fLocale;
937     } // getLocale():Locale
938

939     /**
940      * reset all XML 1.0 components before parsing and namespace context
941      */

942     protected void reset() throws XNIException {
943         int count = fComponents.size();
944         for (int i = 0; i < count; i++) {
945             XMLComponent c = (XMLComponent) fComponents.get(i);
946             c.reset(this);
947         }
948
949     } // reset()
950

951     /**
952      * reset all common components before parsing
953      */

954     protected void resetCommon() throws XNIException {
955         // reset common components
956
int count = fCommonComponents.size();
957         for (int i = 0; i < count; i++) {
958             XMLComponent c = (XMLComponent) fCommonComponents.get(i);
959             c.reset(this);
960         }
961
962     } // resetCommon()
963

964     
965     /**
966      * reset all components before parsing and namespace context
967      */

968     protected void resetXML11() throws XNIException {
969         // reset every component
970
int count = fXML11Components.size();
971         for (int i = 0; i < count; i++) {
972             XMLComponent c = (XMLComponent) fXML11Components.get(i);
973             c.reset(this);
974         }
975
976     } // resetXML11()
977

978
979     /**
980      * Configures the XML 1.1 pipeline.
981      * Note: this method also resets the new XML11 components.
982      */

983     protected void configureXML11Pipeline() {
984         if (fCurrentDVFactory != fXML11DatatypeFactory) {
985             fCurrentDVFactory = fXML11DatatypeFactory;
986             setProperty(DATATYPE_VALIDATOR_FACTORY, fCurrentDVFactory);
987         }
988         if (fCurrentDTDScanner != fXML11DTDScanner) {
989             fCurrentDTDScanner = fXML11DTDScanner;
990             setProperty(DTD_SCANNER, fCurrentDTDScanner);
991             setProperty(DTD_PROCESSOR, fXML11DTDProcessor);
992         }
993
994         fXML11DTDScanner.setDTDHandler(fXML11DTDProcessor);
995         fXML11DTDProcessor.setDTDSource(fXML11DTDScanner);
996         fXML11DTDProcessor.setDTDHandler(fDTDHandler);
997         if (fDTDHandler != null) {
998             fDTDHandler.setDTDSource(fXML11DTDProcessor);
999         }
1000
1001        fXML11DTDScanner.setDTDContentModelHandler(fXML11DTDProcessor);
1002        fXML11DTDProcessor.setDTDContentModelSource(fXML11DTDScanner);
1003        fXML11DTDProcessor.setDTDContentModelHandler(fDTDContentModelHandler);
1004        if (fDTDContentModelHandler != null) {
1005            fDTDContentModelHandler.setDTDContentModelSource(fXML11DTDProcessor);
1006        }
1007
1008        // setup XML 1.1 document pipeline
1009
if (fFeatures.get(NAMESPACES) == Boolean.TRUE) {
1010            if (fCurrentScanner != fXML11NSDocScanner) {
1011                fCurrentScanner = fXML11NSDocScanner;
1012                setProperty(DOCUMENT_SCANNER, fXML11NSDocScanner);
1013                setProperty(DTD_VALIDATOR, fXML11NSDTDValidator);
1014            }
1015
1016            fXML11NSDocScanner.setDTDValidator(fXML11NSDTDValidator);
1017            fXML11NSDocScanner.setDocumentHandler(fXML11NSDTDValidator);
1018            fXML11NSDTDValidator.setDocumentSource(fXML11NSDocScanner);
1019            fXML11NSDTDValidator.setDocumentHandler(fDocumentHandler);
1020
1021            if (fDocumentHandler != null) {
1022                fDocumentHandler.setDocumentSource(fXML11NSDTDValidator);
1023            }
1024            fLastComponent = fXML11NSDTDValidator;
1025
1026        } else {
1027            // create components
1028
if (fXML11DocScanner == null) {
1029                    // non namespace document pipeline
1030
fXML11DocScanner = new XML11DocumentScannerImpl();
1031                    addXML11Component(fXML11DocScanner);
1032                    fXML11DTDValidator = new XML11DTDValidator();
1033                    addXML11Component(fXML11DTDValidator);
1034              }
1035            if (fCurrentScanner != fXML11DocScanner) {
1036                fCurrentScanner = fXML11DocScanner;
1037                setProperty(DOCUMENT_SCANNER, fXML11DocScanner);
1038                setProperty(DTD_VALIDATOR, fXML11DTDValidator);
1039            }
1040            fXML11DocScanner.setDocumentHandler(fXML11DTDValidator);
1041            fXML11DTDValidator.setDocumentSource(fXML11DocScanner);
1042            fXML11DTDValidator.setDocumentHandler(fDocumentHandler);
1043
1044            if (fDocumentHandler != null) {
1045                fDocumentHandler.setDocumentSource(fXML11DTDValidator);
1046            }
1047            fLastComponent = fXML11DTDValidator;
1048        }
1049
1050        // setup document pipeline
1051
if (fFeatures.get(XMLSCHEMA_VALIDATION) == Boolean.TRUE) {
1052            // If schema validator was not in the pipeline insert it.
1053
if (fSchemaValidator == null) {
1054                fSchemaValidator = new XMLSchemaValidator();
1055                // add schema component
1056
setProperty(SCHEMA_VALIDATOR, fSchemaValidator);
1057                addCommonComponent(fSchemaValidator);
1058                fSchemaValidator.reset(this);
1059                // add schema message formatter
1060
if (fErrorReporter.getMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN) == null) {
1061                    XSMessageFormatter xmft = new XSMessageFormatter();
1062                    fErrorReporter.putMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN, xmft);
1063                }
1064            }
1065
1066            fLastComponent.setDocumentHandler(fSchemaValidator);
1067            fSchemaValidator.setDocumentSource(fLastComponent);
1068            fSchemaValidator.setDocumentHandler(fDocumentHandler);
1069            if (fDocumentHandler != null) {
1070                fDocumentHandler.setDocumentSource(fSchemaValidator);
1071            }
1072            fLastComponent = fSchemaValidator;
1073        }
1074
1075    } // configureXML11Pipeline()
1076

1077    /** Configures the pipeline. */
1078    protected void configurePipeline() {
1079        if (fCurrentDVFactory != fDatatypeValidatorFactory) {
1080            fCurrentDVFactory = fDatatypeValidatorFactory;
1081            // use XML 1.0 datatype library
1082
setProperty(DATATYPE_VALIDATOR_FACTORY, fCurrentDVFactory);
1083        }
1084
1085        // setup DTD pipeline
1086
if (fCurrentDTDScanner != fDTDScanner) {
1087            fCurrentDTDScanner = fDTDScanner;
1088            setProperty(DTD_SCANNER, fCurrentDTDScanner);
1089            setProperty(DTD_PROCESSOR, fDTDProcessor);
1090        }
1091        fDTDScanner.setDTDHandler(fDTDProcessor);
1092        fDTDProcessor.setDTDSource(fDTDScanner);
1093        fDTDProcessor.setDTDHandler(fDTDHandler);
1094        if (fDTDHandler != null) {
1095            fDTDHandler.setDTDSource(fDTDProcessor);
1096        }
1097
1098        fDTDScanner.setDTDContentModelHandler(fDTDProcessor);
1099        fDTDProcessor.setDTDContentModelSource(fDTDScanner);
1100        fDTDProcessor.setDTDContentModelHandler(fDTDContentModelHandler);
1101        if (fDTDContentModelHandler != null) {
1102            fDTDContentModelHandler.setDTDContentModelSource(fDTDProcessor);
1103        }
1104
1105        // setup document pipeline
1106
if (fFeatures.get(NAMESPACES) == Boolean.TRUE) {
1107            if (fCurrentScanner != fNamespaceScanner) {
1108                fCurrentScanner = fNamespaceScanner;
1109                setProperty(DOCUMENT_SCANNER, fNamespaceScanner);
1110                setProperty(DTD_VALIDATOR, fDTDValidator);
1111            }
1112            fNamespaceScanner.setDTDValidator(fDTDValidator);
1113            fNamespaceScanner.setDocumentHandler(fDTDValidator);
1114            fDTDValidator.setDocumentSource(fNamespaceScanner);
1115            fDTDValidator.setDocumentHandler(fDocumentHandler);
1116            if (fDocumentHandler != null) {
1117                fDocumentHandler.setDocumentSource(fDTDValidator);
1118            }
1119            fLastComponent = fDTDValidator;
1120        } else {
1121            // create components
1122
if (fNonNSScanner == null) {
1123                fNonNSScanner = new XMLDocumentScannerImpl();
1124                fNonNSDTDValidator = new XMLDTDValidator();
1125                // add components
1126
addComponent((XMLComponent) fNonNSScanner);
1127                addComponent((XMLComponent) fNonNSDTDValidator);
1128            }
1129            if (fCurrentScanner != fNonNSScanner) {
1130                fCurrentScanner = fNonNSScanner;
1131                setProperty(DOCUMENT_SCANNER, fNonNSScanner);
1132                setProperty(DTD_VALIDATOR, fNonNSDTDValidator);
1133            }
1134
1135            fNonNSScanner.setDocumentHandler(fNonNSDTDValidator);
1136            fNonNSDTDValidator.setDocumentSource(fNonNSScanner);
1137            fNonNSDTDValidator.setDocumentHandler(fDocumentHandler);
1138            if (fDocumentHandler != null) {
1139                fDocumentHandler.setDocumentSource(fNonNSDTDValidator);
1140            }
1141            fLastComponent = fNonNSDTDValidator;
1142        }
1143
1144        // add XML Schema validator if needed
1145
if (fFeatures.get(XMLSCHEMA_VALIDATION) == Boolean.TRUE) {
1146            // If schema validator was not in the pipeline insert it.
1147
if (fSchemaValidator == null) {
1148                fSchemaValidator = new XMLSchemaValidator();
1149                // add schema component
1150
setProperty(SCHEMA_VALIDATOR, fSchemaValidator);
1151                addCommonComponent(fSchemaValidator);
1152                fSchemaValidator.reset(this);
1153                // add schema message formatter
1154
if (fErrorReporter.getMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN) == null) {
1155                    XSMessageFormatter xmft = new XSMessageFormatter();
1156                    fErrorReporter.putMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN, xmft);
1157                }
1158
1159            }
1160            fLastComponent.setDocumentHandler(fSchemaValidator);
1161            fSchemaValidator.setDocumentSource(fLastComponent);
1162            fSchemaValidator.setDocumentHandler(fDocumentHandler);
1163            if (fDocumentHandler != null) {
1164                fDocumentHandler.setDocumentSource(fSchemaValidator);
1165            }
1166            fLastComponent = fSchemaValidator;
1167        }
1168    } // configurePipeline()
1169

1170
1171    // features and properties
1172

1173    /**
1174     * Check a feature. If feature is know and supported, this method simply
1175     * returns. Otherwise, the appropriate exception is thrown.
1176     *
1177     * @param featureId The unique identifier (URI) of the feature.
1178     *
1179     * @throws XMLConfigurationException Thrown for configuration error.
1180     * In general, components should
1181     * only throw this exception if
1182     * it is <strong>really</strong>
1183     * a critical error.
1184     */

1185    protected void checkFeature(String JavaDoc featureId) throws XMLConfigurationException {
1186
1187        //
1188
// Xerces Features
1189
//
1190

1191        if (featureId.startsWith(Constants.XERCES_FEATURE_PREFIX)) {
1192            final int suffixLength = featureId.length() - Constants.XERCES_FEATURE_PREFIX.length();
1193            
1194            //
1195
// http://apache.org/xml/features/validation/dynamic
1196
// Allows the parser to validate a document only when it
1197
// contains a grammar. Validation is turned on/off based
1198
// on each document instance, automatically.
1199
//
1200
if (suffixLength == Constants.DYNAMIC_VALIDATION_FEATURE.length() &&
1201                featureId.endsWith(Constants.DYNAMIC_VALIDATION_FEATURE)) {
1202                return;
1203            }
1204
1205            //
1206
// http://apache.org/xml/features/validation/default-attribute-values
1207
//
1208
if (suffixLength == Constants.DEFAULT_ATTRIBUTE_VALUES_FEATURE.length() &&
1209                featureId.endsWith(Constants.DEFAULT_ATTRIBUTE_VALUES_FEATURE)) {
1210                // REVISIT
1211
short type = XMLConfigurationException.NOT_SUPPORTED;
1212                throw new XMLConfigurationException(type, featureId);
1213            }
1214            //
1215
// http://apache.org/xml/features/validation/default-attribute-values
1216
//
1217
if (suffixLength == Constants.VALIDATE_CONTENT_MODELS_FEATURE.length() &&
1218                featureId.endsWith(Constants.VALIDATE_CONTENT_MODELS_FEATURE)) {
1219                // REVISIT
1220
short type = XMLConfigurationException.NOT_SUPPORTED;
1221                throw new XMLConfigurationException(type, featureId);
1222            }
1223            //
1224
// http://apache.org/xml/features/validation/nonvalidating/load-dtd-grammar
1225
//
1226
if (suffixLength == Constants.LOAD_DTD_GRAMMAR_FEATURE.length() &&
1227                featureId.endsWith(Constants.LOAD_DTD_GRAMMAR_FEATURE)) {
1228                return;
1229            }
1230            //
1231
// http://apache.org/xml/features/validation/nonvalidating/load-external-dtd
1232
//
1233
if (suffixLength == Constants.LOAD_EXTERNAL_DTD_FEATURE.length() &&
1234                featureId.endsWith(Constants.LOAD_EXTERNAL_DTD_FEATURE)) {
1235                return;
1236            }
1237
1238            //
1239
// http://apache.org/xml/features/validation/default-attribute-values
1240
//
1241
if (suffixLength == Constants.VALIDATE_DATATYPES_FEATURE.length() &&
1242                featureId.endsWith(Constants.VALIDATE_DATATYPES_FEATURE)) {
1243                short type = XMLConfigurationException.NOT_SUPPORTED;
1244                throw new XMLConfigurationException(type, featureId);
1245            }
1246            
1247            //
1248
// http://apache.org/xml/features/validation/schema
1249
// Lets the user turn Schema validation support on/off.
1250
//
1251
if (suffixLength == Constants.SCHEMA_VALIDATION_FEATURE.length() &&
1252                featureId.endsWith(Constants.SCHEMA_VALIDATION_FEATURE)) {
1253                return;
1254            }
1255            // activate full schema checking
1256
if (suffixLength == Constants.SCHEMA_FULL_CHECKING.length() &&
1257                featureId.endsWith(Constants.SCHEMA_FULL_CHECKING)) {
1258                return;
1259            }
1260            // Feature identifier: expose schema normalized value
1261
// http://apache.org/xml/features/validation/schema/normalized-value
1262
if (suffixLength == Constants.SCHEMA_NORMALIZED_VALUE.length() &&
1263                featureId.endsWith(Constants.SCHEMA_NORMALIZED_VALUE)) {
1264                return;
1265            }
1266            // Feature identifier: send element default value via characters()
1267
// http://apache.org/xml/features/validation/schema/element-default
1268
if (suffixLength == Constants.SCHEMA_ELEMENT_DEFAULT.length() &&
1269                featureId.endsWith(Constants.SCHEMA_ELEMENT_DEFAULT)) {
1270                return;
1271            }
1272             
1273            // special performance feature: only component manager is allowed to set it.
1274
if (suffixLength == Constants.PARSER_SETTINGS.length() &&
1275                featureId.endsWith(Constants.PARSER_SETTINGS)) {
1276                short type = XMLConfigurationException.NOT_SUPPORTED;
1277                throw new XMLConfigurationException(type, featureId);
1278            }
1279
1280        }
1281
1282        //
1283
// Not recognized
1284
//
1285

1286        super.checkFeature(featureId);
1287
1288    } // checkFeature(String)
1289

1290    /**
1291     * Check a property. If the property is know and supported, this method
1292     * simply returns. Otherwise, the appropriate exception is thrown.
1293     *
1294     * @param propertyId The unique identifier (URI) of the property
1295     * being set.
1296     *
1297     * @throws XMLConfigurationException Thrown for configuration error.
1298     * In general, components should
1299     * only throw this exception if
1300     * it is <strong>really</strong>
1301     * a critical error.
1302     */

1303    protected void checkProperty(String JavaDoc propertyId) throws XMLConfigurationException {
1304
1305        //
1306
// Xerces Properties
1307
//
1308

1309        if (propertyId.startsWith(Constants.XERCES_PROPERTY_PREFIX)) {
1310            final int suffixLength = propertyId.length() - Constants.XERCES_PROPERTY_PREFIX.length();
1311
1312            if (suffixLength == Constants.DTD_SCANNER_PROPERTY.length() &&
1313                propertyId.endsWith(Constants.DTD_SCANNER_PROPERTY)) {
1314                return;
1315            }
1316            if (suffixLength == Constants.SCHEMA_LOCATION.length() &&
1317                propertyId.endsWith(Constants.SCHEMA_LOCATION)) {
1318                return;
1319            }
1320            if (suffixLength == Constants.SCHEMA_NONS_LOCATION.length() &&
1321                propertyId.endsWith(Constants.SCHEMA_NONS_LOCATION)) {
1322                return;
1323            }
1324        }
1325        
1326        if (propertyId.startsWith(Constants.JAXP_PROPERTY_PREFIX)) {
1327            final int suffixLength = propertyId.length() - Constants.JAXP_PROPERTY_PREFIX.length();
1328
1329            if (suffixLength == Constants.SCHEMA_SOURCE.length() &&
1330                propertyId.endsWith(Constants.SCHEMA_SOURCE)) {
1331                return;
1332            }
1333        }
1334        
1335        // special cases
1336
if (propertyId.startsWith(Constants.SAX_PROPERTY_PREFIX)) {
1337            final int suffixLength = propertyId.length() - Constants.SAX_PROPERTY_PREFIX.length();
1338            
1339            //
1340
// http://xml.org/sax/properties/xml-string
1341
// Value type: String
1342
// Access: read-only
1343
// Get the literal string of characters associated with the
1344
// current event. If the parser recognises and supports this
1345
// property but is not currently parsing text, it should return
1346
// null (this is a good way to check for availability before the
1347
// parse begins).
1348
//
1349
if (suffixLength == Constants.XML_STRING_PROPERTY.length() &&
1350                propertyId.endsWith(Constants.XML_STRING_PROPERTY)) {
1351                // REVISIT - we should probably ask xml-dev for a precise
1352
// definition of what this is actually supposed to return, and
1353
// in exactly which circumstances.
1354
short type = XMLConfigurationException.NOT_SUPPORTED;
1355                throw new XMLConfigurationException(type, propertyId);
1356            }
1357        }
1358
1359        //
1360
// Not recognized
1361
//
1362

1363        super.checkProperty(propertyId);
1364
1365    } // checkProperty(String)
1366

1367
1368    /**
1369     * Adds a component to the parser configuration. This method will
1370     * also add all of the component's recognized features and properties
1371     * to the list of default recognized features and properties.
1372     *
1373     * @param component The component to add.
1374     */

1375    protected void addComponent(XMLComponent component) {
1376
1377        // don't add a component more than once
1378
if (fComponents.contains(component)) {
1379            return;
1380        }
1381        fComponents.add(component);
1382        addRecognizedParamsAndSetDefaults(component);
1383    
1384    } // addComponent(XMLComponent)
1385

1386    /**
1387     * Adds common component to the parser configuration. This method will
1388     * also add all of the component's recognized features and properties
1389     * to the list of default recognized features and properties.
1390     *
1391     * @param component The component to add.
1392     */

1393    protected void addCommonComponent(XMLComponent component) {
1394
1395        // don't add a component more than once
1396
if (fCommonComponents.contains(component)) {
1397            return;
1398        }
1399        fCommonComponents.add(component);
1400        addRecognizedParamsAndSetDefaults(component);
1401
1402    } // addCommonComponent(XMLComponent)
1403

1404    /**
1405     * Adds an XML 1.1 component to the parser configuration. This method will
1406     * also add all of the component's recognized features and properties
1407     * to the list of default recognized features and properties.
1408     *
1409     * @param component The component to add.
1410     */

1411    protected void addXML11Component(XMLComponent component) {
1412
1413        // don't add a component more than once
1414
if (fXML11Components.contains(component)) {
1415            return;
1416        }
1417        fXML11Components.add(component);
1418        addRecognizedParamsAndSetDefaults(component);
1419        
1420    } // addXML11Component(XMLComponent)
1421

1422    /**
1423     * Adds all of the component's recognized features and properties
1424     * to the list of default recognized features and properties, and
1425     * sets default values on the configuration for features and
1426     * properties which were previously absent from the configuration.
1427     *
1428     * @param component The component whose recognized features
1429     * and properties will be added to the configuration
1430     */

1431    protected void addRecognizedParamsAndSetDefaults(XMLComponent component) {
1432        
1433        // register component's recognized features
1434
String JavaDoc[] recognizedFeatures = component.getRecognizedFeatures();
1435        addRecognizedFeatures(recognizedFeatures);
1436        
1437        // register component's recognized properties
1438
String JavaDoc[] recognizedProperties = component.getRecognizedProperties();
1439        addRecognizedProperties(recognizedProperties);
1440
1441        // set default values
1442
if (recognizedFeatures != null) {
1443            for (int i = 0; i < recognizedFeatures.length; ++i) {
1444                String JavaDoc featureId = recognizedFeatures[i];
1445                Boolean JavaDoc state = component.getFeatureDefault(featureId);
1446                if (state != null) {
1447                    // Do not overwrite values already set on the configuration.
1448
if (!fFeatures.containsKey(featureId)) {
1449                        fFeatures.put(featureId, state);
1450                        // For newly added components who recognize this feature
1451
// but did not offer a default value, we need to make
1452
// sure these components will get an opportunity to read
1453
// the value before parsing begins.
1454
fConfigUpdated = true;
1455                    }
1456                }
1457            }
1458        }
1459        if (recognizedProperties != null) {
1460            for (int i = 0; i < recognizedProperties.length; ++i) {
1461                String JavaDoc propertyId = recognizedProperties[i];
1462                Object JavaDoc value = component.getPropertyDefault(propertyId);
1463                if (value != null) {
1464                    // Do not overwrite values already set on the configuration.
1465
if (!fProperties.containsKey(propertyId)) {
1466                        fProperties.put(propertyId, value);
1467                        // For newly added components who recognize this property
1468
// but did not offer a default value, we need to make
1469
// sure these components will get an opportunity to read
1470
// the value before parsing begins.
1471
fConfigUpdated = true;
1472                    }
1473                }
1474            }
1475        }
1476    }
1477
1478    private void initXML11Components() {
1479        if (!f11Initialized) {
1480
1481            // create datatype factory
1482
fXML11DatatypeFactory = DTDDVFactory.getInstance(XML11_DATATYPE_VALIDATOR_FACTORY);
1483
1484            // setup XML 1.1 DTD pipeline
1485
fXML11DTDScanner = new XML11DTDScannerImpl();
1486            addXML11Component(fXML11DTDScanner);
1487            fXML11DTDProcessor = new XML11DTDProcessor();
1488            addXML11Component(fXML11DTDProcessor);
1489
1490            // setup XML 1.1. document pipeline - namespace aware
1491
fXML11NSDocScanner = new XML11NSDocumentScannerImpl();
1492            addXML11Component(fXML11NSDocScanner);
1493            fXML11NSDTDValidator = new XML11NSDTDValidator();
1494            addXML11Component(fXML11NSDTDValidator);
1495                
1496            f11Initialized = true;
1497        }
1498    }
1499    
1500    /**
1501     * Returns the state of a feature. This method calls getFeature()
1502     * on ParserConfigurationSettings, bypassing getFeature() on this
1503     * class.
1504     */

1505    boolean getFeature0(String JavaDoc featureId)
1506        throws XMLConfigurationException {
1507        return super.getFeature(featureId);
1508    }
1509
1510} // class XML11Configuration
1511
Popular Tags