|
|
Line 1: |
Line 1: |
| <div style="border: 1px solid rgb(0, 0, 0); margin: 5px; padding: 5px; float: right;">__TOC__</div> | | <div style="border: 1px solid rgb(0, 0, 0); margin: 5px; padding: 5px; float: right;">__TOC__</div> |
− | = XMLDirectMapping = | + | = XMLDirectMapping (page under construction) = |
| | | |
− | Provide support for XML direct mappings via xml-element and xml-attribute. | + | Provide support for XML direct mappings via xml-element and xml-attribute. |
− | | + | |
− | == Open Issues ==
| + | |
− | | + | |
− | * XPath Support
| + | |
− | ** There are a number of options:
| + | |
− | *** [http://wiki.eclipse.org/EclipseLink/DesignDocs/293925/XMLDirectMapping#XML_Metadata__Option_1:_overload_name_attribute_on_xml-element.2Fxml-attribute 1] overload <code>name</code> attribute on xml-element/xml-attribute
| + | |
− | *** [http://wiki.eclipse.org/EclipseLink/DesignDocs/293925/XMLDirectMapping#XML_Metadata__Option_2:_add_an_xml-path_attribute_to_xml-element.2Fxml-attribute 2] add an <code>xml-path</code> attribute to xml-element/xml-attribute
| + | |
− | *** [http://wiki.eclipse.org/EclipseLink/DesignDocs/293925/XMLDirectMapping#XML_Metadata__Option_3:_combine_name_and_xml-path_on_xml-element.2Fxml-attribute 3] combine <code>name</code> and <code>xml-path</code> on xml-element/xml-attribute
| + | |
− | *** enable use of xml-element-wrapper with non-collections and xml-attribute and one of:
| + | |
− | **** [http://wiki.eclipse.org/EclipseLink/DesignDocs/293925/XMLDirectMapping#XML_Metadata__Option_4:_overload_name_attribute_on_xml-element-wrapper 4] overload <code>name</code> attribute on xml-element-wrapper
| + | |
− | **** [http://wiki.eclipse.org/EclipseLink/DesignDocs/293925/XMLDirectMapping#XML_Metadata__Option_5:_add_an_xml-path_attribute_to_xml-element-wrapper 5] add an <code>xml-path</code> attribute to xml-element-wrapper for case where path is more than one level deep
| + | |
− | ** If overloading the <code>name</code> attribute is desirable, should we support <code>xml-path</code> as well such that users who prefer not to overload <code>name</code> have another option?
| + | |
− | ** If we choose to support both <code>name</code> and <code>xml-path</code>, which one takes precedence?
| + | |
− | ** Namespaces
| + | |
− | *** What is the expected behavior when a namespace is set with an XPath? For example, if we have <code><xml-element java-attribute="firstName" xml-path="myname/names/fname" namespace="www.example.com" /></code> to which element is the namespace applied, if any? Do we force the user to use a prefix on path elements individually, i.e. <code><xml-element java-attribute="firstName" xml-path="myname/ns0:names/fname" /></code>?
| + | |
− | | + | |
− | == Example: XPath Use With XMLDirectMapping ==
| + | |
− | | + | |
− | The following example will demonstrate how to configure an XMLDirectMapping using XPaths via XML Metadata:
| + | |
− | | + | |
− | === org.example.Employee.java ===
| + | |
− | | + | |
− | <source lang="java">
| + | |
− | package org.example;
| + | |
− | | + | |
− | public class Employee {
| + | |
− | public int empId;
| + | |
− | public int mgrId;
| + | |
− | public String firstName;
| + | |
− | public String lastName;
| + | |
− | public String projectName;
| + | |
− | }
| + | |
− | </source>
| + | |
− | | + | |
− | === Deployment XML ===
| + | |
− | | + | |
− | <source lang="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>
| + | |
− | </source>
| + | |
− | | + | |
− | === 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">
| + | |
− | <?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>
| + | |
− | </source>
| + | |
− | | + | |
− | === XML Metadata Option 2: add an <code>xml-path</code> attribute to xml-element/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" 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" xml-path="projects/prj:project" />
| + | |
− | </java-attributes>
| + | |
− | </java-type>
| + | |
− | </java-types>
| + | |
− | </xml-bindings>
| + | |
− | </source>
| + | |
− | | + | |
− | === XML Metadata Option 3: combine <code>name</code> and <code>xml-path</code> on xml-element/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-path="projects/prj:project" />
| + | |
− | <xml-element java-attribute="firstName" name="first-name" xml-path="name" />
| + | |
− | <xml-element java-attribute="lastName" name="last-name" xml-path="name" />
| + | |
− | <xml-element java-attribute="projectName" name="prj:project" xml-path="projects" />
| + | |
− | </java-attributes>
| + | |
− | </java-type>
| + | |
− | </java-types>
| + | |
− | </xml-bindings>
| + | |
− | </source>
| + | |
− | | + | |
− | === XML Metadata Option 4: overload <code>name</code> attribute on xml-element-wrapper ===
| + | |
− | | + | |
− | <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="project" namespace="http://www.example.com/projects">
| + | |
− | <xml-element-wrapper name="projects" />
| + | |
− | </xml-attribute>
| + | |
− | </java-attributes>
| + | |
− | </java-type>
| + | |
− | </java-types>
| + | |
− | </xml-bindings>
| + | |
− | </source>
| + | |
− | | + | |
− | === XML Metadata Option 5: add an <code>xml-path</code> attribute to xml-element-wrapper ===
| + | |
− | | + | |
− | <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">
| + | |
− | <!-- use xml-path if more than 1 level deep -->
| + | |
− | <xml-element-wrapper xml-path="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="project" namespace="http://www.example.com/projects">
| + | |
− | <xml-element-wrapper name="projects" />
| + | |
− | </xml-attribute>
| + | |
− | </java-attributes>
| + | |
− | </java-type>
| + | |
− | </java-types>
| + | |
− | </xml-bindings>
| + | |
− | </source>
| + | |
Provide support for XML direct mappings via xml-element and xml-attribute.