|
|
(14 intermediate revisions by the same user not shown) |
Line 1: |
Line 1: |
− | {{EclipseLink_UserGuide
| + | See http://www.eclipse.org/eclipselink/documentation/2.4/moxy/dynamic_jaxb002.htm |
− | |info=y
| + | |
− | |eclipselink=y
| + | |
− | |eclipselinktype=MOXy
| + | |
− | |api=y
| + | |
− | |apis= * [http://www.eclipse.org/eclipselink/api/2.1/index.html?org/eclipse/persistence/jaxb/JAXBContextFactory.html *.jaxb.JAXBContextFactory]
| + | |
− | }}
| + | |
− | | + | |
− | =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.
| + | |
− | | + | |
− | The following methods on <tt>DynamicJAXBContextFactory</tt> can be used to create <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 keys:
| + | |
− | | + | |
− | **<tt>JAXBContext.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>, or <tt>javax.xml.transform.Source</tt>.
| + | |
− | **<tt>JAXBContext.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>, or <tt>org.xml.sax.InputSource</tt>.
| + | |
− | ***A <tt>List</tt> of objects from the set above.
| + | |
− | ***A <tt>Map<String, Object></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. If using this option, a <tt>package-name</tt> element is not required in the <tt>xml-bindings</tt> element of your OXM file.
| + | |
− | {{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}}
| + | |