| 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: JaxbUnmarshallerFactory.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.bind.JAXBContext; |
| 41 | import javax.xml.bind.JAXBException; |
| 42 | import javax.xml.bind.Unmarshaller; |
| 43 | import org.jomc.sdk.model.SchemaType; |
| 44 | import static org.jomc.sdk.model.modlet.SdkModelProvider.XML_SCHEMA_JAVA_CONTEXT_ID_ATTRIBUTE; |
| 45 | import org.xml.sax.SAXException; |
| 46 | |
| 47 | // SECTION-START[Documentation] |
| 48 | // <editor-fold defaultstate="collapsed" desc=" Generated Documentation "> |
| 49 | /** |
| 50 | * XML Schema Set JAXB 'Unmarshaller' factory implementation. |
| 51 | * <p><b>Specifications</b><ul> |
| 52 | * <li>{@code 'javax.xml.bind.Unmarshaller'} {@code (javax.xml.bind.Unmarshaller)} {@code Multiton}</li> |
| 53 | * </ul></p> |
| 54 | * <p><b>Properties</b><ul> |
| 55 | * <li>"{@link #getSchemas schemas}" |
| 56 | * <blockquote>Property of type {@code org.jomc.sdk.model.SchemasType}. |
| 57 | * <p>List of XML schemas ('schemas' element from XML namespace 'http://jomc.org/sdk/model).</p> |
| 58 | * </blockquote></li> |
| 59 | * <li>"{@link #getUnmarshallerProperties unmarshallerProperties}" |
| 60 | * <blockquote>Property of type {@code java.util.Map<String,Object>}. |
| 61 | * </blockquote></li> |
| 62 | * </ul></p> |
| 63 | * <p><b>Dependencies</b><ul> |
| 64 | * <li>"{@link #getAttachmentUnmarshaller attachmentUnmarshaller}"<blockquote> |
| 65 | * Dependency on {@code 'javax.xml.bind.attachment.AttachmentUnmarshaller'} {@code (javax.xml.bind.attachment.AttachmentUnmarshaller)} bound to an instance.</blockquote></li> |
| 66 | * <li>"{@link #getSchema schema}"<blockquote> |
| 67 | * Dependency on {@code 'javax.xml.validation.Schema'} {@code (javax.xml.validation.Schema)} bound to an instance.</blockquote></li> |
| 68 | * <li>"{@link #getValidationEventHandler validationEventHandler}"<blockquote> |
| 69 | * Dependency on {@code 'javax.xml.bind.ValidationEventHandler'} {@code (javax.xml.bind.ValidationEventHandler)} bound to an instance.</blockquote></li> |
| 70 | * </ul></p> |
| 71 | * |
| 72 | * @author <a href="mailto:schulte2005@users.sourceforge.net">Christian Schulte</a> 1.0 |
| 73 | * @version $Id: JaxbUnmarshallerFactory.java 2234 2010-06-29 00:03:38Z schulte2005 $ |
| 74 | */ |
| 75 | // </editor-fold> |
| 76 | // SECTION-END |
| 77 | // SECTION-START[Annotations] |
| 78 | // <editor-fold defaultstate="collapsed" desc=" Generated Annotations "> |
| 79 | @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" ) |
| 80 | // </editor-fold> |
| 81 | // SECTION-END |
| 82 | public final class JaxbUnmarshallerFactory |
| 83 | { |
| 84 | // SECTION-START[Unmarshaller] |
| 85 | // SECTION-END |
| 86 | // SECTION-START[JaxbUnmarshallerFactory] |
| 87 | |
| 88 | public Unmarshaller getObject() throws JAXBException, SAXException |
| 89 | { |
| 90 | Unmarshaller unmarshaller = null; |
| 91 | final StringBuilder packageNames = new StringBuilder(); |
| 92 | |
| 93 | for ( SchemaType s : this.getSchemas().getSchema() ) |
| 94 | { |
| 95 | if ( s.getOtherAttributes().containsKey( XML_SCHEMA_JAVA_CONTEXT_ID_ATTRIBUTE ) ) |
| 96 | { |
| 97 | packageNames.append( ':' ).append( s.getOtherAttributes().get( XML_SCHEMA_JAVA_CONTEXT_ID_ATTRIBUTE ) ); |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | if ( packageNames.length() > 0 ) |
| 102 | { |
| 103 | unmarshaller = JAXBContext.newInstance( packageNames.substring( 1 ) ).createUnmarshaller(); |
| 104 | |
| 105 | for ( Map.Entry<String, Object> e : this.getUnmarshallerProperties().entrySet() ) |
| 106 | { |
| 107 | unmarshaller.setProperty( e.getKey(), e.getValue() ); |
| 108 | } |
| 109 | |
| 110 | unmarshaller.setAttachmentUnmarshaller( this.getAttachmentUnmarshaller() ); |
| 111 | unmarshaller.setEventHandler( this.getValidationEventHandler() ); |
| 112 | unmarshaller.setSchema( this.getSchema() ); |
| 113 | } |
| 114 | |
| 115 | return unmarshaller; |
| 116 | } |
| 117 | |
| 118 | // SECTION-END |
| 119 | // SECTION-START[Constructors] |
| 120 | // <editor-fold defaultstate="collapsed" desc=" Generated Constructors "> |
| 121 | |
| 122 | /** Creates a new {@code JaxbUnmarshallerFactory} instance. */ |
| 123 | @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" ) |
| 124 | public JaxbUnmarshallerFactory() |
| 125 | { |
| 126 | // SECTION-START[Default Constructor] |
| 127 | super(); |
| 128 | // SECTION-END |
| 129 | } |
| 130 | // </editor-fold> |
| 131 | // SECTION-END |
| 132 | // SECTION-START[Dependencies] |
| 133 | // <editor-fold defaultstate="collapsed" desc=" Generated Dependencies "> |
| 134 | |
| 135 | /** |
| 136 | * Gets the {@code attachmentUnmarshaller} dependency. |
| 137 | * <p>This method returns the {@code 'JOMC SDK Model Default'} object of the {@code 'javax.xml.bind.attachment.AttachmentUnmarshaller'} {@code (javax.xml.bind.attachment.AttachmentUnmarshaller)} specification.</p> |
| 138 | * <p>That specification does not apply to any scope. A new object is returned whenever requested and bound to this instance.</p> |
| 139 | * @return The {@code attachmentUnmarshaller} dependency. |
| 140 | * {@code null} if no object is available. |
| 141 | * @throws org.jomc.ObjectManagementException if getting the dependency instance fails. |
| 142 | */ |
| 143 | @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" ) |
| 144 | private javax.xml.bind.attachment.AttachmentUnmarshaller getAttachmentUnmarshaller() |
| 145 | { |
| 146 | return (javax.xml.bind.attachment.AttachmentUnmarshaller) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getDependency( this, "attachmentUnmarshaller" ); |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * Gets the {@code schema} dependency. |
| 151 | * <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> |
| 152 | * <p>That specification does not apply to any scope. A new object is returned whenever requested and bound to this instance.</p> |
| 153 | * @return The {@code schema} dependency. |
| 154 | * {@code null} if no object is available. |
| 155 | * @throws org.jomc.ObjectManagementException if getting the dependency instance fails. |
| 156 | */ |
| 157 | @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" ) |
| 158 | private javax.xml.validation.Schema getSchema() |
| 159 | { |
| 160 | return (javax.xml.validation.Schema) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getDependency( this, "schema" ); |
| 161 | } |
| 162 | |
| 163 | /** |
| 164 | * Gets the {@code validationEventHandler} dependency. |
| 165 | * <p>This method returns the {@code 'JOMC SDK Model Default'} object of the {@code 'javax.xml.bind.ValidationEventHandler'} {@code (javax.xml.bind.ValidationEventHandler)} specification.</p> |
| 166 | * <p>That specification does not apply to any scope. A new object is returned whenever requested and bound to this instance.</p> |
| 167 | * @return The {@code validationEventHandler} dependency. |
| 168 | * {@code null} if no object is available. |
| 169 | * @throws org.jomc.ObjectManagementException if getting the dependency instance fails. |
| 170 | */ |
| 171 | @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" ) |
| 172 | private javax.xml.bind.ValidationEventHandler getValidationEventHandler() |
| 173 | { |
| 174 | return (javax.xml.bind.ValidationEventHandler) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getDependency( this, "validationEventHandler" ); |
| 175 | } |
| 176 | // </editor-fold> |
| 177 | // SECTION-END |
| 178 | // SECTION-START[Properties] |
| 179 | // <editor-fold defaultstate="collapsed" desc=" Generated Properties "> |
| 180 | |
| 181 | /** |
| 182 | * Gets the value of the {@code schemas} property. |
| 183 | * @return List of XML schemas ('schemas' element from XML namespace 'http://jomc.org/sdk/model). |
| 184 | * @throws org.jomc.ObjectManagementException if getting the property instance fails. |
| 185 | */ |
| 186 | @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" ) |
| 187 | private org.jomc.sdk.model.SchemasType getSchemas() |
| 188 | { |
| 189 | final org.jomc.sdk.model.SchemasType _p = (org.jomc.sdk.model.SchemasType) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "schemas" ); |
| 190 | assert _p != null : "'schemas' property not found."; |
| 191 | return _p; |
| 192 | } |
| 193 | |
| 194 | /** |
| 195 | * Gets the value of the {@code unmarshallerProperties} property. |
| 196 | * @return The value of the {@code unmarshallerProperties} property. |
| 197 | * @throws org.jomc.ObjectManagementException if getting the property instance fails. |
| 198 | */ |
| 199 | @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" ) |
| 200 | private java.util.Map<String,Object> getUnmarshallerProperties() |
| 201 | { |
| 202 | final java.util.Map<String,Object> _p = (java.util.Map<String,Object>) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "unmarshallerProperties" ); |
| 203 | assert _p != null : "'unmarshallerProperties' property not found."; |
| 204 | return _p; |
| 205 | } |
| 206 | // </editor-fold> |
| 207 | // SECTION-END |
| 208 | // SECTION-START[Messages] |
| 209 | // SECTION-END |
| 210 | } |