从WSDL生成的Eclipse Web Service客户端无法正常工作

时间:2013-03-06 18:18:35

标签: eclipse web-services enums wsdl

我有一个带有以下代码的wsdl(只是一部分):

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

我已经使用这个wsdl使用Eclipse生成Java源文件(File-&gt; New-&gt; Other-&gt; Web Services-&gt; Web Service Client)。 它已经从wsdl生成了所有类。但是,生成枚举类型时,只有这样:

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

}

我想知道是否有任何选项可以使用xs:documentation描述作为枚举的键来生成一个简单的枚举类。

1 个答案:

答案 0 :(得分:0)

确定。将jaxws与maven一起使用,生成的类现在是:

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

}

好多了,但还不完美,是吗?