Search code examples
javawsdl

Enum Type in WSDL representation


A WSDL representation as below :

<xs:simpleType name="customerType">
    <xs:restriction base="xs:string">
        <xs:enumeration value="PRIVATE"/>
        <xs:enumeration value="BUSINESS"/>
    </xs:restriction>
</xs:simpleType>

resulted in the code as below by cxf-codegen-plugin:

public enum CustomerType { 
    PRIVATE, BUSINESS 
} 

Can be represented in WSDL as:

How can we represent enum in WSDL so that the cxf-codegen-plugin can generate code as below:

public enum CustomerType { 
        PRIVATE{public BigInteger getNcid() { 
                return new BigInteger("1"); 
}, 
BUSINESS{public BigInteger getNcid() { 
                return new BigInteger("2"); 
} 

public abstract BigInteger getNcid(); 
    }

If we can't have cxf-codegen generate this what is the best way we can handle this case in java. I really appreciate your help.


Solution

  • That is not a representation of the same thing.

    You haven't said which programming language you're using, but it looks like you intend for PRIVATE to be associated with the value 1, and BUSINESS to be associated with the value 2. That is not represented in the WSDL.

    WSDL uses XML Schema to describe the shape of data. XML Schema has no concept equivalent to an enum in a programming language. In most programming languages I know, an enum is a named constant. The enumeration facet in XML Schema does not describe named values. It simply says that the value at that point can be one of the listed (string) values.