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.
Difference between revisions of "EclipseLink/DesignDocs/293925/Phase10"
(→org/example/eclipselink-oxm.xml) |
(→org/example/eclipselink-oxm.xml) |
||
(20 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> | <div style="border: 1px solid rgb(0, 0, 0); margin: 5px; padding: 5px; float: right;">__TOC__</div> | ||
− | = Phase 10 - XmlRegistry | + | = Phase 10 - XmlRegistry = |
− | Provide support for ObjectFactory methods. | + | Provide support for <code>ObjectFactory</code> methods. |
== Annotations == | == Annotations == | ||
Line 43: | Line 43: | ||
package org.example; | 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 { | class ObjectFactory { | ||
− | @ | + | @XmlElementDecl(name="foo") |
− | + | public JAXBElement<String> createFoo(String s) { | |
+ | return new JAXBElement<String>(new QName("foo"), String.class, s); | ||
+ | } | ||
} | } | ||
</source> | </source> | ||
Line 54: | Line 61: | ||
==== xml-registry ==== | ==== xml-registry ==== | ||
− | If this is present in XML, the corresponding | + | If this is present in XML, the corresponding Java class will be treated as an Object Factory. |
==== xml-element-decl ==== | ==== xml-element-decl ==== | ||
Line 62: | Line 69: | ||
==== org/example/eclipselink-oxm.xml ==== | ==== org/example/eclipselink-oxm.xml ==== | ||
− | This XML file represents metadata overrides for the | + | This XML file represents metadata overrides for the <code>org.example</code> package. |
<source lang="xml"> | <source lang="xml"> | ||
Line 69: | Line 76: | ||
<xml-registries> | <xml-registries> | ||
<xml-registry name="org.example.ObjectFactory"> | <xml-registry name="org.example.ObjectFactory"> | ||
− | <xml-element-decl name="foo" /> | + | <xml-element-decl java-method="createFoo" name="foo" /> |
</xml-registry> | </xml-registry> | ||
</xml-registries> | </xml-registries> | ||
Line 79: | Line 86: | ||
=== Java Metadata === | === Java Metadata === | ||
− | The following example will demonstrate how the [http://java.sun.com/javase/6/docs/api/javax/xml/bind/annotation/XmlRegistry.html XmlRegistry] and [http://java.sun.com/javase/6/docs/api/javax/xml/bind/annotation/XmlElementDecl.html XmlElementDecl] annotations can be applied: | + | The following example will demonstrate how the [http://java.sun.com/javase/6/docs/api/javax/xml/bind/annotation/XmlRegistry.html XmlRegistry] and [http://java.sun.com/javase/6/docs/api/javax/xml/bind/annotation/XmlElementDecl.html XmlElementDecl] annotations can be applied in the case where one or more <code>xml-element-decl</code> declarations define a non-local scope: |
==== org.example.ObjectFactory.java ==== | ==== org.example.ObjectFactory.java ==== | ||
Line 86: | Line 93: | ||
package org.example; | package org.example; | ||
+ | import javax.xml.bind.JAXBElement; | ||
import javax.xml.bind.annotation.XmlElementDecl; | import javax.xml.bind.annotation.XmlElementDecl; | ||
import javax.xml.bind.annotation.XmlRegistry; | import javax.xml.bind.annotation.XmlRegistry; | ||
− | import javax.xml. | + | import javax.xml.namespace.QName; |
@XmlRegistry | @XmlRegistry | ||
− | class ObjectFactory { | + | public class ObjectFactory { |
− | @XmlElementDecl(scope=FooBar.class,name="foo") | + | @XmlElementDecl(scope=FooBar.class, name="foo") |
− | JAXBElement createFooBarFoo(String s); | + | public JAXBElement<String> createFooBarFoo(String s) { |
− | + | return new JAXBElement<String>(new QName("foo"), String.class, FooBar.class, s); | |
− | @XmlElementDecl(scope=FooBar.class,name="bar") | + | } |
− | JAXBElement createFooBarBar(String s); | + | |
− | + | @XmlElementDecl(scope=FooBar.class, name="bar") | |
− | @XmlElementDecl(name=" | + | public JAXBElement<String> createFooBarBar(String s) { |
− | JAXBElement | + | return new JAXBElement<String>(new QName("bar"), String.class, FooBar.class, s); |
− | } | + | } |
+ | |||
+ | @XmlElementDecl(name="foos") | ||
+ | public JAXBElement<Integer> createFoos(Integer i) { | ||
+ | return new JAXBElement<Integer>(new QName("foos"), Integer.class, i); | ||
+ | } | ||
</source> | </source> | ||
Line 117: | Line 130: | ||
@XmlElementRef(name="bar",type=JAXBElement.class) | @XmlElementRef(name="bar",type=JAXBElement.class) | ||
}) | }) | ||
− | List<JAXBElement<String>> fooOrBar; | + | public List<JAXBElement<String>> fooOrBar; |
} | } | ||
</source> | </source> | ||
Line 125: | Line 138: | ||
==== xml-registry ==== | ==== xml-registry ==== | ||
− | If this is present in XML, the corresponding | + | If this is present in XML, the corresponding Java class will be treated as an Object Factory. |
==== xml-element-decl ==== | ==== xml-element-decl ==== | ||
Line 133: | Line 146: | ||
==== org/example/eclipselink-oxm.xml ==== | ==== org/example/eclipselink-oxm.xml ==== | ||
− | This XML file represents metadata overrides for the | + | This XML file represents metadata overrides for the <code>org.example</code> package. |
<source lang="xml"> | <source lang="xml"> | ||
Line 140: | Line 153: | ||
<xml-registries> | <xml-registries> | ||
<xml-registry name="org.example.ObjectFactory"> | <xml-registry name="org.example.ObjectFactory"> | ||
− | <xml-element-decl name="foo" scope=" | + | <xml-element-decl java-method="createFooBarFoo" name="foo" scope="org.example.FooBar" /> |
− | <xml-element-decl name="bar" scope=" | + | <xml-element-decl java-method="createFooBarBar" name="bar" scope="org.example.FooBar" /> |
− | <xml-element-decl name=" | + | <xml-element-decl java-method="createFoos" name="foos" /> |
</xml-registry> | </xml-registry> | ||
</xml-registries> | </xml-registries> |
Latest revision as of 09:49, 27 January 2010
Phase 10 - XmlRegistry
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") public JAXBElement<String> createFoo(String s) { return new JAXBElement<String>(new QName("foo"), String.class, s); } }
XML Metadata
xml-registry
If this is present in XML, the corresponding Java class will be treated as an Object Factory.
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-method="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") public JAXBElement<String> createFooBarFoo(String s) { return new JAXBElement<String>(new QName("foo"), String.class, FooBar.class, s); } @XmlElementDecl(scope=FooBar.class, name="bar") public JAXBElement<String> createFooBarBar(String s) { return new JAXBElement<String>(new QName("bar"), String.class, FooBar.class, s); } @XmlElementDecl(name="foos") public JAXBElement<Integer> createFoos(Integer i) { return new JAXBElement<Integer>(new QName("foos"), Integer.class, i); }
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) }) public List<JAXBElement<String>> fooOrBar; }
XML Metadata
xml-registry
If this is present in XML, the corresponding Java class will be treated as an Object Factory.
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-method="createFooBarFoo" name="foo" scope="org.example.FooBar" /> <xml-element-decl java-method="createFooBarBar" name="bar" scope="org.example.FooBar" /> <xml-element-decl java-method="createFoos" name="foos" /> </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>