zoukankan      html  css  js  c++  java
  • JAXB

    If you want a data type that enumerates discrete values you should use a restriction of the schema type xsd:string, enumerating all the values as you would in a Java enum type.

    <xsd:simpleType name="IXLType">
        <xsd:restriction base="xsd:string">
            <xsd:enumeration value="eStwA"/>
            <xsd:enumeration value="eStwS"/>
            <xsd:enumeration value="SpDrL"/>
            <xsd:enumeration value="SpDrS"/>
            <xsd:enumeration value="VGS80"/>
        </xsd:restriction>
    </xsd:simpleType>

    The JAXB compiler generates a Java enum, but the names of the enum constants are transformed so that they conform to the style commonly accepted in the Java community. Below is the (somewhat shortened) Java code.

    public enum IXLType {
    
        E_STW_A("eStwA"),
        E_STW_S("eStwS"),
        SP_DR_L("SpDrL"),
        SP_DR_S("SpDrS"),
        VGS_80("VGS80");
    
        private final String value;
    
        IXLType(String v) {
            value = v;
        }
    
        public String value() {
            return value;
        }
    }

    If you want to use the original identifiers as enum constant names, you may resort to an explicit specification of the binding, for each enum constant name, as shown below.

    <xsd:simpleType name="IXLType">
        <xsd:restriction base="xsd:string">
            <xsd:enumeration value="eStwA">
                <xsd:annotation>
                    <xsd:appinfo>
                        <jxb:typesafeEnumMember name="eStwA"/>
                    </xsd:appinfo>
                </xsd:annotation>
            </xsd:enumeration>
            ...
        </xsd:restriction>
    </xsd:simpleType>

    The generated enum class will now contain enum constant names that exactly match the original strings.

    public enum IXLType {
     
        eStwA,
        eStwS,
        SpDrL,
        SpDrS,
        VGS80;
    
        public String value() {
            return name();
        }
        ...
    }

    There is no need now to store the XML representations along with each enum constant, and method value may now simply call name() to obtain the stringified value.

  • 相关阅读:
    [BZOJ 4318] OSU!
    [BZOJ 4720][NOIP 2016] 换教室
    [Tyvj 1729] 文艺平衡树
    [BZOJ 1500]维修数列 [Splay Tree从进阶到住院]
    [学习笔记] CDQ分治 从感性理解到彻底晕菜
    [COGS 1752] 摩基亚Mokia
    [Tyvj 1730] 二逼平衡树
    [学习笔记] Splay Tree 从入门到放弃
    [Tyvj 1728] 普通平衡树
    [BZOJ 3594] 方伯伯的玉米田
  • 原文地址:https://www.cnblogs.com/huey/p/5505117.html
Copyright © 2011-2022 走看看