| <!DOCTYPE HTML> |
| <!-- NewPage --> |
| <html lang="en"> |
| <head> |
| <!-- Generated by javadoc (11.0.2) on Wed Apr 22 10:19:16 CDT 2020 --> |
| <title>XmlElementRef (EclipseLink 3.0.0, API Reference)</title> |
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> |
| <meta name="dc.created" content="2020-04-22"> |
| <link rel="stylesheet" type="text/css" href="../../../../stylesheet.css" title="Style"> |
| <link rel="stylesheet" type="text/css" href="../../../../jquery/jquery-ui.css" title="Style"> |
| <script type="text/javascript" src="../../../../script.js"></script> |
| <script type="text/javascript" src="../../../../jquery/jszip/dist/jszip.min.js"></script> |
| <script type="text/javascript" src="../../../../jquery/jszip-utils/dist/jszip-utils.min.js"></script> |
| <!--[if IE]> |
| <script type="text/javascript" src="../../../../jquery/jszip-utils/dist/jszip-utils-ie.min.js"></script> |
| <![endif]--> |
| <script type="text/javascript" src="../../../../jquery/jquery-3.3.1.js"></script> |
| <script type="text/javascript" src="../../../../jquery/jquery-migrate-3.0.1.js"></script> |
| <script type="text/javascript" src="../../../../jquery/jquery-ui.js"></script> |
| </head> |
| <body> |
| <script type="text/javascript"><!-- |
| try { |
| if (location.href.indexOf('is-external=true') == -1) { |
| parent.document.title="XmlElementRef (EclipseLink 3.0.0, API Reference)"; |
| } |
| } |
| catch(err) { |
| } |
| //--> |
| var pathtoroot = "../../../../"; |
| var useModuleDirectories = true; |
| loadScripts(document, 'script');</script> |
| <noscript> |
| <div>JavaScript is disabled on your browser.</div> |
| </noscript> |
| <header role="banner"> |
| <nav role="navigation"> |
| <div class="fixedNav"> |
| <!-- ========= START OF TOP NAVBAR ======= --> |
| <div class="topNav"><a id="navbar.top"> |
| <!-- --> |
| </a> |
| <div class="skipNav"><a href="#skip.navbar.top" title="Skip navigation links">Skip navigation links</a></div> |
| <a id="navbar.top.firstrow"> |
| <!-- --> |
| </a> |
| <ul class="navList" title="Navigation"> |
| <li><a href="../../../../index.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">EclipseLink 3.0.0, API Reference</div> |
| </div> |
| <div class="subNav"> |
| <ul class="navList" id="allclasses_navbar_top"> |
| <li><a href="../../../../allclasses.html">All Classes</a></li> |
| </ul> |
| <ul class="navListSearch"> |
| <li><label for="search">SEARCH:</label> |
| <input type="text" id="search" value="search" disabled="disabled"> |
| <input type="reset" id="reset" value="reset" disabled="disabled"> |
| </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> |
| <noscript> |
| <div>JavaScript is disabled on your browser.</div> |
| </noscript> |
| </div> |
| <div> |
| <ul class="subNavList"> |
| <li>Summary: </li> |
| <li>Field | </li> |
| <li>Required | </li> |
| <li><a href="#annotation.type.optional.element.summary">Optional</a></li> |
| </ul> |
| <ul class="subNavList"> |
| <li>Detail: </li> |
| <li>Field | </li> |
| <li><a href="#annotation.type.element.detail">Element</a></li> |
| </ul> |
| </div> |
| <a id="skip.navbar.top"> |
| <!-- --> |
| </a></div> |
| <!-- ========= END OF TOP NAVBAR ========= --> |
| </div> |
| <div class="navPadding"> </div> |
| <script type="text/javascript"><!-- |
| $('.navPadding').css('padding-top', $('.fixedNav').css("height")); |
| //--> |
| </script> |
| </nav> |
| </header> |
| <!-- ======== START OF CLASS DATA ======== --> |
| <main role="main"> |
| <div class="header"> |
| <div class="subTitle"><span class="packageLabelInType">Package</span> <a href="package-summary.html">jakarta.xml.bind.annotation</a></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> |
| <pre><a href="https://docs.oracle.com/javase/8/docs/api/java/lang/annotation/Retention.html?is-external=true" title="class or interface in java.lang.annotation" class="externalLink">@Retention</a>(<a href="https://docs.oracle.com/javase/8/docs/api/java/lang/annotation/RetentionPolicy.html?is-external=true#RUNTIME" title="class or interface in java.lang.annotation" class="externalLink">RUNTIME</a>) |
| <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/annotation/Target.html?is-external=true" title="class or interface in java.lang.annotation" class="externalLink">@Target</a>({<a href="https://docs.oracle.com/javase/8/docs/api/java/lang/annotation/ElementType.html?is-external=true#FIELD" title="class or interface in java.lang.annotation" class="externalLink">FIELD</a>,<a href="https://docs.oracle.com/javase/8/docs/api/java/lang/annotation/ElementType.html?is-external=true#METHOD" title="class or interface in java.lang.annotation" class="externalLink">METHOD</a>}) |
| public @interface <span class="memberNameLabel">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> |
| <code>@XmlElementRef</code> annotation can be used with a |
| JavaBean property or from within <a href="XmlElementRefs.html" title="annotation in jakarta.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="XmlElement.html" title="annotation in jakarta.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. |
| |
| <h2> XML Schema substitution group support </h2> |
| 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><code> |
| public void setTerm(JAXBElement<? extends Operator>); |
| public JAXBElement<? extends Operator> getTerm(); |
| </code></pre> |
| <p> |
| An element factory method annotated with <a href="XmlElementDecl.html" title="annotation in jakarta.xml.bind.annotation"><code>XmlElementDecl</code></a> is |
| used to create a <code>JAXBElement</code> instance, containing an XML |
| element name. The presence of <code>@XmlElementRef</code> annotation on an |
| element property indicates that the element name from <code>JAXBElement</code> |
| 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="../JAXBElement.html" title="class in jakarta.xml.bind"><code>JAXBElement</code></a>, then |
| <code>@XmlElementRef.name()</code> and <code>@XmlElementRef.namespace()</code> 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="../JAXBElement.html" title="class in jakarta.xml.bind"><code>JAXBElement</code></a>, then the type referenced by the |
| property or field must be annotated with <a href="XmlRootElement.html" title="annotation in jakarta.xml.bind.annotation"><code>XmlRootElement</code></a>. </li> |
| <li> This annotation can be used with the following annotations: |
| <a href="XmlElementWrapper.html" title="annotation in jakarta.xml.bind.annotation"><code>XmlElementWrapper</code></a>, <a href="adapters/XmlJavaTypeAdapter.html" title="annotation in jakarta.xml.bind.annotation.adapters"><code>XmlJavaTypeAdapter</code></a>. |
| </ul> |
| |
| <p>See "Package Specification" in jakarta.xml.bind.package javadoc for |
| additional common information.</p> |
| |
| <p><b>Example 1: 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 { |
| ... |
| } |
| <code> |
| |
| <!-- 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> |
| |
| </code></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><code> |
| <target> |
| <jar> |
| .... |
| </jar> |
| <javac> |
| .... |
| </javac> |
| </target> |
| </code></pre> |
| <p> |
| It is not an error to have a class that extends <code>Task</code> |
| that doesn't have <a href="XmlRootElement.html" title="annotation in jakarta.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="#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="#name()"><code>name()</code></a> is "operator", a pointer to a |
| // factory method annotated with a |
| // <a href="XmlElementDecl.html" title="annotation in jakarta.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><code> |
| <math> |
| <add>...</add> |
| </math> |
| </code></pre></div> |
| <dl> |
| <dt><span class="seeLabel">See Also:</span></dt> |
| <dd><a href="XmlElementRefs.html" title="annotation in jakarta.xml.bind.annotation"><code>XmlElementRefs</code></a></dd> |
| <dt><span class="simpleTagLabel">Author:</span></dt> |
| <dd><ul><li>Kohsuke Kawaguchi, Sun Microsystems,Inc. </li><li>Sekhar Vajjhala, Sun Microsystems, Inc.</li></ul></dd> |
| <dt><span class="simpleTagLabel">Since:</span></dt> |
| <dd>1.6, JAXB 2.0</dd> |
| </dl> |
| </li> |
| </ul> |
| </div> |
| <div class="summary"> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <!-- =========== ANNOTATION TYPE OPTIONAL MEMBER SUMMARY =========== --> |
| <section role="region"> |
| <ul class="blockList"> |
| <li class="blockList"><a id="annotation.type.optional.element.summary"> |
| <!-- --> |
| </a> |
| <h3>Optional Element Summary</h3> |
| <table class="memberSummary"> |
| <caption><span>Optional Elements</span><span class="tabEnd"> </span></caption> |
| <tr> |
| <th class="colFirst" scope="col">Modifier and Type</th> |
| <th class="colSecond" scope="col">Optional Element</th> |
| <th class="colLast" scope="col">Description</th> |
| </tr> |
| <tr class="altColor"> |
| <td class="colFirst"><code><a href="https://docs.oracle.com/javase/8/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang" class="externalLink">String</a></code></td> |
| <th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#name()">name</a></span></code></th> |
| <td class="colLast"> </td> |
| </tr> |
| <tr class="rowColor"> |
| <td class="colFirst"><code><a href="https://docs.oracle.com/javase/8/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang" class="externalLink">String</a></code></td> |
| <th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#namespace()">namespace</a></span></code></th> |
| <td class="colLast"> |
| <div class="block">This parameter and <a href="#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> |
| <th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#required()">required</a></span></code></th> |
| <td class="colLast"> |
| <div class="block">Customize the element declaration to be required.</div> |
| </td> |
| </tr> |
| <tr class="rowColor"> |
| <td class="colFirst"><code><a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Class.html?is-external=true" title="class or interface in java.lang" class="externalLink">Class</a></code></td> |
| <th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#type()">type</a></span></code></th> |
| <td class="colLast"> |
| <div class="block">The Java type being referenced.</div> |
| </td> |
| </tr> |
| </table> |
| </li> |
| </ul> |
| </section> |
| </li> |
| </ul> |
| </div> |
| <div class="details"> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <!-- ============ ANNOTATION TYPE MEMBER DETAIL =========== --> |
| <section role="region"> |
| <ul class="blockList"> |
| <li class="blockList"><a id="annotation.type.element.detail"> |
| <!-- --> |
| </a> |
| <h3>Element Detail</h3> |
| <a id="type()"> |
| <!-- --> |
| </a> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <h4>type</h4> |
| <pre><a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Class.html?is-external=true" title="class or interface in java.lang" class="externalLink">Class</a> 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>jakarta.xml.bind.annotation.XmlElementRef.DEFAULT.class</dd> |
| </dl> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| </section> |
| <section role="region"> |
| <ul class="blockList"> |
| <li class="blockList"><a id="namespace()"> |
| <!-- --> |
| </a> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <h4>namespace</h4> |
| <pre><a href="https://docs.oracle.com/javase/8/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang" class="externalLink">String</a> namespace</pre> |
| <div class="block">This parameter and <a href="#name()"><code>name()</code></a> are used to determine the |
| XML element for the JavaBean property. |
| |
| <p> If <code>type()</code> is <code>JAXBElement.class</code> , then |
| <code>namespace()</code> and <code>name()</code> |
| point to a factory method with <a href="XmlElementDecl.html" title="annotation in jakarta.xml.bind.annotation"><code>XmlElementDecl</code></a>. The XML |
| element name is the element name from the factory method's |
| <a href="XmlElementDecl.html" title="annotation in jakarta.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="XmlElementDecl.html" title="annotation in jakarta.xml.bind.annotation"><code>XmlElementDecl</code></a> on the substituted element. |
| |
| <p> If <a href="#type()"><code>type()</code></a> is not <code>JAXBElement.class</code>, then |
| the XML element name is the XML element name statically |
| associated with the type using the annotation <a href="XmlRootElement.html" title="annotation in jakarta.xml.bind.annotation"><code>XmlRootElement</code></a> on the type. If the type is not annotated with |
| an <a href="XmlElementDecl.html" title="annotation in jakarta.xml.bind.annotation"><code>XmlElementDecl</code></a>, then it is an error. |
| |
| <p> If <code>type()</code> is not <code>JAXBElement.class</code>, then |
| this value must be "".</div> |
| <dl> |
| <dt>Default:</dt> |
| <dd>""</dd> |
| </dl> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| </section> |
| <section role="region"> |
| <ul class="blockList"> |
| <li class="blockList"><a id="name()"> |
| <!-- --> |
| </a> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <h4>name</h4> |
| <pre><a href="https://docs.oracle.com/javase/8/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang" class="externalLink">String</a> name</pre> |
| <dl> |
| <dt><span class="seeLabel">See Also:</span></dt> |
| <dd><a href="#namespace()"><code>namespace()</code></a></dd> |
| </dl> |
| <dl> |
| <dt>Default:</dt> |
| <dd>"##default"</dd> |
| </dl> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| </section> |
| <section role="region"> |
| <ul class="blockList"> |
| <li class="blockList"><a id="required()"> |
| <!-- --> |
| </a> |
| <ul class="blockListLast"> |
| <li class="blockList"> |
| <h4>required</h4> |
| <pre>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 <code>true</code>, |
| despite the fact that <a href="XmlElement.html#required()"><code>XmlElement.required()</code></a> defaults to false.</div> |
| <dl> |
| <dt><span class="simpleTagLabel">Since:</span></dt> |
| <dd>1.7, JAXB 2.2</dd> |
| </dl> |
| <dl> |
| <dt>Default:</dt> |
| <dd>true</dd> |
| </dl> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| </section> |
| </li> |
| </ul> |
| </div> |
| </div> |
| </main> |
| <!-- ========= END OF CLASS DATA ========= --> |
| <footer role="contentinfo"> |
| <nav role="navigation"> |
| <!-- ======= START OF BOTTOM NAVBAR ====== --> |
| <div class="bottomNav"><a id="navbar.bottom"> |
| <!-- --> |
| </a> |
| <div class="skipNav"><a href="#skip.navbar.bottom" title="Skip navigation links">Skip navigation links</a></div> |
| <a id="navbar.bottom.firstrow"> |
| <!-- --> |
| </a> |
| <ul class="navList" title="Navigation"> |
| <li><a href="../../../../index.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">EclipseLink 3.0.0, API Reference</div> |
| </div> |
| <div class="subNav"> |
| <ul class="navList" id="allclasses_navbar_bottom"> |
| <li><a href="../../../../allclasses.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> |
| <noscript> |
| <div>JavaScript is disabled on your browser.</div> |
| </noscript> |
| </div> |
| <div> |
| <ul class="subNavList"> |
| <li>Summary: </li> |
| <li>Field | </li> |
| <li>Required | </li> |
| <li><a href="#annotation.type.optional.element.summary">Optional</a></li> |
| </ul> |
| <ul class="subNavList"> |
| <li>Detail: </li> |
| <li>Field | </li> |
| <li><a href="#annotation.type.element.detail">Element</a></li> |
| </ul> |
| </div> |
| <a id="skip.navbar.bottom"> |
| <!-- --> |
| </a></div> |
| <!-- ======== END OF BOTTOM NAVBAR ======= --> |
| </nav> |
| <p class="legalCopy"><small>Copyright © 2017–2020 <a href="http://www.eclipse.org/eclipselink">Eclipse.org - EclipseLink Project</a>. All rights reserved.</small></p> |
| </footer> |
| </body> |
| </html> |