没有通过JAX-WS RI 2.2.1亚马逊ECS WSDL文件生成的枚举 [英] No enums generated by jax-ws ri 2.2.1 for amazon ecs wsdl file

查看:225
本文介绍了没有通过JAX-WS RI 2.2.1亚马逊ECS WSDL文件生成的枚举的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图生成工件以下亚马逊WSDL:结果
<一href=\"http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl\">http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl

I'm attempting to generate artifacts for the following amazon wsdl:
http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl

使用以下Ant任务:

<taskdef name="wsimport" classname="com.sun.tools.ws.ant.WsImport">
    <classpath>
        <pathelement location="${BUILD_LIBS}/jaxws-ri/lib/jaxws-tools.jar"/>
    </classpath>
</taskdef>

<target name="wsimport" depends="init">
    <delete dir="${generated.src}" />
    <mkdir dir="${generated.src}"/>
    <wsimport
        debug="true"
    keep="true"
    verbose="true"
    destdir="${generated.src}"
    package="com.amazon.webservices.ecs"
    wsdl="wsdl/AWSECommerceService.wsdl"/>
</target>

但没有Java工件以下元素,它看起来是这样产生的:

but no java artifacts are generated for the following element which look like this:

<xs:element name="Condition">
    <xs:simpleType>
        <xs:restriction base="xs:string">
            <xs:enumeration value="All"/>
            <xs:enumeration value="New"/>
            <xs:enumeration value="Used"/>
            <xs:enumeration value="Collectible"/>
            <xs:enumeration value="Refurbished"/>
       </xs:restriction>
   </xs:simpleType>
</xs:element>

基本上没有枚举的,即使产生的所有其他元素生成的。有没有人见过这个问题吗?我使用的JAX-WS RI 2.2.1 http://jax-ws.java.net/2.2.1/ 结果
谢谢

推荐答案

由Puspendu,绑定的客户端JAXB定制引用正好/ pretty接近你所需要的 - 你需要使用一个JAX-WS客户定制为您的例子。 JAXB和JAX-WS自定义基本上可以让你增加的架构元素定义WSDL /模式的,你不用管。有许多不同的东西,你可以完成诸如XML映射元素名称自定义Java元素,改变生成的API,并回答你的问题,产生的类型安全的枚举类为与枚举制约因素。

as referenced by Puspendu, JAXB client customization of the binding is exactly/pretty close to what you need -- you need to use a JAX-WS client customization for your example. JAXB and JAX-WS customizations essentially allows you to augment the definition of schema elements for WSDL/schema's that you do not control. there are MANY different things you can accomplish such as mapping xml element names to custom java elements, altering the generated API, and to answer your question, generating type-safe enum classes for elements that are restricted with an enum.

有两种方式/部件做了JAX-WS客户端定制。

There are two ways/parts to doing a client customization for JAX-WS.

1)如果WSDL引入外部架构文件
2)如果WSDL包含了完整的架构定义没有任何进口

1) if the WSDL imports an external schema file 2) if the WSDL contains the entire schema definition without any imports

如果WSDL引入外部架构文件的话,

if the wsdl imports an external schema file then,

基本上你需要创建一个新的文件(通常与JXB扩展,但其实并不重要),你将沿着一侧保持您正在生成的客户端存根/ API的WSDL。通常我命名这些文件中的架构的文件name_clientcustomization.jxb

basically you need to create a new file (typically with a jxb extension, but it really doesn't matter) that you will maintain along side the wsdl you are generating the client stub/api for. typically I name these files schema-file-name_clientcustomization.jxb

每次获得更新的WSDL的时候,你应该验证您的JXB文件仍然有效,该WSDL。我发现去寻找,尤其是枚举限制的最大的事情,被限制值的变化,空间变化,类型名称的变化等。

every time you get an updated wsdl, you should validate that your JXB file is still valid for that wsdl. The biggest things I've found to look for, especially with enum restrictions, is restricted value changes, namespace changes, type name changes, etc..

这个新的文件的内容将类似于这样:

the content of this new file will look something similar to this:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<jxb:bindings 
  xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
  xmlns:jxb="http://java.sun.com/xml/ns/jaxb"     
  targetNamespace="http://java.sun.com/xml/ns/jaxb" 
   version="1.0">

    <jxb:bindings schemaLocation="NameOfYourSchemaFile.xsd" 
         node="/xsd:schema[@targetNamespace='SCHEMANAMESPACE']">
        <jxb:schemaBindings>
            <jxb:package name="com.amazon.webservices.ecs" />
        </jxb:schemaBindings>

        <jxb:bindings node="xsd:element[@name='Condition']/xsd:simpleType">
            <jxb:typesafeEnumClass name="ConditionEnum" >
                <jxb:typesafeEnumMember value="All" name="ALL" />
                <jxb:typesafeEnumMember value="New" name="NEW" />
                <jxb:typesafeEnumMember value="Used" name="USED" />
                <jxb:typesafeEnumMember value="Collectible" name="COLLECTIBLE" />
                <jxb:typesafeEnumMember value="Refurbished" name="REFURBISHED" />
            </jxb:typesafeEnumClass>
        </jxb:bindings>
         </jxb:bindings>
</jxb:bindings>

本质上讲,这文件定义隆胸应该做的引用XSD文件。在这个文件中的所有绑定元素都有一个节点属性,是一个XPATH前pression的选择要增加的架构项目。在这个例子中,我指定的XPATH只选择元素的简单类型声明,我没有任何空间或其他信息。内的结合,我们定义了typesafeenumclass,这将导致JAXB / wsimport的生成枚举类重新present引用简单类型。因为它是一个匿名简单类型,这有效地定义一个类只为引用的元素。生成的类将是一个ENUM谁的承包商,​​客人被typesafeEnumMember元素的名属性定义的。

Essentially this file defines augmentation that should be done to the referenced xsd file. all bindings elements in this file have a node attribute which is an XPATH expression that selects the schema item that you want to augment. in the example, I don't have any namespace or other information so I specified the XPATH to select just the element's simple type declaration. within that binding, we define the typesafeenumclass, this causes the jaxb/wsimport to generate an enum class to represent the referenced simple type. since it's an anonymous simple type, this effectively defines a class just for the referenced element. The generated class will be an ENUM who's memebers are defined by the "name" attribute of the typesafeEnumMember element.

使用此JXB文件,你需要引用它在你的Ant任务,像这样:

to use this JXB file, you need to reference it in your ant task, like so:

<wsimport
        debug="true"
    keep="true"
    verbose="true"
    destdir="${generated.src}"
    package="com.amazon.webservices.ecs"
    wsdl="wsdl/AWSECommerceService.wsdl">

    <binding dir="wsdl" includes="*.jxb"/>

</wsimport>

如果WSDL定义内部的整个模式,那么你就需要使用JAX-WS自定义文件。这起案件是你的问题相符。

if the WSDL defines the entire schema internally, then you need to use a JAX-WS customization file. This case is what matches your question.

http://jax-ws.java.net/ nonav / 2.1.7 /文档/ customizations.html

JAX-WS客户定制是非常相似的JAXB定制。我们的想法是一致的,在大多数情况下自定义文件将改变那些专门与WSDL生成的构件的JAX-WS部分,而嵌入式JAXB定制执行相同的功能作为一个外部自定义文件:它改变基于生成的对象在架构。

JAX-WS client customization is very similar to the JAXB customization. The idea is identical, for the most part the JAX-WS portion of the customization file will alter generated artifacts that are specifically related to WSDL, whereas the embedded JAXB customization performs the same function as an external customization file: it alters the generated objects based on the schema.

最大的区别是,而不是告诉JAXB解析模式文件,你提供了一个结合部,其选择模式定义(使用XPATH)要应用定制。

The big difference is that rather than tell the JAXB parser where the schema file is, you provide a binding section that selects the schema definition (using XPATH) that you want to apply customization to.

这个例子其实我测试和验证生成则是问有关问题的元素枚举类,所以你可以逐字复制此JAX-WS定制的例子。

This example I actually tested and verified to generate an Enum class for the element you are asking questions about, so you can copy this JAX-WS customization example verbatim.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<jaxws:bindings
        wsdlLocation="AWSECommerceService.wsdl" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
    >

    <jaxws:bindings node="wsdl:definitions/wsdl:types/xsd:schema[@targetNamespace='http://webservices.amazon.com/AWSECommerceService/2010-11-01']">
        <jaxb:schemaBindings>
            <jaxb:package name="com.amazon.webservices.ecs"/>
        </jaxb:schemaBindings>


        <jaxb:bindings node="xsd:element[@name='Condition']/xsd:simpleType">
            <jaxb:typesafeEnumClass name="ConditionEnum" >
                <jaxb:typesafeEnumMember value="All" name="ALL" />
                <jaxb:typesafeEnumMember value="New" name="NEW" />
                <jaxb:typesafeEnumMember value="Used" name="USED" />
                <jaxb:typesafeEnumMember value="Collectible" name="COLLECTIBLE" />
                <jaxb:typesafeEnumMember value="Refurbished" name="REFURBISHED" />
            </jaxb:typesafeEnumClass>
        </jaxb:bindings>

    </jaxws:bindings>

</jaxws:bindings>

你会再引用此JAX-WS自定义文件,你会引用JXB文件的方式。

you would then reference this JAX-WS customization file the same way you would reference the JXB file.

我没有验证独立JAXB定制的例子,因为我真的只包括它作为一个例子,作为JAX-WS定制例如precursor解释。

I did not validate the standalone JAXB customization example, since I really only included it as an example and as a precursor explanation for the JAX-WS customization example.

在JAX-WS定制的例子,我没实际测试/验证对已链接的WSDL,所以你应该能够使用它作为一个起点。我注意到,有在WSDL定义枚举大量限制,所以我会假设你希望为大多数枚举/所有的人。

The JAX-WS customization example I did actually test/validate against the WSDL you have linked, so you should be able to use it as a starting point. I noticed that there are numerous enumerated restrictions in the defined WSDL, so I would assume you'll want to generate enums for most/all of them.

我希望这有助于。

这篇关于没有通过JAX-WS RI 2.2.1亚马逊ECS WSDL文件生成的枚举的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆