问题描述
我正在使用 JAXB 从带有 Apache CXF 的 WSDL 生成 Java 类。 在服务的 XSD 中,存在多个 ErrorElement,如 ValidationFaultType 等。 使用继承插件,我创建了一个自定义绑定,它告诉 JAXB 将元素绑定到我提供的接口。不幸的是,其中一些元素也有嵌套元素,我还想为其提供一个接口(请参阅下面的 XSD-Snippets)。不幸的是,生成的父级没有使用嵌套接口,而是使用了 conrete 类......
这是父元素:
<xsd:complexType name="ValidationFaultType">
<xsd:complexContent>
<xsd:extension base="ns0:AbstractFaultType">
<xsd:sequence>
<xsd:element name="functionalError" type="ns3:FunctionalErrorType" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
这是嵌套元素:
<xsd:complexType name="FunctionalErrorType">
<xsd:sequence>
<xsd:element name="errorCode" type="ns1:ErrorCodeContentType"/>
<xsd:element name="errorPointer" type="ns2:ErrorPointerContentType" minOccurs="0"/>
<xsd:element name="errorReason" type="ns3:ErrorTextContentType" minOccurs="0"/>
<xsd:element name="originalAttributeValue" type="ns0:AttributeValueContentType" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
这是绑定文件。
<jxb:bindings schemaLocation="*">
<jxb:bindings node="//xs:complexType[@name='FunctionalErrorType']" multiple="true" required="false">
<inheritance:implements>interfaces.IFunctionalErrorType</inheritance:implements>
</jxb:bindings>
<jxb:bindings node="//xs:complexType[@name='ValidationFaultType']" multiple="true" required="false">
<inheritance:implements>interfaces.IValidationFaultType</inheritance:implements>
</jxb:bindings>
</jxb:bindings>
不幸的是,这会导致接口 IValidationFaultType 和生成的类之间出现 incompatible return types,因为它返回的是 FunctionalErrorType 列表而不是 IFunctionalErrorType 列表。有谁知道生成使用定义的接口作为返回类型的类的方法吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)