Thu, 31 Aug 2017 15:18:52 +0800
merge
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. Oracle designates this |
aoqi@0 | 8 | * particular file as subject to the "Classpath" exception as provided |
aoqi@0 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
aoqi@0 | 10 | * |
aoqi@0 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 15 | * accompanied this code). |
aoqi@0 | 16 | * |
aoqi@0 | 17 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 20 | * |
aoqi@0 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 22 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 23 | * questions. |
aoqi@0 | 24 | */ |
aoqi@0 | 25 | |
aoqi@0 | 26 | package javax.xml.bind.annotation; |
aoqi@0 | 27 | |
aoqi@0 | 28 | import java.lang.annotation.Retention; |
aoqi@0 | 29 | import java.lang.annotation.Target; |
aoqi@0 | 30 | import static java.lang.annotation.RetentionPolicy.RUNTIME; |
aoqi@0 | 31 | import static java.lang.annotation.ElementType.FIELD; |
aoqi@0 | 32 | |
aoqi@0 | 33 | /** |
aoqi@0 | 34 | * Maps an enum constant in {@link Enum} type to XML representation. |
aoqi@0 | 35 | * |
aoqi@0 | 36 | * <p> <b>Usage</b> </p> |
aoqi@0 | 37 | * |
aoqi@0 | 38 | * <p> The <tt>@XmlEnumValue</tt> annotation can be used with the |
aoqi@0 | 39 | * following program elements: |
aoqi@0 | 40 | * <ul> |
aoqi@0 | 41 | * <li>enum constant</li> |
aoqi@0 | 42 | * </ul> |
aoqi@0 | 43 | * |
aoqi@0 | 44 | * <p>See "Package Specification" in javax.xml.bind.package javadoc for |
aoqi@0 | 45 | * additional common information.</p> |
aoqi@0 | 46 | * |
aoqi@0 | 47 | * <p>This annotation, together with {@link XmlEnum} provides a |
aoqi@0 | 48 | * mapping of enum type to XML representation. |
aoqi@0 | 49 | * |
aoqi@0 | 50 | * <p>An enum type is mapped to a schema simple type with enumeration |
aoqi@0 | 51 | * facets. The schema type is derived from the Java type specified in |
aoqi@0 | 52 | * <tt>@XmlEnum.value()</tt>. Each enum constant <tt>@XmlEnumValue</tt> |
aoqi@0 | 53 | * must have a valid lexical representation for the type |
aoqi@0 | 54 | * <tt>@XmlEnum.value()</tt> |
aoqi@0 | 55 | * |
aoqi@0 | 56 | * <p> In the absence of this annotation, {@link Enum#name()} is used |
aoqi@0 | 57 | * as the XML representation. |
aoqi@0 | 58 | * |
aoqi@0 | 59 | * <p> <b>Example 1: </b>Map enum constant name -> enumeration facet</p> |
aoqi@0 | 60 | * <pre> |
aoqi@0 | 61 | * //Example: Code fragment |
aoqi@0 | 62 | * @XmlEnum(String.class) |
aoqi@0 | 63 | * public enum Card { CLUBS, DIAMONDS, HEARTS, SPADES } |
aoqi@0 | 64 | * |
aoqi@0 | 65 | * <!-- Example: XML Schema fragment --> |
aoqi@0 | 66 | * <xs:simpleType name="Card"> |
aoqi@0 | 67 | * <xs:restriction base="xs:string"/> |
aoqi@0 | 68 | * <xs:enumeration value="CLUBS"/> |
aoqi@0 | 69 | * <xs:enumeration value="DIAMONDS"/> |
aoqi@0 | 70 | * <xs:enumeration value="HEARTS"/> |
aoqi@0 | 71 | * <xs:enumeration value="SPADES"/> |
aoqi@0 | 72 | * </xs:simpleType> |
aoqi@0 | 73 | * </pre> |
aoqi@0 | 74 | * |
aoqi@0 | 75 | * <p><b>Example 2: </b>Map enum constant name(value) -> enumeration facet </p> |
aoqi@0 | 76 | * <pre> |
aoqi@0 | 77 | * //Example: code fragment |
aoqi@0 | 78 | * @XmlType |
aoqi@0 | 79 | * @XmlEnum(Integer.class) |
aoqi@0 | 80 | * public enum Coin { |
aoqi@0 | 81 | * @XmlEnumValue("1") PENNY(1), |
aoqi@0 | 82 | * @XmlEnumValue("5") NICKEL(5), |
aoqi@0 | 83 | * @XmlEnumValue("10") DIME(10), |
aoqi@0 | 84 | * @XmlEnumValue("25") QUARTER(25) } |
aoqi@0 | 85 | * |
aoqi@0 | 86 | * <!-- Example: XML Schema fragment --> |
aoqi@0 | 87 | * <xs:simpleType name="Coin"> |
aoqi@0 | 88 | * <xs:restriction base="xs:int"> |
aoqi@0 | 89 | * <xs:enumeration value="1"/> |
aoqi@0 | 90 | * <xs:enumeration value="5"/> |
aoqi@0 | 91 | * <xs:enumeration value="10"/> |
aoqi@0 | 92 | * <xs:enumeration value="25"/> |
aoqi@0 | 93 | * </xs:restriction> |
aoqi@0 | 94 | * </xs:simpleType> |
aoqi@0 | 95 | * </pre> |
aoqi@0 | 96 | * |
aoqi@0 | 97 | * <p><b>Example 3: </b>Map enum constant name -> enumeration facet </p> |
aoqi@0 | 98 | * |
aoqi@0 | 99 | * <pre> |
aoqi@0 | 100 | * //Code fragment |
aoqi@0 | 101 | * @XmlType |
aoqi@0 | 102 | * @XmlEnum(Integer.class) |
aoqi@0 | 103 | * public enum Code { |
aoqi@0 | 104 | * @XmlEnumValue("1") ONE, |
aoqi@0 | 105 | * @XmlEnumValue("2") TWO; |
aoqi@0 | 106 | * } |
aoqi@0 | 107 | * |
aoqi@0 | 108 | * <!-- Example: XML Schema fragment --> |
aoqi@0 | 109 | * <xs:simpleType name="Code"> |
aoqi@0 | 110 | * <xs:restriction base="xs:int"> |
aoqi@0 | 111 | * <xs:enumeration value="1"/> |
aoqi@0 | 112 | * <xs:enumeration value="2"/> |
aoqi@0 | 113 | * </xs:restriction> |
aoqi@0 | 114 | * </xs:simpleType> |
aoqi@0 | 115 | * </pre> |
aoqi@0 | 116 | * |
aoqi@0 | 117 | * @since JAXB 2.0 |
aoqi@0 | 118 | */ |
aoqi@0 | 119 | @Retention(RUNTIME) |
aoqi@0 | 120 | @Target({FIELD}) |
aoqi@0 | 121 | public @interface XmlEnumValue { |
aoqi@0 | 122 | String value(); |
aoqi@0 | 123 | } |