2013-03-06 86 views
0

我有下面的代碼(只是部分)WSDL:Eclipse中的WebService客戶端生成工作不正常

<?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簡單枚舉類:文檔描述爲枚舉密鑰。

回答

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

} 

好多了,但還不夠完善,是嗎?

+0

嘿,我知道這有點過時,但你是如何產生這樣的類?任何鏈接或教程?我目前遇到類似的問題,我的日食 – thekucays 2016-08-18 07:04:00

+0

看看http://stackoverflow.com/questions/18338196/how-to-generate-classes-from-wsdl-using-maven-and-wsimport – Goyo 2016-08-22 06:32:31

相關問題