Source Code Cross Referenced for XSOMParser.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.File;
023:        import java.io.IOException;
024:        import java.io.InputStream;
025:        import java.io.Reader;
026:        import java.net.URL;
027:        import java.util.Set;
028:        import java.util.HashSet;
029:
030:        import javax.xml.parsers.SAXParserFactory;
031:
032:        import org.xml.sax.ContentHandler;
033:        import org.xml.sax.EntityResolver;
034:        import org.xml.sax.ErrorHandler;
035:        import org.xml.sax.InputSource;
036:        import org.xml.sax.SAXException;
037:
038:        import com.sun.xml.xsom.XSSchemaSet;
039:        import com.sun.xml.xsom.impl.parser.NGCCRuntimeEx;
040:        import com.sun.xml.xsom.impl.parser.ParserContext;
041:        import com.sun.xml.xsom.impl.parser.state.Schema;
042:
043:        /**
044:         * Parses possibly multiple W3C XML Schema files and compose
045:         * them into one grammar.
046:         * 
047:         * @author
048:         *     Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
049:         */
050:        public final class XSOMParser {
051:
052:            private EntityResolver entityResolver;
053:            private ErrorHandler userErrorHandler;
054:
055:            private AnnotationParserFactory apFactory;
056:
057:            private final ParserContext context;
058:
059:            /**
060:             * Creates a new XSOMParser by using a SAX parser from JAXP.
061:             */
062:            public XSOMParser() {
063:                this (new JAXPParser());
064:            }
065:
066:            /**
067:             * Creates a new XSOMParser that uses the given SAXParserFactory
068:             * for creating new SAX parsers.
069:             * 
070:             * The caller needs to configure
071:             * it properly. Don't forget to call <code>setNamespaceAware(true)</code>
072:             * or you'll see some strange errors.
073:             */
074:            public XSOMParser(SAXParserFactory factory) {
075:                this (new JAXPParser(factory));
076:            }
077:
078:            /**
079:             * Creates a new XSOMParser that reads XML Schema from non-standard
080:             * inputs.
081:             * 
082:             * By implementing the {@link XMLParser} interface, XML Schema
083:             * can be read from something other than XML.
084:             * 
085:             * @param   parser
086:             *      This parser will be called to parse XML Schema documents.
087:             */
088:            public XSOMParser(XMLParser parser) {
089:                context = new ParserContext(this , parser);
090:            }
091:
092:            /**
093:             * Parses a new XML Schema document.
094:             *
095:             * <p>
096:             * When using this method, XSOM does not know the system ID of
097:             * this document, therefore, when this stream contains relative
098:             * references to other schemas, XSOM will fail to resolve them.
099:             * To specify an system ID with a stream, use {@link InputSource}
100:             */
101:            public void parse(InputStream is) throws SAXException {
102:                parse(new InputSource(is));
103:            }
104:
105:            /**
106:             * Parses a new XML Schema document.
107:             *
108:             * <p>
109:             * When using this method, XSOM does not know the system ID of
110:             * this document, therefore, when this reader contains relative
111:             * references to other schemas, XSOM will fail to resolve them.
112:             * To specify an system ID with a reader, use {@link InputSource}
113:             */
114:            public void parse(Reader reader) throws SAXException {
115:                parse(new InputSource(reader));
116:            }
117:
118:            /**
119:             * Parses a new XML Schema document.
120:             */
121:            public void parse(File schema) throws SAXException, IOException {
122:                parse(schema.toURL());
123:            }
124:
125:            /**
126:             * Parses a new XML Schema document.
127:             */
128:            public void parse(URL url) throws SAXException {
129:                parse(url.toExternalForm());
130:            }
131:
132:            /**
133:             * Parses a new XML Schema document.
134:             */
135:            public void parse(String systemId) throws SAXException {
136:                parse(new InputSource(systemId));
137:            }
138:
139:            /**
140:             * Parses a new XML Schema document.
141:             *
142:             * <p>
143:             * Note that if the {@link InputSource} does not have a system ID,
144:             * XSOM will fail to resolve them.
145:             */
146:            public void parse(InputSource source) throws SAXException {
147:                context.parse(source);
148:            }
149:
150:            /**
151:             * Gets the parser implemented as a ContentHandler.
152:             * 
153:             * One can feed XML Schema as SAX events to this interface to
154:             * parse a schema. To parse multiple schema files, feed multiple
155:             * sets of events.
156:             * 
157:             * <p>
158:             * If you don't send a complete event sequence from a startDocument
159:             * event to an endDocument event, the state of XSOMParser can become
160:             * unstable. This sometimes happen when you encounter an error while
161:             * generating SAX events. Don't call the getResult method in that case.
162:             * 
163:             * <p>
164:             * This way of reading XML Schema can be useful when XML Schema is
165:             * not available as a stand-alone XML document.
166:             * For example, one can feed XML Schema inside a WSDL document.
167:             */
168:            public ContentHandler getParserHandler() {
169:                NGCCRuntimeEx runtime = context.newNGCCRuntime();
170:                Schema s = new Schema(runtime, false, null);
171:                runtime.setRootHandler(s);
172:                return runtime;
173:            }
174:
175:            /**
176:             * Gets the parsed result. Don't call this method until
177:             * you parse all the schemas.
178:             * 
179:             * @return
180:             *      If there was any parse error, this method returns null.
181:             *      To receive error information, specify your error handler
182:             *      through the setErrorHandler method.
183:             * @exception SAXException
184:             *      This exception will never be thrown unless it is thrown
185:             *      by an error handler.
186:             */
187:            public XSSchemaSet getResult() throws SAXException {
188:                return context.getResult();
189:            }
190:
191:            /**
192:             * Gets the set of {@link SchemaDocument} that represents
193:             * parsed documents so far.
194:             *
195:             * @return
196:             *      can be empty but never null.
197:             */
198:            public Set<SchemaDocument> getDocuments() {
199:                return new HashSet<SchemaDocument>(context.parsedDocuments
200:                        .keySet());
201:            }
202:
203:            public EntityResolver getEntityResolver() {
204:                return entityResolver;
205:            }
206:
207:            /**
208:             * Set an entity resolver that is used to resolve things
209:             * like &lt;xsd:import> and &lt;xsd:include>.
210:             */
211:            public void setEntityResolver(EntityResolver resolver) {
212:                this .entityResolver = resolver;
213:            }
214:
215:            public ErrorHandler getErrorHandler() {
216:                return userErrorHandler;
217:            }
218:
219:            /**
220:             * Set an error handler that receives all the errors encountered
221:             * during the parsing.
222:             */
223:            public void setErrorHandler(ErrorHandler errorHandler) {
224:                this .userErrorHandler = errorHandler;
225:            }
226:
227:            /**
228:             * Sets the annotation parser.
229:             * 
230:             * Annotation parser can be used to parse application-specific
231:             * annotations inside a schema.
232:             * 
233:             * <p>
234:             * For each annotation, new instance of this class will be
235:             * created and used to parse &lt;xs:annotation>.
236:             */
237:            public void setAnnotationParser(final Class annParser) {
238:                setAnnotationParser(new AnnotationParserFactory() {
239:                    public AnnotationParser create() {
240:                        try {
241:                            return (AnnotationParser) annParser.newInstance();
242:                        } catch (InstantiationException e) {
243:                            throw new InstantiationError(e.getMessage());
244:                        } catch (IllegalAccessException e) {
245:                            throw new IllegalAccessError(e.getMessage());
246:                        }
247:                    }
248:                });
249:            }
250:
251:            /**
252:             * Sets the annotation parser factory.
253:             * 
254:             * <p>
255:             * The specified factory will be used to create AnnotationParsers.
256:             */
257:            public void setAnnotationParser(AnnotationParserFactory factory) {
258:                this .apFactory = factory;
259:            }
260:
261:            public AnnotationParserFactory getAnnotationParserFactory() {
262:                return apFactory;
263:            }
264:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.