users@jaxb.java.net

Problem with imported schema: There's no ObjectFactory with an @XmlElementDecl for the element {http://purl.org/dc/terms/}identifier.

From: <m.turra_at_kion.it>
Date: Tue, 25 Oct 2011 08:04:15 +0000 (GMT)

My schema reference other schema with following import element:

        <xs:import namespace="http://purl.org/dc/terms/"
schemaLocation="http://dublincore.org/schemas/xmls/qdc/dcterms.xsd"/>

        <xs:import namespace="http://purl.org/dc/dcmitype/"
schemaLocation="http://dublincore.org/schemas/xmls/qdc/dcmitype.xsd"/>

After xjc compilation I obtain 3 ObjectFactory:
- in com.example.gen: the package specified in bindings.xjb
file(element jaxb:bindings/jaxb:schemaBindings/jaxb:package).
- in org/purl/dc/terms package (for xmlns="http://purl.org/dc/terms/")
- in org/purl/dc/elements._1 (for
xmlns="http://purl.org/dc/elements/1.1/" ???)

I use spring framework to marshal response on http directly (with
org.springframework.http.converter.xml.AbstractJaxb2HttpMessageConverte
r class).
This class construct JABContext passing only the object class:
jaxbContext = JAXBContext.newInstance(clazz);
The result is jaxb not seeing other ObjectFacotry in org/purl/dc/terms
and org/purl/dc/elements._1 packages.
This is the error message on console:
com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of
IllegalAnnotationExceptions
There's no ObjectFactory with an @XmlElementDecl for the element
{http://purl.org/dc/terms/}identifier.
        this problem is related to the following location:
                at protected javax.xml.bind.JAXBElement
com.example.gen.DocumentMetadataType.identifier

To solve this problem I follow two path:
a) Make my own javax.xml.bind.context.factory with jaxb.properties file
b) Use the @XmlSeeAlso annotation on generated class file

Results:

a) In my MyJAXBContextFactory.createContext method I call
JAXBContext.newInstance("com.example.gen:org.purl.dc.terms:org.purl.dc.
elements._1"); this leads in a infinte loop because looking in
com.example.gen package jaxb finds jax.properties again. If I remove
com.example.gen from the package list jaxb can't find the generated
classes in com.example.gen package!

b) I got the error before jaxb look for annotation. I'm not sure
XmlSeeAlso could be the solution.

How can I extend JAXBContext to see other packages?

Thank you in advance.
Matteo