Skip to main content

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.

Jump to: navigation, search

EclipseLink/DesignDocs/293925/MOXyExtensions/XmlAnyAttributeMapping

XMLAnyAttributeMapping

Requirements

Provide support for XML any attribute mapping configuration via XML metadata file.

The following should be configurable:

Design

Basic XML any attribute mapping support

We will extend our current xml-any-attribute support to allow any mapping configuration. We will need to modify the XSD such that xml-path, xml-access-methods, read-only, etc. can be set on xml-any-attribute . For example, the following XML metadata snippet would be used to setup an any attribute mapping for 'stuff':

<xml-any-attribute java-attribute="stuff" />

If stuff was to be mapped to things/junk/stuff, then the following would be used:

<xml-any-attribute java-attribute="stuff" xml-path="things/junk/stuff" />

Read Only

The following demonstrates how an xml-any-attribute can be set as read-only:

<xml-any-attribute java-attribute="stuff" xml-path="things/junk/stuff" read-only="true" />

Write Only

The following demonstrates how an xml-any-attribute can be set as write-only:

<xml-any-attribute java-attribute="stuff" xml-path="things/junk/stuff" write-only="true" />

Equivalent annotations

@javax.xml.bind.annotation.XmlAnyAttribute
@org.eclipse.persistence.oxm.annotations.XmlPath("things/junk/stuff")
public Map<QName, String> stuff;

Example:

The following example will demonstrate how to configure XML any attribute mappings via XML metadata by using xml-any-attribute.

org.example.Employee.java

package org.example;
 
public class Employee {
    public Map<QName, String> stuff;
 
    public Map<QName, String> getStuff() {
        return stuff;
    }
 
    public void setStuff(Map<QName, String> stuff) {
        this.stuff = stuff;
    }
 
}

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-any-attribute-mapping">
      <attribute-name>stuff</attribute-name>
      <get-method>getStuff</get-method>
      <set-method>setStuff</set-method>
      <field name="things/junk/s:stuff" xsi:type="node"/>
      <container xsi:type="direct-map-container-policy">
        <collection-type>java.util.HashMap</collection-type>
      </container>
      <include-namespace-declaration>true</include-namespace-declaration>
      <include-schema-instance>true</include-schema-instance>
    </attribute-mapping>
  </attribute-mappings>
  <default-root-element>employee</default-root-element>
  <default-root-element-field name="employee"/>
  <namespace-resolver>
    <namespaces>
      <namespace>
        <prefix>s</prefix>
        <namespace-uri>http://www.example.com/stuff</namespace-uri>
      </namespace>
    </namespaces>
  </namespace-resolver>
</class-mapping-descriptor>

XML Instance Document

<?xml version="1.0" encoding="UTF-8"?>
<employee xmlns:s="http://www.example.com/stuff">
  <things>
    <junk>
      <s:stuff first-name="Joe" last-name="Oracle" />
    </junk>
  </things> 
</employee>


org/example/eclipselink-oxm.xml

This XML file demonstrates configuring XML any object mappings on the "org.example.Employee" class.

<?xml version="1.0" encoding="US-ASCII"?>
<xml-bindings xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm">
    <xml-schema>
        <xml-ns namespace-uri="http://www.example.com/stuff" prefix="s"/>
    </xml-schema>
    <java-types>
        <java-type name="org.example.Employee">
            <xml-root-element name="employee" />
            <java-attributes>
                <xml-any-attribute java-attribute="stuff" xml-path="things/junk/s:stuff">
                    <xml-access-methods get-method="getStuff" set-method="setStuff" />
                </xml-any-attribute>
            </java-attributes>
        </java-type>
    </java-types>
</xml-bindings>

Open Issues

This section lists the open issues that are still pending that must be decided prior to fully implementing this project's requirements.

Issue# Owner Description/Notes

Decisions

This section lists decisions made. These are intended to document the resolution of open issues or constraints added to the project that are important.

Issue# Description/Notes Decision

Back to the top