001 // SECTION-START[License Header] 002 // <editor-fold defaultstate="collapsed" desc=" Generated License "> 003 /* 004 * Copyright (c) 2010 The JOMC Project 005 * Copyright (c) 2005 Christian Schulte <schulte2005@users.sourceforge.net> 006 * All rights reserved. 007 * 008 * Redistribution and use in source and binary forms, with or without 009 * modification, are permitted provided that the following conditions 010 * are met: 011 * 012 * o Redistributions of source code must retain the above copyright 013 * notice, this list of conditions and the following disclaimer. 014 * 015 * o Redistributions in binary form must reproduce the above copyright 016 * notice, this list of conditions and the following disclaimer in 017 * the documentation and/or other materials provided with the 018 * distribution. 019 * 020 * THIS SOFTWARE IS PROVIDED BY THE JOMC PROJECT AND CONTRIBUTORS "AS IS" 021 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 022 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 023 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE JOMC PROJECT OR 024 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 025 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 026 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 027 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 028 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 029 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 030 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 031 * 032 * $Id: JaxpSaxXmlReaderFactory.java 2234 2010-06-29 00:03:38Z schulte2005 $ 033 * 034 */ 035 // </editor-fold> 036 // SECTION-END 037 package org.jomc.sdk.model.support; 038 039 import java.util.Map; 040 import javax.xml.parsers.ParserConfigurationException; 041 import javax.xml.parsers.SAXParser; 042 import javax.xml.parsers.SAXParserFactory; 043 import org.xml.sax.SAXException; 044 import org.xml.sax.XMLReader; 045 046 // SECTION-START[Documentation] 047 // <editor-fold defaultstate="collapsed" desc=" Generated Documentation "> 048 /** 049 * JAXP 'SAXParser' factory implementation. 050 * <p><b>Specifications</b><ul> 051 * <li>{@code 'org.xml.sax.XMLReader'} {@code (org.xml.sax.XMLReader)} {@code Multiton}</li> 052 * </ul></p> 053 * <p><b>Properties</b><ul> 054 * <li>"{@link #isXIncludeAware XIncludeAware}" 055 * <blockquote>Property of type {@code java.lang.Boolean}. 056 * <p>{@code true} if the factory is configured to produce XInclude aware parsers; {@code false} otherwise.</p> 057 * </blockquote></li> 058 * <li>"{@link #getFeatures features}" 059 * <blockquote>Property of type {@code java.util.Map<String,Boolean>}. 060 * </blockquote></li> 061 * <li>"{@link #isNamespaceAware namespaceAware}" 062 * <blockquote>Property of type {@code java.lang.Boolean}. 063 * <p>{@code true} if the factory is configured to produce parsers which are namespace aware; {@code false} otherwise.</p> 064 * </blockquote></li> 065 * <li>"{@link #getProperties properties}" 066 * <blockquote>Property of type {@code java.util.Map<String,Object>}. 067 * </blockquote></li> 068 * <li>"{@link #isValidating validating}" 069 * <blockquote>Property of type {@code java.lang.Boolean}. 070 * <p>{@code true} if the factory is configured to produce parsers which validate the XML content during parse; {@code false} otherwise.</p> 071 * </blockquote></li> 072 * </ul></p> 073 * <p><b>Dependencies</b><ul> 074 * <li>"{@link #getContentHandler contentHandler}"<blockquote> 075 * Dependency on {@code 'org.xml.sax.ContentHandler'} {@code (org.xml.sax.ContentHandler)} bound to an instance.</blockquote></li> 076 * <li>"{@link #getDtdHandler dtdHandler}"<blockquote> 077 * Dependency on {@code 'org.xml.sax.DTDHandler'} {@code (org.xml.sax.DTDHandler)} bound to an instance.</blockquote></li> 078 * <li>"{@link #getEntityResolver entityResolver}"<blockquote> 079 * Dependency on {@code 'org.xml.sax.EntityResolver'} {@code (org.xml.sax.EntityResolver)} bound to an instance.</blockquote></li> 080 * <li>"{@link #getErrorHandler errorHandler}"<blockquote> 081 * Dependency on {@code 'org.xml.sax.ErrorHandler'} {@code (org.xml.sax.ErrorHandler)} bound to an instance.</blockquote></li> 082 * <li>"{@link #getSchema schema}"<blockquote> 083 * Dependency on {@code 'javax.xml.validation.Schema'} {@code (javax.xml.validation.Schema)} bound to an instance.</blockquote></li> 084 * </ul></p> 085 * 086 * @author <a href="mailto:schulte2005@users.sourceforge.net">Christian Schulte</a> 1.0 087 * @version $Id: JaxpSaxXmlReaderFactory.java 2234 2010-06-29 00:03:38Z schulte2005 $ 088 */ 089 // </editor-fold> 090 // SECTION-END 091 // SECTION-START[Annotations] 092 // <editor-fold defaultstate="collapsed" desc=" Generated Annotations "> 093 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" ) 094 // </editor-fold> 095 // SECTION-END 096 public final class JaxpSaxXmlReaderFactory 097 { 098 // SECTION-START[XMLReader] 099 // 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 }