Difference between revisions of "EclipseLink/UserGuide/MOXy/Overview/DynamicEntities"

From Eclipsepedia

Jump to: navigation, search
(Creating Dynamic Entities)
Line 45: Line 45:
  
 
===Creating Dynamic Entities===
 
===Creating Dynamic Entities===
To create and use Dynamic MOXy entities, create a '''JAXBContext''' by using the '''DynamicJAXBContextFactory''' class. You can create a '''DynamicJAXBContext''' from an XML Schema file (XSD), EclipseLink OXM metadata file, or from an EclipseLink Project specified in the EclipseLink sessions.xml file. <br>'''Note:''' DynamicJAXBContexts cannot be instantiated directly, they must be created through the factory API.
+
To create and use Dynamic MOXy entities, create a '''JAXBContext''' by using the '''DynamicJAXBContextFactory''' class. You can create a '''DynamicJAXBContext''' from an XML Schema file (XSD), EclipseLink OXM metadata file, or from an EclipseLink Project specified in the EclipseLink sessions.xml file.
 +
 
 
*[[UserGuide/MOXy/Runtime/Bootstrapping/From_Schema|Bootstrapping from XML schema (XSD)]]
 
*[[UserGuide/MOXy/Runtime/Bootstrapping/From_Schema|Bootstrapping from XML schema (XSD)]]
 
* Bootstrapping from EclipseLink OXM metadata  
 
* Bootstrapping from EclipseLink OXM metadata  

Revision as of 16:51, 21 December 2010


link="http://wiki.eclipse.org/EclipseLink"
EclipseLink
Website
Download
Community
Mailing ListForumsIRC
Bugzilla
Open
Help Wanted
Bug Day
Contribute
Browse Source

Static and Dynamic Entities


Using Static MOXy

Using Dynamic MOXy

With EclipseLink Dynamic MOXy, you can bootstrap a JAXBContext from a variety of metadata sources and use existing JAXB APIs to marshal and unmarshal data… without having compiled Java class files on the classpath. This allows you to alter the metadata source as needed, without having to update and recompile the previously-generated Java source code.

You should consider using Dynamic MOXy when:

  • You want EclipseLink to generate classes from an XML schema (XSD).
  • You do not want to deal with concrete Java domain classes.


Dynamic Entities

Instead of using actual Java classes (such as Customer.class or Address.class), Dynamic MOXy uses a simple get(propertyName)/set(propertyName, propertyValue) API to manipulate data. EclipseLink generates (in memory) a DynamicType associated with each DynamicEntity.


Idea.png
DynamicTypes are similar to Java classes; whereas DynamicEntities can be thought of as instances of a DynamicType.


Example

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);
Elug javaspec icon.gif

For more information, see Appendix D: Binding XML Names to Java Identifiers in the JPA Specification.

Creating Dynamic Entities

To create and use Dynamic MOXy entities, create a JAXBContext by using the DynamicJAXBContextFactory class. You can create a DynamicJAXBContext from an XML Schema file (XSD), EclipseLink OXM metadata file, or from an EclipseLink Project specified in the EclipseLink sessions.xml file.



Eclipselink-logo.gif
Version: 2.2.0 Draft
Other versions...