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

From Eclipsepedia

Jump to: navigation, search
Line 9: Line 9:
 
=Specifying the EclipseLink Runtime=
 
=Specifying the EclipseLink Runtime=
  
In order to use EclipseLink MOXy as your JAXB implementation, you must identify the EclipseLink <tt>JAXBContextFactory</tt> in your <tt>jaxb.properties</tt> file.
+
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> with the following content:<br><div><source lang="java">
+
# Create a text file named <tt>jaxb.properties</tt>, specifying <tt>DynamicJAXBContextFactory</tt> as the factory used to build new <tt>JAXBContexts</tt>.
javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory
+
javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContextFactory
 
</source></div>
 
</source></div>
# Copy the file to the same package (directory) in which your model classes reside.
+
# Copy the file to your application package (or any of your packages on your classpath).
# Create a <tt>JAXBContent</tt> using the standard APIs:<br><div><source lang="java">
+
# Use the standard <tt>JAXBContext.newInstance(String contextPath)</tt> API to create a <tt>DynamicJAXBContext</tt>.<br>When this method is called, MOXy attempts to locate a <tt>jaxb.properties</tt> file on the classpath in the package specified by <tt>contextPath</tt>, and use the specified factory.<div><source lang="java">
JAXBContext jaxbContext = JAXBContext.newInstance(Customer.class);
+
DynamicJAXBContext jaxbContext = (DynamicJAXBContext) JAXBContext.newInstance("mynamespace");
 
</source></div>
 
</source></div>
  
Line 24: Line 24:
 
* Create a <tt>JAXBContext</tt> from an array of Classes and a Properties object
 
* Create a <tt>JAXBContext</tt> from an array of Classes and a Properties object
 
* Create a <tt>JAXBContext</tt> from a context path and a ClassLoader
 
* Create a <tt>JAXBContext</tt> from a context path and a ClassLoader
 
=Specifying Dynamic JAXB Bootstrapping in EclipseLink Runtime=
 
You can create <tt>JAXBContexts</tt> by specifying a factory class in <tt>jaxb.properties</tt> file and then using the <tt>JAXBContext.newInstance()</tt> API.
 
 
#Create a <tt>jaxb.properties</tt>, specifying <tt>DynamicJAXBContextFactory</tt> as the factory used to build new <tt>JAXBContexts</tt>. 
 
#Place the <tt>jaxb.properties</tt> on your classpath within the package in which the <tt>DynamicEntites</tt> will be generated.<div>In this example, the <tt>mynamespace</tt> package will contain the <tt>DynamicEntities</tt>: <br><source lang="java">
 
javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContextFactory
 
</source></div>
 
#Use the <tt>newInstance(String contextPath)</tt> method to create a <tt>DynamicJAXBContext</tt>.  <br />When this method is called, MOXy attempts to locate a <tt>jaxb.properties</tt> file on the classpath in the package specified by <tt>contextPath</tt>, and use the specified factory.<div><source lang="java">
 
 
DynamicJAXBContext jaxbContext = (DynamicJAXBContext) JAXBContext.newInstance("mynamespace");
 
 
</source></div>
 
 
  
  

Revision as of 12:22, 6 January 2011

EclipseLink MOXy

link="http://wiki.eclipse.org/EclipseLink"
EclipseLink
Website
Download
Community
Mailing ListForumsIRC
Bugzilla
Open
Help Wanted
Bug Day
Contribute
Browse Source


Specifying the EclipseLink Runtime

In order to use EclipseLink Dynamic MOXy as your JAXB implementation, you must identify the EclipseLink DynamicJAXBContextFactory in your jaxb.properties file.

  1. Create a text file named jaxb.properties, specifying DynamicJAXBContextFactory as the factory used to build new JAXBContexts.

javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContextFactory </source></div>

  1. Copy the file to your application package (or any of your packages on your classpath).
  2. Use the standard JAXBContext.newInstance(String contextPath) API to create a DynamicJAXBContext.
    When this method is called, MOXy attempts to locate a jaxb.properties file on the classpath in the package specified by contextPath, and use the specified factory.
    DynamicJAXBContext jaxbContext = (DynamicJAXBContext) JAXBContext.newInstance("mynamespace");

Because you do not need to change any application code, you can easily switch between different JAXB implementations.

The JAXBContextFactory can

  • Create a JAXBContext from an array of Classes and a Properties object
  • Create a JAXBContext from a context path and a ClassLoader


Eclipselink-logo.gif
Version: 2.2.0 - DRAFT
Other versions...