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 を使用して Java ソース ファイルを生成しました ([ファイル] -> [新規] -> [その他] -> [Web サービス] -> [Web サービス クライアント])。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 記述を列挙型のキーとして使用して単純な列挙型クラスを生成するオプションがあるかどうか疑問に思っていました。

4

1 に答える 1

0

Ok。Maven で jaxws を使用すると、生成されるクラスは次のようになります。

@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 に答える