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: JaxpSaxParserFactory.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
045 // SECTION-START[Documentation]
046 // <editor-fold defaultstate="collapsed" desc=" Generated Documentation ">
047 /**
048 * JAXP 'SAXParser' factory implementation.
049 * <p><b>Specifications</b><ul>
050 * <li>{@code 'javax.xml.parsers.SAXParser'} {@code (javax.xml.parsers.SAXParser)} {@code Multiton}</li>
051 * </ul></p>
052 * <p><b>Properties</b><ul>
053 * <li>"{@link #isXIncludeAware XIncludeAware}"
054 * <blockquote>Property of type {@code java.lang.Boolean}.
055 * <p>{@code true} if the factory is configured to produce XInclude aware parsers; {@code false} otherwise.</p>
056 * </blockquote></li>
057 * <li>"{@link #getFeatures features}"
058 * <blockquote>Property of type {@code java.util.Map<String,Boolean>}.
059 * </blockquote></li>
060 * <li>"{@link #isNamespaceAware namespaceAware}"
061 * <blockquote>Property of type {@code java.lang.Boolean}.
062 * <p>{@code true} if the factory is configured to produce parsers which are namespace aware; {@code false} otherwise.</p>
063 * </blockquote></li>
064 * <li>"{@link #getProperties properties}"
065 * <blockquote>Property of type {@code java.util.Map<String,Object>}.
066 * </blockquote></li>
067 * <li>"{@link #isValidating validating}"
068 * <blockquote>Property of type {@code java.lang.Boolean}.
069 * <p>{@code true} if the factory is configured to produce parsers which validate the XML content during parse; {@code false} otherwise.</p>
070 * </blockquote></li>
071 * </ul></p>
072 * <p><b>Dependencies</b><ul>
073 * <li>"{@link #getSchema schema}"<blockquote>
074 * Dependency on {@code 'javax.xml.validation.Schema'} {@code (javax.xml.validation.Schema)} bound to an instance.</blockquote></li>
075 * </ul></p>
076 *
077 * @author <a href="mailto:schulte2005@users.sourceforge.net">Christian Schulte</a> 1.0
078 * @version $Id: JaxpSaxParserFactory.java 2234 2010-06-29 00:03:38Z schulte2005 $
079 */
080 // </editor-fold>
081 // SECTION-END
082 // SECTION-START[Annotations]
083 // <editor-fold defaultstate="collapsed" desc=" Generated Annotations ">
084 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" )
085 // </editor-fold>
086 // SECTION-END
087 public final class JaxpSaxParserFactory
088 {
089 // SECTION-START[SAXParser]
090 // SECTION-END
091 // SECTION-START[JaxpSaxParserFactory]
092
093 public SAXParser getObject() throws ParserConfigurationException, SAXException
094 {
095 final SAXParserFactory f = SAXParserFactory.newInstance();
096 f.setSchema( this.getSchema() );
097 f.setNamespaceAware( this.isNamespaceAware() );
098 f.setValidating( this.isValidating() );
099 f.setXIncludeAware( this.isXIncludeAware() );
100
101 for ( Map.Entry<String, Boolean> e : this.getFeatures().entrySet() )
102 {
103 f.setFeature( e.getKey(), e.getValue() );
104 }
105
106 final SAXParser p = f.newSAXParser();
107
108 for ( Map.Entry<String, Object> e : this.getProperties().entrySet() )
109 {
110 p.setProperty( e.getKey(), e.getValue() );
111 }
112
113 return p;
114 }
115
116 // SECTION-END
117 // SECTION-START[Constructors]
118 // <editor-fold defaultstate="collapsed" desc=" Generated Constructors ">
119
120 /** Creates a new {@code JaxpSaxParserFactory} instance. */
121 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" )
122 public JaxpSaxParserFactory()
123 {
124 // SECTION-START[Default Constructor]
125 super();
126 // SECTION-END
127 }
128 // </editor-fold>
129 // SECTION-END
130 // SECTION-START[Dependencies]
131 // <editor-fold defaultstate="collapsed" desc=" Generated Dependencies ">
132
133 /**
134 * Gets the {@code schema} dependency.
135 * <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>
136 * <p>That specification does not apply to any scope. A new object is returned whenever requested and bound to this instance.</p>
137 * @return The {@code schema} dependency.
138 * {@code null} if no object is available.
139 * @throws org.jomc.ObjectManagementException if getting the dependency instance fails.
140 */
141 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" )
142 private javax.xml.validation.Schema getSchema()
143 {
144 return (javax.xml.validation.Schema) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getDependency( this, "schema" );
145 }
146 // </editor-fold>
147 // SECTION-END
148 // SECTION-START[Properties]
149 // <editor-fold defaultstate="collapsed" desc=" Generated Properties ">
150
151 /**
152 * Gets the value of the {@code XIncludeAware} property.
153 * @return {@code true} if the factory is configured to produce XInclude aware parsers; {@code false} otherwise.
154 * @throws org.jomc.ObjectManagementException if getting the property 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 java.lang.Boolean isXIncludeAware()
158 {
159 final java.lang.Boolean _p = (java.lang.Boolean) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "XIncludeAware" );
160 assert _p != null : "'XIncludeAware' property not found.";
161 return _p;
162 }
163
164 /**
165 * Gets the value of the {@code features} property.
166 * @return The value of the {@code features} property.
167 * @throws org.jomc.ObjectManagementException if getting the property instance fails.
168 */
169 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" )
170 private java.util.Map<String,Boolean> getFeatures()
171 {
172 final java.util.Map<String,Boolean> _p = (java.util.Map<String,Boolean>) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "features" );
173 assert _p != null : "'features' property not found.";
174 return _p;
175 }
176
177 /**
178 * Gets the value of the {@code namespaceAware} property.
179 * @return {@code true} if the factory is configured to produce parsers which are namespace aware; {@code false} otherwise.
180 * @throws org.jomc.ObjectManagementException if getting the property instance fails.
181 */
182 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" )
183 private java.lang.Boolean isNamespaceAware()
184 {
185 final java.lang.Boolean _p = (java.lang.Boolean) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "namespaceAware" );
186 assert _p != null : "'namespaceAware' property not found.";
187 return _p;
188 }
189
190 /**
191 * Gets the value of the {@code properties} property.
192 * @return The value of the {@code properties} property.
193 * @throws org.jomc.ObjectManagementException if getting the property instance fails.
194 */
195 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" )
196 private java.util.Map<String,Object> getProperties()
197 {
198 final java.util.Map<String,Object> _p = (java.util.Map<String,Object>) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "properties" );
199 assert _p != null : "'properties' property not found.";
200 return _p;
201 }
202
203 /**
204 * Gets the value of the {@code validating} property.
205 * @return {@code true} if the factory is configured to produce parsers which validate the XML content during parse; {@code false} otherwise.
206 * @throws org.jomc.ObjectManagementException if getting the property instance fails.
207 */
208 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" )
209 private java.lang.Boolean isValidating()
210 {
211 final java.lang.Boolean _p = (java.lang.Boolean) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "validating" );
212 assert _p != null : "'validating' property not found.";
213 return _p;
214 }
215 // </editor-fold>
216 // SECTION-END
217 // SECTION-START[Messages]
218 // SECTION-END
219 }