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"

(Removing all content from page)
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
= 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> 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.
 
 
<br><br>
 
 
== Dynamic Entities ==
 
 
Instead of actual Java classes (e.g. <tt>Customer.class</tt>, <tt>Address.class</tt>, etc), the "domain" objects used in Dynamic MOXy will be subclasses of <tt>DynamicEntity</tt>.  <tt>DynamicEntities</tt> offer a simple <tt>get(propertyName)</tt> / <tt>set(propertyName, propertyValue)</tt> API to manipulate their data.  <tt>DynamicEntities</tt> have an associated <tt>DynamicType</tt>, which will be generated in memory when the metadata is parsed.
 
 
<div style="margin-left:40px;width:65%">
 
 
{{tip||<tt>DynamicTypes</tt> are analogous to Java Classes, whereas <tt>DynamicEntities</tt> can be thought of as instances of a <tt>DynamicType</tt>.}}
 
 
</div>
 
 
Following is an example of using the <tt>DynamicEntity</tt> APIs:
 
 
<div style="width:80%"><source lang="java">
 
 
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);
 
 
</source></div>
 
 
<div style="margin-left:40px;width:65%">
 
 
{{tip||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.}}
 
 
</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.
 
 
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.
 

Latest revision as of 17:03, 30 November 2010

Back to the top