001 /*
002 * Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025
026 package javax.xml.bind.annotation;
027
028 import java.lang.annotation.Retention;
029 import java.lang.annotation.Target;
030 import static java.lang.annotation.RetentionPolicy.RUNTIME;
031 import static java.lang.annotation.ElementType.FIELD;
032
033 /**
034 * Maps an enum constant in {@link Enum} type to XML representation.
035 *
036 * <p> <b>Usage</b> </p>
037 *
038 * <p> The <tt>@XmlEnumValue</tt> annotation can be used with the
039 * following program elements:
040 * <ul>
041 * <li>enum constant</li>
042 * </ul>
043 *
044 * <p>See "Package Specification" in javax.xml.bind.package javadoc for
045 * additional common information.</p>
046 *
047 * <p>This annotation, together with {@link XmlEnum} provides a
048 * mapping of enum type to XML representation.
049 *
050 * <p>An enum type is mapped to a schema simple type with enumeration
051 * facets. The schema type is derived from the Java type specified in
052 * <tt>@XmlEnum.value()</tt>. Each enum constant <tt>@XmlEnumValue</tt>
053 * must have a valid lexical representation for the type
054 * <tt>@XmlEnum.value()</tt>
055 *
056 * <p> In the absence of this annotation, {@link Enum#name()} is used
057 * as the XML representation.
058 *
059 * <p> <b>Example 1: </b>Map enum constant name -> enumeration facet</p>
060 * <pre>
061 * //Example: Code fragment
062 * @XmlEnum(String.class)
063 * public enum Card { CLUBS, DIAMONDS, HEARTS, SPADES }
064 *
065 * <!-- Example: XML Schema fragment -->
066 * <xs:simpleType name="Card">
067 * <xs:restriction base="xs:string"/>
068 * <xs:enumeration value="CLUBS"/>
069 * <xs:enumeration value="DIAMONDS"/>
070 * <xs:enumeration value="HEARTS"/>
071 * <xs:enumeration value="SPADES"/>
072 * </xs:simpleType>
073 * </pre>
074 *
075 * <p><b>Example 2: </b>Map enum constant name(value) -> enumeration facet </p>
076 * <pre>
077 * //Example: code fragment
078 * @XmlType
079 * @XmlEnum(Integer.class)
080 * public enum Coin {
081 * @XmlEnumValue("1") PENNY(1),
082 * @XmlEnumValue("5") NICKEL(5),
083 * @XmlEnumValue("10") DIME(10),
084 * @XmlEnumValue("25") QUARTER(25) }
085 *
086 * <!-- Example: XML Schema fragment -->
087 * <xs:simpleType name="Coin">
088 * <xs:restriction base="xs:int">
089 * <xs:enumeration value="1"/>
090 * <xs:enumeration value="5"/>
091 * <xs:enumeration value="10"/>
092 * <xs:enumeration value="25"/>
093 * </xs:restriction>
094 * </xs:simpleType>
095 * </pre>
096 *
097 * <p><b>Example 3: </b>Map enum constant name -> enumeration facet </p>
098 *
099 * <pre>
100 * //Code fragment
101 * @XmlType
102 * @XmlEnum(Integer.class)
103 * public enum Code {
104 * @XmlEnumValue("1") ONE,
105 * @XmlEnumValue("2") TWO;
106 * }
107 *
108 * <!-- Example: XML Schema fragment -->
109 * <xs:simpleType name="Code">
110 * <xs:restriction base="xs:int">
111 * <xs:enumeration value="1"/>
112 * <xs:enumeration value="2"/>
113 * </xs:restriction>
114 * </xs:simpleType>
115 * </pre>
116 *
117 * @since JAXB 2.0
118 */
119 @Retention(RUNTIME)
120 @Target({FIELD})
121 public @interface XmlEnumValue {
122 String value();
123 }
|