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: JaxbBinderFactory.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.bind.Binder; 041 import javax.xml.bind.JAXBContext; 042 import javax.xml.bind.JAXBException; 043 import org.jomc.sdk.model.SchemaType; 044 import static org.jomc.sdk.model.modlet.SdkModelProvider.XML_SCHEMA_JAVA_CONTEXT_ID_ATTRIBUTE; 045 046 // SECTION-START[Documentation] 047 // <editor-fold defaultstate="collapsed" desc=" Generated Documentation "> 048 /** 049 * XML Schema Set 'Binder' factory implementation. 050 * <p><b>Specifications</b><ul> 051 * <li>{@code 'javax.xml.bind.Binder'} {@code (javax.xml.bind.Binder)} {@code Multiton}</li> 052 * </ul></p> 053 * <p><b>Properties</b><ul> 054 * <li>"{@link #getBinderProperties binderProperties}" 055 * <blockquote>Property of type {@code java.util.Map<String,Object>}. 056 * </blockquote></li> 057 * <li>"{@link #getSchemas schemas}" 058 * <blockquote>Property of type {@code org.jomc.sdk.model.SchemasType}. 059 * <p>List of XML schemas ('schemas' element from XML namespace 'http://jomc.org/sdk/model).</p> 060 * </blockquote></li> 061 * </ul></p> 062 * <p><b>Dependencies</b><ul> 063 * <li>"{@link #getSchema schema}"<blockquote> 064 * Dependency on {@code 'javax.xml.validation.Schema'} {@code (javax.xml.validation.Schema)} bound to an instance.</blockquote></li> 065 * <li>"{@link #getValidationEventHandler validationEventHandler}"<blockquote> 066 * Dependency on {@code 'javax.xml.bind.ValidationEventHandler'} {@code (javax.xml.bind.ValidationEventHandler)} bound to an instance.</blockquote></li> 067 * </ul></p> 068 * 069 * @author <a href="mailto:schulte2005@users.sourceforge.net">Christian Schulte</a> 1.0 070 * @version $Id: JaxbBinderFactory.java 2234 2010-06-29 00:03:38Z schulte2005 $ 071 */ 072 // </editor-fold> 073 // SECTION-END 074 // SECTION-START[Annotations] 075 // <editor-fold defaultstate="collapsed" desc=" Generated Annotations "> 076 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" ) 077 // </editor-fold> 078 // SECTION-END 079 public final class JaxbBinderFactory 080 { 081 // SECTION-START[Binder] 082 // SECTION-END 083 // SECTION-START[JaxbBinderFactory] 084 085 public Binder getObject() throws JAXBException 086 { 087 Binder binder = null; 088 final StringBuilder packages = new StringBuilder(); 089 090 for ( SchemaType s : this.getSchemas().getSchema() ) 091 { 092 if ( s.getOtherAttributes().containsKey( XML_SCHEMA_JAVA_CONTEXT_ID_ATTRIBUTE ) ) 093 { 094 packages.append( ':' ).append( s.getOtherAttributes().get( XML_SCHEMA_JAVA_CONTEXT_ID_ATTRIBUTE ) ); 095 } 096 } 097 098 if ( packages.length() > 0 ) 099 { 100 final String ctx = packages.toString().substring( 1 ); 101 binder = JAXBContext.newInstance( ctx ).createBinder(); 102 binder.setSchema( this.getSchema() ); 103 binder.setEventHandler( this.getValidationEventHandler() ); 104 105 for ( Map.Entry<String, Object> e : this.getBinderProperties().entrySet() ) 106 { 107 binder.setProperty( e.getKey(), e.getValue() ); 108 } 109 } 110 111 return binder; 112 } 113 114 // SECTION-END 115 // SECTION-START[Constructors] 116 // <editor-fold defaultstate="collapsed" desc=" Generated Constructors "> 117 118 /** Creates a new {@code JaxbBinderFactory} instance. */ 119 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" ) 120 public JaxbBinderFactory() 121 { 122 // SECTION-START[Default Constructor] 123 super(); 124 // SECTION-END 125 } 126 // </editor-fold> 127 // SECTION-END 128 // SECTION-START[Dependencies] 129 // <editor-fold defaultstate="collapsed" desc=" Generated Dependencies "> 130 131 /** 132 * Gets the {@code schema} dependency. 133 * <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> 134 * <p>That specification does not apply to any scope. A new object is returned whenever requested and bound to this instance.</p> 135 * @return The {@code schema} dependency. 136 * {@code null} if no object is available. 137 * @throws org.jomc.ObjectManagementException if getting the dependency instance fails. 138 */ 139 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" ) 140 private javax.xml.validation.Schema getSchema() 141 { 142 return (javax.xml.validation.Schema) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getDependency( this, "schema" ); 143 } 144 145 /** 146 * Gets the {@code validationEventHandler} dependency. 147 * <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> 148 * <p>That specification does not apply to any scope. A new object is returned whenever requested and bound to this instance.</p> 149 * @return The {@code validationEventHandler} dependency. 150 * {@code null} if no object is available. 151 * @throws org.jomc.ObjectManagementException if getting the dependency instance fails. 152 */ 153 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" ) 154 private javax.xml.bind.ValidationEventHandler getValidationEventHandler() 155 { 156 return (javax.xml.bind.ValidationEventHandler) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getDependency( this, "validationEventHandler" ); 157 } 158 // </editor-fold> 159 // SECTION-END 160 // SECTION-START[Properties] 161 // <editor-fold defaultstate="collapsed" desc=" Generated Properties "> 162 163 /** 164 * Gets the value of the {@code binderProperties} property. 165 * @return The value of the {@code binderProperties} property. 166 * @throws org.jomc.ObjectManagementException if getting the property instance fails. 167 */ 168 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" ) 169 private java.util.Map<String,Object> getBinderProperties() 170 { 171 final java.util.Map<String,Object> _p = (java.util.Map<String,Object>) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "binderProperties" ); 172 assert _p != null : "'binderProperties' property not found."; 173 return _p; 174 } 175 176 /** 177 * Gets the value of the {@code schemas} property. 178 * @return List of XML schemas ('schemas' element from XML namespace 'http://jomc.org/sdk/model). 179 * @throws org.jomc.ObjectManagementException if getting the property instance fails. 180 */ 181 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" ) 182 private org.jomc.sdk.model.SchemasType getSchemas() 183 { 184 final org.jomc.sdk.model.SchemasType _p = (org.jomc.sdk.model.SchemasType) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "schemas" ); 185 assert _p != null : "'schemas' property not found."; 186 return _p; 187 } 188 // </editor-fold> 189 // SECTION-END 190 // SECTION-START[Messages] 191 // SECTION-END 192 }