users@jaxb.java.net

Re: specifying minOccurs when using _at_XmlElementRef?

From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Date: Mon, 30 Jul 2007 13:53:40 -0700

James.Strachan wrote:
> So I really like @XmlElementRef; it means if a base class is used throughout
> a POJO model (such as a Task in the example given in the JavaDoc)
>
> https://jaxb.dev.java.net/nonav/jaxb20-pfd/api/javax/xml/bind/annotation/XmlElementRef.html
>
> then you don't have to litter your code on all field/properties of type Task
> with an @XmlElements({every single @XmlElement goes here}).

Yes. Exactly.

>
> By default the use of @XmlElementRef in code like this...
> @XmlElementRef
> List<Task> tasks;
>
> generates a choice as follows...
> <xs:choice maxOccurs="unbounded">
> <xs:element ref="jar">
> <xs:element ref="javac">
> ...
>
> I don't see a way to specify the minOccurs property. I'd like it to be zero
> by default :). Anyone any clue how you could specify 0 or 1?

We really should have had @XmlElementRef.required() just like
XmlElement.required() and XmlElementWrapper.required()

> If there's no way to do this via the JAXB 2 standard annotations; I wonder
> if we could add an extension annotation in the com.sun.* namespace that the
> schemagen could use?

That's doable, and thank you for filing an issue.

-- 
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com