Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "EclipseLink/UserGuide/MOXy/Runtime/Bootstrapping/Introduction"
(New page: = Dynamic MOXy - JAXB with Dynamically Generated Java Classes = EclipseLink Dynamic MOXy introduces a new concept in JAXB development - the freedom to bootstrap a <tt>JAXBContext</tt> fro...) |
|||
Line 37: | Line 37: | ||
</div> | </div> | ||
− | |||
− | |||
As with conventional JAXB, the first step is to create a <tt>JAXBContext</tt>. This is achieved by use of the <tt>DynamicJAXBContextFactory</tt> class. <tt>DynamicJAXBContexts</tt> cannot be instantiated directly, they must be created through the factory API. | As with conventional JAXB, the first step is to create a <tt>JAXBContext</tt>. This is achieved by use of the <tt>DynamicJAXBContextFactory</tt> class. <tt>DynamicJAXBContexts</tt> cannot be instantiated directly, they must be created through the factory API. | ||
A <tt>DynamicJAXBContext</tt> can be created from an XML Schema file (XSD), EclipseLink OXM metadata file, or from an EclipseLink Project specified in the EclipseLink <tt>sessions.xml</tt> file. | A <tt>DynamicJAXBContext</tt> can be created from an XML Schema file (XSD), EclipseLink OXM metadata file, or from an EclipseLink Project specified in the EclipseLink <tt>sessions.xml</tt> file. | ||
− | |||
− |
Revision as of 11:29, 29 November 2010
Dynamic MOXy - JAXB with Dynamically Generated Java Classes
EclipseLink Dynamic MOXy introduces a new concept in JAXB development - the freedom to bootstrap a JAXBContext from a variety of metadata sources and use familiar JAXB APIs to marshal and unmarshal data, all without having actual compiled Java class files on the classpath. This gives the user the flexibility to alter their metadata and not have to worry about updating and recompiling the previously-generated Java source code.
Dynamic Entities
Instead of actual Java classes (e.g. Customer.class, Address.class, etc), the "domain" objects used in Dynamic MOXy will be subclasses of DynamicEntity. DynamicEntities offer a simple get(propertyName) / set(propertyName, propertyValue) API to manipulate their data. DynamicEntities have an associated DynamicType, which will be generated in memory when the metadata is parsed.
Following is an example of using the DynamicEntity APIs:
DynamicEntity customer = (DynamicEntity) dynamicJAXBContext.createUnmarshaller().unmarshal(instanceDoc); String lastName = customer.get("lastName"); List orders = customer.get("orders"); ... DynamicEntity address = dContext.newDynamicEntity("mynamespace.Address"); address.set("street", "1001 Fleet St."); customer.set("lastName", lastName + "Jr."); customer.set("address", address);
As with conventional JAXB, the first step is to create a JAXBContext. This is achieved by use of the DynamicJAXBContextFactory class. DynamicJAXBContexts cannot be instantiated directly, they must be created through the factory API.
A DynamicJAXBContext can be created from an XML Schema file (XSD), EclipseLink OXM metadata file, or from an EclipseLink Project specified in the EclipseLink sessions.xml file.