简体   繁体   English

更改生成的jaxb类的包

[英]change package of generated jaxb class

I have the following data type defined in a wsdl: 我在wsdl中定义了以下数据类型:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="myService" targetNamespace="http://example.com" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://example.com" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
    <wsdl:types>
        <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="example.com" targetNamespace="example.com" version="1.0">
            <xs:simpleType name="MyEnum">
                <xs:restriction base="xs:string">
                    <xs:enumeration value="one"/>
                    <xs:enumeration value="two"/>
                </xs:restriction>
            </xs:simpleType>
            <!-- SNIP other data types -->
        </xs:schema>
    </wsdl:types>
</wsdl:definitions>

I want MyEnum to fall into its own package. 我希望MyEnum落入自己的包中。 So, I used a jaxws binding file, and used XPATH to traverse the schema and jaxb bindings to set the package, as follows: 所以,我使用了一个jaxws绑定文件,并使用XPATH遍历模式和jaxb绑定来设置包,如下所示:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<jaxws:bindings xmlns:jxb="http://java.sun.com/xml/ns/jaxb" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://java.sun.com/xml/ns/jaxws">
    <jaxws:bindings node="wsdl:definitions/wsdl:types/xs:schema[@targetNamespace='example.com']">
      <jxb:schemaBindings>
          <jxb:package name="abra.ca.dabra" /> <!-- this works, and changes package of all classes in the namespace-->
      </jxb:schemaBindings>
      <jxb:bindings node="//xs:simpleType[@name='MyEnum']">
          <jxb:package name="a.b.c"/> <!-- this does not work -->
      </jxb:bindings>
    </jaxws:bindings>
    <!-- SNIP - other functional jaxws bindings -->
</jaxws:bindings>

Now, the path set in schemaBindings takes - and puts all data types from that schema/targetnamespace into package abra.ca.dabra. 现在,schemaBindings中设置的路径采用 - 并将来自该模式/目标名称空间的所有数据类型放入包abra.ca.dabra中。 However, I can't seem to set the package of just MyEnum - which is what I want. 但是,我似乎无法设置MyEnum的包 - 这就是我想要的。

I use cxf's wsdl2java to provide the bindings file. 我使用cxf的wsdl2java来提供绑定文件。 Am I missing something? 我错过了什么吗?

I would try it with something likethis: 我会用它的东西来尝试:

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

<jaxws:enableWrapperStyle>false</jaxws:enableWrapperStyle>

<!-- set default package structure -->
<jaxws:package name="abra.ca.dabra" />

<!-- set package structure for complex schema types -->
<jaxws:bindings node="wsdl:definitions/wsdl:types/xs:schema/xs:simpleType[@name='MyEnum']">
    <jaxb:schemaBindings>
        <jaxb:package name="a.b.c" />
    </jaxb:schemaBindings>
</jaxws:bindings>

To be more precise you should make the whole wsdl available 更准确地说,你应该让整个wsdl可用

Hope this helps ... 希望这可以帮助 ...

Have you tried to add a second schema to the WSDL that only contains MyEnum, with a different namespace? 您是否尝试将第二个模式添加到仅包含MyEnum的WSDL,并使用不同的命名空间? The original schema definition should then import that type from the new namespace. 然后,原始模式定义应从新名称空间中导入该类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM