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 class or an enum type to a XML Schema type. 325N/A * <p> The <tt>@XmlType</tt> annnotation can be used with the following program 325N/A * <li> a top level class </li> 325N/A * <li> an enum type </li> 325N/A * <p>See "Package Specification" in javax.xml.bind.package javadoc for 325N/A * additional common information.</p> 325N/A * <h3> Mapping a Class </h3> 325N/A * A class maps to a XML Schema type. A class is a data container for 325N/A * values represented by properties and fields. A schema type is a 325N/A * data container for values represented by schema components within a 325N/A * schema type's content model (e.g. model groups, attributes etc). 325N/A * <p> To be mapped, a class must either have a public no-arg 325N/A * constructor or a static no-arg factory method. The static factory 325N/A * method can be specified in <tt>factoryMethod()</tt> and 325N/A * <tt>factoryClass()</tt> annotation elements. The static factory 325N/A * method or the no-arg constructor is used during unmarshalling to 325N/A * create an instance of this class. If both are present, the static 325N/A * factory method overrides the no-arg constructor. 325N/A * A class maps to either a XML Schema complex type or a XML Schema simple 325N/A * type. The XML Schema type is derived based on the 325N/A * mapping of JavaBean properties and fields contained within the 325N/A * class. The schema type to which the class is mapped can either be 325N/A * named or anonymous. A class can be mapped to an anonymous schema 325N/A * type by annotating the class with <tt>@XmlType(name="")</tt>. 325N/A * Either a global element, local element or a local attribute can be 325N/A * associated with an anonymous type as follows: 325N/A * <li><b>global element: </b> A global element of an anonymous 325N/A * type can be derived by annotating the class with @{@link 325N/A * XmlRootElement}. See Example 3 below. </li> 325N/A * <li><b>local element: </b> A JavaBean property that references 325N/A * a class annotated with @XmlType(name="") and is mapped to the 325N/A * element associated with the anonymous type. See Example 4 325N/A * <li><b>attribute: </b> A JavaBean property that references 325N/A * a class annotated with @XmlType(name="") and is mapped to the 325N/A * attribute associated with the anonymous type. See Example 5 below. </li> 325N/A * <b> Mapping to XML Schema Complex Type </b> 325N/A * <li>If class is annotated with <tt>@XmlType(name="") </tt>, it 325N/A * is mapped to an anonymous type otherwise, the class name maps 325N/A * to a complex type name. The <tt>XmlName()</tt> annotation element 325N/A * can be used to customize the name.</li> 325N/A * <li> Properties and fields that are mapped to elements are mapped to a 325N/A * content model within a complex type. The annotation element 325N/A * <tt>propOrder()</tt> can be used to customize the content model to be 325N/A * <tt>xs:all</tt> or <tt>xs:sequence</tt>. It is used for specifying 325N/A * the order of XML elements in <tt>xs:sequence</tt>. </li> 325N/A * <li> Properties and fields can be mapped to attributes within the 325N/A * <li> The targetnamespace of the XML Schema type can be customized 325N/A * using the annotation element <tt>namespace()</tt>. </li> 325N/A * <b> Mapping class to XML Schema simple type </b> 325N/A * A class can be mapped to a XML Schema simple type using the 325N/A * <tt>@XmlValue</tt> annotation. For additional details and examples, 325N/A * see @{@link XmlValue} annotation type. 325N/A * The following table shows the mapping of the class to a XML Schema 325N/A * complex type or simple type. The notational symbols used in the table are: 325N/A * <li> -> : represents a mapping </li> 325N/A * <li> [x]+ : one or more occurances of x </li> 325N/A * <li> [ <tt>@XmlValue</tt> property ]: JavaBean property annotated with 325N/A * <tt>@XmlValue</tt></li> 325N/A * <table border="1" cellpadding="4" cellspacing="3"> 325N/A * <td><b>Target</b></td> 325N/A * <td><b>propOrder</b></td> 325N/A * <td><b>ClassBody</b></td> 325N/A * <td><b>ComplexType</b></td> 325N/A * <td><b>SimpleType</b></td> 325N/A * <td>[property]+ -> elements</td> 325N/A * <td>complexcontent<br>xs:all</td> 325N/A * <td>[property]+ -> elements</td> 325N/A * <td>complexcontent<br>xs:sequence</td> 325N/A * <td>no property -> element</td> 325N/A * <td>complexcontent<br>empty sequence</td> 325N/A * <td>1 [ <tt>@XmlValue</tt> property] && <br> [property]+ 325N/A * <td>simplecontent</td> 325N/A * <td>1 [ <tt>@XmlValue</tt> property ]&& <br> no properties 325N/A * <h3> Mapping an enum type </h3> 325N/A * An enum type maps to a XML schema simple type with enumeration 325N/A * facets. The following annotation elements are ignored since they 325N/A * are not meaningful: <tt>propOrder()</tt> , <tt>factoryMethod()</tt> , 325N/A * <tt>factoryClass()</tt> . 325N/A * <h3> Usage with other annotations </h3> 325N/A * <p> This annotation can be used with the following annotations: 325N/A * {@link XmlRootElement}, {@link XmlAccessorOrder}, {@link XmlAccessorType}, 325N/A * {@link XmlEnum}. However, {@link 325N/A * XmlAccessorOrder} and {@link XmlAccessorType} are ignored when this 325N/A * annotation is used on an enum type. 325N/A * <p> <b> Example 1: </b> Map a class to a complex type with 325N/A * xs:sequence with a customized ordering of JavaBean properties. 325N/A * @XmlType(propOrder={"street", "city" , "state", "zip", "name" }) 325N/A * public class USAddress { 325N/A * String getName() {..}; 325N/A * void setName(String) {..}; 325N/A * String getStreet() {..}; 325N/A * void setStreet(String) {..}; 325N/A * String getCity() {..}; 325N/A * void setCity(String) {..}; 325N/A * String getState() {..}; 325N/A * void setState(String) {..}; 325N/A * java.math.BigDecimal getZip() {..}; 325N/A * void setZip(java.math.BigDecimal) {..}; 325N/A * <!-- XML Schema mapping for USAddress --> 325N/A * <xs:complexType name="USAddress"> 325N/A * <xs:element name="street" type="xs:string"/> 325N/A * <xs:element name="city" type="xs:string"/> 325N/A * <xs:element name="state" type="xs:string"/> 325N/A * <xs:element name="zip" type="xs:decimal"/> 325N/A * <xs:element name="name" type="xs:string"/> 325N/A * <p> <b> Example 2: </b> Map a class to a complex type with 325N/A * @XmlType(propOrder={}) 325N/A * public class USAddress { ...} 325N/A * <!-- XML Schema mapping for USAddress --> 325N/A * <xs:complexType name="USAddress"> 325N/A * <xs:element name="name" type="xs:string"/> 325N/A * <xs:element name="street" type="xs:string"/> 325N/A * <xs:element name="city" type="xs:string"/> 325N/A * <xs:element name="state" type="xs:string"/> 325N/A * <xs:element name="zip" type="xs:decimal"/> 325N/A * <p> <b> Example 3: </b> Map a class to a global element with an 325N/A * @XmlType(name="") 325N/A * public class USAddress { ...} 325N/A * <!-- XML Schema mapping for USAddress --> 325N/A * <xs:element name="USAddress"> 325N/A * <xs:element name="name" type="xs:string"/> 325N/A * <xs:element name="street" type="xs:string"/> 325N/A * <xs:element name="city" type="xs:string"/> 325N/A * <xs:element name="state" type="xs:string"/> 325N/A * <xs:element name="zip" type="xs:decimal"/> 325N/A * <p> <b> Example 4: </b> Map a property to a local element with 325N/A * //Example: Code fragment 325N/A * public class Invoice { 325N/A * @XmlType(name="") 325N/A * public class USAddress { ... } 325N/A * <!-- XML Schema mapping for USAddress --> 325N/A * <xs:complexType name="Invoice"> 325N/A * <xs:element name="addr"> 325N/A * <xs:element name="name", type="xs:string"/> 325N/A * <xs:element name="city", type="xs:string"/> 325N/A * <xs:element name="city" type="xs:string"/> 325N/A * <xs:element name="state" type="xs:string"/> 325N/A * <xs:element name="zip" type="xs:decimal"/> 325N/A * <p> <b> Example 5: </b> Map a property to an attribute with 325N/A * //Example: Code fragment 325N/A * public USPrice price; 325N/A * // map class to anonymous simple type. 325N/A * @XmlType(name="") 325N/A * public class USPrice { 325N/A * public java.math.BigDecimal price; 325N/A * <!-- Example: XML Schema fragment --> 325N/A * <xs:complexType name="Item"> 325N/A * <xs:element name="name" type="xs:string"/> 325N/A * <xs:attribute name="price"> 325N/A * <xs:restriction base="xs:decimal"/> 325N/A * <p> <b> Example 6: </b> Define a factoryClass and factoryMethod 325N/A * @XmlType(name="USAddressType", factoryClass=USAddressFactory.class, 325N/A * factoryMethod="getUSAddress") 325N/A * public class USAddress { 325N/A * private String state; 325N/A * private String street; 325N/A * public USAddress(String name, String street, String city, 325N/A * String state, int zip) { 325N/A * this.street = street; 325N/A * public class USAddressFactory { 325N/A * public static USAddress getUSAddress(){ 325N/A * return new USAddress("Mark Baker", "23 Elm St", 325N/A * "Dayton", "OH", 90952); 325N/A * <p> <b> Example 7: </b> Define factoryMethod and use the default factoryClass 325N/A * @XmlType(name="USAddressType", factoryMethod="getNewInstance") 325N/A * public class USAddress { 325N/A * private String state; 325N/A * private String street; 325N/A * private USAddress() {} 325N/A * public static USAddress getNewInstance(){ 325N/A * return new USAddress(); 325N/A * @author Sekhar Vajjhala, Sun Microsystems, Inc. 325N/A * Name of the XML Schema type which the class is mapped. 325N/A * Specifies the order for XML Schema elements when class is 325N/A * mapped to a XML Schema complex type. 325N/A * <p> Refer to the table for how the propOrder affects the 325N/A * mapping of class </p> 325N/A * <p> The propOrder is a list of names of JavaBean properties in 325N/A * the class. Each name in the list is the name of a Java 325N/A * identifier of the JavaBean property. The order in which 325N/A * JavaBean properties are listed is the order of XML Schema 325N/A * elements to which the JavaBean properties are mapped. </p> 325N/A * <p> All of the JavaBean properties being mapped to XML Schema elements 325N/A * <p> A JavaBean property or field listed in propOrder must not 325N/A * be transient or annotated with <tt>@XmlTransient</tt>. 325N/A * <p> The default ordering of JavaBean properties is determined 325N/A * by @{@link XmlAccessorOrder}. 325N/A * Name of the target namespace of the XML Schema type. By 325N/A * default, this is the target namespace to which the package 325N/A * containing the class is mapped. 325N/A * Class containing a no-arg factory method for creating an 325N/A * instance of this class. The default is this class. 325N/A * <p>If <tt>factoryClass</tt> is DEFAULT.class and 325N/A * <tt>factoryMethod</tt> is "", then there is no static factory 325N/A * <p>If <tt>factoryClass</tt> is DEFAULT.class and 325N/A * <tt>factoryMethod</tt> is not "", then 325N/A * <tt>factoryMethod</tt> is the name of a static factory method 325N/A * <p>If <tt>factoryClass</tt> is not DEFAULT.class, then 325N/A * <tt>factoryMethod</tt> must not be "" and must be the name of 325N/A * a static factory method specified in <tt>factoryClass</tt>. 325N/A * Used in {@link XmlType#factoryClass()} to 325N/A * signal that either factory mehod is not used or 325N/A * that it's in the class with this {@link XmlType} itself. 325N/A * Name of a no-arg factory method in the class specified in 325N/A * <tt>factoryClass</tt> factoryClass().