|
|
(42 intermediate revisions by the same user not shown) |
Line 1: |
Line 1: |
− | {{EclipseLink_UserGuide
| + | '''[[Image:Elug_draft_icon.png|Warning]] For the current release, see [http://www.eclipse.org/eclipselink/documentation/2.4/moxy Developing JAXB Applications Using EclipseLink MOXy, EclipseLink 2.4] |
− | |eclipselink=y | + | ''' |
− | |eclipselinktype=MOXy
| + | |
− | |info=y
| + | |
− | |toc=y
| + | |
− | |api=y
| + | |
− | |apis= * [http://www.eclipse.org/eclipselink/api/latest/javax/xml/bind/annotation/XmlRootElement.html XmlRootElement]
| + | |
− | }}
| + | |
| | | |
− | = Bootstrapping =
| + | http://www.eclipse.org/eclipselink/documentation/2.4/moxy/runtime002.htm |
− | | + | |
− | EclipseLink MOXy offers several options when creating your '''JAXBContext'''. You have the option of bootstrapping from:
| + | |
− | | + | |
− | * A list of one or more JAXB-annotated '''Classes'''
| + | |
− | * A list of one or more EclipseLink OXM Bindings Files defining the mappings for your Java classes
| + | |
− | * A combination of '''Classes''' and OXM files
| + | |
− | * A '''Session''' name, referring to an EclipseLink '''Session''' defined in '''sessions.xml'''
| + | |
− | | + | |
− | | + | |
− | == JAXBContext API ==
| + | |
− | | + | |
− | The following methods on '''JAXBContext''' are used to create new instances of '''JAXBContexts''':
| + | |
− | | + | |
− | <source lang="java">
| + | |
− | public static JAXBContext newInstance(Class... classesToBeBound) throws JAXBException
| + | |
− | | + | |
− | public static JAXBContext newInstance(Class[] classesToBeBound, Map<String,?> properties) throws JAXBException
| + | |
− | | + | |
− | 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>
| + | |
− | | + | |
− | * '''classesToBeBound''' - List of Java classes to be recognized by the new '''JAXBContext'''.
| + | |
− | * '''contextPath''' - List of Java package names that contain mapped classes.
| + | |
− | * '''classLoader''' - The class loader used to locate the mapped classes.
| + | |
− | * '''properties''' - A map of additional properties.
| + | |
− | | + | |
− | | + | |
− | == Bootstrapping from Classes ==
| + | |
− | | + | |
− | If you already have a collection of Java '''Classes''' annotated with JAXB annotations, you can provide an list of these '''Classes''' directly:
| + | |
− | | + | |
− | <source lang="java">
| + | |
− | JAXBContext context = JAXBContext.newInstance(Company.class, Employee.class);
| + | |
− | </source>
| + | |
− | | + | |
− | | + | |
− | == Bootstrapping from EclipseLink OXM ==
| + | |
− | | + | |
− | Links to the actual OXM files are passed in via the '''properties''' parameter, using a special key, '''JAXBContextFactory.ECLIPSELINK_OXM_XML_KEY'''. The value of this key will be a handle to the OXM metadata file, in the form of one of the following:
| + | |
− | | + | |
− | * '''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'''
| + | |
− | | + | |
− | <source lang="java">
| + | |
− | InputStream iStream = myClassLoader.getResourceAsStream("example/eclipselink-oxm.xml");
| + | |
− |
| + | |
− | Map<String, Object> properties = new HashMap<String, Object>();
| + | |
− | properties.put(JAXBContextFactory.ECLIPSELINK_OXM_XML_KEY, iStream);
| + | |
− |
| + | |
− | JAXBContext context = JAXBContext.newInstance(null, myClassLoader, properties);
| + | |
− | </source>
| + | |
− | | + | |
− | | + | |
− | == Bootstrapping from Context Path ==
| + | |
− | | + | |
− | | + | |
− | === ObjectFactory ===
| + | |
− | | + | |
− | | + | |
− | === jaxb.index ===
| + | |
− | | + | |
− | | + | |
− | === sessions.xml ===
| + | |