wsgen工具與JAX-B工件(Artifacts)

任何Document樣式的服務,不管具備包裝仍是非包裝,都須要由wsgen工具產生的工件(Artifacts,支持客戶端開發的相關代碼資源)。wsgen工具能夠產生構建WSDL文檔所須要的類,這些類就是一般所說的wsgen工件。以HelloWord爲例,命令以下:java

% wsgen -keep -cp . ch03.ts.HelloWordImpl

產生的工件以下:shell

SayHello.java:工具

package ch03.ts.jaxws;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

@XmlRootElement(name = "sayHello", namespace = "http://ts.ch03/")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "sayHello", namespace = "http://ts.ch03/", propOrder = {
    "name",
    "wh"
})
public class SayHello {

    @XmlElement(name = "name", namespace = "")
    private String name;
    @XmlElement(name = "wh", namespace = "")
    private String wh;

    /**
     * @return
     * returns String
     */
    public String getName() {
        return this.name;
    }

    /**
     * @param name
     * the value for the name property
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @return
     * returns String
     */
    public String getWh() {
        return this.wh;
    }

    /**
     * @param wh
     * the value for the wh property
     */
    public void setWh(String wh) {
        this.wh = wh;
    }

}

SayHelloResponse.java:this

package ch03.ts.jaxws;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

@XmlRootElement(name = "sayHelloResponse", namespace = "http://ts.ch03/")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "sayHelloResponse", namespace = "http://ts.ch03/", propOrder = {
    "wh",
    "hf"
})
public class SayHelloResponse {

    @XmlElement(name = "wh", namespace = "")
    private String wh;
    @XmlElement(name = "hf", namespace = "")
    private String hf;

    /**
     * @return
     * returns String
     */
    public String getWh() {
        return this.wh;
    }

    /**
     * @param wh
     * the value for the wh property
     */
    public void setWh(String wh) {
        this.wh = wh;
    }

    /**
     * @return
     * returns String
     */
    public String getHf() {
        return this.hf;
    }

    /**
     * @param hf
     * the value for the hf property
     */
    public void setHf(String hf) {
        this.hf = hf;
    }
}

上面的命令生成了相應的工件,同時根據須要產生這些工件存儲的包:ch03.ts.jaxws。在HelloWord這個例子中,總共有2種消息(Message),sayHello操做的請求與響應消息。wsgen工具針對每一種消息均產生了一個java類來對應一個Java數據類型。發佈程序正是利用這些java數據類型來產生Document綁定樣式服務的WSDL文檔。所以每個Java數據類型對應一個XML模式類型,而這些XML模式類型又用來定義服務中涉及的2個消息。(注:原來這樣啊!wsgen產生的工件對應WSDL中message部分定義的類型)wsgen工具產生綁定到XML模式類型的Java類型。而在底層,這個工具用到了JAX-B(Java API for XML-Binding)相關的API包。歸納地講,JAX-B對Java和XML之間的類型轉換提供支持。spa

wsgen工具說明code

wsgen工具主要產生構建WSDL文檔所須要的類。這個工具用在服務實現類上,用來生成工件與WSDL文檔。命令示例以下:xml

% wsgen -keep -cp . ch03.ts.HelloWordImpl

命令參數說明以下:
資源

參數 說明
-cp                                                                       
定義classpath
-r 指定生成WSDL文檔的存放目錄
-s
指定生成的源代碼文件的存放目錄
-d 指定生成的class文件的存放目錄
-wsdl 生成WSDL文檔與XSD文檔
相關文章
相關標籤/搜索