KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xerces > internal > impl > xs > opti > SchemaParsingConfig


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 2001-2004 The Apache Software Foundation. All rights
6  * 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) 2001, 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.impl.xs.opti;
59
60 import java.io.IOException JavaDoc;
61 import java.util.Locale JavaDoc;
62
63 import com.sun.org.apache.xerces.internal.impl.Constants;
64 import com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl;
65 import com.sun.org.apache.xerces.internal.impl.XMLEntityManager;
66 import com.sun.org.apache.xerces.internal.impl.XMLErrorReporter;
67 import com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl;
68 import com.sun.org.apache.xerces.internal.impl.dv.DTDDVFactory;
69 import com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter;
70 import com.sun.org.apache.xerces.internal.impl.validation.ValidationManager;
71 import com.sun.org.apache.xerces.internal.impl.xs.XSMessageFormatter;
72 import com.sun.org.apache.xerces.internal.parsers.BasicParserConfiguration;
73 import com.sun.org.apache.xerces.internal.util.SymbolTable;
74 import com.sun.org.apache.xerces.internal.xni.XMLLocator;
75 import com.sun.org.apache.xerces.internal.xni.XNIException;
76 import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool;
77 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponent;
78 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager;
79 import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException;
80 import com.sun.org.apache.xerces.internal.xni.parser.XMLDTDScanner;
81 import com.sun.org.apache.xerces.internal.xni.parser.XMLDocumentScanner;
82 import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource;
83 import com.sun.org.apache.xerces.internal.xni.parser.XMLPullParserConfiguration;
84 import org.w3c.dom.Document JavaDoc;
85
86
87 /**
88  * @author Rahul Srivastava, Sun Microsystems Inc.
89  *
90  * @version $Id: SchemaParsingConfig.java,v 1.5 2004/01/26 17:28:11 mrglavas Exp $
91  */

92 public class SchemaParsingConfig extends BasicParserConfiguration
93                                  implements XMLPullParserConfiguration {
94
95     //
96
// Constants
97
//
98

99     // feature identifiers
100

101     /** Feature identifier: warn on duplicate attribute definition. */
102     protected static final String JavaDoc WARN_ON_DUPLICATE_ATTDEF =
103         Constants.XERCES_FEATURE_PREFIX + Constants.WARN_ON_DUPLICATE_ATTDEF_FEATURE;
104
105     /** Feature identifier: warn on duplicate entity definition. */
106     // protected static final String WARN_ON_DUPLICATE_ENTITYDEF = Constants.XERCES_FEATURE_PREFIX + Constants.WARN_ON_DUPLICATE_ENTITYDEF_FEATURE;
107

108     /** Feature identifier: warn on undeclared element definition. */
109     protected static final String JavaDoc WARN_ON_UNDECLARED_ELEMDEF =
110         Constants.XERCES_FEATURE_PREFIX + Constants.WARN_ON_UNDECLARED_ELEMDEF_FEATURE;
111     
112     /** Feature identifier: allow Java encodings. */
113     protected static final String JavaDoc ALLOW_JAVA_ENCODINGS =
114         Constants.XERCES_FEATURE_PREFIX + Constants.ALLOW_JAVA_ENCODINGS_FEATURE;
115     
116     /** Feature identifier: continue after fatal error. */
117     protected static final String JavaDoc CONTINUE_AFTER_FATAL_ERROR =
118         Constants.XERCES_FEATURE_PREFIX + Constants.CONTINUE_AFTER_FATAL_ERROR_FEATURE;
119
120     /** Feature identifier: load external DTD. */
121     protected static final String JavaDoc LOAD_EXTERNAL_DTD =
122         Constants.XERCES_FEATURE_PREFIX + Constants.LOAD_EXTERNAL_DTD_FEATURE;
123
124     /** Feature identifier: notify built-in refereces. */
125     protected static final String JavaDoc NOTIFY_BUILTIN_REFS =
126         Constants.XERCES_FEATURE_PREFIX + Constants.NOTIFY_BUILTIN_REFS_FEATURE;
127     
128     /** Feature identifier: notify character refereces. */
129     protected static final String JavaDoc NOTIFY_CHAR_REFS =
130         Constants.XERCES_FEATURE_PREFIX + Constants.NOTIFY_CHAR_REFS_FEATURE;
131     
132
133     /** Feature identifier: expose schema normalized value */
134     protected static final String JavaDoc NORMALIZE_DATA =
135     Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_NORMALIZED_VALUE;
136
137
138     /** Feature identifier: send element default value via characters() */
139     protected static final String JavaDoc SCHEMA_ELEMENT_DEFAULT =
140     Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_ELEMENT_DEFAULT;
141         
142
143     // property identifiers
144

145     /** Property identifier: error reporter. */
146     protected static final String JavaDoc ERROR_REPORTER =
147         Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY;
148
149     /** Property identifier: entity manager. */
150     protected static final String JavaDoc ENTITY_MANAGER =
151         Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_MANAGER_PROPERTY;
152     
153     /** Property identifier document scanner: */
154     protected static final String JavaDoc DOCUMENT_SCANNER =
155         Constants.XERCES_PROPERTY_PREFIX + Constants.DOCUMENT_SCANNER_PROPERTY;
156
157     /** Property identifier: DTD scanner. */
158     protected static final String JavaDoc DTD_SCANNER =
159         Constants.XERCES_PROPERTY_PREFIX + Constants.DTD_SCANNER_PROPERTY;
160
161     /** Property identifier: grammar pool. */
162     protected static final String JavaDoc XMLGRAMMAR_POOL =
163         Constants.XERCES_PROPERTY_PREFIX + Constants.XMLGRAMMAR_POOL_PROPERTY;
164     
165     /** Property identifier: DTD validator. */
166     protected static final String JavaDoc DTD_VALIDATOR =
167         Constants.XERCES_PROPERTY_PREFIX + Constants.DTD_VALIDATOR_PROPERTY;
168
169     /** Property identifier: namespace binder. */
170     protected static final String JavaDoc NAMESPACE_BINDER =
171         Constants.XERCES_PROPERTY_PREFIX + Constants.NAMESPACE_BINDER_PROPERTY;
172
173     /** Property identifier: datatype validator factory. */
174     protected static final String JavaDoc DATATYPE_VALIDATOR_FACTORY =
175         Constants.XERCES_PROPERTY_PREFIX + Constants.DATATYPE_VALIDATOR_FACTORY_PROPERTY;
176
177     protected static final String JavaDoc VALIDATION_MANAGER =
178         Constants.XERCES_PROPERTY_PREFIX + Constants.VALIDATION_MANAGER_PROPERTY;
179
180     /** Property identifier: XML Schema validator. */
181     protected static final String JavaDoc SCHEMA_VALIDATOR =
182         Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_VALIDATOR_PROPERTY;
183
184
185     // debugging
186

187     /** Set to true and recompile to print exception stack trace. */
188     private static final boolean PRINT_EXCEPTION_STACK_TRACE = false;
189
190     //
191
// Data
192
//
193

194     // components (non-configurable)
195

196     /** Grammar pool. */
197     protected XMLGrammarPool fGrammarPool;
198
199     /** Datatype validator factory. */
200     protected DTDDVFactory fDatatypeValidatorFactory;
201
202     // components (configurable)
203

204     /** Error reporter. */
205     protected XMLErrorReporter fErrorReporter;
206
207     /** Entity manager. */
208     protected XMLEntityManager fEntityManager;
209
210     /** Document scanner. */
211     protected XMLDocumentScanner fScanner;
212
213     /** Input Source */
214     protected XMLInputSource fInputSource;
215
216     /** DTD scanner. */
217     protected XMLDTDScanner fDTDScanner;
218
219     
220     protected SchemaDOMParser fSchemaDOMParser;
221
222     protected ValidationManager fValidationManager;
223     // state
224

225     /** Locator */
226     protected XMLLocator fLocator;
227
228     /**
229      * True if a parse is in progress. This state is needed because
230      * some features/properties cannot be set while parsing (e.g.
231      * validation and namespaces).
232      */

233     protected boolean fParseInProgress = false;
234
235     //
236
// Constructors
237
//
238

239     /** Default constructor. */
240     public SchemaParsingConfig() {
241         this(null, null, null);
242     } // <init>()
243

244     /**
245      * Constructs a parser configuration using the specified symbol table.
246      *
247      * @param symbolTable The symbol table to use.
248      */

249     public SchemaParsingConfig(SymbolTable symbolTable) {
250         this(symbolTable, null, null);
251     } // <init>(SymbolTable)
252

253     /**
254      * Constructs a parser configuration using the specified symbol table and
255      * grammar pool.
256      * <p>
257      * <strong>REVISIT:</strong>
258      * Grammar pool will be updated when the new validation engine is
259      * implemented.
260      *
261      * @param symbolTable The symbol table to use.
262      * @param grammarPool The grammar pool to use.
263      */

264     public SchemaParsingConfig(SymbolTable symbolTable,
265                                        XMLGrammarPool grammarPool) {
266         this(symbolTable, grammarPool, null);
267     } // <init>(SymbolTable,XMLGrammarPool)
268

269     /**
270      * Constructs a parser configuration using the specified symbol table,
271      * grammar pool, and parent settings.
272      * <p>
273      * <strong>REVISIT:</strong>
274      * Grammar pool will be updated when the new validation engine is
275      * implemented.
276      *
277      * @param symbolTable The symbol table to use.
278      * @param grammarPool The grammar pool to use.
279      * @param parentSettings The parent settings.
280      */

281     public SchemaParsingConfig(SymbolTable symbolTable,
282                                        XMLGrammarPool grammarPool,
283                                        XMLComponentManager parentSettings) {
284         super(symbolTable, parentSettings);
285
286         // add default recognized features
287
final String JavaDoc[] recognizedFeatures = {
288             PARSER_SETTINGS, WARN_ON_DUPLICATE_ATTDEF, WARN_ON_UNDECLARED_ELEMDEF,
289             ALLOW_JAVA_ENCODINGS, CONTINUE_AFTER_FATAL_ERROR,
290             LOAD_EXTERNAL_DTD, NOTIFY_BUILTIN_REFS,
291             NOTIFY_CHAR_REFS
292         };
293         addRecognizedFeatures(recognizedFeatures);
294         fFeatures.put(PARSER_SETTINGS, Boolean.TRUE);
295         // set state for default features
296
fFeatures.put(WARN_ON_DUPLICATE_ATTDEF, Boolean.FALSE);
297         //setFeature(WARN_ON_DUPLICATE_ENTITYDEF, false);
298
fFeatures.put(WARN_ON_UNDECLARED_ELEMDEF, Boolean.FALSE);
299         fFeatures.put(ALLOW_JAVA_ENCODINGS, Boolean.FALSE);
300         fFeatures.put(CONTINUE_AFTER_FATAL_ERROR, Boolean.FALSE);
301         fFeatures.put(LOAD_EXTERNAL_DTD, Boolean.TRUE);
302         fFeatures.put(NOTIFY_BUILTIN_REFS, Boolean.FALSE);
303         fFeatures.put(NOTIFY_CHAR_REFS, Boolean.FALSE);
304
305         // add default recognized properties
306
final String JavaDoc[] recognizedProperties = {
307             ERROR_REPORTER,
308             ENTITY_MANAGER,
309             DOCUMENT_SCANNER,
310             DTD_SCANNER,
311             DTD_VALIDATOR,
312             NAMESPACE_BINDER,
313             XMLGRAMMAR_POOL,
314             DATATYPE_VALIDATOR_FACTORY,
315             VALIDATION_MANAGER
316         };
317         addRecognizedProperties(recognizedProperties);
318     
319         fGrammarPool = grammarPool;
320         if(fGrammarPool != null){
321             setProperty(XMLGRAMMAR_POOL, fGrammarPool);
322         }
323
324         fEntityManager = new XMLEntityManager();
325         fProperties.put(ENTITY_MANAGER, fEntityManager);
326         addComponent(fEntityManager);
327
328         fErrorReporter = new XMLErrorReporter();
329         fErrorReporter.setDocumentLocator(fEntityManager.getEntityScanner());
330         fProperties.put(ERROR_REPORTER, fErrorReporter);
331         addComponent(fErrorReporter);
332
333         fScanner = new XMLNSDocumentScannerImpl();
334         fProperties.put(DOCUMENT_SCANNER, fScanner);
335         addComponent((XMLComponent)fScanner);
336
337         fDTDScanner = new XMLDTDScannerImpl();
338         fProperties.put(DTD_SCANNER, fDTDScanner);
339         addComponent((XMLComponent)fDTDScanner);
340
341         
342         fDatatypeValidatorFactory = DTDDVFactory.getInstance();;
343         fProperties.put(DATATYPE_VALIDATOR_FACTORY,
344                         fDatatypeValidatorFactory);
345         
346         fValidationManager = new ValidationManager();
347         fProperties.put(VALIDATION_MANAGER, fValidationManager);
348
349         // add message formatters
350
if (fErrorReporter.getMessageFormatter(XMLMessageFormatter.XML_DOMAIN) == null) {
351             XMLMessageFormatter xmft = new XMLMessageFormatter();
352             fErrorReporter.putMessageFormatter(XMLMessageFormatter.XML_DOMAIN, xmft);
353             fErrorReporter.putMessageFormatter(XMLMessageFormatter.XMLNS_DOMAIN, xmft);
354         }
355         
356         if (fErrorReporter.getMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN) == null) {
357             XSMessageFormatter xmft = new XSMessageFormatter();
358             fErrorReporter.putMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN, xmft);
359         }
360
361         // set locale
362
try {
363             setLocale(Locale.getDefault());
364         }
365         catch (XNIException e) {
366             // do nothing
367
// REVISIT: What is the right thing to do? -Ac
368
}
369
370     } // <init>(SymbolTable,XMLGrammarPool)
371

372     //
373
// Public methods
374
//
375

376     /**
377      * Set the locale to use for messages.
378      *
379      * @param locale The locale object to use for localization of messages.
380      *
381      * @exception XNIException Thrown if the parser does not support the
382      * specified locale.
383      */

384     public void setLocale(Locale JavaDoc locale) throws XNIException {
385         super.setLocale(locale);
386         fErrorReporter.setLocale(locale);
387     } // setLocale(Locale)
388

389     //
390
// XMLPullParserConfiguration methods
391
//
392

393     // parsing
394

395     /**
396      * Sets the input source for the document to parse.
397      *
398      * @param inputSource The document's input source.
399      *
400      * @exception XMLConfigurationException Thrown if there is a
401      * configuration error when initializing the
402      * parser.
403      * @exception IOException Thrown on I/O error.
404      *
405      * @see #parse(boolean)
406      */

407     public void setInputSource(XMLInputSource inputSource)
408         throws XMLConfigurationException, IOException JavaDoc {
409         
410         // REVISIT: this method used to reset all the components and
411
// construct the pipeline. Now reset() is called
412
// in parse (boolean) just before we parse the document
413
// Should this method still throw exceptions..?
414

415         fInputSource = inputSource;
416         
417     } // setInputSource(XMLInputSource)
418

419     /**
420      * Parses the document in a pull parsing fashion.
421      *
422      * @param complete True if the pull parser should parse the
423      * remaining document completely.
424      *
425      * @returns True if there is more document to parse.
426      *
427      * @exception XNIException Any XNI exception, possibly wrapping
428      * another exception.
429      * @exception IOException An IO exception from the parser, possibly
430      * from a byte stream or character stream
431      * supplied by the parser.
432      *
433      * @see #setInputSource
434      */

435     public boolean parse(boolean complete) throws XNIException, IOException JavaDoc {
436         //
437
// reset and configure pipeline and set InputSource.
438
if (fInputSource !=null) {
439             try {
440                 // resets and sets the pipeline.
441
reset();
442                 fScanner.setInputSource(fInputSource);
443                 fInputSource = null;
444             }
445             catch (XNIException ex) {
446                 if (PRINT_EXCEPTION_STACK_TRACE)
447                     ex.printStackTrace();
448                 throw ex;
449             }
450             catch (IOException JavaDoc ex) {
451                 if (PRINT_EXCEPTION_STACK_TRACE)
452                     ex.printStackTrace();
453                 throw ex;
454             }
455             catch (RuntimeException JavaDoc ex) {
456                 if (PRINT_EXCEPTION_STACK_TRACE)
457                     ex.printStackTrace();
458                 throw ex;
459             }
460             catch (Exception JavaDoc ex) {
461                 if (PRINT_EXCEPTION_STACK_TRACE)
462                     ex.printStackTrace();
463                 throw new XNIException(ex);
464             }
465         }
466
467         try {
468             return fScanner.scanDocument(complete);
469         }
470         catch (XNIException ex) {
471             if (PRINT_EXCEPTION_STACK_TRACE)
472                 ex.printStackTrace();
473             throw ex;
474         }
475         catch (IOException JavaDoc ex) {
476             if (PRINT_EXCEPTION_STACK_TRACE)
477                 ex.printStackTrace();
478             throw ex;
479         }
480         catch (RuntimeException JavaDoc ex) {
481             if (PRINT_EXCEPTION_STACK_TRACE)
482                 ex.printStackTrace();
483             throw ex;
484         }
485         catch (Exception JavaDoc ex) {
486             if (PRINT_EXCEPTION_STACK_TRACE)
487                 ex.printStackTrace();
488             throw new XNIException(ex);
489         }
490
491     } // parse(boolean):boolean
492

493     /**
494      * If the application decides to terminate parsing before the xml document
495      * is fully parsed, the application should call this method to free any
496      * resource allocated during parsing. For example, close all opened streams.
497      */

498     public void cleanup() {
499         fEntityManager.closeReaders();
500     }
501     
502     //
503
// XMLParserConfiguration methods
504
//
505

506     /**
507      * Parses the specified input source.
508      *
509      * @param source The input source.
510      *
511      * @exception XNIException Throws exception on XNI error.
512      * @exception java.io.IOException Throws exception on i/o error.
513      */

514     public void parse(XMLInputSource source) throws XNIException, IOException JavaDoc {
515
516         if (fParseInProgress) {
517             // REVISIT - need to add new error message
518
throw new XNIException("FWK005 parse may not be called while parsing.");
519         }
520         fParseInProgress = true;
521
522         try {
523             setInputSource(source);
524             parse(true);
525         }
526         catch (XNIException ex) {
527             if (PRINT_EXCEPTION_STACK_TRACE)
528                 ex.printStackTrace();
529             throw ex;
530         }
531         catch (IOException JavaDoc ex) {
532             if (PRINT_EXCEPTION_STACK_TRACE)
533                 ex.printStackTrace();
534             throw ex;
535         }
536         catch (RuntimeException JavaDoc ex) {
537             if (PRINT_EXCEPTION_STACK_TRACE)
538                 ex.printStackTrace();
539             throw ex;
540         }
541         catch (Exception JavaDoc ex) {
542             if (PRINT_EXCEPTION_STACK_TRACE)
543                 ex.printStackTrace();
544             throw new XNIException(ex);
545         }
546         finally {
547             fParseInProgress = false;
548             // close all streams opened by xerces
549
this.cleanup();
550         }
551
552     } // parse(InputSource)
553

554     //
555
// Protected methods
556
//
557

558     /**
559      * Reset all components before parsing.
560      *
561      * @throws XNIException Thrown if an error occurs during initialization.
562      */

563     public void reset() throws XNIException {
564
565         // set handlers
566
if (fSchemaDOMParser == null)
567             fSchemaDOMParser = new SchemaDOMParser(fErrorReporter);
568         fDocumentHandler = fSchemaDOMParser;
569         fDTDHandler = fSchemaDOMParser;
570         fDTDContentModelHandler = fSchemaDOMParser;
571
572         // configure the pipeline and initialize the components
573
configurePipeline();
574         super.reset();
575
576     } // reset()
577

578     /** Configures the pipeline. */
579     protected void configurePipeline() {
580
581         // setup document pipeline
582
fScanner.setDocumentHandler(fDocumentHandler);
583         fDocumentHandler.setDocumentSource(fScanner);
584         fLastComponent = fScanner;
585
586         // setup dtd pipeline
587
if (fDTDScanner != null) {
588                 fDTDScanner.setDTDHandler(fDTDHandler);
589                 fDTDScanner.setDTDContentModelHandler(fDTDContentModelHandler);
590         }
591
592
593     } // configurePipeline()
594

595     // features and properties
596

597     /**
598      * Check a feature. If feature is know and supported, this method simply
599      * returns. Otherwise, the appropriate exception is thrown.
600      *
601      * @param featureId The unique identifier (URI) of the feature.
602      *
603      * @throws XMLConfigurationException Thrown for configuration error.
604      * In general, components should
605      * only throw this exception if
606      * it is <strong>really</strong>
607      * a critical error.
608      */

609     protected void checkFeature(String JavaDoc featureId)
610         throws XMLConfigurationException {
611
612         //
613
// Xerces Features
614
//
615

616         if (featureId.startsWith(Constants.XERCES_FEATURE_PREFIX)) {
617             final int suffixLength = featureId.length() - Constants.XERCES_FEATURE_PREFIX.length();
618             
619             //
620
// http://apache.org/xml/features/validation/dynamic
621
// Allows the parser to validate a document only when it
622
// contains a grammar. Validation is turned on/off based
623
// on each document instance, automatically.
624
//
625
if (suffixLength == Constants.DYNAMIC_VALIDATION_FEATURE.length() &&
626                 featureId.endsWith(Constants.DYNAMIC_VALIDATION_FEATURE)) {
627                 return;
628             }
629             //
630
// http://apache.org/xml/features/validation/default-attribute-values
631
//
632
if (suffixLength == Constants.DEFAULT_ATTRIBUTE_VALUES_FEATURE.length() &&
633                 featureId.endsWith(Constants.DEFAULT_ATTRIBUTE_VALUES_FEATURE)) {
634                 // REVISIT
635
short type = XMLConfigurationException.NOT_SUPPORTED;
636                 throw new XMLConfigurationException(type, featureId);
637             }
638             //
639
// http://apache.org/xml/features/validation/default-attribute-values
640
//
641
if (suffixLength == Constants.VALIDATE_CONTENT_MODELS_FEATURE.length() &&
642                 featureId.endsWith(Constants.VALIDATE_CONTENT_MODELS_FEATURE)) {
643                 // REVISIT
644
short type = XMLConfigurationException.NOT_SUPPORTED;
645                 throw new XMLConfigurationException(type, featureId);
646             }
647             //
648
// http://apache.org/xml/features/validation/nonvalidating/load-dtd-grammar
649
//
650
if (suffixLength == Constants.LOAD_DTD_GRAMMAR_FEATURE.length() &&
651                 featureId.endsWith(Constants.LOAD_DTD_GRAMMAR_FEATURE)) {
652                 return;
653             }
654             //
655
// http://apache.org/xml/features/validation/nonvalidating/load-external-dtd
656
//
657
if (suffixLength == Constants.LOAD_EXTERNAL_DTD_FEATURE.length() &&
658                 featureId.endsWith(Constants.LOAD_EXTERNAL_DTD_FEATURE)) {
659                 return;
660             }
661
662             //
663
// http://apache.org/xml/features/validation/default-attribute-values
664
//
665
if (suffixLength == Constants.VALIDATE_DATATYPES_FEATURE.length() &&
666                 featureId.endsWith(Constants.VALIDATE_DATATYPES_FEATURE)) {
667                 short type = XMLConfigurationException.NOT_SUPPORTED;
668                 throw new XMLConfigurationException(type, featureId);
669             }
670         }
671
672         //
673
// Not recognized
674
//
675

676         super.checkFeature(featureId);
677
678     } // checkFeature(String)
679

680     /**
681      * Check a property. If the property is know and supported, this method
682      * simply returns. Otherwise, the appropriate exception is thrown.
683      *
684      * @param propertyId The unique identifier (URI) of the property
685      * being set.
686      *
687      * @throws XMLConfigurationException Thrown for configuration error.
688      * In general, components should
689      * only throw this exception if
690      * it is <strong>really</strong>
691      * a critical error.
692      */

693     protected void checkProperty(String JavaDoc propertyId)
694         throws XMLConfigurationException {
695
696         //
697
// Xerces Properties
698
//
699

700         if (propertyId.startsWith(Constants.XERCES_PROPERTY_PREFIX)) {
701             final int suffixLength = propertyId.length() - Constants.XERCES_PROPERTY_PREFIX.length();
702             
703             if (suffixLength == Constants.DTD_SCANNER_PROPERTY.length() &&
704                 propertyId.endsWith(Constants.DTD_SCANNER_PROPERTY)) {
705                 return;
706             }
707         }
708
709         if (propertyId.startsWith(Constants.JAXP_PROPERTY_PREFIX)) {
710             final int suffixLength = propertyId.length() - Constants.JAXP_PROPERTY_PREFIX.length();
711             
712             if (suffixLength == Constants.SCHEMA_SOURCE.length() &&
713                 propertyId.endsWith(Constants.SCHEMA_SOURCE)) {
714                 return;
715             }
716         }
717
718         //
719
// Not recognized
720
//
721

722         super.checkProperty(propertyId);
723
724     } // checkProperty(String)
725

726     
727     
728     //
729
// other methods
730
//
731

732     /** Returns the Document object. */
733     public Document JavaDoc getDocument() {
734         return fSchemaDOMParser.getDocument();
735     }
736
737     /** */
738     public void resetNodePool() {
739         // REVISIT: to implement: introduce a node pool to reuse DTM nodes.
740
// reset this pool here.
741
}
742     
743 }
744
Popular Tags