View Javadoc

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: JaxpSaxParserFactory.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  
45  // SECTION-START[Documentation]
46  // <editor-fold defaultstate="collapsed" desc=" Generated Documentation ">
47  /**
48   * JAXP 'SAXParser' factory implementation.
49   * <p><b>Specifications</b><ul>
50   * <li>{@code 'javax.xml.parsers.SAXParser'} {@code (javax.xml.parsers.SAXParser)} {@code Multiton}</li>
51   * </ul></p>
52   * <p><b>Properties</b><ul>
53   * <li>"{@link #isXIncludeAware XIncludeAware}"
54   * <blockquote>Property of type {@code java.lang.Boolean}.
55   * <p>{@code true} if the factory is configured to produce XInclude aware parsers; {@code false} otherwise.</p>
56   * </blockquote></li>
57   * <li>"{@link #getFeatures features}"
58   * <blockquote>Property of type {@code java.util.Map<String,Boolean>}.
59   * </blockquote></li>
60   * <li>"{@link #isNamespaceAware namespaceAware}"
61   * <blockquote>Property of type {@code java.lang.Boolean}.
62   * <p>{@code true} if the factory is configured to produce parsers which are namespace aware; {@code false} otherwise.</p>
63   * </blockquote></li>
64   * <li>"{@link #getProperties properties}"
65   * <blockquote>Property of type {@code java.util.Map<String,Object>}.
66   * </blockquote></li>
67   * <li>"{@link #isValidating validating}"
68   * <blockquote>Property of type {@code java.lang.Boolean}.
69   * <p>{@code true} if the factory is configured to produce parsers which validate the XML content during parse; {@code false} otherwise.</p>
70   * </blockquote></li>
71   * </ul></p>
72   * <p><b>Dependencies</b><ul>
73   * <li>"{@link #getSchema schema}"<blockquote>
74   * Dependency on {@code 'javax.xml.validation.Schema'} {@code (javax.xml.validation.Schema)} bound to an instance.</blockquote></li>
75   * </ul></p>
76   *
77   * @author <a href="mailto:schulte2005@users.sourceforge.net">Christian Schulte</a> 1.0
78   * @version $Id: JaxpSaxParserFactory.java 2234 2010-06-29 00:03:38Z schulte2005 $
79   */
80  // </editor-fold>
81  // SECTION-END
82  // SECTION-START[Annotations]
83  // <editor-fold defaultstate="collapsed" desc=" Generated Annotations ">
84  @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" )
85  // </editor-fold>
86  // SECTION-END
87  public final class JaxpSaxParserFactory
88  {
89      // SECTION-START[SAXParser]
90      // SECTION-END
91      // SECTION-START[JaxpSaxParserFactory]
92  
93      public SAXParser getObject() throws ParserConfigurationException, SAXException
94      {
95          final SAXParserFactory f = SAXParserFactory.newInstance();
96          f.setSchema( this.getSchema() );
97          f.setNamespaceAware( this.isNamespaceAware() );
98          f.setValidating( this.isValidating() );
99          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 }