通过JaxB JXC为XSD序列生成数组 [英] Generating Arrays for XSD Sequences via JaxB JXC

查看:94
本文介绍了通过JaxB JXC为XSD序列生成数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个描述复杂类型序列的XSD,例如

I've got a XSD describing some sequences of complex types e.g.

<xs:complexType name="Catalog">
  <xs:sequence>
    <xs:element name="Category" minOccurs="0" maxOccurs="unbounded">
      <xs:complexType>
        <xs:sequence>
          <xs:element type="xs:string" name="ParentCategoryIDRef"/>
          <xs:element type="xs:string" name="Method"/>
        </xs:sequence>
      <xs:complexType>
    </xs:element>
  </xs:sequence>
<xs:complexType>

现在,当我使用JaxBs XJC将其转换为Java类时,它将生成一个 java.util.List 在我的目录类中,字段和getter / setter为类别

Now when I use JaxBs XJC to convert this into Java classes it will generate me a java.util.List in my Catalog class for the field and getter/setter of Category.

但是,使用java2wsdl在Axis2 webservice中使用它需要的是像 <$ c $这样的数组c>类别[]

However, what I need for using it in an Axis2 webservice using java2wsdl are Arrays like Category[].

我对JaxB绑定有点熟悉,并且已经尝试使用以下方法指定集合类型:

I'm a bit familiar with JaxB bindings and already tried specifying the collection type using:

<jaxb:property collectionType="Category[]"/>

导致代码无效,因为它仍然使用 java.util .List ,但是使用构造函数 new Category []< Category>

which resulted in invalid code, because it was still using a java.util.List, but with a constructor new Category[]<Category>.

当然,我总是可以在生成后编辑生成的代码,但是当我尝试重新生成代码时,这会导致问题。

Of course I can always edit the generated code after generation, but this would cause problems when I try to re-generate it.

我有什么现在是:

public class Catalog {
  @XmlElement(name = "Category")
  protected List<Category> category;
}

我想要的是:

public class Catalog {
  @XmlElement(name = "Category")
  protected Category[] category;
}

有什么想法吗?
我目前正在使用XJC 2.2.6和Axis2 1.6.2。

Any ideas? I'm currently using XJC 2.2.6 with Axis2 1.6.2.

推荐答案

我认为你需要使用javaType标记:

I think you need to use the javaType tag:

<xs:complexType name="catalog">
        <xs:sequence>
            <xs:element name="category" type="ns:Category" >
                <xs:annotation>
                    <xs:appinfo>
                        <jxb:javaType name="Category[]"/>
                    </xs:appinfo>
                </xs:annotation>
            </xs:element>
        </xs:sequence>
    </xs:complexType>

生成以下类:

public class Catalog {

        @XmlElement(required = true, type = Category.class)
        protected Category[] category;

        public Category[] getCategory() {
            return category;
        }

        public void setCategory(Category[] value) {
            this.category = value;
        }

    }

(使用org.apache。 cxf cxf-xjc-plugin 2.6.2 maven插件)

(Using the org.apache.cxf cxf-xjc-plugin 2.6.2 maven plugin)

您还需要在XSD中定义Category ...

You will also need the definition of Category in your XSD...

这篇关于通过JaxB JXC为XSD序列生成数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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