KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > xml > bind > annotation > XmlEnumValue


1 /*
2  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
3  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
4  */

5
6 package javax.xml.bind.annotation;
7
8 import java.lang.annotation.Retention JavaDoc;
9 import java.lang.annotation.Target JavaDoc;
10 import static java.lang.annotation.RetentionPolicy.RUNTIME JavaDoc;
11 import static java.lang.annotation.ElementType.FIELD JavaDoc;
12
13 /**
14  * Maps an enum constant in {@link Enum} type to XML representation.
15  *
16  * <p> <b>Usage</b> </p>
17  *
18  * <p> The <tt>@XmlEnumValue</tt> annotation can be used with the
19  * following program elements:
20  * <ul>
21  * <li>enum constant</li>
22  * </ul>
23  *
24  * <p>See "Package Specification" in javax.xml.bind.package javadoc for
25  * additional common information.</p>
26  *
27  * <p>This annotation, together with {@link XmlEnum} provides a
28  * mapping of enum type to XML representation.
29  *
30  * <p>An enum type is mapped to a schema simple type with enumeration
31  * facets. The schema type is derived from the Java type specified in
32  * <tt>@XmlEnum.value()</tt>. Each enum constant <tt>@XmlEnumValue</tt>
33  * must have a valid lexical representation for the type
34  * <tt>@XmlEnum.value()</tt>
35  *
36  * <p> In the absence of this annotation, {@link Enum#name()} is used
37  * as the XML representation.
38  *
39  * <p> <b>Example 1: </b>Map enum constant name -> enumeration facet</p>
40  * <pre>
41  * //Example: Code fragment
42  * &#64;XmlEnum(String.class)
43  * public enum Card { CLUBS, DIAMONDS, HEARTS, SPADES }
44  *
45  * &lt;!-- Example: XML Schema fragment -->
46  * &lt;xs:simpleType name="Card">
47  * &lt;xs:restriction base="xs:string"/>
48  * &lt;xs:enumeration value="CLUBS"/>
49  * &lt;xs:enumeration value="DIAMONDS"/>
50  * &lt;xs:enumeration value="HEARTS"/>
51  * &lt;xs:enumeration value="SPADES"/>
52  * &lt;/xs:simpleType>
53  * </pre>
54  *
55  * <p><b>Example 2: </b>Map enum constant name(value) -> enumeration facet </p>
56  * <pre>
57  * //Example: code fragment
58  * &#64;XmlType
59  * &#64;XmlEnum(Integer.class)
60  * public enum Coin {
61  * &#64;XmlEnumValue("1") PENNY(1),
62  * &#64;XmlEnumValue("5") NICKEL(5),
63  * &#64;XmlEnumValue("10") DIME(10),
64  * &#64;XmlEnumValue("25") QUARTER(25) }
65  *
66  * &lt;!-- Example: XML Schema fragment -->
67  * &lt;xs:simpleType name="Coin">
68  * &lt;xs:restriction base="xs:int">
69  * &lt;xs:enumeration value="1"/>
70  * &lt;xs:enumeration value="5"/>
71  * &lt;xs:enumeration value="10"/>
72  * &lt;xs:enumeration value="25"/>
73  * &lt;/xs:restriction>
74  * &lt;/xs:simpleType>
75  * </pre>
76  *
77  * <p><b>Example 3: </b>Map enum constant name -> enumeration facet </p>
78  *
79  * <pre>
80  * //Code fragment
81  * &#64;XmlType
82  * &#64;XmlEnum(Integer.class)
83  * public enum Code {
84  * &#64;XmlEnumValue("1") ONE,
85  * &#64;XmlEnumValue("2") TWO;
86  * }
87  *
88  * &lt;!-- Example: XML Schema fragment -->
89  * &lt;xs:simpleType name="Code">
90  * &lt;xs:restriction base="xs:int">
91  * &lt;xs:enumeration value="1"/>
92  * &lt;xs:enumeration value="2"/>
93  * &lt;/xs:restriction>
94  * &lt;/xs:simpleType>
95  * </pre>
96  *
97  * @since JAXB 2.0
98  */

99 @Retention JavaDoc(RUNTIME)
100 @Target JavaDoc({FIELD})
101 public @interface XmlEnumValue {
102     String JavaDoc value();
103 }
104
Popular Tags