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.
Difference between revisions of "EclipseLink/UserGuide/MOXy/Overview/DynamicEntities"
m (fixed links) |
|||
Line 6: | Line 6: | ||
}} | }} | ||
=Static and Dynamic Entities= | =Static and Dynamic Entities= | ||
− | |||
− | |||
==Using Static MOXy== | ==Using Static MOXy== | ||
− | |||
− | |||
− | |||
==Using Dynamic 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 | + | 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 as needed, without having to update and recompile the previously-generated Java source code. |
You should consider using Dynamic MOXy when: | You should consider using Dynamic MOXy when: | ||
*You want EclipseLink to generate classes from an XML schema (XSD). | *You want EclipseLink to generate classes from an XML schema (XSD). | ||
*You do not want to deal with concrete Java domain classes. | *You do not want to deal with concrete Java domain classes. | ||
− | |||
===Dynamic Entities=== | ===Dynamic Entities=== | ||
Instead of using actual Java classes (such as <tt>Customer.class</tt> or <tt>Address.class</tt>), Dynamic MOXy uses a simple <tt>get(propertyName)</tt>/<tt>set(propertyName, propertyValue)</tt> API to manipulate data. EclipseLink generates (in memory) a <tt>DynamicType</tt> associated with each <tt>DynamicEntity</tt>. | Instead of using actual Java classes (such as <tt>Customer.class</tt> or <tt>Address.class</tt>), Dynamic MOXy uses a simple <tt>get(propertyName)</tt>/<tt>set(propertyName, propertyValue)</tt> API to manipulate data. EclipseLink generates (in memory) a <tt>DynamicType</tt> associated with each <tt>DynamicEntity</tt>. | ||
− | |||
{{tip||<tt>DynamicTypes</tt> are similar to Java classes; whereas <tt>DynamicEntities</tt> can be thought of as instances of a <tt>DynamicType</tt>.}} | {{tip||<tt>DynamicTypes</tt> are similar to Java classes; whereas <tt>DynamicEntities</tt> can be thought of as instances of a <tt>DynamicType</tt>.}} | ||
Line 55: | Line 48: | ||
**[[EclipseLink/UserGuide/MOXy/Runtime/Bootstrapping/Single_Project/From_sessions.xml_using_DynamicEntities|Single project]] | **[[EclipseLink/UserGuide/MOXy/Runtime/Bootstrapping/Single_Project/From_sessions.xml_using_DynamicEntities|Single project]] | ||
**[[EclipseLink/MOXy/Runtime/Bootstrapping/Single_Project/From_sessions.xml_using_DynamicEntities|Multiple projects]] | **[[EclipseLink/MOXy/Runtime/Bootstrapping/Single_Project/From_sessions.xml_using_DynamicEntities|Multiple projects]] | ||
− | |||
− | |||
Revision as of 14:29, 11 March 2011
EclipseLink MOXy
EclipseLink | |
Website | |
Download | |
Community | |
Mailing List • Forums • IRC • mattermost | |
Issues | |
Open • Help Wanted • Bug Day | |
Contribute | |
Browse Source |
Contents
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 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.
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);
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.
- Bootstrapping from XML schema (XSD)
- Bootstrapping from EclipseLink OXM metadata
- Bootstrapping from EclipseLink project (sessions.xml)
|
||
EclipseLink Home MOXy User Guide: Table of Contents, Search | ||
How to contribute to this guide... |