更改生成的jaxb类的包
我在 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>
我希望 MyEnum 落入其自己的包中。因此,我使用了 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>
现在,schemaBindings 中设置的路径采用 - 并将该模式/目标命名空间中的所有数据类型放入包 abra 中。 ca.达布拉。但是,我似乎无法仅设置 MyEnum 的包 - 这正是我想要的。
我使用 cxf 的 wsdl2java 来提供绑定文件。我错过了什么吗?
I have the following data type defined in a 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. So, I used a jaxws binding file, and used XPATH to traverse the schema and jaxb bindings to set the package, as follows:
<?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. However, I can't seem to set the package of just MyEnum - which is what I want.
I use cxf's wsdl2java to provide the bindings file. Am I missing something?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我会尝试这样的事情:
更准确地说,您应该使整个 wsdl 可用
希望这有帮助......
I would try it with something likethis:
To be more precise you should make the whole wsdl available
Hope this helps ...
您是否尝试过向仅包含 MyEnum 且具有不同名称空间的 WSDL 添加第二个模式?然后,原始架构定义应从新命名空间导入该类型。
Have you tried to add a second schema to the WSDL that only contains MyEnum, with a different namespace? The original schema definition should then import that type from the new namespace.