Jump to: navigation, search

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

(Instantiating a DynamicJAXBContext)
m
Line 16: Line 16:
 
javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContextFactory
 
javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContextFactory
 
</source></div>
 
</source></div>
# Copy the file to your application package (or any of your packages on your classpath).
+
# Copy the '''jaxb.properties''' file to the context path used to create the '''JAXBContext'''.
 
# Use the standard <tt>JAXBContext.newInstance(String contextPath)</tt> API to create a <tt>DynamicJAXBContext</tt>.<div><source lang="java">
 
# 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");
 
DynamicJAXBContext jaxbContext = (DynamicJAXBContext) JAXBContext.newInstance("org.example.mypackage");
Line 65: Line 65:
 
|previous= [[EclipseLink/UserGuide/MOXy/Runtime/Bootstrapping_Dynamic|Dynamic JAXB Bootstrapping]]
 
|previous= [[EclipseLink/UserGuide/MOXy/Runtime/Bootstrapping_Dynamic|Dynamic JAXB Bootstrapping]]
 
|up=      [[EclipseLink/UserGuide/MOXy/Runtime/Bootstrapping_Dynamic|Dynamic JAXB Bootstrapping]]
 
|up=      [[EclipseLink/UserGuide/MOXy/Runtime/Bootstrapping_Dynamic|Dynamic JAXB Bootstrapping]]
|version=2.2.0 - DRAFT}}
+
|version=2.2.0}}

Revision as of 14:52, 19 January 2011

EclipseLink MOXy

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
  2. Copy the jaxb.properties file to the context path used to create the JAXBContext.
  3. Use the standard JAXBContext.newInstance(String contextPath) API to create a DynamicJAXBContext.
    DynamicJAXBContext jaxbContext = (DynamicJAXBContext) JAXBContext.newInstance("org.example.mypackage");

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 JAXBContext can be used to create new instances of DynamicJAXBContexts:

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
  • contextPath - Location of jaxb.properties file.
  • classLoader - The application's current class loader, which will be used to first lookup classes to see if they exist before new DynamicTypes are generated.
  • properties - A map of properties to use when creating a new DynamicJAXBContext. This map must contain one of the following two keys:
    • org.eclipse.persistence.jaxb.JAXBContextFactory.XML_SCHEMA_KEY, which can have several possible values:
      • One of the following, pointing to your XML Schema file:
        • java.io.InputStream
        • org.w3c.dom.Node
        • javax.xml.transform.Source
    • org.eclipse.persistence.jaxb.JAXBContextFactory.ECLIPSELINK_OXM_XML_KEY, which can have several possible values:
      • One of the following, pointing to your OXM file:
        • java.io.File
        • java.io.InputStream
        • java.io.Reader
        • java.net.URL
        • javax.xml.stream.XMLEventReader
        • javax.xml.stream.XMLStreamReader
        • javax.xml.transform.Source
        • org.w3c.dom.Node
        • org.xml.sax.InputSource
        • Note: If using one of these options, a package-name element must be defined in the xml-bindings element of your OXM file.
      • A List of objects from the set above.
        • Note: If using this option, a package-name element must be defined in the xml-bindings element of your OXM file.
      • A Map<String, Object>, where String is a package name, and Object is the pointer to the OXM file, from the set of possibilities above.


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