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/DesignDocs/293925/MOXyExtensions/XMLDirectMapping"
< EclipseLink | DesignDocs | 293925 | MOXyExtensions
(→Open Issues) |
|||
Line 48: | Line 48: | ||
<attribute-mapping xsi:type="xml-direct-mapping"> | <attribute-mapping xsi:type="xml-direct-mapping"> | ||
<attribute-name>projectName</attribute-name> | <attribute-name>projectName</attribute-name> | ||
− | <field name="prj:project/text()" xsi:type="node"/> | + | <field name="projects/prj:project/text()" xsi:type="node"/> |
</attribute-mapping> | </attribute-mapping> | ||
<attribute-mapping xsi:type="xml-direct-mapping"> | <attribute-mapping xsi:type="xml-direct-mapping"> | ||
<attribute-name>mgrId</attribute-name> | <attribute-name>mgrId</attribute-name> | ||
− | <field name="prj:project/@managerId" xsi:type="node"/> | + | <field name="projects/prj:project/@managerId" xsi:type="node"/> |
</attribute-mapping> | </attribute-mapping> | ||
</attribute-mappings> | </attribute-mappings> | ||
Line 70: | Line 70: | ||
</source> | </source> | ||
− | === XML Metadata === | + | === XML Instance Document === |
+ | |||
+ | <source lang="xml"> | ||
+ | <?xml version="1.0" encoding="UTF-8"?> | ||
+ | <employee id="66" xmlns="http://www.example.com/employees" xmlns:prj="http://www.example.com/projects"> | ||
+ | <name> | ||
+ | <first-name>Joe</first-name> | ||
+ | <last-name>Black</last-name> | ||
+ | </name> | ||
+ | <projects> | ||
+ | <prj:project managerId="99">XML External Metadata Support</prj:project> | ||
+ | </projects> | ||
+ | </employee> | ||
+ | </source> | ||
+ | |||
+ | === XML Metadata Option 1: overload <code>name</code> attribute on xml-element/xml-attribute === | ||
<source lang="xml"> | <source lang="xml"> | ||
Line 83: | Line 98: | ||
<java-attributes> | <java-attributes> | ||
<xml-attribute java-attribute="empId" name="id" /> | <xml-attribute java-attribute="empId" name="id" /> | ||
− | <xml-attribute java-attribute="mgrId" | + | <xml-attribute java-attribute="mgrId" name="projects/prj:project/managerId" /> |
− | <xml-element java-attribute="firstName" | + | <xml-element java-attribute="firstName" name="name/first-name" /> |
− | <xml-element java-attribute="lastName" | + | <xml-element java-attribute="lastName" name="name/last-name" /> |
− | <xml-element java-attribute="projectName" | + | <xml-element java-attribute="projectName" name="projects/prj:project" /> |
</java-attributes> | </java-attributes> | ||
</java-type> | </java-type> | ||
Line 93: | Line 108: | ||
</source> | </source> | ||
− | === XML | + | === XML Metadata Option 2: add an <code>xml-path</code> attribute to xml-element/xml-attribute === |
<source lang="xml"> | <source lang="xml"> | ||
− | <?xml version="1.0" encoding=" | + | <?xml version="1.0" encoding="US-ASCII"?> |
− | <employee id=" | + | <xml-bindings xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm"> |
− | < | + | <xml-schema namespace="http://www.example.com/employees"> |
− | < | + | <xml-ns namespace-uri="http://www.example.com/projects" prefix="prj" /> |
− | + | </xml-schema> | |
− | + | <java-types> | |
− | + | <java-type name="org.example.Employee"> | |
− | </ | + | <xml-root-element name="employee" /> |
+ | <java-attributes> | ||
+ | <xml-attribute java-attribute="empId" name="id" /> | ||
+ | <xml-attribute java-attribute="mgrId" xml-path="projects/prj:project/managerId" /> | ||
+ | <xml-element java-attribute="firstName" xml-path="name/first-name" /> | ||
+ | <xml-element java-attribute="lastName" xml-path="name/last-name" /> | ||
+ | <xml-element java-attribute="projectName" name="projects/prj:project" /> | ||
+ | </java-attributes> | ||
+ | </java-type> | ||
+ | </java-types> | ||
+ | </xml-bindings> | ||
+ | </source> | ||
+ | |||
+ | === XML Metadata Option 3: overload <code>name</name> attribute on xml-element-wrapper and enable use with non-collections and xml-attribute === | ||
+ | |||
+ | <source lang="xml"> | ||
+ | <?xml version="1.0" encoding="US-ASCII"?> | ||
+ | <xml-bindings xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm"> | ||
+ | <xml-schema namespace="http://www.example.com/employees"> | ||
+ | <xml-ns namespace-uri="http://www.example.com/projects" prefix="prj" /> | ||
+ | </xml-schema> | ||
+ | <java-types> | ||
+ | <java-type name="org.example.Employee"> | ||
+ | <xml-root-element name="employee" /> | ||
+ | <java-attributes> | ||
+ | <xml-attribute java-attribute="empId" name="id" /> | ||
+ | <xml-attribute java-attribute="mgrId" name="managerId"> | ||
+ | <xml-element-wrapper name="projects/prj:project" /> | ||
+ | </xml-attribute> | ||
+ | <xml-element java-attribute="firstName" name="first-name"> | ||
+ | <xml-element-wrapper name="name" /> | ||
+ | </xml-element> | ||
+ | <xml-element java-attribute="lastName" name="last-name"> | ||
+ | <xml-element-wrapper name="name" /> | ||
+ | </xml-element> | ||
+ | <xml-element java-attribute="projectName" name="prj:project"> | ||
+ | <xml-element-wrapper name="projects" /> | ||
+ | </xml-attribute> | ||
+ | </java-attributes> | ||
+ | </java-type> | ||
+ | </java-types> | ||
+ | </xml-bindings> | ||
+ | </source> | ||
+ | |||
+ | === XML Metadata Option 4: add an <code>xml-path</code> attribute to xml-element-wrapper and enable use with non-collections and xml-attribute === | ||
+ | |||
+ | <source lang="xml"> | ||
+ | <?xml version="1.0" encoding="US-ASCII"?> | ||
+ | <xml-bindings xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm"> | ||
+ | <xml-schema namespace="http://www.example.com/employees"> | ||
+ | <xml-ns namespace-uri="http://www.example.com/projects" prefix="prj" /> | ||
+ | </xml-schema> | ||
+ | <java-types> | ||
+ | <java-type name="org.example.Employee"> | ||
+ | <xml-root-element name="employee" /> | ||
+ | <java-attributes> | ||
+ | <xml-attribute java-attribute="empId" name="id" /> | ||
+ | <xml-attribute java-attribute="mgrId" name="managerId"> | ||
+ | <xml-element-wrapper xml-path="projects/prj:project" /> | ||
+ | </xml-attribute> | ||
+ | <xml-element java-attribute="firstName" name="first-name"> | ||
+ | <xml-element-wrapper xml-path="name" /> | ||
+ | </xml-element> | ||
+ | <xml-element java-attribute="lastName" name="last-name"> | ||
+ | <xml-element-wrapper xml-path="name" /> | ||
+ | </xml-element> | ||
+ | <xml-element java-attribute="projectName" name="prj:project"> | ||
+ | <xml-element-wrapper xml-path="projects" /> | ||
+ | </xml-attribute> | ||
+ | </java-attributes> | ||
+ | </java-type> | ||
+ | </java-types> | ||
+ | </xml-bindings> | ||
</source> | </source> |
Revision as of 16:05, 3 February 2010
Contents
- 1 XMLDirectMapping
- 1.1 Open Issues
- 1.2 Example: XPath Use With XMLDirectMapping
- 1.2.1 org.example.Employee.java
- 1.2.2 Deployment XML
- 1.2.3 XML Instance Document
- 1.2.4 XML Metadata Option 1: overload name attribute on xml-element/xml-attribute
- 1.2.5 XML Metadata Option 2: add an xml-path attribute to xml-element/xml-attribute
- 1.2.6 XML Metadata Option 3: overload name</name> attribute on xml-element-wrapper and enable use with non-collections and xml-attribute
- 1.2.7 XML Metadata Option 4: add an <code>xml-path attribute to xml-element-wrapper and enable use with non-collections and xml-attribute
XMLDirectMapping
Provide support for XML direct mappings via xml-element and xml-attribute.
Open Issues
- XPath - should we overload the
name
attribute on xml-attribute and xml-element to set the XPath, or create a new attributexml-path
?- The current approach is to use
xml-path
and NOT overloadname
, asname
is not intended to be used in this manner
- The current approach is to use
Example: XPath Use With XMLDirectMapping
The following example will demonstrate how to configure an XMLDirectMapping using XPaths via XML Metadata:
org.example.Employee.java
package org.example; public class Employee { public int empId; public int mgrId; public String firstName; public String lastName; public String projectName; }
Deployment XML
<class-mapping-descriptor xsi:type="xml-class-mapping-descriptor"> <class>org.example.Employee</class> <alias>Employee</alias> <attribute-mappings> <attribute-mapping xsi:type="xml-direct-mapping"> <attribute-name>empId</attribute-name> <field name="@id" xsi:type="node"/> </attribute-mapping> <attribute-mapping xsi:type="xml-direct-mapping"> <attribute-name>firstName</attribute-name> <field name="name/first-name/text()" xsi:type="node"/> </attribute-mapping> <attribute-mapping xsi:type="xml-direct-mapping"> <attribute-name>lasstName</attribute-name> <field name="name/last-name/text()" xsi:type="node"/> </attribute-mapping> <attribute-mapping xsi:type="xml-direct-mapping"> <attribute-name>projectName</attribute-name> <field name="projects/prj:project/text()" xsi:type="node"/> </attribute-mapping> <attribute-mapping xsi:type="xml-direct-mapping"> <attribute-name>mgrId</attribute-name> <field name="projects/prj:project/@managerId" xsi:type="node"/> </attribute-mapping> </attribute-mappings> <descriptor-type>aggregate</descriptor-type> <default-root-element>employee</default-root-element> <default-root-element-field name="employee" xsi:type="node"/> <namespace-resolver> <namespaces> <namespace> <prefix>prj</prefix> <namespace-uri>http://www.example.com/projects</namespace-uri> </namespace> </namespaces> <default-namespace-uri>http://www.example.com/employees</default-namespace-uri> </namespace-resolver> </class-mapping-descriptor>
XML Instance Document
<?xml version="1.0" encoding="UTF-8"?> <employee id="66" xmlns="http://www.example.com/employees" xmlns:prj="http://www.example.com/projects"> <name> <first-name>Joe</first-name> <last-name>Black</last-name> </name> <projects> <prj:project managerId="99">XML External Metadata Support</prj:project> </projects> </employee>
XML Metadata Option 1: overload name
attribute on xml-element/xml-attribute
<?xml version="1.0" encoding="US-ASCII"?> <xml-bindings xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm"> <xml-schema namespace="http://www.example.com/employees"> <xml-ns namespace-uri="http://www.example.com/projects" prefix="prj" /> </xml-schema> <java-types> <java-type name="org.example.Employee"> <xml-root-element name="employee" /> <java-attributes> <xml-attribute java-attribute="empId" name="id" /> <xml-attribute java-attribute="mgrId" name="projects/prj:project/managerId" /> <xml-element java-attribute="firstName" name="name/first-name" /> <xml-element java-attribute="lastName" name="name/last-name" /> <xml-element java-attribute="projectName" name="projects/prj:project" /> </java-attributes> </java-type> </java-types> </xml-bindings>
XML Metadata Option 2: add an xml-path
attribute to xml-element/xml-attribute
<?xml version="1.0" encoding="US-ASCII"?> <xml-bindings xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm"> <xml-schema namespace="http://www.example.com/employees"> <xml-ns namespace-uri="http://www.example.com/projects" prefix="prj" /> </xml-schema> <java-types> <java-type name="org.example.Employee"> <xml-root-element name="employee" /> <java-attributes> <xml-attribute java-attribute="empId" name="id" /> <xml-attribute java-attribute="mgrId" xml-path="projects/prj:project/managerId" /> <xml-element java-attribute="firstName" xml-path="name/first-name" /> <xml-element java-attribute="lastName" xml-path="name/last-name" /> <xml-element java-attribute="projectName" name="projects/prj:project" /> </java-attributes> </java-type> </java-types> </xml-bindings>
XML Metadata Option 3: overload name</name> attribute on xml-element-wrapper and enable use with non-collections and xml-attribute
<?xml version="1.0" encoding="US-ASCII"?> <xml-bindings xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm"> <xml-schema namespace="http://www.example.com/employees"> <xml-ns namespace-uri="http://www.example.com/projects" prefix="prj" /> </xml-schema> <java-types> <java-type name="org.example.Employee"> <xml-root-element name="employee" /> <java-attributes> <xml-attribute java-attribute="empId" name="id" /> <xml-attribute java-attribute="mgrId" name="managerId"> <xml-element-wrapper name="projects/prj:project" /> </xml-attribute> <xml-element java-attribute="firstName" name="first-name"> <xml-element-wrapper name="name" /> </xml-element> <xml-element java-attribute="lastName" name="last-name"> <xml-element-wrapper name="name" /> </xml-element> <xml-element java-attribute="projectName" name="prj:project"> <xml-element-wrapper name="projects" /> </xml-attribute> </java-attributes> </java-type> </java-types> </xml-bindings>
XML Metadata Option 4: add an <code>xml-path attribute to xml-element-wrapper and enable use with non-collections and xml-attribute
<?xml version="1.0" encoding="US-ASCII"?> <xml-bindings xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm"> <xml-schema namespace="http://www.example.com/employees"> <xml-ns namespace-uri="http://www.example.com/projects" prefix="prj" /> </xml-schema> <java-types> <java-type name="org.example.Employee"> <xml-root-element name="employee" /> <java-attributes> <xml-attribute java-attribute="empId" name="id" /> <xml-attribute java-attribute="mgrId" name="managerId"> <xml-element-wrapper xml-path="projects/prj:project" /> </xml-attribute> <xml-element java-attribute="firstName" name="first-name"> <xml-element-wrapper xml-path="name" /> </xml-element> <xml-element java-attribute="lastName" name="last-name"> <xml-element-wrapper xml-path="name" /> </xml-element> <xml-element java-attribute="projectName" name="prj:project"> <xml-element-wrapper xml-path="projects" /> </xml-attribute> </java-attributes> </java-type> </java-types> </xml-bindings>