Source Code Cross Referenced for JAXPParser.java in  » 6.0-JDK-Modules » jaxb-xjc » com » sun » xml » xsom » parser » 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 » 6.0 JDK Modules » jaxb xjc » com.sun.xml.xsom.parser 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * The contents of this file are subject to the terms
003:         * of the Common Development and Distribution License
004:         * (the "License").  You may not use this file except
005:         * in compliance with the License.
006:         * 
007:         * You can obtain a copy of the license at
008:         * https://jwsdp.dev.java.net/CDDLv1.0.html
009:         * See the License for the specific language governing
010:         * permissions and limitations under the License.
011:         * 
012:         * When distributing Covered Code, include this CDDL
013:         * HEADER in each file and include the License file at
014:         * https://jwsdp.dev.java.net/CDDLv1.0.html  If applicable,
015:         * add the following below this CDDL HEADER, with the
016:         * fields enclosed by brackets "[]" replaced with your
017:         * own identifying information: Portions Copyright [yyyy]
018:         * [name of copyright owner]
019:         */
020:        package com.sun.xml.xsom.parser;
021:
022:        import java.io.IOException;
023:        import java.net.URL;
024:
025:        import javax.xml.parsers.ParserConfigurationException;
026:        import javax.xml.parsers.SAXParserFactory;
027:
028:        import org.xml.sax.ContentHandler;
029:        import org.xml.sax.EntityResolver;
030:        import org.xml.sax.ErrorHandler;
031:        import org.xml.sax.InputSource;
032:        import org.xml.sax.Locator;
033:        import org.xml.sax.SAXException;
034:        import org.xml.sax.SAXParseException;
035:        import org.xml.sax.XMLReader;
036:        import org.xml.sax.helpers.XMLFilterImpl;
037:
038:        import com.sun.xml.xsom.impl.parser.Messages;
039:
040:        /**
041:         * Standard XMLParser implemented by using JAXP.
042:         * 
043:         * @author
044:         *     Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
045:         */
046:        public class JAXPParser implements  XMLParser {
047:
048:            private final SAXParserFactory factory;
049:
050:            public JAXPParser(SAXParserFactory factory) {
051:                factory.setNamespaceAware(true); // just in case
052:                this .factory = factory;
053:            }
054:
055:            public JAXPParser() {
056:                this (SAXParserFactory.newInstance());
057:            }
058:
059:            public void parse(InputSource source, ContentHandler handler,
060:                    ErrorHandler errorHandler, EntityResolver entityResolver)
061:
062:            throws SAXException, IOException {
063:
064:                try {
065:                    XMLReader reader = factory.newSAXParser().getXMLReader();
066:                    reader = new XMLReaderEx(reader);
067:
068:                    reader.setContentHandler(handler);
069:                    if (errorHandler != null)
070:                        reader.setErrorHandler(errorHandler);
071:                    if (entityResolver != null)
072:                        reader.setEntityResolver(entityResolver);
073:                    reader.parse(source);
074:                } catch (ParserConfigurationException e) {
075:                    // in practice this won't happen
076:                    SAXParseException spe = new SAXParseException(e
077:                            .getMessage(), null, e);
078:                    errorHandler.fatalError(spe);
079:                    throw spe;
080:                }
081:            }
082:
083:            /**
084:             * XMLReader with improved error message for entity resolution failure.
085:             * 
086:             * TODO: this class is completely stand-alone, so it shouldn't be
087:             * an inner class.
088:             */
089:            private static class XMLReaderEx extends XMLFilterImpl {
090:
091:                private Locator locator;
092:
093:                XMLReaderEx(XMLReader parent) {
094:                    this .setParent(parent);
095:                }
096:
097:                /**
098:                 * Resolves entities and reports user-friendly error messages.
099:                 * 
100:                 * <p>
101:                 * Some XML parser (at least Xerces) does not report much information
102:                 * when it fails to resolve an entity, which is often quite
103:                 * frustrating. For example, if you are behind a firewall and the 
104:                 * schema contains a reference to www.w3.org, and there is no
105:                 * entity resolver, the parser will just throw an IOException
106:                 * that doesn't contain any information about where that reference
107:                 * occurs nor what it is accessing.
108:                 * 
109:                 * <p>
110:                 * By implementing an EntityResolver and resolving the reference
111:                 * by ourselves, we can report an error message with all the
112:                 * necessary information to fix the problem.
113:                 * 
114:                 * <p>
115:                 * Note that we still need to the client-specified entity resolver
116:                 * to let the application handle entity resolution. Here we just catch
117:                 * an IOException and add more information.
118:                 */
119:                public InputSource resolveEntity(String publicId,
120:                        String systemId) throws SAXException {
121:                    try {
122:                        InputSource is = null;
123:
124:                        // ask the client-specified entity resolver first
125:                        if (this .getEntityResolver() != null)
126:                            is = this .getEntityResolver().resolveEntity(
127:                                    publicId, systemId);
128:                        if (is != null)
129:                            return is; // if that succeeds, fine.
130:
131:                        // rather than returning null, resolve it now
132:                        // so that we can detect errors.
133:                        is = new InputSource(new URL(systemId).openStream());
134:                        is.setSystemId(systemId);
135:                        is.setPublicId(publicId);
136:                        return is;
137:                    } catch (IOException e) {
138:                        // catch this error and provide a nice error message, rather than
139:                        // just throwing this IOException.
140:                        SAXParseException spe = new SAXParseException(Messages
141:                                .format(Messages.ERR_ENTITY_RESOLUTION_FAILURE,
142:                                        systemId, e.toString()), // use the toString method to get the class name
143:                                locator, e);
144:                        if (this .getErrorHandler() != null)
145:                            this .getErrorHandler().fatalError(spe);
146:                        throw spe;
147:                    }
148:                }
149:
150:                public void setDocumentLocator(Locator locator) {
151:                    super.setDocumentLocator(locator);
152:                    this.locator = locator;
153:                }
154:            }
155:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.