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

Difference between revisions of "EclipseLink/DesignDocs/293925/MOXyExtensions/XmlBinaryDataMapping"

(New page: <div style="border: 1px solid rgb(0, 0, 0); margin: 5px; padding: 5px; float: right;">__TOC__</div> = XMLBinaryDataMapping = == Requirements == Provide support for XML binary data mappin...)
 
(Equivalent annotations)
 
(5 intermediate revisions by the same user not shown)
Line 14: Line 14:
 
== Design ==
 
== Design ==
 
=== Basic XML binary data mapping support ===
 
=== Basic XML binary data mapping support ===
We will extend our current <code>xml-element</code> and <code>xml-attribute</code> support to allow binary data mapping configuration.  For example, the following XML metadata snippet would be used to setup a binary data mapping for 'bytes' (where bytes is a byte[] in the object model):  
+
We will extend our current <code>xml-element</code> and <code>xml-attribute</code> support to allow binary data mapping configuration.  For example, the following XML metadata snippet would be used to setup a binary data mapping for 'bytes' (where bytes is a <code>byte[]</code> in the object model):  
 
<source lang="xml">
 
<source lang="xml">
 
<xml-attribute java-attribute="bytes" />
 
<xml-attribute java-attribute="bytes" />
Line 21: Line 21:
 
<source lang="xml">
 
<source lang="xml">
 
<xml-attribute java-attribute="bytes" xml-path="@mybytes" />
 
<xml-attribute java-attribute="bytes" xml-path="@mybytes" />
 +
</source>
 +
 +
=== Equivalent annotations ===
 +
<source lang="java">
 +
@javax.xml.bind.annotation.XmlElement
 +
@org.eclipse.persistence.oxm.annotations.XmlPath("@mybytes")
 +
public byte[] bytes;
 
</source>
 
</source>
  
Line 32: Line 39:
 
public class MyData {
 
public class MyData {
 
     public byte[] bytes;
 
     public byte[] bytes;
 +
    public byte[] readOnlyBytes;
 +
    public byte[] writeOnlyBytes;
 +
 +
    public byte[] getBytes() {
 +
        return bytes;
 +
    }
 +
 +
    public void setBytes(byte[] bytes) {
 +
        this.bytes = bytes;
 +
    }
 
}
 
}
 
</source>
 
</source>
Line 37: Line 54:
 
=== Deployment XML  ===
 
=== Deployment XML  ===
 
<source lang="xml">
 
<source lang="xml">
 +
<class-mapping-descriptor xsi:type="xml-class-mapping-descriptor">
 +
  <class>org.example.MyData</class>
 +
  <alias>MyData</alias>
 +
  <attribute-mappings>
 +
    <attribute-mapping xsi:type="xml-binary-data-mapping">
 +
      <attribute-name>bytes</attribute-name>
 +
      <get-method>getBytes</get-method>
 +
      <set-method>setBytes</set-method>
 +
      <field name="@mybytes" xsi:type="node"/>
 +
      <is-swa-ref>false</is-swa-ref>
 +
      <should-inline-data>false</should-inline-data>
 +
    </attribute-mapping>
 +
    <attribute-mapping xsi:type="xml-binary-data-mapping">
 +
      <attribute-name>readOnlyBytes</attribute-name>
 +
      <read-only>true</read-only>
 +
      <field name="@my-read-only-bytes" xsi:type="node"/>
 +
      <is-swa-ref>false</is-swa-ref>
 +
      <should-inline-data>false</should-inline-data>
 +
    </attribute-mapping>
 +
    <attribute-mapping xsi:type="xml-binary-data-mapping">
 +
      <attribute-name>writeOnlyBytes</attribute-name>
 +
      <field name="@my-write-only-bytes" xsi:type="node"/>
 +
      <is-swa-ref>false</is-swa-ref>
 +
      <should-inline-data>false</should-inline-data>
 +
    </attribute-mapping>
 +
  </attribute-mappings>
 +
  <default-root-element>my-data</default-root-element>
 +
  <default-root-element-field name="my-data"/>
 +
</class-mapping-descriptor>
 
</source>
 
</source>
  
=== XML Instance Document ===
+
=== XML Instance Document (read) ===
 +
<source lang="xml">
 +
<?xml version="1.0" encoding="UTF-8"?>
 +
<my-data mybytes="AAECAw==" my-read-only-bytes="AQIDBA==">
 +
  <write-only-bytes>AgMEBQ==</write-only-bytes>
 +
</my-data>
 +
</source>
 +
 +
=== XML Instance Document (write) ===
 
<source lang="xml">
 
<source lang="xml">
 
<?xml version="1.0" encoding="UTF-8"?>
 
<?xml version="1.0" encoding="UTF-8"?>
<my-data mybytes="AAECAw=="/>
+
<my-data mybytes="AAECAw==">
 +
  <write-only-bytes>AgMEBQ==</write-only-bytes>
 +
</my-data>
 
</source>
 
</source>
 
   
 
   
Line 54: Line 110:
 
             <xml-root-element name="my-data" />
 
             <xml-root-element name="my-data" />
 
             <java-attributes>
 
             <java-attributes>
                 <xml-attribute java-attribute="bytes" xml-path="@mybytes" />
+
                 <xml-attribute java-attribute="bytes" xml-path="@mybytes">
 +
                    <xml-access-methods get-method="getBytes" set-method="setBytes" />
 +
                </xml-attribute>
 +
                <xml-attribute java-attribute="readOnlyBytes" xml-path="@my-read-only-bytes" read-only="true" />
 +
                <xml-element java-attribute="writeOnlyBytes" name="write-only-bytes" write-only="true" />
 
             </java-attributes>
 
             </java-attributes>
 
         </java-type>
 
         </java-type>

Latest revision as of 15:27, 2 June 2010

XMLBinaryDataMapping

Requirements

Provide support for XML binary data mapping configuration via XML metadata file.

The following should be configurable:

Design

Basic XML binary data mapping support

We will extend our current xml-element and xml-attribute support to allow binary data mapping configuration. For example, the following XML metadata snippet would be used to setup a binary data mapping for 'bytes' (where bytes is a byte[] in the object model):

<xml-attribute java-attribute="bytes" />

The same thing mapped to 'mybytes':

<xml-attribute java-attribute="bytes" xml-path="@mybytes" />

Equivalent annotations

@javax.xml.bind.annotation.XmlElement
@org.eclipse.persistence.oxm.annotations.XmlPath("@mybytes")
public byte[] bytes;

Example:

The following example will demonstrate how to configure XML binary data mappings via XML metadata by using xml-element and xml-attribute.

org.example.MyData.java

package org.example;
 
public class MyData {
    public byte[] bytes;
    public byte[] readOnlyBytes;
    public byte[] writeOnlyBytes;
 
    public byte[] getBytes() {
        return bytes;
    }
 
    public void setBytes(byte[] bytes) {
        this.bytes = bytes;
    }
}

Deployment XML

<class-mapping-descriptor xsi:type="xml-class-mapping-descriptor">
  <class>org.example.MyData</class>
  <alias>MyData</alias>
  <attribute-mappings>
    <attribute-mapping xsi:type="xml-binary-data-mapping">
      <attribute-name>bytes</attribute-name>
      <get-method>getBytes</get-method>
      <set-method>setBytes</set-method>
      <field name="@mybytes" xsi:type="node"/>
      <is-swa-ref>false</is-swa-ref>
      <should-inline-data>false</should-inline-data>
    </attribute-mapping>
    <attribute-mapping xsi:type="xml-binary-data-mapping">
      <attribute-name>readOnlyBytes</attribute-name>
      <read-only>true</read-only>
      <field name="@my-read-only-bytes" xsi:type="node"/>
      <is-swa-ref>false</is-swa-ref>
      <should-inline-data>false</should-inline-data>
    </attribute-mapping>
    <attribute-mapping xsi:type="xml-binary-data-mapping">
      <attribute-name>writeOnlyBytes</attribute-name>
      <field name="@my-write-only-bytes" xsi:type="node"/>
      <is-swa-ref>false</is-swa-ref>
      <should-inline-data>false</should-inline-data>
    </attribute-mapping>
  </attribute-mappings>
  <default-root-element>my-data</default-root-element>
  <default-root-element-field name="my-data"/>
</class-mapping-descriptor>

XML Instance Document (read)

<?xml version="1.0" encoding="UTF-8"?>
<my-data mybytes="AAECAw==" my-read-only-bytes="AQIDBA==">
  <write-only-bytes>AgMEBQ==</write-only-bytes>
</my-data>

XML Instance Document (write)

<?xml version="1.0" encoding="UTF-8"?>
<my-data mybytes="AAECAw==">
  <write-only-bytes>AgMEBQ==</write-only-bytes>
</my-data>

org/example/eclipselink-oxm.xml

This XML file demonstrates configuring XML binary data mappings on the "org.example.MyData" class.

<?xml version="1.0" encoding="US-ASCII"?>
<xml-bindings xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <java-types>
        <java-type name="org.example.MyData">
            <xml-root-element name="my-data" />
            <java-attributes>
                <xml-attribute java-attribute="bytes" xml-path="@mybytes">
                    <xml-access-methods get-method="getBytes" set-method="setBytes" />
                </xml-attribute>
                <xml-attribute java-attribute="readOnlyBytes" xml-path="@my-read-only-bytes" read-only="true" />
                <xml-element java-attribute="writeOnlyBytes" name="write-only-bytes" write-only="true" />
            </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