Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "EclipseLink/UserGuide/MOXy/Runtime/Bootstrapping Dynamic/Specifying the EclipseLink Runtime"

(Instantiating a DynamicJAXBContext)
m (Replacing page with 'See http://www.eclipse.org/eclipselink/documentation/2.4/moxy/dynamic_jaxb002.htm')
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{EclipseLink_UserGuide
+
See http://www.eclipse.org/eclipselink/documentation/2.4/moxy/dynamic_jaxb002.htm
|eclipselink=y
+
|eclipselinktype=MOXy
+
|info=y
+
|api=y
+
|apis= * [http://www.eclipse.org/eclipselink/api/latest/org/eclipse/persistence/jaxb/dynamic/DynamicJAXBContext.html DynamicJAXBContext]
+
* [http://www.eclipse.org/eclipselink/api/latest/org/eclipse/persistence/jaxb/dynamic/DynamicJAXBContextFactory.html DynamicJAXBContextFactory]
+
|toc=y
+
}}
+
 
+
=Specifying the EclipseLink Runtime=
+
 
+
In order to use EclipseLink Dynamic MOXy as your JAXB implementation, you must identify the EclipseLink <tt>DynamicJAXBContextFactory</tt> in your <tt>jaxb.properties</tt> file.
+
 
+
# Create a text file named <tt>jaxb.properties</tt>, specifying <tt>DynamicJAXBContextFactory</tt> as the factory used to build new <tt>JAXBContexts</tt>.<div><source lang="java">
+
javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContextFactory
+
</source></div>
+
# Copy the file to your application package (or any of your packages on your classpath).
+
# Use the standard <tt>JAXBContext.newInstance(String contextPath)</tt> API to create a <tt>DynamicJAXBContext</tt>.<div><source lang="java">
+
DynamicJAXBContext jaxbContext = (DynamicJAXBContext) JAXBContext.newInstance("org.example.mypackage");
+
</source></div>
+
 
+
Because you do not need to change any application code, you can easily switch between different JAXB implementations.
+
 
+
 
+
=Instantiating a DynamicJAXBContext=
+
 
+
The following methods on <tt>JAXBContext</tt> can be used to create new instances of <tt>DynamicJAXBContexts</tt>:
+
 
+
<source lang="java">
+
public static JAXBContext newInstance(String contextPath) throws JAXBException
+
 
+
public static JAXBContext newInstance(String contextPath, ClassLoader classLoader) throws JAXBException
+
 
+
public static JAXBContext newInstance(String contextPath, ClassLoader classLoader, Map<String,?> properties) throws JAXBException
+
</source>
+
 
+
* <tt>contextPath</tt> - Location of <tt>jaxb.properties</tt> file.
+
* <tt>classLoader</tt> - The application's current class loader, which will be used to first lookup classes to see if they exist before new <tt>DynamicTypes</tt> are generated.
+
* <tt>properties</tt> -  A map of properties to use when creating a new <tt>DynamicJAXBContext</tt>.  This map must contain one of the following two keys:
+
**<tt>JAXBContextFactory.XML_SCHEMA_KEY</tt>, which can have several possible values:
+
***One of the following, pointing to your XML Schema file:
+
****<tt>java.io.InputStream</tt>
+
****<tt>org.w3c.dom.Node</tt>
+
****<tt>javax.xml.transform.Source</tt>
+
**<tt>JAXBContextFactory.ECLIPSELINK_OXM_XML_KEY</tt>, which can have several possible values:
+
***One of the following, pointing to your OXM file:
+
****<tt>java.io.File</tt>
+
****<tt>java.io.InputStream</tt>
+
****<tt>java.io.Reader</tt>
+
****<tt>java.net.URL</tt>
+
****<tt>javax.xml.stream.XMLEventReader</tt>
+
****<tt>javax.xml.stream.XMLStreamReader</tt>
+
****<tt>javax.xml.transform.Source</tt>
+
****<tt>org.w3c.dom.Node</tt>
+
****<tt>org.xml.sax.InputSource</tt>
+
****Note: If using one of these options, a <tt>package-name</tt> element must be defined in the <tt>xml-bindings</tt> element of your OXM file.
+
***A <tt>List</tt> of objects from the set above.
+
****Note: If using this option, a <tt>package-name</tt> element must be defined in the <tt>xml-bindings</tt> element of your OXM file.
+
***A <tt>Map&lt;String, Object&gt;</tt>, where <tt>String</tt> is a package name, and <tt>Object</tt> is the pointer to the OXM file, from the set of possibilities above. 
+
 
+
 
+
{{EclipseLink_MOXy
+
|next= [[EclipseLink/UserGuide/MOXy/Runtime/Bootstrapping/From_Schema|From XML Schema]]
+
|previous= [[EclipseLink/UserGuide/MOXy/Runtime/Bootstrapping_Dynamic|Dynamic JAXB Bootstrapping]]
+
|up=      [[EclipseLink/UserGuide/MOXy/Runtime/Bootstrapping_Dynamic|Dynamic JAXB Bootstrapping]]
+
|version=2.2.0 - DRAFT}}
+

Latest revision as of 10:36, 8 November 2012

See http://www.eclipse.org/eclipselink/documentation/2.4/moxy/dynamic_jaxb002.htm

Back to the top