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/Phase6"

Line 44: Line 44:
 
The following example will demonstrate how the [http://java.sun.com/javase/6/docs/api/javax/xml/bind/annotation/XmlElements.html XmlElements] annotation can be applied:
 
The following example will demonstrate how the [http://java.sun.com/javase/6/docs/api/javax/xml/bind/annotation/XmlElements.html XmlElements] annotation can be applied:
  
==== org.example.Bar.java  ====
+
==== org.example.Foo.java  ====
  
 
<source lang="java">
 
<source lang="java">
Line 50: Line 50:
  
 
@javax.xml.bind.annotation.XmlRootElement
 
@javax.xml.bind.annotation.XmlRootElement
public class Bar {
+
public class Foo {
    @javax.xml.bind.annotation.XmlIDREF
+
     @javax.xml.bind.annotation.XmlElementWrapper(name="items")
     @javax.xml.bind.annotation.XmlElementWrapper(name="contact")
+
 
     @javax.xml.bind.annotation.XmlElements({
 
     @javax.xml.bind.annotation.XmlElements({
         @javax.xml.bind.annotation.XmlElement(name="address", type=Address.class),
+
         @javax.xml.bind.annotation.XmlElement(name="A", type=Integer.class),
         @javax.xml.bind.annotation.XmlElement(name="phone", type=Phone.class)
+
         @javax.xml.bind.annotation.XmlElement(name="B", type=Float.class)
 
     })
 
     })
 
     public java.util.List items;
 
     public java.util.List items;
}
 
</source>
 
 
==== org.example.Address.java  ====
 
 
<source lang="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;
 
}
 
</source>
 
 
==== org.example.Phone.java  ====
 
 
<source lang="java">
 
package org.example;
 
 
@javax.xml.bind.annotation.XmlRootElement
 
public class Phone {
 
    public String id;
 
    public String area-code;
 
    public String number;
 
 
}
 
}
 
</source>
 
</source>
Line 96: Line 68:
 
==== org/example/eclipselink-oxm.xml  ====
 
==== org/example/eclipselink-oxm.xml  ====
  
This XML file represents metadata overrides for the <code>org.example.Bar</code>, <code>org.example.Address</code> and <code>org.example.Phone</code> classes.
+
This XML file represents metadata overrides for the <code>org.example.Foo</code> class.
  
 
<source lang="xml">
 
<source lang="xml">
Line 102: Line 74:
 
<xml-bindings xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm">
 
<xml-bindings xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm">
 
     <java-types>
 
     <java-types>
         <java-type name="org.example.Bar">
+
         <java-type name="org.example.Foo">
             <xml-root-element name="bar"/>
+
             <xml-root-element name="foo"/>
 
             <java-attributes>
 
             <java-attributes>
                 <xml-elements java-attribute="items" xml-idref="true">
+
                 <xml-elements java-attribute="items">
                    <xml-element-wrapper name="contact" />
+
                     <xml-element java-attribute="A" type="java.lang.Integer" />
                     <xml-element java-attribute="address" type="org.example.Address" />
+
                     <xml-element java-attribute="B" type="java.lang.Float" />
                     <xml-element java-attribute="phone" type="org.example.Phone" />
+
 
                 </xml-elements>
 
                 </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-attributes>
 
         </java-type>
 
         </java-type>

Revision as of 12:51, 3 December 2009

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.Foo.java

package org.example;
 
@javax.xml.bind.annotation.XmlRootElement
public class Foo {
    @javax.xml.bind.annotation.XmlElementWrapper(name="items")
    @javax.xml.bind.annotation.XmlElements({
        @javax.xml.bind.annotation.XmlElement(name="A", type=Integer.class),
        @javax.xml.bind.annotation.XmlElement(name="B", type=Float.class)
    })
    public java.util.List items;
}

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.Foo 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.Foo">
            <xml-root-element name="foo"/>
            <java-attributes>
                <xml-elements java-attribute="items">
                    <xml-element java-attribute="A" type="java.lang.Integer" />
                    <xml-element java-attribute="B" type="java.lang.Float" />
                </xml-elements>
            </java-attributes>
        </java-type>
    </java-types>
</xml-bindings>

Back to the top