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

(org/example/eclipselink-oxm.xml)
(org.example.ObjectFactory.java)
Line 100: Line 100:
 
@XmlRegistry
 
@XmlRegistry
 
public class ObjectFactory {
 
public class ObjectFactory {
     @XmlElementDecl(scope=FooBar.class,name="foo")
+
     @XmlElementDecl(scope=FooBar.class, name="foo")
 
     JAXBElement<String> createFooBarFoo(String s) {
 
     JAXBElement<String> createFooBarFoo(String s) {
 
         return new JAXBElement<String>(new QName("foo"), String.class, FooBar.class, "FooBarFoo");
 
         return new JAXBElement<String>(new QName("foo"), String.class, FooBar.class, "FooBarFoo");
 
     }
 
     }
 
   
 
   
     @XmlElementDecl(scope=FooBar.class,name="bar")
+
     @XmlElementDecl(scope=FooBar.class, name="bar")
     JAXBElement createFooBarBar(String s) {
+
     JAXBElement<String> createFooBarBar(String s) {
 
         return new JAXBElement<String>(new QName("bar"), String.class, FooBar.class, "FooBarBar");
 
         return new JAXBElement<String>(new QName("bar"), String.class, FooBar.class, "FooBarBar");
 
     }
 
     }
 
   
 
   
     @XmlElementDecl(name="foo")
+
     @XmlElementDecl(name="foos")
     JAXBElement createFoo(Integer i) {
+
     JAXBElement<Integer> createFoos(Integer i) {
         return new JAXBElement<Integer>(new QName("foo"), Integer.class, Integer.parseInt("66"));
+
         return new JAXBElement<Integer>(new QName("foos"), Integer.class, Integer.parseInt("66"));
 
     }
 
     }
 
</source>
 
</source>

Revision as of 09:19, 26 January 2010

Phase 10 - XmlRegistry (page under construction)

Provide support for ObjectFactory methods.

Annotations

The following annotations will be targetted in this phase:

Annotation XML Metadata Tag Package Type Field Method
XmlElementDecl xml-element-decl     X X
XmlRegistry xml-registry   X    

Example: XmlRegistry and XmlElementDecl Annotations - Factory method

Java Metadata

The following example will demonstrate how the XmlRegistry and XmlElementDecl annotations can be applied:

org.example.ObjectFactory.java

package org.example;
 
import javax.xml.bind.JAXBElement;
import javax.xml.bind.annotation.XmlElementDecl;
import javax.xml.bind.annotation.XmlRegistry;
import javax.xml.namespace.QName;
 
@XmlRegistry
class ObjectFactory {
    @XmlElementDecl(name="foo")
    JAXBElement<String> createFoo(String s) {
        return new JAXBElement<String>(new QName("foo"), String.class, "Foo");
    }
}

XML Metadata

xml-registry

If this is present in XML, the corresponding annotation will be ignored, and the true/false value set in XML used instead.

xml-element-decl

If this is present in XML, the corresponding annotation will be completely replaced.

org/example/eclipselink-oxm.xml

This XML file represents metadata overrides for the org.example package.

<?xml version="1.0" encoding="US-ASCII"?>
<xml-bindings xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm">
    <xml-registries>
        <xml-registry name="org.example.ObjectFactory">
            <xml-element-decl java-attribute="createFoo" name="foo" />
        </xml-registry>
    </xml-registries>
</xml-bindings>

Example: XmlRegistry and XmlElementDecl Annotations - Element declaration with non local scope

Java Metadata

The following example will demonstrate how the XmlRegistry and XmlElementDecl annotations can be applied in the case where one or more xml-element-decl declarations define a non-local scope:

org.example.ObjectFactory.java

package org.example;
 
import javax.xml.bind.JAXBElement;
import javax.xml.bind.annotation.XmlElementDecl;
import javax.xml.bind.annotation.XmlRegistry;
import javax.xml.namespace.QName;
 
@XmlRegistry
public class ObjectFactory {
    @XmlElementDecl(scope=FooBar.class, name="foo")
    JAXBElement<String> createFooBarFoo(String s) {
        return new JAXBElement<String>(new QName("foo"), String.class, FooBar.class, "FooBarFoo");
    }
 
    @XmlElementDecl(scope=FooBar.class, name="bar")
    JAXBElement<String> createFooBarBar(String s) {
        return new JAXBElement<String>(new QName("bar"), String.class, FooBar.class, "FooBarBar");
    }
 
    @XmlElementDecl(name="foos")
    JAXBElement<Integer> createFoos(Integer i) {
        return new JAXBElement<Integer>(new QName("foos"), Integer.class, Integer.parseInt("66"));
    }

org.example.FooBar.java

package org.example;
 
import javax.xml.bind.annotation.XmlElementRef;
import javax.xml.bind.annotation.XmlElementRefs;
import javax.xml.bind.JAXBElement;
 
class FooBar {
    @XmlElementRefs({
        @XmlElementRef(name="foo",type=JAXBElement.class),
        @XmlElementRef(name="bar",type=JAXBElement.class)
    })
    List<JAXBElement<String>> fooOrBar;
}

XML Metadata

xml-registry

If this is present in XML, the corresponding annotation will be ignored, and the true/false value set in XML used instead.

xml-element-decl

If this is present in XML, the corresponding annotation will be completely replaced.

org/example/eclipselink-oxm.xml

This XML file represents metadata overrides for the org.example package.

<?xml version="1.0" encoding="US-ASCII"?>
<xml-bindings xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm">
    <xml-registries>
        <xml-registry name="org.example.ObjectFactory">
            <xml-element-decl name="foo" scope="FooBar.class" />
            <xml-element-decl name="bar" scope="FooBar.class" />
            <xml-element-decl name="foo" />
        </xml-registry>
    </xml-registries>
    <java-types>
        <java-type name="org.example.FooBar">
            <java-attributes>
                <xml-element-refs java-attribute="fooOrBar" >
                    <xml-element-ref name="foo" type="javax.xml.bind.JAXBElement" />
                    <xml-element-ref name="bar" type="javax.xml.bind.JAXBElement" />
                </xml-element-refs>
            </java-attributes>
        </java-type>
    </java-types>
</xml-bindings>

Back to the top