简体   繁体   中英

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. 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.

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:

 <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

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:

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;
    }

...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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