users@jaxb.java.net

Re: On Demand Valiadtion under JAXB 2.0

From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Date: Wed, 21 Jun 2006 08:07:42 -0700

Robinson Guifo Guifo wrote:
> I am migrating my application to jaxb 2 platform.
> I am suprised to note that ON_DEmand validation functionality is not upwards
> compatible.
> How can one implement on-demand validation in jaxb2 which is compatible with
> jaxb 1 implemention.
> I need on the fly and on demand validation.
> Please point me to some clear working examples

Due to various issues --- such as implementability, this feature was
made optional in the spec.

The closest equivalent would be to perform a validating marshalling.

> In order to do on demand validation on my jaxb2 migration
> I have carried out the following.
> Please note that schema Cameroun.xsd includes Camroun_simple_types.xsd.
>
>
> // References to the schema files
> Source[] schemas = new Source[]{
> new StreamSource("Cameroun.xsd"),
> new StreamSource("Cameroun_simple_types.xsd")
> };
>
> // Obtain schema object
> SchemaFactory schemaFactory =
> schemaFactory.newInstance(XMLConstants.W3C_XML_SCH EMA_NS_URI);
> Schema schema = schemaFacotry.newSchema(schemas);
>
> // create unmarshaller
> JAXBContext jCtx = JAXBContext.newInstance("MountCamerounCoupe.bar");
> Unmarshaller unmarshaller = jCtx.createUnmarshaller();
> unmarshaller.setSchema(shema);
>
> When my application runs, i get the folloeing exception
> SaxParseException: Cannot resolve the name townType.
>
> Clearly TownType is clearly specified in Cameroun_simple_types.xsd.
> Am I expected to write the resolver ?
>
> Any clear suggestions ?

It's hard to say. JAXP has a "feature" where it doesn't report any error
on failing <import> nor <include>. So errors like that usually suggest
that there was something wrong with the way your schemas are referencing
each other.

I filed this as a bug in JAXP, but I don't think that has been fixed yet.

-- 
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com