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: JaxbContextFactory.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 javax.xml.bind.JAXBContext;
040 import javax.xml.bind.JAXBException;
041 import org.jomc.sdk.model.SchemaType;
042 import static org.jomc.sdk.model.modlet.SdkModelProvider.XML_SCHEMA_JAVA_CONTEXT_ID_ATTRIBUTE;
043
044 // SECTION-START[Documentation]
045 // <editor-fold defaultstate="collapsed" desc=" Generated Documentation ">
046 /**
047 * XML Schema Set 'JAXBContext' factory implementation.
048 * <p><b>Specifications</b><ul>
049 * <li>{@code 'javax.xml.bind.JAXBContext'} {@code (javax.xml.bind.JAXBContext)} {@code Multiton}</li>
050 * </ul></p>
051 * <p><b>Properties</b><ul>
052 * <li>"{@link #getSchemas schemas}"
053 * <blockquote>Property of type {@code org.jomc.sdk.model.SchemasType}.
054 * <p>List of XML schemas ('schemas' element from XML namespace 'http://jomc.org/sdk/model).</p>
055 * </blockquote></li>
056 * </ul></p>
057 *
058 * @author <a href="mailto:schulte2005@users.sourceforge.net">Christian Schulte</a> 1.0
059 * @version $Id: JaxbContextFactory.java 2234 2010-06-29 00:03:38Z schulte2005 $
060 */
061 // </editor-fold>
062 // SECTION-END
063 // SECTION-START[Annotations]
064 // <editor-fold defaultstate="collapsed" desc=" Generated Annotations ">
065 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" )
066 // </editor-fold>
067 // SECTION-END
068 public final class JaxbContextFactory
069 {
070 // SECTION-START[JAXBContext]
071 // SECTION-END
072 // SECTION-START[JaxbContextFactory]
073
074 public JAXBContext getObject() throws JAXBException
075 {
076 JAXBContext context = null;
077 final StringBuilder packages = new StringBuilder();
078
079 for ( SchemaType s : this.getSchemas().getSchema() )
080 {
081 if ( s.getOtherAttributes().containsKey( XML_SCHEMA_JAVA_CONTEXT_ID_ATTRIBUTE ) )
082 {
083 packages.append( ':' ).append( s.getOtherAttributes().get( XML_SCHEMA_JAVA_CONTEXT_ID_ATTRIBUTE ) );
084 }
085 }
086
087 if ( packages.length() > 0 )
088 {
089 final String ctx = packages.toString().substring( 1 );
090 context = JAXBContext.newInstance( ctx );
091 }
092
093 return context;
094 }
095
096 // SECTION-END
097 // SECTION-START[Constructors]
098 // <editor-fold defaultstate="collapsed" desc=" Generated Constructors ">
099
100 /** Creates a new {@code JaxbContextFactory} instance. */
101 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" )
102 public JaxbContextFactory()
103 {
104 // SECTION-START[Default Constructor]
105 super();
106 // SECTION-END
107 }
108 // </editor-fold>
109 // SECTION-END
110 // SECTION-START[Dependencies]
111 // SECTION-END
112 // SECTION-START[Properties]
113 // <editor-fold defaultstate="collapsed" desc=" Generated Properties ">
114
115 /**
116 * Gets the value of the {@code schemas} property.
117 * @return List of XML schemas ('schemas' element from XML namespace 'http://jomc.org/sdk/model).
118 * @throws org.jomc.ObjectManagementException if getting the property instance fails.
119 */
120 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" )
121 private org.jomc.sdk.model.SchemasType getSchemas()
122 {
123 final org.jomc.sdk.model.SchemasType _p = (org.jomc.sdk.model.SchemasType) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "schemas" );
124 assert _p != null : "'schemas' property not found.";
125 return _p;
126 }
127 // </editor-fold>
128 // SECTION-END
129 // SECTION-START[Messages]
130 // SECTION-END
131 }