325N/A * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved. 325N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 325N/A * This code is free software; you can redistribute it and/or modify it 325N/A * under the terms of the GNU General Public License version 2 only, as 325N/A * published by the Free Software Foundation. Oracle designates this 325N/A * particular file as subject to the "Classpath" exception as provided 325N/A * by Oracle in the LICENSE file that accompanied this code. 325N/A * This code is distributed in the hope that it will be useful, but WITHOUT 325N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 325N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 325N/A * version 2 for more details (a copy is included in the LICENSE file that 325N/A * accompanied this code). 325N/A * You should have received a copy of the GNU General Public License version 325N/A * 2 along with this work; if not, write to the Free Software Foundation, 325N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 325N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 325N/A * or visit www.oracle.com if you need additional information or have any 325N/A * Maps a JavaBean property to a XML element derived from property's type. 325N/A * <tt>@XmlElementRef</tt> annotation can be used with a 325N/A * JavaBean property or from within {@link XmlElementRefs} 325N/A * This annotation dynamically associates an XML element name with the JavaBean 325N/A * property. When a JavaBean property is annotated with {@link 325N/A * XmlElement}, the XML element name is statically derived from the 325N/A * JavaBean property name. However, when this annotation is used, the 325N/A * XML element name is derived from the instance of the type of the 325N/A * JavaBean property at runtime. 325N/A * <h3> XML Schema substitution group support </h3> 325N/A * XML Schema allows a XML document author to use XML element names 325N/A * that were not statically specified in the content model of a 325N/A * schema using substitution groups. Schema derived code provides 325N/A * support for substitution groups using an <i>element property</i>, 325N/A * (section 5.5.5, "Element Property" of JAXB 2.0 specification). An 325N/A * element property method signature is of the form: 325N/A * public void setTerm(JAXBElement<? extends Operator>); 325N/A * public JAXBElement<? extends Operator> getTerm(); 325N/A * An element factory method annotated with {@link XmlElementDecl} is 325N/A * used to create a <tt>JAXBElement</tt> instance, containing an XML 325N/A * element name. The presence of @XmlElementRef annotation on an 325N/A * element property indicates that the element name from <tt>JAXBElement</tt> 325N/A * instance be used instead of deriving an XML element name from the 325N/A * JavaBean property name. 325N/A * The usage is subject to the following constraints: 325N/A * <li> If the collection item type (for collection property) or 325N/A * property type (for single valued property) is 325N/A * <tt>@XmlElementRef}.name()</tt> and <tt>@XmlElementRef.namespace()</tt> must 325N/A * point an element factory method with an @XmlElementDecl 325N/A * annotation in a class annotated with @XmlRegistry (usually 325N/A * ObjectFactory class generated by the schema compiler) : 325N/A * <li> @XmlElementDecl.name() must equal @XmlElementRef.name() </li> 325N/A * <li> @XmlElementDecl.namespace() must equal @XmlElementRef.namespace(). </li> 325N/A * <li> If the collection item type (for collection property) or 325N/A * property type (for single valued property) is not 325N/A * {@link javax.xml.bind.JAXBElement}, then the type referenced by the 325N/A * property or field must be annotated with {@link XmlRootElement}. </li> 325N/A * <li> This annotation can be used with the following annotations: 325N/A * {@link XmlElementWrapper}, {@link XmlJavaTypeAdapter}. 325N/A * <p>See "Package Specification" in javax.xml.bind.package javadoc for 325N/A * additional common information.</p> 325N/A * <p><b>Example 1: Ant Task Example</b></p> 325N/A * The following Java class hierarchy models an Ant build 325N/A * script. An Ant task corresponds to a class in the class 325N/A * hierarchy. The XML element name of an Ant task is indicated by the 325N/A * @XmlRootElement annotation on its corresponding class. 325N/A * @XmlRootElement(name="target") 325N/A * // The presence of @XmlElementRef indicates that the XML 325N/A * // element name will be derived from the @XmlRootElement 325N/A * // annotation on the type (for e.g. "jar" for JarTask). 325N/A * abstract class Task { 325N/A * @XmlRootElement(name="jar") 325N/A * class JarTask extends Task { 325N/A * @XmlRootElement(name="javac") 325N/A * class JavacTask extends Task { 325N/A * <!-- XML Schema fragment --> 325N/A * <xs:element name="target" type="Target"> 325N/A * <xs:complexType name="Target"> 325N/A * <xs:choice maxOccurs="unbounded"> 325N/A * <xs:element ref="jar"> 325N/A * <xs:element ref="javac"> 325N/A * Thus the following code fragment: 325N/A * Target target = new Target(); 325N/A * target.tasks.add(new JarTask()); 325N/A * target.tasks.add(new JavacTask()); 325N/A * will produce the following XML output: 325N/A * It is not an error to have a class that extends <tt>Task</tt> 325N/A * that doesn't have {@link XmlRootElement}. But they can't show up in an 325N/A * XML instance (because they don't have XML element names). 325N/A * <p><b>Example 2: XML Schema Susbstitution group support</b> 325N/A * <p> The following example shows the annotations for XML Schema 325N/A * substitution groups. The annotations and the ObjectFactory are 325N/A * derived from the schema. 325N/A * // The value of {@link #type()}is 325N/A * // JAXBElement.class , which indicates the XML 325N/A * // element name ObjectFactory - in general a class marked 325N/A * // with @XmlRegistry. (See ObjectFactory below) 325N/A * // The {@link #name()} is "operator", a pointer to a 325N/A * // factory method annotated with a 325N/A * // {@link XmlElementDecl} with the name "operator". Since 325N/A * // "operator" is the head of a substitution group that 325N/A * // contains elements "add" and "sub" elements, "operator" 325N/A * // element can be substituted in an instance document by 325N/A * // elements "add" or "sub". At runtime, JAXBElement 325N/A * // instance contains the element name that has been 325N/A * // substituted in the XML document. 325N/A * @XmlElementRef(type=JAXBElement.class,name="operator") 325N/A * JAXBElement<? extends Operator> term; 325N/A * class ObjectFactory { 325N/A * @XmlElementDecl(name="operator") 325N/A * JAXBElement<Operator> createOperator(Operator o) {...} 325N/A * @XmlElementDecl(name="add",substitutionHeadName="operator") 325N/A * JAXBElement<Operator> createAdd(Operator o) {...} 325N/A * @XmlElementDecl(name="sub",substitutionHeadName="operator") 325N/A * JAXBElement<Operator> createSub(Operator o) {...} 325N/A * Thus, the following code fragment 325N/A * m.term = new ObjectFactory().createAdd(new Operator()); 325N/A * will produce the following XML output: 325N/A * @author <ul><li>Kohsuke Kawaguchi, Sun Microsystems,Inc. </li><li>Sekhar Vajjhala, Sun Microsystems, Inc.</li></ul> 325N/A * The Java type being referenced. 325N/A * If the value is DEFAULT.class, the type is inferred from the 325N/A * the type of the JavaBean property. 325N/A * This parameter and {@link #name()} are used to determine the 325N/A * XML element for the JavaBean property. 325N/A * <p> If <tt>type()</tt> is <tt>JAXBElement.class</tt> , then 325N/A * <tt>namespace()</tt> and <tt>name()</tt> 325N/A * point to a factory method with {@link XmlElementDecl}. The XML 325N/A * element name is the element name from the factory method's 325N/A * {@link XmlElementDecl} annotation or if an element from its 325N/A * substitution group (of which it is a head element) has been 325N/A * substituted in the XML document, then the element name is from the 325N/A * {@link XmlElementDecl} on the substituted element. 325N/A * <p> If {@link #type()} is not <tt>JAXBElement.class</tt>, then 325N/A * the XML element name is the XML element name statically 325N/A * associated with the type using the annotation {@link 325N/A * XmlRootElement} on the type. If the type is not annotated with 325N/A * an {@link XmlElementDecl}, then it is an error. 325N/A * <p> If <tt>type()</tt> is not <tt>JAXBElement.class</tt>, then 325N/A * this value must be "". 325N/A * Used in {@link XmlElementRef#type()} to 325N/A * signal that the type be inferred from the signature 325N/A * Customize the element declaration to be required. 325N/A * If required() is true, then Javabean property is mapped to 325N/A * an XML schema element declaration with minOccurs="1". 325N/A * maxOccurs is "1" for a single valued property and "unbounded" 325N/A * for a multivalued property. 325N/A * If required() is false, then the Javabean property is mapped 325N/A * to XML Schema element declaration with minOccurs="0". 325N/A * maxOccurs is "1" for a single valued property and "unbounded" 325N/A * for a multivalued property. 325N/A * For compatibility with JAXB 2.1, this property defaults to <tt>true</tt>, 325N/A * despite the fact that {@link XmlElement#required()} defaults to false.