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/277920/Phase5"

 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
<div style="border: 1px solid rgb(0, 0, 0); margin: 5px; padding: 5px; float: right;">__TOC__</div>
 
= Phase 5 - Reference Mappings =
 
= Phase 5 - Reference Mappings =
  
Line 7: Line 8:
 
The following annotations will be targetted in this phase:  
 
The following annotations will be targetted in this phase:  
  
{| border="1" style="width: 100%;" class="wikitable"
+
{|{{BMTableStyle}}
|+ <br>
+
|-{{BMTHStyle}}
|-
+
 
! Annotation  
 
! Annotation  
 +
! XML Metadata Tag
 
! Package  
 
! Package  
 
! Type  
 
! Type  
 
! Field  
 
! Field  
 
! Method
 
! Method
|-
 
| [http://java.sun.com/javase/6/docs/api/javax/xml/bind/annotation/XmlAnyAttribute.html XmlAnyAttribute<br>]
 
| &nbsp;
 
| &nbsp;
 
| X
 
| X
 
|-
 
| [http://java.sun.com/javase/6/docs/api/javax/xml/bind/annotation/XmlMixed.html XmlMixed]<br>
 
| &nbsp;
 
| &nbsp;
 
| X
 
| X
 
 
|-
 
|-
 
| [http://java.sun.com/javase/6/docs/api/javax/xml/bind/annotation/XmlID.html XmlID<br>]  
 
| [http://java.sun.com/javase/6/docs/api/javax/xml/bind/annotation/XmlID.html XmlID<br>]  
| &nbsp;
+
| xml-id
| &nbsp;
+
| align="center" | &nbsp;  
| X  
+
| align="center" | &nbsp;  
| X
+
| align="center" | X  
 +
| align="center" | X
 
|-
 
|-
| [http://java.sun.com/javase/6/docs/api/javax/xml/bind/annotation/XmlIDREF.html XmlIDREF]<br>
+
| [http://java.sun.com/javase/6/docs/api/javax/xml/bind/annotation/XmlIDREF.html XmlIDREF]<br>  
| &nbsp;
+
| xml-idref
|
+
| align="center" | &nbsp;  
| X<br>
+
| align="center" |  
| X<br>
+
| align="center" | X<br>  
|-
+
| align="center" | X<br>
| XmlBidirectional<br>
+
| &nbsp;  
+
|  
+
| X<br>
+
| X<br>
+
 
|}
 
|}
 
== Example: XmlAnyAttribute annotation ==
 
 
=== Java Metadata  ===
 
 
The following example will demonstrate how the [http://java.sun.com/javase/6/docs/api/javax/xml/bind/annotation/XmlAnyAttribute.html XmlAnyAttribute] annotation can be applied:
 
 
==== org.example.Employee.java  ====
 
 
<source lang="java">
 
package org.example;
 
 
import javax.xml.namespace.QName;
 
 
@javax.xml.bind.annotation.XmlRootElement
 
public class Employee {
 
    public int a;
 
    public String b;
 
   
 
    @javax.xml.bind.annotation.XmlAnyAttribute
 
    public java.util.Map<QName, Object> stuff;
 
}
 
</source>
 
 
=== XML Metadata  ===
 
 
==== xml-any-attribute  ====
 
 
If this is present in the XML then the associated property will be treated as an Any property.  To unset an @XmlAnyAttribute annotated property via xml, the property can be declared using an appropriate tag other than xml-any-attribute, such as xml-any-element or xml-transient.
 
 
==== org/example/eclipselink-oxm.xml  ====
 
 
This XML file represents metadata overrides for the "org.example.Employee" class.
 
 
<source lang="xml">
 
<?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-any-attribute java-attribute="stuff" />
 
            </java-attributes>
 
        </java-type>
 
    </java-types>
 
</xml-bindings>
 
</source>
 
 
== Example: XmlMixed annotation ==
 
 
=== Java Metadata  ===
 
 
The following example will demonstrate how the [http://java.sun.com/javase/6/docs/api/javax/xml/bind/annotation/XmlMixed.html XmlMixed] annotation can be applied:
 
 
==== org.example.Employee.java  ====
 
 
<source lang="java">
 
package org.example;
 
 
@javax.xml.bind.annotation.XmlRootElement
 
public class Employee {
 
    public int a;
 
    public String b;
 
   
 
    @javax.xml.bind.annotation.XmlAnyElement
 
    @javax.xml.bind.annotation.XmlMixed
 
    public java.util.List<Object> stuff;
 
}
 
</source>
 
 
=== XML Metadata  ===
 
 
==== xml-mixed  ====
 
 
If this is present, and set to "true", in the XML then the associated property will be treated as containing mixed content.  To unset an @XmlMixed annotated property via xml, xml-any-element can be used with an xml-mixed="false" entry, or none (the default is false).
 
 
==== org/example/eclipselink-oxm.xml  ====
 
 
This XML file represents metadata overrides for the "org.example.Employee" class.
 
 
<source lang="xml">
 
<?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-any-element java-attribute="stuff" xml-mixed="true"/>
 
            </java-attributes>
 
        </java-type>
 
    </java-types>
 
</xml-bindings>
 
</source>
 
  
 
== Example: XmlID and XmlIDREF annotations ==
 
== Example: XmlID and XmlIDREF annotations ==
Line 250: Line 142:
 
             <java-attributes>
 
             <java-attributes>
 
                 <xml-attribute java-attribute="id" xml-id="false" />
 
                 <xml-attribute java-attribute="id" xml-id="false" />
            </java-attributes>
 
        </java-type>
 
    </java-types>
 
</xml-bindings>
 
</source>
 
 
== Example: XmlBidirectional annotation ==
 
 
=== Java Metadata  ===
 
 
The following example will demonstrate how the XmlBidirectional annotation can be applied:
 
 
==== org.example.Employee.java  ====
 
 
<source lang="java">
 
package org.example;
 
 
@javax.xml.bind.annotation.XmlRootElement
 
public class Employee {
 
    public String name;
 
   
 
    @javax.xml.bind.annotation.XmlIDREF
 
    @javax.xml.bind.annotation.XmlAttribute(name="address-id")
 
    @org.eclipse.persistence.oxm.annotations.XmlBidirectional(targetAttribute = "emp")
 
    public Address address;
 
}
 
</source>
 
 
==== org.example.Address.java  ====
 
 
<source lang="java">
 
package org.example;
 
 
@javax.xml.bind.annotation.XmlRootElement
 
public class Address {
 
    @javax.xml.bind.annotation.XmlID
 
    @javax.xml.bind.annotation.XmlAttribute(required=true)
 
    public String id;
 
   
 
    @javax.xml.bind.annotation.XmlTransient
 
    public Employee emp;
 
}
 
</source>
 
 
=== XML Metadata  ===
 
 
==== xml-bidirectional  ====
 
 
Use this to indicate the name of a transient property on the target object of this property that refers back to the owning object.
 
 
==== org/example/eclipselink-oxm.xml  ====
 
 
This XML file represents metadata overrides for the "org.example.Employee" and "org.example.Address" classes.
 
 
<source lang="xml">
 
<?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="address" name="address-id" xml-idref="true">
 
                    <xml-bidirectional target-attribute="emp" />
 
                </xml-attribute>
 
            </java-attributes>
 
        </java-type>
 
        <java-type name="org.example.Address">
 
            <xml-root-element name="address" />
 
            <java-attributes>
 
                <xml-attribute java-attribute="id" xml-id="true" required="true" />
 
                <xml-transient java-attribute="emp"/>
 
 
             </java-attributes>
 
             </java-attributes>
 
         </java-type>
 
         </java-type>

Latest revision as of 11:29, 2 December 2009

Phase 5 - Reference Mappings

Provide support for key based mappings.

Annotations

The following annotations will be targetted in this phase:

Annotation XML Metadata Tag Package Type Field Method
XmlID
xml-id     X X
XmlIDREF
xml-idref   X
X

Example: XmlID and XmlIDREF annotations

Java Metadata

The following example will demonstrate how the XmlID and XmlIDREF annotations can be applied:

org.example.Employee.java

package org.example;
 
@javax.xml.bind.annotation.XmlRootElement
public class Employee {
    public String name;
 
    @javax.xml.bind.annotation.XmlIDREF
    @javax.xml.bind.annotation.XmlElement(name="address-id")
    public Address address;
}

org.example.Address.java

package org.example;
 
@javax.xml.bind.annotation.XmlRootElement
public class Address {
    @javax.xml.bind.annotation.XmlID
    @javax.xml.bind.annotation.XmlAttribute(required=true)
    public String id;
 
    public String city;
}

XML Metadata

xml-id

If this is present, and set to "true", in the XML then the associated property will be treated as an ID. To unset an @XmlID annotated property via xml, xml-element or xml-attribute can be used with an xml-id="false" entry, or none (the default is false).

xml-idref

If this is present in the XML then the associated property will be treated as an IDREF. To unset an @XmlIDREF annotated property via xml, xml-element or xml-attribute can be used with an xml-idref="false" entry, or none (the default is false).

org/example/eclipselink-oxm.xml

This XML file represents metadata overrides for the "org.example.Employee" and "org.example.Address" classes.

<?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-element java-attribute="address" name="address-id" xml-idref="true" />
            </java-attributes>
        </java-type>
        <java-type name="org.example.Address">
            <xml-root-element name="address" />
            <java-attributes>
                <xml-attribute java-attribute="id" xml-id="true" required="true" />
            </java-attributes>
        </java-type>
    </java-types>
</xml-bindings>

Example: Unset XmlID via XML Metadata

Java Metadata

The following example will demonstrate how the XmlID annotation can be unset via XML metadata:

org.example.Address.java

package org.example;
 
@javax.xml.bind.annotation.XmlRootElement
public class Address {
    @javax.xml.bind.annotation.XmlID
    public String id;
 
    public String street;
    public String city;
    public String zip;
}

XML Metadata

xml-id

If this is present in the XML then the associated property will be treated as an ID. To unset an @XmlID annotated property via xml, xml-element or xml-attribute can be used with an xml-id="false" entry, or none (the default is false).

org/example/eclipselink-oxm.xml

This XML file represents metadata overrides for the "org.example.Address" class. Here, the @XmlID annotated property [id] will be unset.

<?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.Address">
            <xml-root-element name="address" />
            <java-attributes>
                <xml-attribute java-attribute="id" xml-id="false" />
            </java-attributes>
        </java-type>
    </java-types>
</xml-bindings>

Back to the top