0

我有一个带有以下代码的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(文件->新建->其他->Web 服务->Web 服务客户端)生成 Java 源文件。它从 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_);}

}

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.

4

1 回答 1

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

}

好多了,但仍然不完美,是吗?

于 2013-03-07T17:30:38.987 回答