1 /*
   2  * Copyright (c) 2005, 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
  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  * {@code @XmlSchemaType} 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> {@code @XmlSchemaType} annotation defined for Java type
  50  * applies to all references to the Java type from a property/field.
  51  * A {@code @XmlSchemaType} annotation specified on the
  52  * property/field overrides the {@code @XmlSchemaType} 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  *         @XmlElement
  65  *         @XmlSchemaType(name="date")
  66  *         public XMLGregorianCalendar date;
  67  *     }
  68  * {@code
  69  *
  70  *     <!-- Example: Local XML Schema element -->
  71  *     <xs:complexType name="USPrice"/>
  72  *       <xs:sequence>
  73  *         <xs:element name="date" type="xs:date"/>
  74  *       </sequence>
  75  *     </xs:complexType>
  76  * }</pre>
  77  *
  78  * <p> <b> Example 2: </b> Customize mapping of XMLGregorianCalendar at package
  79  *     level </p>
  80  * <pre>
  81  *     package foo;
  82  *     @javax.xml.bind.annotation.XmlSchemaType(
  83  *          name="date", type=javax.xml.datatype.XMLGregorianCalendar.class)
  84  *     }
  85  * </pre>
  86  *
  87  * @since 1.6, JAXB 2.0
  88  */
  89 
  90 @Retention(RUNTIME) @Target({FIELD,METHOD,PACKAGE})
  91 public @interface XmlSchemaType {
  92     String name();
  93     String namespace() default "http://www.w3.org/2001/XMLSchema";
  94     /**
  95      * If this annotation is used at the package level, then value of
  96      * the type() must be specified.
  97      */
  98 
  99     Class type() default DEFAULT.class;
 100 
 101     /**
 102      * Used in {@link XmlSchemaType#type()} to
 103      * signal that the type be inferred from the signature
 104      * of the property.
 105      */
 106 
 107     static final class DEFAULT {}
 108 
 109 }