001: /*
002: * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
003: * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
004: */
005:
006: package javax.xml.bind.annotation;
007:
008: import java.lang.annotation.Retention;
009: import java.lang.annotation.Target;
010: import static java.lang.annotation.RetentionPolicy.RUNTIME;
011: import static java.lang.annotation.ElementType.FIELD;
012:
013: /**
014: * Maps an enum constant in {@link Enum} type to XML representation.
015: *
016: * <p> <b>Usage</b> </p>
017: *
018: * <p> The <tt>@XmlEnumValue</tt> annotation can be used with the
019: * following program elements:
020: * <ul>
021: * <li>enum constant</li>
022: * </ul>
023: *
024: * <p>See "Package Specification" in javax.xml.bind.package javadoc for
025: * additional common information.</p>
026: *
027: * <p>This annotation, together with {@link XmlEnum} provides a
028: * mapping of enum type to XML representation.
029: *
030: * <p>An enum type is mapped to a schema simple type with enumeration
031: * facets. The schema type is derived from the Java type specified in
032: * <tt>@XmlEnum.value()</tt>. Each enum constant <tt>@XmlEnumValue</tt>
033: * must have a valid lexical representation for the type
034: * <tt>@XmlEnum.value()</tt>
035: *
036: * <p> In the absence of this annotation, {@link Enum#name()} is used
037: * as the XML representation.
038: *
039: * <p> <b>Example 1: </b>Map enum constant name -> enumeration facet</p>
040: * <pre>
041: * //Example: Code fragment
042: * @XmlEnum(String.class)
043: * public enum Card { CLUBS, DIAMONDS, HEARTS, SPADES }
044: *
045: * <!-- Example: XML Schema fragment -->
046: * <xs:simpleType name="Card">
047: * <xs:restriction base="xs:string"/>
048: * <xs:enumeration value="CLUBS"/>
049: * <xs:enumeration value="DIAMONDS"/>
050: * <xs:enumeration value="HEARTS"/>
051: * <xs:enumeration value="SPADES"/>
052: * </xs:simpleType>
053: * </pre>
054: *
055: * <p><b>Example 2: </b>Map enum constant name(value) -> enumeration facet </p>
056: * <pre>
057: * //Example: code fragment
058: * @XmlType
059: * @XmlEnum(Integer.class)
060: * public enum Coin {
061: * @XmlEnumValue("1") PENNY(1),
062: * @XmlEnumValue("5") NICKEL(5),
063: * @XmlEnumValue("10") DIME(10),
064: * @XmlEnumValue("25") QUARTER(25) }
065: *
066: * <!-- Example: XML Schema fragment -->
067: * <xs:simpleType name="Coin">
068: * <xs:restriction base="xs:int">
069: * <xs:enumeration value="1"/>
070: * <xs:enumeration value="5"/>
071: * <xs:enumeration value="10"/>
072: * <xs:enumeration value="25"/>
073: * </xs:restriction>
074: * </xs:simpleType>
075: * </pre>
076: *
077: * <p><b>Example 3: </b>Map enum constant name -> enumeration facet </p>
078: *
079: * <pre>
080: * //Code fragment
081: * @XmlType
082: * @XmlEnum(Integer.class)
083: * public enum Code {
084: * @XmlEnumValue("1") ONE,
085: * @XmlEnumValue("2") TWO;
086: * }
087: *
088: * <!-- Example: XML Schema fragment -->
089: * <xs:simpleType name="Code">
090: * <xs:restriction base="xs:int">
091: * <xs:enumeration value="1"/>
092: * <xs:enumeration value="2"/>
093: * </xs:restriction>
094: * </xs:simpleType>
095: * </pre>
096: *
097: * @since JAXB 2.0
098: */
099: @Retention(RUNTIME)
100: @Target({FIELD})
101: public @interface XmlEnumValue {
102: String value();
103: }
|