Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

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>
 
<br><br>
 
  
 
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.
 
<br><br>
 

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.

Idea.png
DynamicTypes are analogous to Java Classes, whereas DynamicEntities can be thought of as instances of a DynamicType.


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);
Idea.png
XML names found in the metadata (complex type names, element names, attribute names) will be translated to Java identifiers according to the algorithms described in "Appendix D: Binding XML Names to Java Identifiers" of the Java Architecture for XML Binding (JAXB) 2.2 Specification. In the example above, "last-name" in XML was translated to "lastName" for the Java object.


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.

Back to the top