简体   繁体   English

我可以改变typesafeEnumMemberName生成的bij cxf-xjc-plugin吗?

[英]Can I alter the typesafeEnumMemberName generated bij cxf-xjc-plugin?

I'm generating java class files using org.apache.cxf:cxf-xjc-plugin from an xsd. 我正在使用来自xsd的org.apache.cxf:cxf-xjc-plugin生成java类文件。 I'm using the global binding typesafeEnumMemberName="generateName" so the plugin generates member names for the enum class when the plugin cannot create a valid Java identifier for a member of the enumeration. 我正在使用全局绑定typesafeEnumMemberName="generateName"因此当插件无法为枚举成员创建有效的Java标识符时,插件会为枚举类生成成员名称。

My question is: 我的问题是:
Is there a way to alter the way these typesafe enum member names are generated? 有没有办法改变这些类型安全的枚举成员名称的生成方式?
For example, alter it to include the value? 例如,改变它以包含值? This so the member represents the value in stead of just an incremental number. 这样,成员代表的值不是增量数。


Additional info: 附加信息:
The xsd I have specifies the following simpleType: 我有的xsd指定了以下simpleType:

 <xs:simpleType name="CodeBurgelijkeStaat"> <xs:annotation> <xs:documentation>COD366_NEN</xs:documentation> </xs:annotation> <xs:restriction base="xs:string"> <xs:enumeration value="0"> <xs:annotation> <xs:documentation>Onbekend</xs:documentation> </xs:annotation> </xs:enumeration> <xs:enumeration value="1"> <xs:annotation> <xs:documentation>Ongehuwd en geen geregistreerd partner en nooit gehuwd of geregistreerd partner geweest</xs:documentation> </xs:annotation> </xs:enumeration> </xs:restriction> </xs:simpleType> 

Which results in the following class: 结果如下:

 @XmlType(name = "CodeBurgelijkeStaat") @XmlEnum public enum CodeBurgelijkeStaat { /** * Onbekend * */ @XmlEnumValue("0") VALUE_1("0"), /** * Ongehuwd en geen geregistreerd partner en nooit gehuwd of geregistreerd partner geweest * */ @XmlEnumValue("1") VALUE_2("1"); private final String value; CodeBurgelijkeStaat(String v) { value = v; } public String value() { return value; } public static CodeBurgelijkeStaat fromValue(String v) { for (CodeBurgelijkeStaat c: CodeBurgelijkeStaat.values()) { if (c.value.equals(v)) { return c; } } throw new IllegalArgumentException(v); } } 

You mean something like this? 你的意思是这样的? This is done by the maven jaxws:wsimport plugin 这是由maven jaxws:wsimport插件完成的

XSD: XSD:

 <xs:simpleType name="Status">
                <xs:restriction base="xs:string">
                    <xs:enumeration value="FirstStatus"/>
                    <xs:enumeration value="SecondStatus"/>
                    <xs:enumeration value="ThirdStatus"/>
                </xs:restriction>
            </xs:simpleType>

Generated java code: 生成的java代码:

public enum Status {

    @XmlEnumValue("FirstStatus")
    FIRST_STATUS("FirstStatus"),
    @XmlEnumValue("SecondStatus")
    SECOND_STATUS("SecondStatus"),
    @XmlEnumValue("ThirdStatus")
    THIRD_STATUS("ThirdStatus");
    private final String value;

    Status(String v) {
        value = v;
    }

...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM