users@jaxb.java.net

Re: accessing schema info at runtime

From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Date: Thu, 04 Aug 2005 16:47:11 -0700

Dmitri Colebatch wrote:
> On 8/5/05, JAXB User <jaxbuser_at_yahoo.com> wrote:
>> Thanks, this is helpful. One follow-up question: if I want to whether each
>> sub-element is required or not (i.e. minOccurs > 0), is this information
>> available as well?
>
> I'm not sure - I don't believe that there are annotations for
> validation. I imagine Kohsuke could give a better answer...

In general, XJC's compilation may lose some of the schema information.
Whether a property is required or not maybe one of them.

In some cases, annotations capture that information, such as
XmlAttribute.required(). You also know that if the property is a
primitive type, it is required. But otherwise it's assumed to be optional.

If you need to be able to mark required element, you might need to come
up with your own annotation, like maybe @NotNull or something.

-- 
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com