JAXB绑定自定义 [英] JAXB Binding Customization

查看:108
本文介绍了JAXB绑定自定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试从xsd生成类时,我遇到了这个错误:

While trying to generate classes from a xsd, i got this error:

java.lang.IllegalArgumentException: Illegal class inheritance loop.  Outer class OrderPropertyList may not subclass from inner class: OrderPropertyList

我的xsd定义一个元素来对无界元素进行分组像这样:

My xsd define a element to group a unbounded element like this:

  <element minOccurs="0" name="orderPropertyList">
    <complexType>
      <sequence>
        <element maxOccurs="unbounded" name="orderProperty" type="tns:orderProperty" />
      </sequence>
    </complexType>
  </element>

我的自定义绑定遵循这个页面,但它不起作用。
这里我的绑定:

And my customization binding follows as specified on this page, but it doesn´t work. Here my binding:

<jaxb:bindings schemaLocation="../xsd/Schema.xsd" node="/xs:schema">
    <jaxb:bindings node="//xs:element[@name='orderPropertyList']">
        <jaxb:class name="OrderPropertyList"/>
    </jaxb:bindings>
</jaxb:bindings>

我的目的是为orderPropertyList生成一个单独的类,而不是生成内部类的默认行为在xsd的根元素内。

My intention is to generate a individual class for orderPropertyList, not the default behave that is generating a inner class inside the root element of the xsd.

我看了一个意图相同的人这里这里,但它对我不起作用。 :(

I´ve watched someone with the same intention here and here, but it doesn´t work properly for me. :(

JAXB版本:

Specification-Version: 2.1
Implementation-Version: 2.1.8

任何帮助?

推荐答案

我相信您需要设置的内容:

I believe what you need to to is set:

<jaxb:globalBindings localScoping="toplevel"/>

这将生成独立的类而不是嵌套类。

This will generate standalone classes instead of nested classes.

执行

<jaxb:bindings schemaLocation="../xsd/Schema.xsd" node="/xs:schema">
    <jaxb:bindings node="//xs:element[@name='orderPropertyList']">
            <jaxb:class name="OrderPropertyList"/>
    </jaxb:bindings>
</jaxb:bindings>

是一个冗余绑定,因为orderPropertyList默认会映射到OrderPropertyList。包的名称包含默认嵌套的外部类名,所以你''不要改变那个。

is a redundant binding, since orderPropertyList will map by default to OrderPropertyList. The name of the package includes the outer class name it is nested in by default, so you're not changing that.

另外,如果你确实想要更改生成的类的名称,我认为XPath实际上是:

Also, if you did want to change the name of the generated class, I think the XPath would actually be:

<jaxb:bindings node="//xs:element[@name='orderPropertyList']/xs:complexType">

末尾带有complexType。我认为排除这是导致你得到错误信息的原因。

with complexType on the end. I think excluding this was what was causing the error message you got.

这篇关于JAXB绑定自定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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