Skip to main content

Notice: This Wiki is now read only and edits are no longer 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"

(org/example/eclipselink-oxm.xml)
Line 94: Line 94:
 
The following example will demonstrate how the [http://java.sun.com/javase/6/docs/api/javax/xml/bind/annotation/XmlElementRef.html XmlElementRef] annotation can be applied:
 
The following example will demonstrate how the [http://java.sun.com/javase/6/docs/api/javax/xml/bind/annotation/XmlElementRef.html XmlElementRef] annotation can be applied:
  
==== org.example.Foo.java  ====
+
==== org.example.Foos.java  ====
  
 
<source lang="java">
 
<source lang="java">
Line 100: Line 100:
  
 
@javax.xml.bind.annotation.XmlRootElement
 
@javax.xml.bind.annotation.XmlRootElement
public class Foo {
+
public class Foos {
 +
    @javax.xml.bind.annotation.XmlElementWrapper(name="items")
 
     @javax.xml.bind.annotation.XmlElementRef(type=Bar.class)
 
     @javax.xml.bind.annotation.XmlElementRef(type=Bar.class)
     public Bar item;
+
     public java.util.List<Bar> items;
 
}
 
}
 
</source>
 
</source>
Line 125: Line 126:
 
==== org/example/eclipselink-oxm.xml  ====
 
==== org/example/eclipselink-oxm.xml  ====
  
This XML file represents metadata overrides for the <code>org.example.Foo</code> and <code>org.example.Bar</code> classes.
+
This XML file represents metadata overrides for the <code>org.example.Foos</code> and <code>org.example.Bar</code> classes.
  
 
<source lang="xml">
 
<source lang="xml">
Line 131: Line 132:
 
<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.Foo">
+
         <java-type name="org.eclipse.persistence.testing.jaxb.externalizedmetadata.xmlelementref.Foos">
             <xml-root-element name="foo" />
+
             <xml-root-element name="foos" />
 
             <java-attributes>
 
             <java-attributes>
                 <xml-element-ref java-attribute="item" type="org.example.Bar"/>
+
                 <xml-element-ref java-attribute="items" type="org.eclipse.persistence.testing.jaxb.externalizedmetadata.xmlelementref.Bar" >
 +
                    <xml-element-wrapper name="items" />
 +
                </xml-element-ref>
 
             </java-attributes>
 
             </java-attributes>
 
         </java-type>
 
         </java-type>
         <java-type name="org.example.Bar">
+
         <java-type name="org.eclipse.persistence.testing.jaxb.externalizedmetadata.xmlelementref.Bar">
 
             <xml-root-element name="foobar" />
 
             <xml-root-element name="foobar" />
 
         </java-type>
 
         </java-type>

Revision as of 15:31, 4 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>

Example: XmlElementRef annotation

Java Metadata

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

org.example.Foos.java

package org.example;
 
@javax.xml.bind.annotation.XmlRootElement
public class Foos {
    @javax.xml.bind.annotation.XmlElementWrapper(name="items")
    @javax.xml.bind.annotation.XmlElementRef(type=Bar.class)
    public java.util.List<Bar> items;
}

org.example.Bar.java

package org.example;
 
@javax.xml.bind.annotation.XmlRootElement(name="foobar")
public class Bar {
    public int id;
}

XML Metadata

xml-element-ref

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.Foos and org.example.Bar 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.eclipse.persistence.testing.jaxb.externalizedmetadata.xmlelementref.Foos">
            <xml-root-element name="foos" />
            <java-attributes>
                <xml-element-ref java-attribute="items" type="org.eclipse.persistence.testing.jaxb.externalizedmetadata.xmlelementref.Bar" >
                    <xml-element-wrapper name="items" />
                </xml-element-ref>
            </java-attributes>
        </java-type>
        <java-type name="org.eclipse.persistence.testing.jaxb.externalizedmetadata.xmlelementref.Bar">
            <xml-root-element name="foobar" />
        </java-type>
    </java-types>
</xml-bindings>

Back to the top