xsd 架构的以下部分:
<xs:simpleType name="Component">
<xs:enumeration value="Common"/>
</xs:simpleType>
Run Code Online (Sandbox Code Playgroud)
使用一个常量 - 来创建 Java 枚举Component.COMMON。是否可以使用 JAXB 生成小写常量(例如 Component.common)的枚举?
是的,它应该基于实现类型安全枚举(例如整数值)的相同技术。
这个链接应该有帮助。
在你的情况下,它应该看起来像这样:
<xs:simpleType name="Component" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb">
<xs:restriction base="xs:string">
<xs:enumeration value="Common">
<xs:annotation>
<xs:appinfo>
<jaxb:typesafeEnumMember name="common" />
</xs:appinfo>
</xs:annotation>
</xs:enumeration>
</xs:restriction>
</xs:simpleType>
Run Code Online (Sandbox Code Playgroud)
你得到这个:
@XmlType(name = "Component")
@XmlEnum
public enum Component {
@XmlEnumValue("Common")
common("Common");
private final String value;
Component(String v) {
value = v;
}
public String value() {
return value;
}
public static Component fromValue(String v) {
for (Component c: Component.values()) {
if (c.value.equals(v)) {
return c;
}
}
throw new IllegalArgumentException(v);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3063 次 |
| 最近记录: |