Skip to main content
Jump to: navigation, search

EclipseLink/DesignDocs/293925/Phase6

Phase 6 - Substitution Groups (page under construction)

Provide support for substitution groups.

Annotations

The following annotations will be targeted in this phase:

Annotation XML Metadata Tag Package Type Field Method
XmlElements xml-elements     X X
XmlElementRef xml-element-ref     X X
XmlElementRefs xml-element-refs X
X

Example: XmlElements annotation

Java Metadata

The following example will demonstrate how the XmlElements annotation can be applied:

org.example.Bar.java

package org.example;
 
@javax.xml.bind.annotation.XmlRootElement
public class Bar {
    @javax.xml.bind.annotation.XmlIDREF
    @javax.xml.bind.annotation.XmlElementWrapper(name="contact")
    @javax.xml.bind.annotation.XmlElements({
        @javax.xml.bind.annotation.XmlElement(name="address", type=Address.class),
        @javax.xml.bind.annotation.XmlElement(name="phone", type=Phone.class)
    })
    public java.util.List items;
}

org.example.Address.java

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

org.example.Phone.java

package org.example;
 
@javax.xml.bind.annotation.XmlRootElement
public class Phone {
    public String id;
    public String area-code;
    public String number;
}

XML Metadata

xml-elements

If this is present in the XML then it completely replaces the corresponding annotation.

org/example/eclipselink-oxm.xml

This XML file represents metadata overrides for the org.example.Bar, org.example.Address and org.example.Phone 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.Bar">
            <xml-root-element name="bar"/>
            <java-attributes>
                <xml-elements java-attribute="items" xml-idref="true">
                    <xml-element-wrapper name="contact" />
                    <xml-element java-attribute="address" type="org.example.Address" />
                    <xml-element java-attribute="phone" type="org.example.Phone" />
                </xml-elements>
            </java-attributes>
        </java-type>
        <java-type name="org.example.Address">
            <java-attributes>
                <xml-element java-attribute="id" xml-id="true" />
            </java-attributes>
        </java-type>
        <java-type name="org.example.Phone">
            <java-attributes>
                <xml-element java-attribute="id" xml-id="true" />
            </java-attributes>
        </java-type>
    </java-types>
</xml-bindings>

Back to the top