tags:

views:

24

answers:

1

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:complexType>

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?

A: 

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

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:

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

Blaise Doughan