| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
| <!-- NewPage --> |
| <html lang="en"> |
| <head> |
| <!-- Generated by javadoc (version 1.7.0_11) on Wed Sep 18 01:54:20 EDT 2013 --> |
| <title>XmlElementRef (EclipseLink 2.5.1, build 'v20130918-f2b9fc5' API Reference)</title> |
| <meta name="date" content="2013-09-18"> |
| <link rel="stylesheet" type="text/css" href="../../../../stylesheet.css" title="Style"> |
| </head> |
| <body> |
| <script type="text/javascript"><!-- |
| if (location.href.indexOf('is-external=true') == -1) { |
| parent.document.title="XmlElementRef (EclipseLink 2.5.1, build 'v20130918-f2b9fc5' API Reference)"; |
| } |
| //--> |
| </script> |
| <noscript> |
| <div>JavaScript is disabled on your browser.</div> |
| </noscript> |
| <!-- ========= START OF TOP NAVBAR ======= --> |
| <div class="topNav"><a name="navbar_top"> |
| <!-- --> |
| </a><a href="#skip-navbar_top" title="Skip navigation links"></a><a name="navbar_top_firstrow"> |
| <!-- --> |
| </a> |
| <ul class="navList" title="Navigation"> |
| <li><a href="../../../../overview-summary.html">Overview</a></li> |
| <li><a href="package-summary.html">Package</a></li> |
| <li class="navBarCell1Rev">Class</li> |
| <li><a href="package-tree.html">Tree</a></li> |
| <li><a href="../../../../deprecated-list.html">Deprecated</a></li> |
| <li><a href="../../../../index-all.html">Index</a></li> |
| <li><a href="../../../../help-doc.html">Help</a></li> |
| </ul> |
| <div class="aboutLanguage"><em>EclipseLink 2.5.1, build 'v20130918-f2b9fc5' API Reference</em></div> |
| </div> |
| <div class="subNav"> |
| <ul class="navList"> |
| <li><a href="../../../../javax/xml/bind/annotation/XmlElementDecl.GLOBAL.html" title="class in javax.xml.bind.annotation"><span class="strong">Prev Class</span></a></li> |
| <li><a href="../../../../javax/xml/bind/annotation/XmlElementRef.DEFAULT.html" title="class in javax.xml.bind.annotation"><span class="strong">Next Class</span></a></li> |
| </ul> |
| <ul class="navList"> |
| <li><a href="../../../../index.html?javax/xml/bind/annotation/XmlElementRef.html" target="_top">Frames</a></li> |
| <li><a href="XmlElementRef.html" target="_top">No Frames</a></li> |
| </ul> |
| <ul class="navList" id="allclasses_navbar_top"> |
| <li><a href="../../../../allclasses-noframe.html">All Classes</a></li> |
| </ul> |
| <div> |
| <script type="text/javascript"><!-- |
| allClassesLink = document.getElementById("allclasses_navbar_top"); |
| if(window==top) { |
| allClassesLink.style.display = "block"; |
| } |
| else { |
| allClassesLink.style.display = "none"; |
| } |
| //--> |
| </script> |
| </div> |
| <div> |
| <ul class="subNavList"> |
| <li>Summary: </li> |
| <li>Required | </li> |
| <li><a href="#annotation_type_optional_element_summary">Optional</a></li> |
| </ul> |
| <ul class="subNavList"> |
| <li>Detail: </li> |
| <li><a href="#annotation_type_element_detail">Element</a></li> |
| </ul> |
| </div> |
| <a name="skip-navbar_top"> |
| <!-- --> |
| </a></div> |
| <!-- ========= END OF TOP NAVBAR ========= --> |
| <!-- ======== START OF CLASS DATA ======== --> |
| <div class="header"> |
| <div class="subTitle">javax.xml.bind.annotation</div> |
| <h2 title="Annotation Type XmlElementRef" class="title">Annotation Type XmlElementRef</h2> |
| </div> |
| <div class="contentContainer"> |
| <div class="description"> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <hr> |
| <br> |
| <pre>@Retention(value=RUNTIME) |
| @Target(value={FIELD,METHOD}) |
| public @interface <span class="strong">XmlElementRef</span></pre> |
| <div class="block"><p> |
| Maps a JavaBean property to a XML element derived from property's type. |
| <p> |
| <b>Usage</b> |
| <p> |
| <tt>@XmlElementRef</tt> annotation can be used with a |
| JavaBean property or from within <a href="../../../../javax/xml/bind/annotation/XmlElementRefs.html" title="annotation in javax.xml.bind.annotation"><code>XmlElementRefs</code></a> |
| <p> |
| This annotation dynamically associates an XML element name with the JavaBean |
| property. When a JavaBean property is annotated with <a href="../../../../javax/xml/bind/annotation/XmlElement.html" title="annotation in javax.xml.bind.annotation"><code>XmlElement</code></a>, the XML element name is statically derived from the |
| JavaBean property name. However, when this annotation is used, the |
| XML element name is derived from the instance of the type of the |
| JavaBean property at runtime. |
| |
| <h3> XML Schema substitution group support </h3> |
| XML Schema allows a XML document author to use XML element names |
| that were not statically specified in the content model of a |
| schema using substitution groups. Schema derived code provides |
| support for substitution groups using an <i>element property</i>, |
| (section 5.5.5, "Element Property" of JAXB 2.0 specification). An |
| element property method signature is of the form: |
| <pre><xmp> |
| public void setTerm(JAXBElement<? extends Operator>); |
| public JAXBElement<? extends Operator> getTerm(); |
| </xmp></pre> |
| <p> |
| An element factory method annotated with <a href="../../../../javax/xml/bind/annotation/XmlElementDecl.html" title="annotation in javax.xml.bind.annotation"><code>XmlElementDecl</code></a> is |
| used to create a <tt>JAXBElement</tt> instance, containing an XML |
| element name. The presence of @XmlElementRef annotation on an |
| element property indicates that the element name from <tt>JAXBElement</tt> |
| instance be used instead of deriving an XML element name from the |
| JavaBean property name. |
| |
| <p> |
| The usage is subject to the following constraints: |
| <ul> |
| <li> If the collection item type (for collection property) or |
| property type (for single valued property) is |
| <a href="../../../../javax/xml/bind/JAXBElement.html" title="class in javax.xml.bind"><code>JAXBElement</code></a>, then |
| <tt>@XmlElementRef}.name()</tt> and <tt>@XmlElementRef.namespace()</tt> must |
| point an element factory method with an @XmlElementDecl |
| annotation in a class annotated with @XmlRegistry (usually |
| ObjectFactory class generated by the schema compiler) : |
| <ul> |
| <li> @XmlElementDecl.name() must equal @XmlElementRef.name() </li> |
| <li> @XmlElementDecl.namespace() must equal @XmlElementRef.namespace(). </li> |
| </ul> |
| </li> |
| <li> If the collection item type (for collection property) or |
| property type (for single valued property) is not |
| <a href="../../../../javax/xml/bind/JAXBElement.html" title="class in javax.xml.bind"><code>JAXBElement</code></a>, then the type referenced by the |
| property or field must be annotated with <a href="../../../../javax/xml/bind/annotation/XmlRootElement.html" title="annotation in javax.xml.bind.annotation"><code>XmlRootElement</code></a>. </li> |
| <li> This annotation can be used with the following annotations: |
| <a href="../../../../javax/xml/bind/annotation/XmlElementWrapper.html" title="annotation in javax.xml.bind.annotation"><code>XmlElementWrapper</code></a>, <a href="../../../../javax/xml/bind/annotation/adapters/XmlJavaTypeAdapter.html" title="annotation in javax.xml.bind.annotation.adapters"><code>XmlJavaTypeAdapter</code></a>. |
| </ul> |
| |
| <p>See "Package Specification" in javax.xml.bind.package javadoc for |
| additional common information.</p> |
| |
| <p><b>Example 1: </b>Ant Task Example</b></p> |
| The following Java class hierarchy models an Ant build |
| script. An Ant task corresponds to a class in the class |
| hierarchy. The XML element name of an Ant task is indicated by the |
| @XmlRootElement annotation on its corresponding class. |
| <pre> |
| @XmlRootElement(name="target") |
| class Target { |
| // The presence of @XmlElementRef indicates that the XML |
| // element name will be derived from the @XmlRootElement |
| // annotation on the type (for e.g. "jar" for JarTask). |
| @XmlElementRef |
| List<Task> tasks; |
| } |
| |
| abstract class Task { |
| } |
| |
| @XmlRootElement(name="jar") |
| class JarTask extends Task { |
| ... |
| } |
| |
| @XmlRootElement(name="javac") |
| class JavacTask extends Task { |
| ... |
| } |
| |
| <!-- XML Schema fragment --> |
| <xs:element name="target" type="Target"> |
| <xs:complexType name="Target"> |
| <xs:sequence> |
| <xs:choice maxOccurs="unbounded"> |
| <xs:element ref="jar"> |
| <xs:element ref="javac"> |
| </xs:choice> |
| </xs:sequence> |
| </xs:complexType> |
| |
| </pre> |
| <p> |
| Thus the following code fragment: |
| <pre> |
| Target target = new Target(); |
| target.tasks.add(new JarTask()); |
| target.tasks.add(new JavacTask()); |
| marshal(target); |
| </pre> |
| will produce the following XML output: |
| <pre><xmp> |
| <target> |
| <jar> |
| .... |
| </jar> |
| <javac> |
| .... |
| </javac> |
| </target> |
| </xmp></pre> |
| <p> |
| It is not an error to have a class that extends <tt>Task</tt> |
| that doesn't have <a href="../../../../javax/xml/bind/annotation/XmlRootElement.html" title="annotation in javax.xml.bind.annotation"><code>XmlRootElement</code></a>. But they can't show up in an |
| XML instance (because they don't have XML element names). |
| |
| <p><b>Example 2: XML Schema Susbstitution group support</b> |
| <p> The following example shows the annotations for XML Schema |
| substitution groups. The annotations and the ObjectFactory are |
| derived from the schema. |
| |
| <pre> |
| @XmlElement |
| class Math { |
| // The value of <a href="../../../../javax/xml/bind/annotation/XmlElementRef.html#type()"><code>type()</code></a>is |
| // JAXBElement.class , which indicates the XML |
| // element name ObjectFactory - in general a class marked |
| // with @XmlRegistry. (See ObjectFactory below) |
| // |
| // The <a href="../../../../javax/xml/bind/annotation/XmlElementRef.html#name()"><code>name()</code></a> is "operator", a pointer to a |
| // factory method annotated with a |
| // <a href="../../../../javax/xml/bind/annotation/XmlElementDecl.html" title="annotation in javax.xml.bind.annotation"><code>XmlElementDecl</code></a> with the name "operator". Since |
| // "operator" is the head of a substitution group that |
| // contains elements "add" and "sub" elements, "operator" |
| // element can be substituted in an instance document by |
| // elements "add" or "sub". At runtime, JAXBElement |
| // instance contains the element name that has been |
| // substituted in the XML document. |
| // |
| @XmlElementRef(type=JAXBElement.class,name="operator") |
| JAXBElement<? extends Operator> term; |
| } |
| |
| @XmlRegistry |
| class ObjectFactory { |
| @XmlElementDecl(name="operator") |
| JAXBElement<Operator> createOperator(Operator o) {...} |
| @XmlElementDecl(name="add",substitutionHeadName="operator") |
| JAXBElement<Operator> createAdd(Operator o) {...} |
| @XmlElementDecl(name="sub",substitutionHeadName="operator") |
| JAXBElement<Operator> createSub(Operator o) {...} |
| } |
| |
| class Operator { |
| ... |
| } |
| </pre> |
| <p> |
| Thus, the following code fragment |
| <pre> |
| Math m = new Math(); |
| m.term = new ObjectFactory().createAdd(new Operator()); |
| marshal(m); |
| </pre> |
| will produce the following XML output: |
| <pre> |
| <math> |
| <add>...</add> |
| </math> |
| </pre></div> |
| <dl><dt><span class="strong">See Also:</span></dt><dd><a href="../../../../javax/xml/bind/annotation/XmlElementRefs.html" title="annotation in javax.xml.bind.annotation"><code>XmlElementRefs</code></a></dd><dt><span class="strong">Author:</span></dt> |
| <dd><ul><li>Kohsuke Kawaguchi, Sun Microsystems,Inc. </li><li>Sekhar Vajjhala, Sun Microsystems, Inc.</li></ul></dd> |
| <dt><span class="strong">Since:</span></dt> |
| <dd>JAXB2.0</dd></dl> |
| </li> |
| </ul> |
| </div> |
| <div class="summary"> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <!-- =========== ANNOTATION TYPE OPTIONAL MEMBER SUMMARY =========== --> |
| <ul class="blockList"> |
| <li class="blockList"><a name="annotation_type_optional_element_summary"> |
| <!-- --> |
| </a> |
| <h3>Optional Element Summary</h3> |
| <table class="overviewSummary" border="0" cellpadding="3" cellspacing="0" summary="Optional Element Summary table, listing optional elements, and an explanation"> |
| <caption><span>Optional Elements</span><span class="tabEnd"> </span></caption> |
| <tr> |
| <th class="colFirst" scope="col">Modifier and Type</th> |
| <th class="colLast" scope="col">Optional Element and Description</th> |
| </tr> |
| <tr class="altColor"> |
| <td class="colFirst"><code>java.lang.String</code></td> |
| <td class="colLast"><code><strong><a href="../../../../javax/xml/bind/annotation/XmlElementRef.html#name()">name</a></strong></code> </td> |
| </tr> |
| <tr class="rowColor"> |
| <td class="colFirst"><code>java.lang.String</code></td> |
| <td class="colLast"><code><strong><a href="../../../../javax/xml/bind/annotation/XmlElementRef.html#namespace()">namespace</a></strong></code> |
| <div class="block">This parameter and <a href="../../../../javax/xml/bind/annotation/XmlElementRef.html#name()"><code>name()</code></a> are used to determine the |
| XML element for the JavaBean property.</div> |
| </td> |
| </tr> |
| <tr class="altColor"> |
| <td class="colFirst"><code>boolean</code></td> |
| <td class="colLast"><code><strong><a href="../../../../javax/xml/bind/annotation/XmlElementRef.html#required()">required</a></strong></code> |
| <div class="block">Customize the element declaration to be required.</div> |
| </td> |
| </tr> |
| <tr class="rowColor"> |
| <td class="colFirst"><code>java.lang.Class</code></td> |
| <td class="colLast"><code><strong><a href="../../../../javax/xml/bind/annotation/XmlElementRef.html#type()">type</a></strong></code> |
| <div class="block">The Java type being referenced.</div> |
| </td> |
| </tr> |
| </table> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| </div> |
| <div class="details"> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <!-- ============ ANNOTATION TYPE MEMBER DETAIL =========== --> |
| <ul class="blockList"> |
| <li class="blockList"><a name="annotation_type_element_detail"> |
| <!-- --> |
| </a> |
| <h3>Element Detail</h3> |
| <a name="type()"> |
| <!-- --> |
| </a> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <h4>type</h4> |
| <pre>public abstract java.lang.Class type</pre> |
| <div class="block">The Java type being referenced. |
| <p> |
| If the value is DEFAULT.class, the type is inferred from the |
| the type of the JavaBean property.</div> |
| <dl> |
| <dt>Default:</dt> |
| <dd>javax.xml.bind.annotation.XmlElementRef.DEFAULT.class</dd> |
| </dl> |
| </li> |
| </ul> |
| <a name="namespace()"> |
| <!-- --> |
| </a> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <h4>namespace</h4> |
| <pre>public abstract java.lang.String namespace</pre> |
| <div class="block">This parameter and <a href="../../../../javax/xml/bind/annotation/XmlElementRef.html#name()"><code>name()</code></a> are used to determine the |
| XML element for the JavaBean property. |
| |
| <p> If <tt>type()</tt> is <tt>JAXBElement.class</tt> , then |
| <tt>namespace()</tt> and <tt>name()</tt> |
| point to a factory method with <a href="../../../../javax/xml/bind/annotation/XmlElementDecl.html" title="annotation in javax.xml.bind.annotation"><code>XmlElementDecl</code></a>. The XML |
| element name is the element name from the factory method's |
| <a href="../../../../javax/xml/bind/annotation/XmlElementDecl.html" title="annotation in javax.xml.bind.annotation"><code>XmlElementDecl</code></a> annotation or if an element from its |
| substitution group (of which it is a head element) has been |
| substituted in the XML document, then the element name is from the |
| <a href="../../../../javax/xml/bind/annotation/XmlElementDecl.html" title="annotation in javax.xml.bind.annotation"><code>XmlElementDecl</code></a> on the substituted element. |
| |
| <p> If <a href="../../../../javax/xml/bind/annotation/XmlElementRef.html#type()"><code>type()</code></a> is not <tt>JAXBElement.class</tt>, then |
| the XML element name is the XML element name statically |
| associated with the type using the annotation <a href="../../../../javax/xml/bind/annotation/XmlRootElement.html" title="annotation in javax.xml.bind.annotation"><code>XmlRootElement</code></a> on the type. If the type is not annotated with |
| an <a href="../../../../javax/xml/bind/annotation/XmlElementDecl.html" title="annotation in javax.xml.bind.annotation"><code>XmlElementDecl</code></a>, then it is an error. |
| |
| <p> If <tt>type()</tt> is not <tt>JAXBElement.class</tt>, then |
| this value must be "".</div> |
| <dl> |
| <dt>Default:</dt> |
| <dd>""</dd> |
| </dl> |
| </li> |
| </ul> |
| <a name="name()"> |
| <!-- --> |
| </a> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <h4>name</h4> |
| <pre>public abstract java.lang.String name</pre> |
| <dl><dt><span class="strong">See Also:</span></dt><dd><a href="../../../../javax/xml/bind/annotation/XmlElementRef.html#namespace()"><code>namespace()</code></a></dd></dl> |
| <dl> |
| <dt>Default:</dt> |
| <dd>"##default"</dd> |
| </dl> |
| </li> |
| </ul> |
| <a name="required()"> |
| <!-- --> |
| </a> |
| <ul class="blockListLast"> |
| <li class="blockList"> |
| <h4>required</h4> |
| <pre>public abstract boolean required</pre> |
| <div class="block">Customize the element declaration to be required. |
| <p> |
| If required() is true, then Javabean property is mapped to |
| an XML schema element declaration with minOccurs="1". |
| maxOccurs is "1" for a single valued property and "unbounded" |
| for a multivalued property. |
| |
| <p> |
| If required() is false, then the Javabean property is mapped |
| to XML Schema element declaration with minOccurs="0". |
| maxOccurs is "1" for a single valued property and "unbounded" |
| for a multivalued property. |
| |
| <p> |
| For compatibility with JAXB 2.1, this property defaults to <tt>true</tt>, |
| despite the fact that <a href="../../../../javax/xml/bind/annotation/XmlElement.html#required()"><code>XmlElement.required()</code></a> defaults to false.</div> |
| <dl><dt><span class="strong">Since:</span></dt> |
| <dd>2.2</dd></dl> |
| <dl> |
| <dt>Default:</dt> |
| <dd>true</dd> |
| </dl> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| </div> |
| </div> |
| <!-- ========= END OF CLASS DATA ========= --> |
| <!-- ======= START OF BOTTOM NAVBAR ====== --> |
| <div class="bottomNav"><a name="navbar_bottom"> |
| <!-- --> |
| </a><a href="#skip-navbar_bottom" title="Skip navigation links"></a><a name="navbar_bottom_firstrow"> |
| <!-- --> |
| </a> |
| <ul class="navList" title="Navigation"> |
| <li><a href="../../../../overview-summary.html">Overview</a></li> |
| <li><a href="package-summary.html">Package</a></li> |
| <li class="navBarCell1Rev">Class</li> |
| <li><a href="package-tree.html">Tree</a></li> |
| <li><a href="../../../../deprecated-list.html">Deprecated</a></li> |
| <li><a href="../../../../index-all.html">Index</a></li> |
| <li><a href="../../../../help-doc.html">Help</a></li> |
| </ul> |
| <div class="aboutLanguage"><em>EclipseLink 2.5.1, build 'v20130918-f2b9fc5' API Reference</em></div> |
| </div> |
| <div class="subNav"> |
| <ul class="navList"> |
| <li><a href="../../../../javax/xml/bind/annotation/XmlElementDecl.GLOBAL.html" title="class in javax.xml.bind.annotation"><span class="strong">Prev Class</span></a></li> |
| <li><a href="../../../../javax/xml/bind/annotation/XmlElementRef.DEFAULT.html" title="class in javax.xml.bind.annotation"><span class="strong">Next Class</span></a></li> |
| </ul> |
| <ul class="navList"> |
| <li><a href="../../../../index.html?javax/xml/bind/annotation/XmlElementRef.html" target="_top">Frames</a></li> |
| <li><a href="XmlElementRef.html" target="_top">No Frames</a></li> |
| </ul> |
| <ul class="navList" id="allclasses_navbar_bottom"> |
| <li><a href="../../../../allclasses-noframe.html">All Classes</a></li> |
| </ul> |
| <div> |
| <script type="text/javascript"><!-- |
| allClassesLink = document.getElementById("allclasses_navbar_bottom"); |
| if(window==top) { |
| allClassesLink.style.display = "block"; |
| } |
| else { |
| allClassesLink.style.display = "none"; |
| } |
| //--> |
| </script> |
| </div> |
| <div> |
| <ul class="subNavList"> |
| <li>Summary: </li> |
| <li>Required | </li> |
| <li><a href="#annotation_type_optional_element_summary">Optional</a></li> |
| </ul> |
| <ul class="subNavList"> |
| <li>Detail: </li> |
| <li><a href="#annotation_type_element_detail">Element</a></li> |
| </ul> |
| </div> |
| <a name="skip-navbar_bottom"> |
| <!-- --> |
| </a></div> |
| <!-- ======== END OF BOTTOM NAVBAR ======= --> |
| </body> |
| </html> |