JAXB - XML Schema Types, Defining an Enumeration
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.
JAXB - XML Schema Types, Defining an Enumeration的更多相关文章
- JAXB - XML Schema Types, Defining Subtypes
Although object orientation isn't a key feature of XML or the XML Schema language, it's still possib ...
- JAXB - XML Schema Types, Defining Types for XML Elements With Content
Content: A Value The content of an XML element may be some value, or one or more subordinate element ...
- JAXB - XML Schema Types, Defining Types for XML Elements Without Content
Types for XML elements are constructed using xsd:complexType, even if they do not have content. The ...
- JAXB - XML Schema Types, Date and Time
JAXB binds all three of the schema types xsd:date, xsd:time and xsd:dateTime to XMLGregorianCalendar ...
- JAXB - XML Schema Types, Binary Data
Data that has no "natural" representation with printable characters must, for inclusion in ...
- XML Schema and XMLspy notes
Introduction An xml documents consists of elements, attributes and text. There are two structures in ...
- 【转】XSD (xml Schema Definition)
来自:http://www.cnblogs.com/newsouls/archive/2011/10/28/2227765.html Xml Schema的用途 1. 定义一个Xml文档中都有什么元 ...
- C#与XML Schema的问题
http://bbs.csdn.net/topics/50493564 weileily: 用XmlSchema.Read方法读取了一个xsd文件,请问如何遍历检索器中的ComplexType与Sim ...
- XML Schema的基本语法(转)
XML Schema的基本语法(转) XSDL(XML Schema定义语言)由元素.属性.命名空间和XML文档种的其他节点构成的. 一.XSD中的元素 XSD文档至少要包含:schema根元素和XM ...
随机推荐
- 2.3CUDA矩阵乘法
CPU 矩阵乘法 能相乘的两个矩阵,必须满足一个矩阵的行数和第二个矩阵的列数相同. A(N*P) * B(P*M) = C(N*M). 其中P是行数,N是列数, 从宽高的角度来说,即 A的宽度和B的高 ...
- Bzoj-2005 能量采集 gcd,递推
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2005 题意:题目转换后的模型就是求Σ(gcd(x,y)), 1<=x<=n, ...
- Activity的lanuchmode
假设: 假设栈有A-B-C-D,四个activity.其中D Activity在栈顶 standard: 此时跳转到D Activity,跳转后栈的情况是A-B-C-D-D singleTop: 此时 ...
- Oracle- 存储过程和异常捕捉
这段时间晚上有时候去打打球,回家看看电视剧,日子一天天过…….学了点ORACLE存储过程基础,作一下备注,以便日后需查阅. 创建无参存储过程 create procedure p_myPro1 is ...
- SQL 存储过程(学生,课程表,选修表)
SQL 存储过程(学生,课程表,选修表) 一.存储过程的分类 在SQL Server中存储过程分过两类: 1)系统存储过程("sp_"作为前缀) 2)用户自定义存储过程 二.创建和 ...
- Java基础学习中一些词语和语句的使用
在Java基础学习中,我们刚接触Java会遇到一些词和语句的使用不清的情况,不能很清楚的理解它的运行效果会是怎么样的,如:break,continue在程序中运行效果及跳转位置, 1.先来看看brea ...
- ECSHOP在线手册之布局参考图-首页 index.dwt
A.logo替换 1,设置方法 后台商店设置里,上传logo就行,注意logo的名称必须是logo.gif 2,代码相关 page_header.lbi 中 <a href=" ...
- 最牛X的编码套路
最近,我大量阅读了Steve Yegge的文章.其中有一篇叫"Practicing Programming"(练习编程),写成于2005年,读后令我惊讶不已: 与你所相信的恰恰相反 ...
- java--静态的应用(工具类)
ArrayTool.java文件 /** 静态的应用. 每一个应用程序中都有公行动的功能,可以将这些功能进行抽取,独立封装以便复用 由于ArrayTool中并没有封装特有数据,而且数组的每一个方法也没 ...
- DBHelper数据库操作类(二)
不错文章:http://www.codefans.net/articles/562.shtml http://www.cnblogs.com/gaobing/p/3878342.html using ...