1 /*
   2  * Copyright (c) 2005, 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
  23  * questions.
  24  */
  25 
  26 package javax.xml.bind.annotation;
  27 
  28 import java.lang.annotation.Retention;
  29 import java.lang.annotation.Target;
  30 
  31 import static java.lang.annotation.ElementType.FIELD;
  32 import static java.lang.annotation.ElementType.METHOD;
  33 import static java.lang.annotation.ElementType.PACKAGE;
  34 import static java.lang.annotation.RetentionPolicy.RUNTIME;
  35 
  36 /**
  37  * Maps a Java type to a simple schema built-in type.
  38  *
  39  * <p> <b>Usage</b> </p>
  40  * <p>
  41  * <tt>@XmlSchemaType</tt> annotation can be used with the following program
  42  * elements:
  43  * <ul>
  44  *   <li> a JavaBean property </li>
  45  *   <li> field </li>
  46  *   <li> package</li>
  47  * </ul>
  48  *
  49  * <p> <tt>@XmlSchemaType</tt> annotation defined for Java type
  50  * applies to all references to the Java type from a property/field.
  51  * A <tt>@XmlSchemaType</tt> annotation specified on the
  52  * property/field overrides the <tt>@XmlSchemaType</tt> annotation
  53  * specified at the package level.
  54  *
  55  * <p> This annotation can be used with the following annotations:
  56  * {@link XmlElement},  {@link XmlAttribute}.
  57  * <p>
  58  * <b>Example 1: </b> Customize mapping of XMLGregorianCalendar on the
  59  *  field.
  60  *
  61  * <pre>
  62  *     //Example: Code fragment
  63  *     public class USPrice {
  64  *         &#64;XmlElement
  65  *         &#64;XmlSchemaType(name="date")
  66  *         public XMLGregorianCalendar date;
  67  *     }
  68  *
  69  *     &lt;!-- Example: Local XML Schema element -->
  70  *     &lt;xs:complexType name="USPrice"/>
  71  *       &lt;xs:sequence>
  72  *         &lt;xs:element name="date" type="xs:date"/>
  73  *       &lt;/sequence>
  74  *     &lt;/xs:complexType>
  75  * </pre>
  76  *
  77  * <p> <b> Example 2: </b> Customize mapping of XMLGregorianCalendar at package
  78  *     level </p>
  79  * <pre>
  80  *     package foo;
  81  *     &#64;javax.xml.bind.annotation.XmlSchemaType(
  82  *          name="date", type=javax.xml.datatype.XMLGregorianCalendar.class)
  83  *     }
  84  * </pre>
  85  *
  86  * @since JAXB2.0
  87  */
  88 
  89 @Retention(RUNTIME) @Target({FIELD,METHOD,PACKAGE})
  90 public @interface XmlSchemaType {
  91     String name();
  92     String namespace() default "http://www.w3.org/2001/XMLSchema";
  93     /**
  94      * If this annotation is used at the package level, then value of
  95      * the type() must be specified.
  96      */
  97 
  98     Class type() default DEFAULT.class;
  99 
 100     /**
 101      * Used in {@link XmlSchemaType#type()} to
 102      * signal that the type be inferred from the signature
 103      * of the property.
 104      */
 105 
 106     static final class DEFAULT {}
 107 
 108 }