Source Code Cross Referenced for SAXParserImpl.java in  » XML » xerces-2_9_1 » org » apache » xerces » jaxp » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » XML » xerces 2_9_1 » org.apache.xerces.jaxp 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         * 
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:
018:        package org.apache.xerces.jaxp;
019:
020:        import java.io.IOException;
021:        import java.util.Enumeration;
022:        import java.util.HashMap;
023:        import java.util.Hashtable;
024:        import java.util.Iterator;
025:        import java.util.Map;
026:
027:        import javax.xml.XMLConstants;
028:        import javax.xml.validation.Schema;
029:
030:        import org.apache.xerces.impl.Constants;
031:        import org.apache.xerces.impl.validation.ValidationManager;
032:        import org.apache.xerces.impl.xs.XMLSchemaValidator;
033:        import org.apache.xerces.jaxp.validation.XSGrammarPoolContainer;
034:        import org.apache.xerces.util.SAXMessageFormatter;
035:        import org.apache.xerces.util.SecurityManager;
036:        import org.apache.xerces.xni.XMLDocumentHandler;
037:        import org.apache.xerces.xni.parser.XMLComponent;
038:        import org.apache.xerces.xni.parser.XMLComponentManager;
039:        import org.apache.xerces.xni.parser.XMLConfigurationException;
040:        import org.apache.xerces.xni.parser.XMLDocumentSource;
041:        import org.apache.xerces.xni.parser.XMLParserConfiguration;
042:        import org.apache.xerces.xs.AttributePSVI;
043:        import org.apache.xerces.xs.ElementPSVI;
044:        import org.apache.xerces.xs.PSVIProvider;
045:        import org.xml.sax.EntityResolver;
046:        import org.xml.sax.ErrorHandler;
047:        import org.xml.sax.HandlerBase;
048:        import org.xml.sax.InputSource;
049:        import org.xml.sax.Parser;
050:        import org.xml.sax.SAXException;
051:        import org.xml.sax.SAXNotRecognizedException;
052:        import org.xml.sax.SAXNotSupportedException;
053:        import org.xml.sax.XMLReader;
054:        import org.xml.sax.helpers.DefaultHandler;
055:
056:        /**
057:         * This is the implementation specific class for the
058:         * <code>javax.xml.parsers.SAXParser</code>.
059:         * 
060:         * @author Rajiv Mordani
061:         * @author Edwin Goei
062:         * 
063:         * @version $Id: SAXParserImpl.java 520058 2007-03-19 19:33:53Z mrglavas $
064:         */
065:        public class SAXParserImpl extends javax.xml.parsers.SAXParser
066:                implements  JAXPConstants, PSVIProvider {
067:
068:            /** Feature identifier: namespaces. */
069:            private static final String NAMESPACES_FEATURE = Constants.SAX_FEATURE_PREFIX
070:                    + Constants.NAMESPACES_FEATURE;
071:
072:            /** Feature identifier: namespace prefixes. */
073:            private static final String NAMESPACE_PREFIXES_FEATURE = Constants.SAX_FEATURE_PREFIX
074:                    + Constants.NAMESPACE_PREFIXES_FEATURE;
075:
076:            /** Feature identifier: validation. */
077:            private static final String VALIDATION_FEATURE = Constants.SAX_FEATURE_PREFIX
078:                    + Constants.VALIDATION_FEATURE;
079:
080:            /** Feature identifier: XML Schema validation */
081:            private static final String XMLSCHEMA_VALIDATION_FEATURE = Constants.XERCES_FEATURE_PREFIX
082:                    + Constants.SCHEMA_VALIDATION_FEATURE;
083:
084:            /** Feature identifier: XInclude processing */
085:            private static final String XINCLUDE_FEATURE = Constants.XERCES_FEATURE_PREFIX
086:                    + Constants.XINCLUDE_FEATURE;
087:
088:            /** Property identifier: security manager. */
089:            private static final String SECURITY_MANAGER = Constants.XERCES_PROPERTY_PREFIX
090:                    + Constants.SECURITY_MANAGER_PROPERTY;
091:
092:            private JAXPSAXParser xmlReader;
093:            private String schemaLanguage = null; // null means DTD
094:            private final Schema grammar;
095:
096:            private XMLComponent fSchemaValidator;
097:            private XMLComponentManager fSchemaValidatorComponentManager;
098:            private ValidationManager fSchemaValidationManager;
099:            private UnparsedEntityHandler fUnparsedEntityHandler;
100:
101:            /** Initial ErrorHandler */
102:            private final ErrorHandler fInitErrorHandler;
103:
104:            /** Initial EntityResolver */
105:            private final EntityResolver fInitEntityResolver;
106:
107:            /**
108:             * Create a SAX parser with the associated features
109:             * @param features Hashtable of SAX features, may be null
110:             */
111:            SAXParserImpl(SAXParserFactoryImpl spf, Hashtable features)
112:                    throws SAXException {
113:                this (spf, features, false);
114:            }
115:
116:            /**
117:             * Create a SAX parser with the associated features
118:             * @param features Hashtable of SAX features, may be null
119:             */
120:            SAXParserImpl(SAXParserFactoryImpl spf, Hashtable features,
121:                    boolean secureProcessing) throws SAXException {
122:                // Instantiate a SAXParser directly and not through SAX so that we use the right ClassLoader
123:                xmlReader = new JAXPSAXParser(this );
124:
125:                // JAXP "namespaceAware" == SAX Namespaces feature
126:                // Note: there is a compatibility problem here with default values:
127:                // JAXP default is false while SAX 2 default is true!
128:                xmlReader.setFeature0(NAMESPACES_FEATURE, spf
129:                        .isNamespaceAware());
130:
131:                // SAX "namespaces" and "namespace-prefixes" features should not
132:                // both be false.  We make them opposite for backward compatibility
133:                // since JAXP 1.0 apps may want to receive xmlns* attributes.
134:                xmlReader.setFeature0(NAMESPACE_PREFIXES_FEATURE, !spf
135:                        .isNamespaceAware());
136:
137:                // Avoid setting the XInclude processing feature if the value is false.
138:                // This will keep the configuration from throwing an exception if it
139:                // does not support XInclude.
140:                if (spf.isXIncludeAware()) {
141:                    xmlReader.setFeature0(XINCLUDE_FEATURE, true);
142:                }
143:
144:                // If the secure processing feature is on set a security manager.
145:                if (secureProcessing) {
146:                    xmlReader.setProperty0(SECURITY_MANAGER,
147:                            new SecurityManager());
148:                }
149:
150:                // Set application's features, followed by validation features.
151:                setFeatures(features);
152:
153:                // If validating, provide a default ErrorHandler that prints
154:                // validation errors with a warning telling the user to set an
155:                // ErrorHandler.
156:                if (spf.isValidating()) {
157:                    fInitErrorHandler = new DefaultValidationErrorHandler();
158:                    xmlReader.setErrorHandler(fInitErrorHandler);
159:                } else {
160:                    fInitErrorHandler = xmlReader.getErrorHandler();
161:                }
162:                xmlReader.setFeature0(VALIDATION_FEATURE, spf.isValidating());
163:
164:                // Get the Schema object from the factory
165:                this .grammar = spf.getSchema();
166:                if (grammar != null) {
167:                    XMLParserConfiguration config = xmlReader
168:                            .getXMLParserConfiguration();
169:                    XMLComponent validatorComponent = null;
170:                    /** For Xerces grammars, use built-in schema validator. **/
171:                    if (grammar instanceof  XSGrammarPoolContainer) {
172:                        validatorComponent = new XMLSchemaValidator();
173:                        fSchemaValidationManager = new ValidationManager();
174:                        fUnparsedEntityHandler = new UnparsedEntityHandler(
175:                                fSchemaValidationManager);
176:                        config.setDTDHandler(fUnparsedEntityHandler);
177:                        fUnparsedEntityHandler.setDTDHandler(xmlReader);
178:                        xmlReader.setDTDSource(fUnparsedEntityHandler);
179:                        fSchemaValidatorComponentManager = new SchemaValidatorConfiguration(
180:                                config, (XSGrammarPoolContainer) grammar,
181:                                fSchemaValidationManager);
182:                    }
183:                    /** For third party grammars, use the JAXP validator component. **/
184:                    else {
185:                        validatorComponent = new JAXPValidatorComponent(grammar
186:                                .newValidatorHandler());
187:                        fSchemaValidatorComponentManager = config;
188:                    }
189:                    config.addRecognizedFeatures(validatorComponent
190:                            .getRecognizedFeatures());
191:                    config.addRecognizedProperties(validatorComponent
192:                            .getRecognizedProperties());
193:                    config
194:                            .setDocumentHandler((XMLDocumentHandler) validatorComponent);
195:                    ((XMLDocumentSource) validatorComponent)
196:                            .setDocumentHandler(xmlReader);
197:                    xmlReader
198:                            .setDocumentSource((XMLDocumentSource) validatorComponent);
199:                    fSchemaValidator = validatorComponent;
200:                }
201:
202:                // Initial EntityResolver
203:                fInitEntityResolver = xmlReader.getEntityResolver();
204:            }
205:
206:            /**
207:             * Set any features of our XMLReader based on any features set on the
208:             * SAXParserFactory.
209:             *
210:             * XXX Does not handle possible conflicts between SAX feature names and
211:             * JAXP specific feature names, eg. SAXParserFactory.isValidating()
212:             */
213:            private void setFeatures(Hashtable features)
214:                    throws SAXNotSupportedException, SAXNotRecognizedException {
215:                if (features != null) {
216:                    for (Enumeration e = features.keys(); e.hasMoreElements();) {
217:                        String feature = (String) e.nextElement();
218:                        boolean value = ((Boolean) features.get(feature))
219:                                .booleanValue();
220:                        xmlReader.setFeature0(feature, value);
221:                    }
222:                }
223:            }
224:
225:            public Parser getParser() throws SAXException {
226:                // Xerces2 AbstractSAXParser implements SAX1 Parser
227:                // assert(xmlReader instanceof Parser);
228:                return (Parser) xmlReader;
229:            }
230:
231:            /**
232:             * Returns the XMLReader that is encapsulated by the implementation of
233:             * this class.
234:             */
235:            public XMLReader getXMLReader() {
236:                return xmlReader;
237:            }
238:
239:            public boolean isNamespaceAware() {
240:                try {
241:                    return xmlReader.getFeature(NAMESPACES_FEATURE);
242:                } catch (SAXException x) {
243:                    throw new IllegalStateException(x.getMessage());
244:                }
245:            }
246:
247:            public boolean isValidating() {
248:                try {
249:                    return xmlReader.getFeature(VALIDATION_FEATURE);
250:                } catch (SAXException x) {
251:                    throw new IllegalStateException(x.getMessage());
252:                }
253:            }
254:
255:            /**
256:             * Gets the XInclude processing mode for this parser
257:             * @return the state of XInclude processing mode
258:             */
259:            public boolean isXIncludeAware() {
260:                try {
261:                    return xmlReader.getFeature(XINCLUDE_FEATURE);
262:                } catch (SAXException exc) {
263:                    return false;
264:                }
265:            }
266:
267:            /**
268:             * Sets the particular property in the underlying implementation of 
269:             * org.xml.sax.XMLReader.
270:             */
271:            public void setProperty(String name, Object value)
272:                    throws SAXNotRecognizedException, SAXNotSupportedException {
273:                xmlReader.setProperty(name, value);
274:            }
275:
276:            /**
277:             * returns the particular property requested for in the underlying 
278:             * implementation of org.xml.sax.XMLReader.
279:             */
280:            public Object getProperty(String name)
281:                    throws SAXNotRecognizedException, SAXNotSupportedException {
282:                return xmlReader.getProperty(name);
283:            }
284:
285:            public void parse(InputSource is, DefaultHandler dh)
286:                    throws SAXException, IOException {
287:                if (is == null) {
288:                    throw new IllegalArgumentException();
289:                }
290:                if (dh != null) {
291:                    xmlReader.setContentHandler(dh);
292:                    xmlReader.setEntityResolver(dh);
293:                    xmlReader.setErrorHandler(dh);
294:                    xmlReader.setDTDHandler(dh);
295:                    xmlReader.setDocumentHandler(null);
296:                }
297:                xmlReader.parse(is);
298:            }
299:
300:            public void parse(InputSource is, HandlerBase hb)
301:                    throws SAXException, IOException {
302:                if (is == null) {
303:                    throw new IllegalArgumentException();
304:                }
305:                if (hb != null) {
306:                    xmlReader.setDocumentHandler(hb);
307:                    xmlReader.setEntityResolver(hb);
308:                    xmlReader.setErrorHandler(hb);
309:                    xmlReader.setDTDHandler(hb);
310:                    xmlReader.setContentHandler(null);
311:                }
312:                xmlReader.parse(is);
313:            }
314:
315:            public Schema getSchema() {
316:                return grammar;
317:            }
318:
319:            public void reset() {
320:                try {
321:                    /** Restore initial values of features and properties. **/
322:                    xmlReader.restoreInitState();
323:                } catch (SAXException exc) {
324:                    // This should never happen. We only store recognized
325:                    // features and properties in the hash maps. For now
326:                    // just ignore it.
327:                }
328:                /** Restore various handlers. **/
329:                xmlReader.setContentHandler(null);
330:                xmlReader.setDTDHandler(null);
331:                if (xmlReader.getErrorHandler() != fInitErrorHandler) {
332:                    xmlReader.setErrorHandler(fInitErrorHandler);
333:                }
334:                if (xmlReader.getEntityResolver() != fInitEntityResolver) {
335:                    xmlReader.setEntityResolver(fInitEntityResolver);
336:                }
337:            }
338:
339:            /*
340:             * PSVIProvider methods
341:             */
342:
343:            public ElementPSVI getElementPSVI() {
344:                return ((PSVIProvider) xmlReader).getElementPSVI();
345:            }
346:
347:            public AttributePSVI getAttributePSVI(int index) {
348:                return ((PSVIProvider) xmlReader).getAttributePSVI(index);
349:            }
350:
351:            public AttributePSVI getAttributePSVIByName(String uri,
352:                    String localname) {
353:                return ((PSVIProvider) xmlReader).getAttributePSVIByName(uri,
354:                        localname);
355:            }
356:
357:            /**
358:             * Extension of SAXParser. This class tracks changes to 
359:             * features and properties to allow the parser to be reset to
360:             * its initial state.
361:             */
362:            public static class JAXPSAXParser extends
363:                    org.apache.xerces.parsers.SAXParser {
364:
365:                private HashMap fInitFeatures = new HashMap();
366:                private HashMap fInitProperties = new HashMap();
367:                private SAXParserImpl fSAXParser;
368:
369:                public JAXPSAXParser() {
370:                    super ();
371:                }
372:
373:                JAXPSAXParser(SAXParserImpl saxParser) {
374:                    super ();
375:                    fSAXParser = saxParser;
376:                }
377:
378:                /**
379:                 * Override SAXParser's setFeature method to track the initial state
380:                 * of features. This keeps us from affecting the performance of the
381:                 * SAXParser when it is created with XMLReaderFactory.
382:                 */
383:                public synchronized void setFeature(String name, boolean value)
384:                        throws SAXNotRecognizedException,
385:                        SAXNotSupportedException {
386:                    if (name == null) {
387:                        // TODO: Add localized error message.
388:                        throw new NullPointerException();
389:                    }
390:                    if (name.equals(XMLConstants.FEATURE_SECURE_PROCESSING)) {
391:                        try {
392:                            setProperty(SECURITY_MANAGER,
393:                                    value ? new SecurityManager() : null);
394:                        } catch (SAXNotRecognizedException exc) {
395:                            // If the property is not supported 
396:                            // re-throw the exception if the value is true.
397:                            if (value) {
398:                                throw exc;
399:                            }
400:                        } catch (SAXNotSupportedException exc) {
401:                            // If the property is not supported 
402:                            // re-throw the exception if the value is true.
403:                            if (value) {
404:                                throw exc;
405:                            }
406:                        }
407:                        return;
408:                    }
409:                    if (!fInitFeatures.containsKey(name)) {
410:                        boolean current = super .getFeature(name);
411:                        fInitFeatures.put(name, current ? Boolean.TRUE
412:                                : Boolean.FALSE);
413:                    }
414:                    /** Forward feature to the schema validator if there is one. **/
415:                    if (fSAXParser != null
416:                            && fSAXParser.fSchemaValidator != null) {
417:                        setSchemaValidatorFeature(name, value);
418:                    }
419:                    super .setFeature(name, value);
420:                }
421:
422:                public synchronized boolean getFeature(String name)
423:                        throws SAXNotRecognizedException,
424:                        SAXNotSupportedException {
425:                    if (name == null) {
426:                        // TODO: Add localized error message.
427:                        throw new NullPointerException();
428:                    }
429:                    if (name.equals(XMLConstants.FEATURE_SECURE_PROCESSING)) {
430:                        try {
431:                            return (super .getProperty(SECURITY_MANAGER) != null);
432:                        }
433:                        // If the property is not supported the value must be false.
434:                        catch (SAXException exc) {
435:                            return false;
436:                        }
437:                    }
438:                    return super .getFeature(name);
439:                }
440:
441:                /**
442:                 * Override SAXParser's setProperty method to track the initial state
443:                 * of properties. This keeps us from affecting the performance of the
444:                 * SAXParser when it is created with XMLReaderFactory.
445:                 */
446:                public synchronized void setProperty(String name, Object value)
447:                        throws SAXNotRecognizedException,
448:                        SAXNotSupportedException {
449:                    if (name == null) {
450:                        // TODO: Add localized error message.
451:                        throw new NullPointerException();
452:                    }
453:                    if (fSAXParser != null) {
454:                        // JAXP 1.2 support
455:                        if (JAXP_SCHEMA_LANGUAGE.equals(name)) {
456:                            // The spec says if a schema is given via SAXParserFactory
457:                            // the JAXP 1.2 properties shouldn't be allowed.
458:                            if (fSAXParser.grammar != null) {
459:                                throw new SAXNotSupportedException(
460:                                        SAXMessageFormatter.formatMessage(
461:                                                fConfiguration.getLocale(),
462:                                                "schema-already-specified",
463:                                                new Object[] { name }));
464:                            }
465:                            if (W3C_XML_SCHEMA.equals(value)) {
466:                                //None of the properties will take effect till the setValidating(true) has been called                                                        
467:                                if (fSAXParser.isValidating()) {
468:                                    fSAXParser.schemaLanguage = W3C_XML_SCHEMA;
469:                                    setFeature(XMLSCHEMA_VALIDATION_FEATURE,
470:                                            true);
471:                                    // this will allow the parser not to emit DTD-related
472:                                    // errors, as the spec demands
473:                                    if (!fInitProperties
474:                                            .containsKey(JAXP_SCHEMA_LANGUAGE)) {
475:                                        fInitProperties
476:                                                .put(
477:                                                        JAXP_SCHEMA_LANGUAGE,
478:                                                        super 
479:                                                                .getProperty(JAXP_SCHEMA_LANGUAGE));
480:                                    }
481:                                    super .setProperty(JAXP_SCHEMA_LANGUAGE,
482:                                            W3C_XML_SCHEMA);
483:                                }
484:
485:                            } else if (value == null) {
486:                                fSAXParser.schemaLanguage = null;
487:                                setFeature(XMLSCHEMA_VALIDATION_FEATURE, false);
488:                            } else {
489:                                // REVISIT: It would be nice if we could format this message
490:                                // using a user specified locale as we do in the underlying
491:                                // XMLReader -- mrglavas
492:                                throw new SAXNotSupportedException(
493:                                        SAXMessageFormatter.formatMessage(
494:                                                fConfiguration.getLocale(),
495:                                                "schema-not-supported", null));
496:                            }
497:                            return;
498:                        } else if (JAXP_SCHEMA_SOURCE.equals(name)) {
499:                            // The spec says if a schema is given via SAXParserFactory
500:                            // the JAXP 1.2 properties shouldn't be allowed.
501:                            if (fSAXParser.grammar != null) {
502:                                throw new SAXNotSupportedException(
503:                                        SAXMessageFormatter.formatMessage(
504:                                                fConfiguration.getLocale(),
505:                                                "schema-already-specified",
506:                                                new Object[] { name }));
507:                            }
508:                            String val = (String) getProperty(JAXP_SCHEMA_LANGUAGE);
509:                            if (val != null && W3C_XML_SCHEMA.equals(val)) {
510:                                if (!fInitProperties
511:                                        .containsKey(JAXP_SCHEMA_SOURCE)) {
512:                                    fInitProperties
513:                                            .put(
514:                                                    JAXP_SCHEMA_SOURCE,
515:                                                    super 
516:                                                            .getProperty(JAXP_SCHEMA_SOURCE));
517:                                }
518:                                super .setProperty(name, value);
519:                            } else {
520:                                throw new SAXNotSupportedException(
521:                                        SAXMessageFormatter.formatMessage(
522:                                                fConfiguration.getLocale(),
523:                                                "jaxp-order-not-supported",
524:                                                new Object[] {
525:                                                        JAXP_SCHEMA_LANGUAGE,
526:                                                        JAXP_SCHEMA_SOURCE }));
527:                            }
528:                            return;
529:                        }
530:                    }
531:                    if (!fInitProperties.containsKey(name)) {
532:                        fInitProperties.put(name, super .getProperty(name));
533:                    }
534:                    /** Forward property to the schema validator if there is one. **/
535:                    if (fSAXParser != null
536:                            && fSAXParser.fSchemaValidator != null) {
537:                        setSchemaValidatorProperty(name, value);
538:                    }
539:                    super .setProperty(name, value);
540:                }
541:
542:                public synchronized Object getProperty(String name)
543:                        throws SAXNotRecognizedException,
544:                        SAXNotSupportedException {
545:                    if (name == null) {
546:                        // TODO: Add localized error message.
547:                        throw new NullPointerException();
548:                    }
549:                    if (fSAXParser != null && JAXP_SCHEMA_LANGUAGE.equals(name)) {
550:                        // JAXP 1.2 support
551:                        return fSAXParser.schemaLanguage;
552:                    }
553:                    return super .getProperty(name);
554:                }
555:
556:                synchronized void restoreInitState()
557:                        throws SAXNotRecognizedException,
558:                        SAXNotSupportedException {
559:                    Iterator iter;
560:                    if (!fInitFeatures.isEmpty()) {
561:                        iter = fInitFeatures.entrySet().iterator();
562:                        while (iter.hasNext()) {
563:                            Map.Entry entry = (Map.Entry) iter.next();
564:                            String name = (String) entry.getKey();
565:                            boolean value = ((Boolean) entry.getValue())
566:                                    .booleanValue();
567:                            super .setFeature(name, value);
568:                        }
569:                        fInitFeatures.clear();
570:                    }
571:                    if (!fInitProperties.isEmpty()) {
572:                        iter = fInitProperties.entrySet().iterator();
573:                        while (iter.hasNext()) {
574:                            Map.Entry entry = (Map.Entry) iter.next();
575:                            String name = (String) entry.getKey();
576:                            Object value = entry.getValue();
577:                            super .setProperty(name, value);
578:                        }
579:                        fInitProperties.clear();
580:                    }
581:                }
582:
583:                public void parse(InputSource inputSource) throws SAXException,
584:                        IOException {
585:                    if (fSAXParser != null
586:                            && fSAXParser.fSchemaValidator != null) {
587:                        if (fSAXParser.fSchemaValidationManager != null) {
588:                            fSAXParser.fSchemaValidationManager.reset();
589:                            fSAXParser.fUnparsedEntityHandler.reset();
590:                        }
591:                        resetSchemaValidator();
592:                    }
593:                    super .parse(inputSource);
594:                }
595:
596:                public void parse(String systemId) throws SAXException,
597:                        IOException {
598:                    if (fSAXParser != null
599:                            && fSAXParser.fSchemaValidator != null) {
600:                        if (fSAXParser.fSchemaValidationManager != null) {
601:                            fSAXParser.fSchemaValidationManager.reset();
602:                            fSAXParser.fUnparsedEntityHandler.reset();
603:                        }
604:                        resetSchemaValidator();
605:                    }
606:                    super .parse(systemId);
607:                }
608:
609:                XMLParserConfiguration getXMLParserConfiguration() {
610:                    return fConfiguration;
611:                }
612:
613:                void setFeature0(String name, boolean value)
614:                        throws SAXNotRecognizedException,
615:                        SAXNotSupportedException {
616:                    super .setFeature(name, value);
617:                }
618:
619:                boolean getFeature0(String name)
620:                        throws SAXNotRecognizedException,
621:                        SAXNotSupportedException {
622:                    return super .getFeature(name);
623:                }
624:
625:                void setProperty0(String name, Object value)
626:                        throws SAXNotRecognizedException,
627:                        SAXNotSupportedException {
628:                    super .setProperty(name, value);
629:                }
630:
631:                Object getProperty0(String name)
632:                        throws SAXNotRecognizedException,
633:                        SAXNotSupportedException {
634:                    return super .getProperty(name);
635:                }
636:
637:                private void setSchemaValidatorFeature(String name,
638:                        boolean value) throws SAXNotRecognizedException,
639:                        SAXNotSupportedException {
640:                    try {
641:                        fSAXParser.fSchemaValidator.setFeature(name, value);
642:                    }
643:                    // This should never be thrown from the schema validator.
644:                    catch (XMLConfigurationException e) {
645:                        String identifier = e.getIdentifier();
646:                        if (e.getType() == XMLConfigurationException.NOT_RECOGNIZED) {
647:                            throw new SAXNotRecognizedException(
648:                                    SAXMessageFormatter.formatMessage(
649:                                            fConfiguration.getLocale(),
650:                                            "feature-not-recognized",
651:                                            new Object[] { identifier }));
652:                        } else {
653:                            throw new SAXNotSupportedException(
654:                                    SAXMessageFormatter.formatMessage(
655:                                            fConfiguration.getLocale(),
656:                                            "feature-not-supported",
657:                                            new Object[] { identifier }));
658:                        }
659:                    }
660:                }
661:
662:                private void setSchemaValidatorProperty(String name,
663:                        Object value) throws SAXNotRecognizedException,
664:                        SAXNotSupportedException {
665:                    try {
666:                        fSAXParser.fSchemaValidator.setProperty(name, value);
667:                    }
668:                    // This should never be thrown from the schema validator.
669:                    catch (XMLConfigurationException e) {
670:                        String identifier = e.getIdentifier();
671:                        if (e.getType() == XMLConfigurationException.NOT_RECOGNIZED) {
672:                            throw new SAXNotRecognizedException(
673:                                    SAXMessageFormatter.formatMessage(
674:                                            fConfiguration.getLocale(),
675:                                            "property-not-recognized",
676:                                            new Object[] { identifier }));
677:                        } else {
678:                            throw new SAXNotSupportedException(
679:                                    SAXMessageFormatter.formatMessage(
680:                                            fConfiguration.getLocale(),
681:                                            "property-not-supported",
682:                                            new Object[] { identifier }));
683:                        }
684:                    }
685:                }
686:
687:                private void resetSchemaValidator() throws SAXException {
688:                    try {
689:                        fSAXParser.fSchemaValidator
690:                                .reset(fSAXParser.fSchemaValidatorComponentManager);
691:                    }
692:                    // This should never be thrown from the schema validator.
693:                    catch (XMLConfigurationException e) {
694:                        throw new SAXException(e);
695:                    }
696:                }
697:            }
698:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.