开发者

Can I configure XJC bindings to generate collections as Set instead of List

Given a schema such as this:

<xs:element name="Group" type="GroupType"/>

<xs:complexType name="GroupType">
    <xs:sequence>
        <xs:element type="OptionsType" name="Options" maxOccurs="1" minOccurs="1"/>
        <xs:element type="PageContainerType" name="PageContainer" maxOccurs="unbounded" minOccurs="0"/>
    </xs:sequence>
</xs:complexType>

<xs:complexType name="PageContainerType">
    <xs:sequence>
      ...
    </xs:sequence>
</xs:compl开发者_JAVA百科exType>

XJC will generate Java something like:

public class GroupType {
  @XmlElement(name = "Options", required = true)
  protected OptionsType options;
  @XmlElement(name = "PageContainer")
  protected List<PageContainerType> pageContainer;
  ...
}

I want to enforce a unique collection for the PageContainer element. This is a reverse-engineering project so I'm not too concerned about making sure the schema enforces it explicitly.

Is it possible to generate the PageContainer element as a Set<PageContainerType>, by either specifying something in the schema or in XJC bindings?


JAXB runtimes (atleast Metro and MOXy) can handle properties of type java.util.Set. For an example see:

  • Mapping Java collections which contains super- and sub-types with JAXB

Both the Metro and MOXy JAXB implementations use the same XJC tool to compile XML schemas into Java classes. You may want to post your question to the following forum:

  • http://forums.java.net/jive/forum.jspa?forumID=46

You may also be able to achieve the desired result by writing an XJC plugin:

  • http://weblogs.java.net/blog/kohsuke/archive/2005/06/writing_a_plugi.html
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜