0

I've got a wsdl with the following code (just a part):

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:sch="http://www.test.com/App" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://www.test.com/App" targetNamespace="http://www.test.com/App">
  <wsdl:types>
    <xs:schema xmlns:process="http://www.test.com/App" xmlns:xdb="http://xmlns.oracle.com/xdb" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.test.com/App" version="1.0" xdb:mapStringToNCHAR="true" xdb:mapUnboundedStringToLob="true" xdb:schemaURL="ddd" xdb:storeVarrayAsTable="true">
    <xs:simpleType name="ClientCountry">
        <xs:restriction base="xs:string">
            <xs:enumeration value="CLCO1">
                <xs:annotation>
                    <xs:documentation>Spain</xs:documentation>
                </xs:annotation>
            </xs:enumeration>
            <xs:enumeration value="CLCO2">
                <xs:annotation>
                    <xs:documentation>Portugal</xs:documentation>
                </xs:annotation>
            </xs:enumeration>
        </xs:restriction>
    </xs:simpleType>
    </xs:schema>
  </wsdl:types>
</wsdl:definitions>

I've used this wsdl to generate the Java source files using Eclipse (File->New->Other->Web Services->Web Service Client). It has generated all classes from the wsdl. However, when generating the enumeration types has made just this:

public class ClientCountry implements java.io.Serializable {
    /**
     * 
     */
    private static final long serialVersionUID = -2280793720095616022L;
    private java.lang.String _value_;
    private static java.util.HashMap _table_ = new java.util.HashMap();

    // Constructor
    protected ClientCountry(java.lang.String value) {
        _value_ = value;
        _table_.put(_value_,this);
    }

    public static final java.lang.String _CLCO1 = "CLCO1";
    public static final java.lang.String _CLCO2 = "CLCO2";
    public static final ClientCountry CLCO1 = new ClientCountry(_CLCO1);
    public static final ClientCountry CLCO2 = new ClientCountry(_CLCO2);
    public java.lang.String getValue() { return _value_;}
    public static ClientCountry fromValue(java.lang.String value)
          throws java.lang.IllegalArgumentException {
        ClientCountry enumeration = (ClientCountry)
            _table_.get(value);
        if (enumeration==null) throw new java.lang.IllegalArgumentException();
        return enumeration;
    }
    public static ClientCountry fromString(java.lang.String value)
          throws java.lang.IllegalArgumentException {
        return fromValue(value);
    }
    public boolean equals(java.lang.Object obj) {return (obj == this);}
    public int hashCode() { return toString().hashCode();}
    public java.lang.String toString() { return _value_;}
    public java.lang.Object readResolve() throws java.io.ObjectStreamException { return fromValue(_value_);}

}

I was wondering if there could be any option to make it generates a simple enumeration class using the xs:documentation description as keys for the enum.

Goyo
  • 455
  • 1
  • 9
  • 23

1 Answers1

0

Ok. Using jaxws with maven, the generated class now is:

@XmlType(name = "ClientCountry")
@XmlEnum
public enum ClientCountry {


    /**
     * Spain
     * 
     */
    @XmlEnumValue("CLCO1")
    CLCO_1("CLCO1"),

    /**
     * Portugal
     * 
     */
    @XmlEnumValue("CLCO2")
    CLCO_2("CLCO2");
    private final String value;

    ClientCountry(String v) {
        value = v;
    }

    public String value() {
        return value;
    }

    public static ClientCountry fromValue(String v) {
        for (ClientCountry c: ClientCountry.values()) {
            if (c.value.equals(v)) {
                return c;
            }
        }
        throw new IllegalArgumentException(v);
    }

}

Much better, but still not perfect, is it?

Goyo
  • 455
  • 1
  • 9
  • 23
  • hey i know this is kinda outdated, but how did you generate class like that? any link or tutorials? i'm currently experiencing similar issue with my eclipse – thekucays Aug 18 '16 at 07:04
  • take a look to http://stackoverflow.com/questions/18338196/how-to-generate-classes-from-wsdl-using-maven-and-wsimport – Goyo Aug 22 '16 at 06:32