1 // SECTION-START[License Header]
2 // <editor-fold defaultstate="collapsed" desc=" Generated License ">
3 /*
4 * Copyright (c) 2010 The JOMC Project
5 * Copyright (c) 2005 Christian Schulte <schulte2005@users.sourceforge.net>
6 * All rights 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 * o Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * o 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 * THIS SOFTWARE IS PROVIDED BY THE JOMC PROJECT AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE JOMC PROJECT OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
30 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 * $Id: JaxpSaxXmlReaderFactory.java 2234 2010-06-29 00:03:38Z schulte2005 $
33 *
34 */
35 // </editor-fold>
36 // SECTION-END
37 package org.jomc.sdk.model.support;
38
39 import java.util.Map;
40 import javax.xml.parsers.ParserConfigurationException;
41 import javax.xml.parsers.SAXParser;
42 import javax.xml.parsers.SAXParserFactory;
43 import org.xml.sax.SAXException;
44 import org.xml.sax.XMLReader;
45
46 // SECTION-START[Documentation]
47 // <editor-fold defaultstate="collapsed" desc=" Generated Documentation ">
48 /**
49 * JAXP 'SAXParser' factory implementation.
50 * <p><b>Specifications</b><ul>
51 * <li>{@code 'org.xml.sax.XMLReader'} {@code (org.xml.sax.XMLReader)} {@code Multiton}</li>
52 * </ul></p>
53 * <p><b>Properties</b><ul>
54 * <li>"{@link #isXIncludeAware XIncludeAware}"
55 * <blockquote>Property of type {@code java.lang.Boolean}.
56 * <p>{@code true} if the factory is configured to produce XInclude aware parsers; {@code false} otherwise.</p>
57 * </blockquote></li>
58 * <li>"{@link #getFeatures features}"
59 * <blockquote>Property of type {@code java.util.Map<String,Boolean>}.
60 * </blockquote></li>
61 * <li>"{@link #isNamespaceAware namespaceAware}"
62 * <blockquote>Property of type {@code java.lang.Boolean}.
63 * <p>{@code true} if the factory is configured to produce parsers which are namespace aware; {@code false} otherwise.</p>
64 * </blockquote></li>
65 * <li>"{@link #getProperties properties}"
66 * <blockquote>Property of type {@code java.util.Map<String,Object>}.
67 * </blockquote></li>
68 * <li>"{@link #isValidating validating}"
69 * <blockquote>Property of type {@code java.lang.Boolean}.
70 * <p>{@code true} if the factory is configured to produce parsers which validate the XML content during parse; {@code false} otherwise.</p>
71 * </blockquote></li>
72 * </ul></p>
73 * <p><b>Dependencies</b><ul>
74 * <li>"{@link #getContentHandler contentHandler}"<blockquote>
75 * Dependency on {@code 'org.xml.sax.ContentHandler'} {@code (org.xml.sax.ContentHandler)} bound to an instance.</blockquote></li>
76 * <li>"{@link #getDtdHandler dtdHandler}"<blockquote>
77 * Dependency on {@code 'org.xml.sax.DTDHandler'} {@code (org.xml.sax.DTDHandler)} bound to an instance.</blockquote></li>
78 * <li>"{@link #getEntityResolver entityResolver}"<blockquote>
79 * Dependency on {@code 'org.xml.sax.EntityResolver'} {@code (org.xml.sax.EntityResolver)} bound to an instance.</blockquote></li>
80 * <li>"{@link #getErrorHandler errorHandler}"<blockquote>
81 * Dependency on {@code 'org.xml.sax.ErrorHandler'} {@code (org.xml.sax.ErrorHandler)} bound to an instance.</blockquote></li>
82 * <li>"{@link #getSchema schema}"<blockquote>
83 * Dependency on {@code 'javax.xml.validation.Schema'} {@code (javax.xml.validation.Schema)} bound to an instance.</blockquote></li>
84 * </ul></p>
85 *
86 * @author <a href="mailto:schulte2005@users.sourceforge.net">Christian Schulte</a> 1.0
87 * @version $Id: JaxpSaxXmlReaderFactory.java 2234 2010-06-29 00:03:38Z schulte2005 $
88 */
89 // </editor-fold>
90 // SECTION-END
91 // SECTION-START[Annotations]
92 // <editor-fold defaultstate="collapsed" desc=" Generated Annotations ">
93 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" )
94 // </editor-fold>
95 // SECTION-END
96 public final class JaxpSaxXmlReaderFactory
97 {
98 // SECTION-START[XMLReader]
99 // SECTION-END
100 // SECTION-START[JaxpSaxXmlReaderFactory]
101
102 public XMLReader getObject() throws ParserConfigurationException, SAXException
103 {
104 final SAXParserFactory f = SAXParserFactory.newInstance();
105 f.setSchema( this.getSchema() );
106 f.setNamespaceAware( this.isNamespaceAware() );
107 f.setValidating( this.isValidating() );
108 f.setXIncludeAware( this.isXIncludeAware() );
109
110 final SAXParser p = f.newSAXParser();
111 final XMLReader r = p.getXMLReader();
112
113 r.setContentHandler( this.getContentHandler() );
114 r.setDTDHandler( this.getDtdHandler() );
115 r.setEntityResolver( this.getEntityResolver() );
116 r.setErrorHandler( this.getErrorHandler() );
117
118 for ( Map.Entry<String, Boolean> e : this.getFeatures().entrySet() )
119 {
120 r.setFeature( e.getKey(), e.getValue() );
121 }
122
123 for ( Map.Entry<String, Object> e : this.getProperties().entrySet() )
124 {
125 r.setProperty( e.getKey(), e.getValue() );
126 }
127
128 return r;
129 }
130
131 // SECTION-END
132 // SECTION-START[Constructors]
133 // <editor-fold defaultstate="collapsed" desc=" Generated Constructors ">
134
135 /** Creates a new {@code JaxpSaxXmlReaderFactory} instance. */
136 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" )
137 public JaxpSaxXmlReaderFactory()
138 {
139 // SECTION-START[Default Constructor]
140 super();
141 // SECTION-END
142 }
143 // </editor-fold>
144 // SECTION-END
145 // SECTION-START[Dependencies]
146 // <editor-fold defaultstate="collapsed" desc=" Generated Dependencies ">
147
148 /**
149 * Gets the {@code contentHandler} dependency.
150 * <p>This method returns the {@code 'JOMC SDK Model Default'} object of the {@code 'org.xml.sax.ContentHandler'} {@code (org.xml.sax.ContentHandler)} specification.</p>
151 * <p>That specification does not apply to any scope. A new object is returned whenever requested and bound to this instance.</p>
152 * @return The {@code contentHandler} dependency.
153 * {@code null} if no object is available.
154 * @throws org.jomc.ObjectManagementException if getting the dependency instance fails.
155 */
156 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" )
157 private org.xml.sax.ContentHandler getContentHandler()
158 {
159 return (org.xml.sax.ContentHandler) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getDependency( this, "contentHandler" );
160 }
161
162 /**
163 * Gets the {@code dtdHandler} dependency.
164 * <p>This method returns the {@code 'JOMC SDK Model Default'} object of the {@code 'org.xml.sax.DTDHandler'} {@code (org.xml.sax.DTDHandler)} specification.</p>
165 * <p>That specification does not apply to any scope. A new object is returned whenever requested and bound to this instance.</p>
166 * @return The {@code dtdHandler} dependency.
167 * {@code null} if no object is available.
168 * @throws org.jomc.ObjectManagementException if getting the dependency instance fails.
169 */
170 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" )
171 private org.xml.sax.DTDHandler getDtdHandler()
172 {
173 return (org.xml.sax.DTDHandler) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getDependency( this, "dtdHandler" );
174 }
175
176 /**
177 * Gets the {@code entityResolver} dependency.
178 * <p>This method returns the {@code 'JOMC SDK Model Default'} object of the {@code 'org.xml.sax.EntityResolver'} {@code (org.xml.sax.EntityResolver)} specification.</p>
179 * <p>That specification does not apply to any scope. A new object is returned whenever requested and bound to this instance.</p>
180 * @return The {@code entityResolver} dependency.
181 * {@code null} if no object is available.
182 * @throws org.jomc.ObjectManagementException if getting the dependency instance fails.
183 */
184 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" )
185 private org.xml.sax.EntityResolver getEntityResolver()
186 {
187 return (org.xml.sax.EntityResolver) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getDependency( this, "entityResolver" );
188 }
189
190 /**
191 * Gets the {@code errorHandler} dependency.
192 * <p>This method returns the {@code 'JOMC SDK Model Default'} object of the {@code 'org.xml.sax.ErrorHandler'} {@code (org.xml.sax.ErrorHandler)} specification.</p>
193 * <p>That specification does not apply to any scope. A new object is returned whenever requested and bound to this instance.</p>
194 * @return The {@code errorHandler} dependency.
195 * {@code null} if no object is available.
196 * @throws org.jomc.ObjectManagementException if getting the dependency instance fails.
197 */
198 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" )
199 private org.xml.sax.ErrorHandler getErrorHandler()
200 {
201 return (org.xml.sax.ErrorHandler) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getDependency( this, "errorHandler" );
202 }
203
204 /**
205 * Gets the {@code schema} dependency.
206 * <p>This method returns the {@code 'JOMC SDK Model Default'} object of the {@code 'javax.xml.validation.Schema'} {@code (javax.xml.validation.Schema)} specification.</p>
207 * <p>That specification does not apply to any scope. A new object is returned whenever requested and bound to this instance.</p>
208 * @return The {@code schema} dependency.
209 * {@code null} if no object is available.
210 * @throws org.jomc.ObjectManagementException if getting the dependency instance fails.
211 */
212 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" )
213 private javax.xml.validation.Schema getSchema()
214 {
215 return (javax.xml.validation.Schema) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getDependency( this, "schema" );
216 }
217 // </editor-fold>
218 // SECTION-END
219 // SECTION-START[Properties]
220 // <editor-fold defaultstate="collapsed" desc=" Generated Properties ">
221
222 /**
223 * Gets the value of the {@code XIncludeAware} property.
224 * @return {@code true} if the factory is configured to produce XInclude aware parsers; {@code false} otherwise.
225 * @throws org.jomc.ObjectManagementException if getting the property instance fails.
226 */
227 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" )
228 private java.lang.Boolean isXIncludeAware()
229 {
230 final java.lang.Boolean _p = (java.lang.Boolean) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "XIncludeAware" );
231 assert _p != null : "'XIncludeAware' property not found.";
232 return _p;
233 }
234
235 /**
236 * Gets the value of the {@code features} property.
237 * @return The value of the {@code features} property.
238 * @throws org.jomc.ObjectManagementException if getting the property instance fails.
239 */
240 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" )
241 private java.util.Map<String,Boolean> getFeatures()
242 {
243 final java.util.Map<String,Boolean> _p = (java.util.Map<String,Boolean>) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "features" );
244 assert _p != null : "'features' property not found.";
245 return _p;
246 }
247
248 /**
249 * Gets the value of the {@code namespaceAware} property.
250 * @return {@code true} if the factory is configured to produce parsers which are namespace aware; {@code false} otherwise.
251 * @throws org.jomc.ObjectManagementException if getting the property instance fails.
252 */
253 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" )
254 private java.lang.Boolean isNamespaceAware()
255 {
256 final java.lang.Boolean _p = (java.lang.Boolean) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "namespaceAware" );
257 assert _p != null : "'namespaceAware' property not found.";
258 return _p;
259 }
260
261 /**
262 * Gets the value of the {@code properties} property.
263 * @return The value of the {@code properties} property.
264 * @throws org.jomc.ObjectManagementException if getting the property instance fails.
265 */
266 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" )
267 private java.util.Map<String,Object> getProperties()
268 {
269 final java.util.Map<String,Object> _p = (java.util.Map<String,Object>) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "properties" );
270 assert _p != null : "'properties' property not found.";
271 return _p;
272 }
273
274 /**
275 * Gets the value of the {@code validating} property.
276 * @return {@code true} if the factory is configured to produce parsers which validate the XML content during parse; {@code false} otherwise.
277 * @throws org.jomc.ObjectManagementException if getting the property instance fails.
278 */
279 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" )
280 private java.lang.Boolean isValidating()
281 {
282 final java.lang.Boolean _p = (java.lang.Boolean) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "validating" );
283 assert _p != null : "'validating' property not found.";
284 return _p;
285 }
286 // </editor-fold>
287 // SECTION-END
288 // SECTION-START[Messages]
289 // SECTION-END
290 }