Skip to main content

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.

Jump to: navigation, search

EclipseLink/DesignDocs/293925/MOXyExtensions/XMLDirectMapping

< EclipseLink‎ | DesignDocs‎ | 293925‎ | MOXyExtensions
Revision as of 12:58, 5 February 2010 by Unnamed Poltroon (Talk) (The following information must be configurable via XML metadata)

XMLDirectMapping (page under construction)

Requirements

Provide support for XML direct mappings. The following structures are to be extended to support XML direct mapping configuration:

  • xml-attribute
  • xml-element

The following information must be configurable via XML metadata

<xml-direct-mapping xmlns="http://www.eclipse.org/eclipselink/xsds/persistence">
	<attribute-name>String</attribute-name>
	<read-only>false</read-only>
	<get-method>String</get-method>
	<set-method>String</set-method>
	<properties>
		<property name="String">
			<value>Text</value>
		</property>
		<property name="String">
			<value>Text</value>
		</property>
	</properties>
	<field name="String"/>
	<null-value>String</null-value>
	<converter/>
	<attribute-classification>String</attribute-classification>
	<is-cdata>1</is-cdata>
	<null-policy>
		<xsi-nil-represents-null>false</xsi-nil-represents-null>
		<empty-node-represents-null>false</empty-node-represents-null>
		<null-representation-for-xml>XSI_NIL</null-representation-for-xml>
	</null-policy>
</xml-direct-mapping>

Example: Attribute mapping

The following example will demonstrate how to configure an XML direct mapping for an attribute via XML metadata.

org.example.Employee.java

package org.example;
 
public class Employee {
    public int empId;
}

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-mappings>
    <descriptor-type>aggregate</descriptor-type>
    <default-root-element>employee</default-root-element>
    <default-root-element-field name="employee" xsi:type="node"/>
</class-mapping-descriptor>

XML Metadata

org/example/eclipselink-oxm.xml

This XML file represents metadata overrides for the "org.example.Employee" class.

<?xml version="1.0" encoding="US-ASCII"?>
<xml-bindings xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm">
    <java-types>
        <java-type name="org.example.Employee">
            <xml-root-element name="employee" />
            <java-attributes>
                <xml-attribute java-attribute="empId" name="id" />
            </java-attributes>
        </java-type>
    </java-types>
</xml-bindings>

Back to the top