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/317962/Phase1"
(→Example: XmlCDATA annotation) |
|||
Line 200: | Line 200: | ||
String setMethodName() default ""; | String setMethodName() default ""; | ||
} | } | ||
+ | </source> | ||
+ | |||
+ | == Example: XmlPaths annotation == | ||
+ | |||
+ | The following example will demonstrate how the XmlPaths annotation can be applied: | ||
+ | |||
+ | Path-based mappings on <code>xml-element</code> entries within an <code>xml-elements</code> structure will be supported via <code>xml-path</code> attribute. For example: | ||
+ | <source lang="xml"> | ||
+ | <xml-elements java-attribute="things"> | ||
+ | <xml-access-methods get-method="getThings" set-method="setThings" /> | ||
+ | <xml-element type="java.lang.Integer" xml-path="integers/my-integer/text()" /> | ||
+ | <xml-element type="java.lang.Float" xml-path="floats/my-float/text()" /> | ||
+ | </xml-elements> | ||
+ | </source> | ||
+ | |||
+ | The equivalent configured via annotations would look like: | ||
+ | <source lang="java"> | ||
+ | @javax.xml.bind.annotation.XmlElements { | ||
+ | @javax.xml.bind.annotation.XmlElement(type=java.lang.Integer.class), | ||
+ | @javax.xml.bind.annotation.XmlElement(type=java.lang.Float.class) | ||
+ | } | ||
+ | @org.eclipse.persistence.oxm.annotations.XmlPaths* { | ||
+ | @org.eclipse.persistence.oxm.annotations.XmlPath("integers/my-integer"), | ||
+ | @org.eclipse.persistence.oxm.annotations.XmlPath("floats/my-float") | ||
+ | } | ||
+ | public List<Object> things; | ||
</source> | </source> |
Revision as of 14:05, 7 July 2010
Phase 1 - Provide MOXy annotation support equivalent to our XML metadata support
This phase of development involves providing MOXy annotation support equivalent to the existing EclipseLink XML metadata support
Annotations
The following annotations will be targeted in this phase:
Annotation | XML Metadata Tag | Package | Type | Field | Method |
---|---|---|---|---|---|
XmlReadOnly | read-only | X | X | ||
XmlWriteOnly | write-only | X | X | ||
XmlCDATA | cdata | X | X | ||
XmlAccessMethods | xml-access-methods | X | X | ||
XmlPaths | xml-elements | X | X | ||
XmlNullPolicy | xml-null-policy | X | X | ||
XmlIsSetNullPolicy | xml-is-set-null-policy | X | X | ||
XmlIsSetParameters | n/a | X | X | ||
XmlIsSetParameter | is-set-parameter | X | X |
Example: XmlReadOnly annotation
The following example will demonstrate how the XmlReadOnly annotation can be applied:
A property can be configured to be read-only via EclipseLink XML metadata as follows:
<xml-attribute java-attribute="salary" read-only="true" />
The equivalent configured via annotations would look like:
package org.example; public class Employee { @javax.xml.bind.annotation.XmlAttribute @org.eclipse.persistence.oxm.annotations.XmlReadOnly public String salary; }
Following is the proposed XmlReadOnly annotation:
package org.eclipse.persistence.oxm.annotations; @Target({ElementType.FIELD, ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) public @interface XmlReadOnly {}
Example: XmlWriteOnly annotation
The following example will demonstrate how the XmlWriteOnly annotation can be applied:
A property can be configured to be write-only via EclipseLink XML metadata as follows:
<xml-attribute java-attribute="privateData" write-only="true" />
The equivalent configured via annotations would look like:
package org.example; public class Employee { @javax.xml.bind.annotation.XmlAttribute @org.eclipse.persistence.oxm.annotations.XmlWriteOnly public String privateData; }
Following is the proposed XmlWriteOnly annotation:
package org.eclipse.persistence.oxm.annotations; @Target({ElementType.FIELD, ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) public @interface XmlWriteOnly {}
Example: XmlCDATA annotation
The following example will demonstrate how the XmlCDATA annotation can be applied:
A property can be configured as CDATA (character data) via EclipseLink XML metadata as follows:
<xml-element java-attribute="characterData" cdata="true" />
The equivalent configured via annotations would look like:
package org.example; public class Employee { @javax.xml.bind.annotation.XmlElement @org.eclipse.persistence.oxm.annotations.XmlCDATA public String characterData; }
Following is the proposed XmlCDATA annotation:
package org.eclipse.persistence.oxm.annotations; @Target({ElementType.FIELD, ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) public @interface XmlCDATA {}
Example: XmlAccessMethods annotation
The following example will demonstrate how the XmlAccessMethods annotation can be applied:
A property's accessor methods can be configured via EclipseLink XML metadata as follows:
<xml-element java-attribute="firstName"> <xml-access-methods get-method="getFirstName" set-method="setFirstName" /> </xml-element>
The equivalent configured via annotations would look like:
package org.example; public class Employee { @javax.xml.bind.annotation.XmlElement @org.eclipse.persistence.oxm.annotations.XmlAccessMethods(getMethodName="getFirstName", setMethodName="setFirstName") public String firstName; }
Following is the proposed XmlAccessMethods annotation:
package org.eclipse.persistence.oxm.annotations; @Target({ElementType.FIELD, ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) public @interface XmlAccessMethods { String getMethodName() default ""; String setMethodName() default ""; }
Example: XmlPaths annotation
The following example will demonstrate how the XmlPaths annotation can be applied:
Path-based mappings on xml-element
entries within an xml-elements
structure will be supported via xml-path
attribute. For example:
<xml-elements java-attribute="things"> <xml-access-methods get-method="getThings" set-method="setThings" /> <xml-element type="java.lang.Integer" xml-path="integers/my-integer/text()" /> <xml-element type="java.lang.Float" xml-path="floats/my-float/text()" /> </xml-elements>
The equivalent configured via annotations would look like:
@javax.xml.bind.annotation.XmlElements { @javax.xml.bind.annotation.XmlElement(type=java.lang.Integer.class), @javax.xml.bind.annotation.XmlElement(type=java.lang.Float.class) } @org.eclipse.persistence.oxm.annotations.XmlPaths* { @org.eclipse.persistence.oxm.annotations.XmlPath("integers/my-integer"), @org.eclipse.persistence.oxm.annotations.XmlPath("floats/my-float") } public List<Object> things;