微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

自定义 JAXB 绑定:如何为嵌套元素定义接口?

如何解决自定义 JAXB 绑定:如何为嵌套元素定义接口?

我正在使用 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 举报,一经查实,本站将立刻删除。