< prev index next >

src/java.xml.bind/share/classes/javax/xml/bind/annotation/XmlType.java

Print this page


   1 /*
   2  * Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  47  *
  48  * <h3> Mapping a Class </h3>
  49  * <p>
  50  * A class maps to a XML Schema type. A class is a data container for
  51  * values represented by properties and fields. A schema type is a
  52  * data container for values represented by schema components within a
  53  * schema type's content model (e.g. model groups, attributes etc).
  54  * <p> To be mapped, a class must either have a public no-arg
  55  * constructor or a static no-arg factory method. The static factory
  56  * method can be specified in <tt>factoryMethod()</tt> and
  57  * <tt>factoryClass()</tt> annotation elements. The static factory
  58  * method or the no-arg constructor is used during unmarshalling to
  59  * create an instance of this class. If both are present, the static
  60  * factory method overrides the no-arg constructor.
  61  * <p>
  62  * A class maps to either a XML Schema complex type or a XML Schema simple
  63  * type. The XML Schema type is derived based on the
  64  * mapping of JavaBean properties and fields contained within the
  65  * class. The schema type to which the class is mapped can either be
  66  * named or anonymous. A class can be mapped to an anonymous schema
  67  * type by annotating the class with <tt>&#64XmlType(name="")</tt>.
  68  * <p>
  69  * Either a global element, local element or a local attribute can be
  70  * associated with an anonymous type as follows:
  71  * <ul>
  72  *   <li><b>global element: </b> A global element of an anonymous
  73  *      type can be derived by annotating the class with @{@link
  74  *      XmlRootElement}. See Example 3 below. </li>
  75  *
  76  *   <li><b>local element: </b> A JavaBean property that references
  77  *      a class annotated with @XmlType(name="") and is mapped to the
  78  *      element associated with the anonymous type. See Example 4
  79  *      below.</li>
  80  *
  81  *   <li><b>attribute: </b> A JavaBean property that references
  82  *      a class annotated with @XmlType(name="") and is mapped to the
  83  *      attribute associated with the anonymous type. See Example 5 below. </li>
  84  * </ul>
  85  * <b> Mapping to XML Schema Complex Type </b>
  86  * <ul>
  87  *   <li>If class is annotated with <tt>@XmlType(name="") </tt>, it


  95  *   <tt>xs:all</tt> or <tt>xs:sequence</tt>.  It is used for specifying
  96  *   the order of XML elements in <tt>xs:sequence</tt>. </li>
  97  *
  98  *   <li> Properties and fields can be mapped to attributes within the
  99  *        complex type.  </li>
 100  *
 101  *   <li> The targetnamespace of the XML Schema type can be customized
 102  *        using the annotation element <tt>namespace()</tt>. </li>
 103  * </ul>
 104  *
 105  * <p>
 106  * <b> Mapping class to XML Schema simple type </b>
 107  * <p>
 108  * A class can be mapped to a XML Schema simple type using the
 109  * <tt>@XmlValue</tt> annotation. For additional details and examples,
 110  * see @{@link XmlValue} annotation type.
 111  * <p>
 112  * The following table shows the mapping of the class to a XML Schema
 113  * complex type or simple type. The notational symbols used in the table are:
 114  * <ul>
 115  *   <li> ->    : represents a mapping </li>
 116  *   <li> [x]+  : one or more occurances of x </li>
 117  *   <li> [ <tt>@XmlValue</tt> property ]: JavaBean property annotated with
 118  *         <tt>@XmlValue</tt></li>
 119  *   <li> X     : don't care
 120  * </ul>
 121  * <blockquote>
 122  *   <table border="1" cellpadding="4" cellspacing="3">
 123  *     <tbody>
 124  *       <tr>
 125  *         <td><b>Target</b></td>
 126  *         <td><b>propOrder</b></td>
 127  *         <td><b>ClassBody</b></td>
 128  *         <td><b>ComplexType</b></td>
 129  *         <td><b>SimpleType</b></td>
 130  *       </tr>
 131  *
 132  *       <tr valign="top">
 133  *         <td>Class</td>
 134  *         <td>{}</td>
 135  *         <td>[property]+ -> elements</td>
 136  *         <td>complexcontent<br>xs:all</td>
 137  *         <td> </td>
 138  *       </tr>
 139  *
 140  *       <tr valign="top">
 141  *         <td>Class</td>
 142  *         <td>non empty</td>
 143  *         <td>[property]+ -> elements</td>
 144  *         <td>complexcontent<br>xs:sequence</td>
 145  *         <td> </td>
 146  *       </tr>
 147  *
 148  *       <tr valign="top">
 149  *         <td>Class</td>
 150  *         <td>X</td>
 151  *         <td>no property -> element</td>
 152  *         <td>complexcontent<br>empty sequence</td>
 153  *         <td> </td>
 154  *       </tr>
 155  *
 156  *       <tr valign="top">
 157  *         <td>Class</td>
 158  *         <td>X</td>
 159  *         <td>1 [ <tt>@XmlValue</tt> property] && <br> [property]+
 160  *             ->attributes</td>
 161  *         <td>simplecontent</td>
 162  *         <td> </td>
 163  *       </tr>
 164  *
 165  *       <tr valign="top">
 166  *         <td>Class</td>
 167  *         <td>X</td>
 168  *         <td>1 [ <tt>@XmlValue</tt> property ]&& <br> no properties
 169  *         -> attribute</td>
 170  *         <td> </td>
 171  *         <td>simpletype</td>
 172  *         <td> </td>
 173  *       </tr>
 174  *     </tbody>
 175  *   </table>
 176  * </blockquote>
 177  *
 178  * <h3> Mapping an enum type </h3>
 179  *
 180  * An enum type maps to a XML schema simple type with enumeration
 181  * facets. The following annotation elements are ignored since they
 182  * are not meaningful: <tt>propOrder()</tt> , <tt>factoryMethod()</tt> ,
 183  * <tt>factoryClass()</tt> .
 184  *
 185  *  <h3> Usage with other annotations </h3>
 186  * <p> This annotation can be used with the following annotations:
 187  * {@link XmlRootElement}, {@link XmlAccessorOrder}, {@link XmlAccessorType},
 188  * {@link XmlEnum}. However, {@link
 189  * XmlAccessorOrder} and {@link XmlAccessorType} are ignored when this
 190  * annotation is used on an enum type.
 191  *
 192  * <p> <b> Example 1: </b> Map a class to a complex type with


 195  *
 196  * <pre>
 197  *   @XmlType(propOrder={"street", "city" , "state", "zip", "name" })
 198  *   public class USAddress {
 199  *     String getName() {..};
 200  *     void setName(String) {..};
 201  *
 202  *     String getStreet() {..};
 203  *     void setStreet(String) {..};
 204  *
 205  *     String getCity() {..};
 206  *     void setCity(String) {..};
 207  *
 208  *     String getState() {..};
 209  *     void setState(String) {..};
 210  *
 211  *     java.math.BigDecimal getZip() {..};
 212  *     void setZip(java.math.BigDecimal) {..};
 213  *   }
 214  *
 215  *   &lt;!-- XML Schema mapping for USAddress -->
 216  *   &lt;xs:complexType name="USAddress">
 217  *     &lt;xs:sequence>
 218  *       &lt;xs:element name="street" type="xs:string"/>
 219  *       &lt;xs:element name="city" type="xs:string"/>
 220  *       &lt;xs:element name="state" type="xs:string"/>
 221  *       &lt;xs:element name="zip" type="xs:decimal"/>
 222  *       &lt;xs:element name="name" type="xs:string"/>
 223  *     &lt;/xs:all>
 224  *   &lt;/xs:complexType>
 225  * </pre>
 226  * <p> <b> Example 2: </b> Map a class to a complex type with
 227  *     xs:all </p>
 228  * <pre>
 229  * @XmlType(propOrder={})
 230  * public class USAddress { ...}
 231  *
 232  * &lt;!-- XML Schema mapping for USAddress -->
 233  * &lt;xs:complexType name="USAddress">
 234  *   &lt;xs:all>
 235  *     &lt;xs:element name="name" type="xs:string"/>
 236  *     &lt;xs:element name="street" type="xs:string"/>
 237  *     &lt;xs:element name="city" type="xs:string"/>
 238  *     &lt;xs:element name="state" type="xs:string"/>
 239  *     &lt;xs:element name="zip" type="xs:decimal"/>
 240  *   &lt;/xs:sequence>
 241  * &lt;/xs:complexType>
 242  *</pre>
 243  * <p> <b> Example 3: </b> Map a class to a global element with an
 244  * anonymous type.
 245  * </p>
 246  * <pre>
 247  *   @XmlRootElement
 248  *   @XmlType(name="")
 249  *   public class USAddress { ...}
 250  *
 251  *   &lt;!-- XML Schema mapping for USAddress -->
 252  *   &lt;xs:element name="USAddress">
 253  *     &lt;xs:complexType>
 254  *       &lt;xs:sequence>
 255  *         &lt;xs:element name="name" type="xs:string"/>
 256  *         &lt;xs:element name="street" type="xs:string"/>
 257  *         &lt;xs:element name="city" type="xs:string"/>
 258  *         &lt;xs:element name="state" type="xs:string"/>
 259  *         &lt;xs:element name="zip" type="xs:decimal"/>
 260  *       &lt;/xs:sequence>
 261  *     &lt;/xs:complexType>
 262  *   &lt;/xs:element>
 263  * </pre>
 264  *
 265  * <p> <b> Example 4: </b> Map a property to a local element with
 266  * anonmyous type.
 267  * <pre>
 268  *   //Example: Code fragment
 269  *   public class Invoice {
 270  *       USAddress addr;
 271  *           ...
 272  *       }
 273  *
 274  *   @XmlType(name="")
 275  *   public class USAddress { ... }
 276  *   }
 277  *
 278  *   &lt;!-- XML Schema mapping for USAddress -->
 279  *   &lt;xs:complexType name="Invoice">
 280  *     &lt;xs:sequence>
 281  *       &lt;xs:element name="addr">
 282  *         &lt;xs:complexType>
 283  *           &lt;xs:element name="name", type="xs:string"/>
 284  *           &lt;xs:element name="city", type="xs:string"/>
 285  *           &lt;xs:element name="city" type="xs:string"/>
 286  *           &lt;xs:element name="state" type="xs:string"/>
 287  *           &lt;xs:element name="zip" type="xs:decimal"/>
 288  *         &lt;/xs:complexType>
 289  *       ...
 290  *     &lt;/xs:sequence>
 291  *   &lt;/xs:complexType>
 292  * </pre>
 293  *
 294  * <p> <b> Example 5: </b> Map a property to an attribute with
 295  * anonymous type.
 296  *
 297  * <pre>
 298  *
 299  *     //Example: Code fragment
 300  *     public class Item {
 301  *         public String name;
 302  *         @XmlAttribute
 303  *         public USPrice price;
 304  *     }
 305  *
 306  *     // map class to anonymous simple type.
 307  *     @XmlType(name="")
 308  *     public class USPrice {
 309  *         @XmlValue
 310  *         public java.math.BigDecimal price;
 311  *     }
 312  *
 313  *     &lt;!-- Example: XML Schema fragment -->
 314  *     &lt;xs:complexType name="Item">
 315  *       &lt;xs:sequence>
 316  *         &lt;xs:element name="name" type="xs:string"/>
 317  *         &lt;xs:attribute name="price">
 318  *           &lt;xs:simpleType>
 319  *             &lt;xs:restriction base="xs:decimal"/>
 320  *           &lt;/xs:simpleType>
 321  *         &lt;/xs:attribute>
 322  *       &lt;/xs:sequence>
 323  *     &lt;/xs:complexType>
 324  * </pre>
 325  *
 326  *  <p> <b> Example 6: </b> Define a factoryClass and factoryMethod
 327  *
 328  * <pre>
 329  *      @XmlType(name="USAddressType", factoryClass=USAddressFactory.class,
 330  *      factoryMethod="getUSAddress")
 331  *      public class USAddress {
 332  *
 333  *          private String city;
 334  *          private String name;
 335  *          private String state;
 336  *          private String street;
 337  *          private int    zip;
 338  *
 339  *      public USAddress(String name, String street, String city,
 340  *          String state, int zip) {
 341  *          this.name = name;
 342  *          this.street = street;
 343  *          this.city = city;


   1 /*
   2  * Copyright (c) 2004, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  47  *
  48  * <h3> Mapping a Class </h3>
  49  * <p>
  50  * A class maps to a XML Schema type. A class is a data container for
  51  * values represented by properties and fields. A schema type is a
  52  * data container for values represented by schema components within a
  53  * schema type's content model (e.g. model groups, attributes etc).
  54  * <p> To be mapped, a class must either have a public no-arg
  55  * constructor or a static no-arg factory method. The static factory
  56  * method can be specified in <tt>factoryMethod()</tt> and
  57  * <tt>factoryClass()</tt> annotation elements. The static factory
  58  * method or the no-arg constructor is used during unmarshalling to
  59  * create an instance of this class. If both are present, the static
  60  * factory method overrides the no-arg constructor.
  61  * <p>
  62  * A class maps to either a XML Schema complex type or a XML Schema simple
  63  * type. The XML Schema type is derived based on the
  64  * mapping of JavaBean properties and fields contained within the
  65  * class. The schema type to which the class is mapped can either be
  66  * named or anonymous. A class can be mapped to an anonymous schema
  67  * type by annotating the class with <tt>@XmlType(name="")</tt>.
  68  * <p>
  69  * Either a global element, local element or a local attribute can be
  70  * associated with an anonymous type as follows:
  71  * <ul>
  72  *   <li><b>global element: </b> A global element of an anonymous
  73  *      type can be derived by annotating the class with @{@link
  74  *      XmlRootElement}. See Example 3 below. </li>
  75  *
  76  *   <li><b>local element: </b> A JavaBean property that references
  77  *      a class annotated with @XmlType(name="") and is mapped to the
  78  *      element associated with the anonymous type. See Example 4
  79  *      below.</li>
  80  *
  81  *   <li><b>attribute: </b> A JavaBean property that references
  82  *      a class annotated with @XmlType(name="") and is mapped to the
  83  *      attribute associated with the anonymous type. See Example 5 below. </li>
  84  * </ul>
  85  * <b> Mapping to XML Schema Complex Type </b>
  86  * <ul>
  87  *   <li>If class is annotated with <tt>@XmlType(name="") </tt>, it


  95  *   <tt>xs:all</tt> or <tt>xs:sequence</tt>.  It is used for specifying
  96  *   the order of XML elements in <tt>xs:sequence</tt>. </li>
  97  *
  98  *   <li> Properties and fields can be mapped to attributes within the
  99  *        complex type.  </li>
 100  *
 101  *   <li> The targetnamespace of the XML Schema type can be customized
 102  *        using the annotation element <tt>namespace()</tt>. </li>
 103  * </ul>
 104  *
 105  * <p>
 106  * <b> Mapping class to XML Schema simple type </b>
 107  * <p>
 108  * A class can be mapped to a XML Schema simple type using the
 109  * <tt>@XmlValue</tt> annotation. For additional details and examples,
 110  * see @{@link XmlValue} annotation type.
 111  * <p>
 112  * The following table shows the mapping of the class to a XML Schema
 113  * complex type or simple type. The notational symbols used in the table are:
 114  * <ul>
 115  *   <li> -&gt;    : represents a mapping </li>
 116  *   <li> [x]+  : one or more occurances of x </li>
 117  *   <li> [ <tt>@XmlValue</tt> property ]: JavaBean property annotated with
 118  *         <tt>@XmlValue</tt></li>
 119  *   <li> X     : don't care
 120  * </ul>
 121  * <blockquote>
 122  *   <table summary="" border="1" cellpadding="4" cellspacing="3">
 123  *     <tbody>
 124  *       <tr>
 125  *         <td><b>Target</b></td>
 126  *         <td><b>propOrder</b></td>
 127  *         <td><b>ClassBody</b></td>
 128  *         <td><b>ComplexType</b></td>
 129  *         <td><b>SimpleType</b></td>
 130  *       </tr>
 131  *
 132  *       <tr valign="top">
 133  *         <td>Class</td>
 134  *         <td>{}</td>
 135  *         <td>[property]+ -&gt; elements</td>
 136  *         <td>complexcontent<br>xs:all</td>
 137  *         <td> </td>
 138  *       </tr>
 139  *
 140  *       <tr valign="top">
 141  *         <td>Class</td>
 142  *         <td>non empty</td>
 143  *         <td>[property]+ -&gt; elements</td>
 144  *         <td>complexcontent<br>xs:sequence</td>
 145  *         <td> </td>
 146  *       </tr>
 147  *
 148  *       <tr valign="top">
 149  *         <td>Class</td>
 150  *         <td>X</td>
 151  *         <td>no property -&gt; element</td>
 152  *         <td>complexcontent<br>empty sequence</td>
 153  *         <td> </td>
 154  *       </tr>
 155  *
 156  *       <tr valign="top">
 157  *         <td>Class</td>
 158  *         <td>X</td>
 159  *         <td>1 [<tt>@XmlValue</tt> property] {@literal &&} <br> [property]+ -&gt; attributes</td>

 160  *         <td>simplecontent</td>
 161  *         <td> </td>
 162  *       </tr>
 163  *
 164  *       <tr valign="top">
 165  *         <td>Class</td>
 166  *         <td>X</td>
 167  *         <td>1 [<tt>@XmlValue</tt> property] {@literal &&} <br> no properties -&gt; attribute</td>

 168  *         <td> </td>
 169  *         <td>simpletype</td>

 170  *       </tr>
 171  *     </tbody>
 172  *   </table>
 173  * </blockquote>
 174  *
 175  * <h3> Mapping an enum type </h3>
 176  *
 177  * An enum type maps to a XML schema simple type with enumeration
 178  * facets. The following annotation elements are ignored since they
 179  * are not meaningful: <tt>propOrder()</tt> , <tt>factoryMethod()</tt> ,
 180  * <tt>factoryClass()</tt> .
 181  *
 182  *  <h3> Usage with other annotations </h3>
 183  * <p> This annotation can be used with the following annotations:
 184  * {@link XmlRootElement}, {@link XmlAccessorOrder}, {@link XmlAccessorType},
 185  * {@link XmlEnum}. However, {@link
 186  * XmlAccessorOrder} and {@link XmlAccessorType} are ignored when this
 187  * annotation is used on an enum type.
 188  *
 189  * <p> <b> Example 1: </b> Map a class to a complex type with


 192  *
 193  * <pre>
 194  *   @XmlType(propOrder={"street", "city" , "state", "zip", "name" })
 195  *   public class USAddress {
 196  *     String getName() {..};
 197  *     void setName(String) {..};
 198  *
 199  *     String getStreet() {..};
 200  *     void setStreet(String) {..};
 201  *
 202  *     String getCity() {..};
 203  *     void setCity(String) {..};
 204  *
 205  *     String getState() {..};
 206  *     void setState(String) {..};
 207  *
 208  *     java.math.BigDecimal getZip() {..};
 209  *     void setZip(java.math.BigDecimal) {..};
 210  *   }
 211  *
 212  *   &lt;!-- XML Schema mapping for USAddress --&gt;
 213  *   &lt;xs:complexType name="USAddress"&gt;
 214  *     &lt;xs:sequence&gt;
 215  *       &lt;xs:element name="street" type="xs:string"/&gt;
 216  *       &lt;xs:element name="city" type="xs:string"/&gt;
 217  *       &lt;xs:element name="state" type="xs:string"/&gt;
 218  *       &lt;xs:element name="zip" type="xs:decimal"/&gt;
 219  *       &lt;xs:element name="name" type="xs:string"/&gt;
 220  *     &lt;/xs:all&gt;
 221  *   &lt;/xs:complexType&gt;
 222  * </pre>
 223  * <p> <b> Example 2: </b> Map a class to a complex type with
 224  *     xs:all </p>
 225  * <pre>
 226  * @XmlType(propOrder={})
 227  * public class USAddress { ...}
 228  *
 229  * &lt;!-- XML Schema mapping for USAddress --&gt;
 230  * &lt;xs:complexType name="USAddress"&gt;
 231  *   &lt;xs:all&gt;
 232  *     &lt;xs:element name="name" type="xs:string"/&gt;
 233  *     &lt;xs:element name="street" type="xs:string"/&gt;
 234  *     &lt;xs:element name="city" type="xs:string"/&gt;
 235  *     &lt;xs:element name="state" type="xs:string"/&gt;
 236  *     &lt;xs:element name="zip" type="xs:decimal"/&gt;
 237  *   &lt;/xs:sequence&gt;
 238  * &lt;/xs:complexType&gt;
 239  *</pre>
 240  * <p> <b> Example 3: </b> Map a class to a global element with an
 241  * anonymous type.
 242  * </p>
 243  * <pre>
 244  *   @XmlRootElement
 245  *   @XmlType(name="")
 246  *   public class USAddress { ...}
 247  *
 248  *   &lt;!-- XML Schema mapping for USAddress --&gt;
 249  *   &lt;xs:element name="USAddress"&gt;
 250  *     &lt;xs:complexType&gt;
 251  *       &lt;xs:sequence&gt;
 252  *         &lt;xs:element name="name" type="xs:string"/&gt;
 253  *         &lt;xs:element name="street" type="xs:string"/&gt;
 254  *         &lt;xs:element name="city" type="xs:string"/&gt;
 255  *         &lt;xs:element name="state" type="xs:string"/&gt;
 256  *         &lt;xs:element name="zip" type="xs:decimal"/&gt;
 257  *       &lt;/xs:sequence&gt;
 258  *     &lt;/xs:complexType&gt;
 259  *   &lt;/xs:element&gt;
 260  * </pre>
 261  *
 262  * <p> <b> Example 4: </b> Map a property to a local element with
 263  * anonymous type.
 264  * <pre>
 265  *   //Example: Code fragment
 266  *   public class Invoice {
 267  *       USAddress addr;
 268  *           ...
 269  *       }
 270  *
 271  *   @XmlType(name="")
 272  *   public class USAddress { ... }
 273  *   }
 274  *
 275  *   &lt;!-- XML Schema mapping for USAddress --&gt;
 276  *   &lt;xs:complexType name="Invoice"&gt;
 277  *     &lt;xs:sequence&gt;
 278  *       &lt;xs:element name="addr"&gt;
 279  *         &lt;xs:complexType&gt;
 280  *           &lt;xs:element name="name", type="xs:string"/&gt;
 281  *           &lt;xs:element name="city", type="xs:string"/&gt;
 282  *           &lt;xs:element name="city" type="xs:string"/&gt;
 283  *           &lt;xs:element name="state" type="xs:string"/&gt;
 284  *           &lt;xs:element name="zip" type="xs:decimal"/&gt;
 285  *         &lt;/xs:complexType&gt;
 286  *       ...
 287  *     &lt;/xs:sequence&gt;
 288  *   &lt;/xs:complexType&gt;
 289  * </pre>
 290  *
 291  * <p> <b> Example 5: </b> Map a property to an attribute with
 292  * anonymous type.
 293  *
 294  * <pre>
 295  *
 296  *     //Example: Code fragment
 297  *     public class Item {
 298  *         public String name;
 299  *         @XmlAttribute
 300  *         public USPrice price;
 301  *     }
 302  *
 303  *     // map class to anonymous simple type.
 304  *     @XmlType(name="")
 305  *     public class USPrice {
 306  *         @XmlValue
 307  *         public java.math.BigDecimal price;
 308  *     }
 309  *
 310  *     &lt;!-- Example: XML Schema fragment --&gt;
 311  *     &lt;xs:complexType name="Item"&gt;
 312  *       &lt;xs:sequence&gt;
 313  *         &lt;xs:element name="name" type="xs:string"/&gt;
 314  *         &lt;xs:attribute name="price"&gt;
 315  *           &lt;xs:simpleType&gt;
 316  *             &lt;xs:restriction base="xs:decimal"/&gt;
 317  *           &lt;/xs:simpleType&gt;
 318  *         &lt;/xs:attribute&gt;
 319  *       &lt;/xs:sequence&gt;
 320  *     &lt;/xs:complexType&gt;
 321  * </pre>
 322  *
 323  *  <p> <b> Example 6: </b> Define a factoryClass and factoryMethod
 324  *
 325  * <pre>
 326  *      @XmlType(name="USAddressType", factoryClass=USAddressFactory.class,
 327  *      factoryMethod="getUSAddress")
 328  *      public class USAddress {
 329  *
 330  *          private String city;
 331  *          private String name;
 332  *          private String state;
 333  *          private String street;
 334  *          private int    zip;
 335  *
 336  *      public USAddress(String name, String street, String city,
 337  *          String state, int zip) {
 338  *          this.name = name;
 339  *          this.street = street;
 340  *          this.city = city;


< prev index next >