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文档
相关文章
相关标签/搜索