users@jaxb.java.net

SchemaFactory order source in relation to import directives

From: Young Matthew (4004) <"Young>
Date: Tue, 24 Aug 2010 13:33:19 +0000

Using latest JAXB (Suns)....

Built up a hierarchy of schemas which rely heavy on extensions. So right now I have a lot of schemas that import each other (see below). When creating a SchemaFactory the inputed sources have to be in the correct order (ie. commons.xsd before pojo.xsd because pojo.xsd imports commons.xsd). Otherwise type information isn't found. This is problem if I don't want to know the dependency (import) order prior to creating a Schema instance. Anyway to get around this? Using the import directives since constructing Java pojos from the schemas.


commons.xsd
<xs:schema xmlns="http://www.klistret.com/cmdb/ci/commons"
targetNamespace="http://www.klistret.com/cmdb/ci/commons"
xmlns:xs=http://www.w3.org/2001/XMLSchema
elementFormDefault="qualified">
.....
<xs:complexType name="Element" abstract="true">
     <xs:complexContent>
          <xs:extension base="Base">
               <xs:sequence>
                    <xs:element name="Ownership" type="Ownership" maxOccurs="1" />
               </xs:sequence>
         </xs:extension>
    </xs:complexContent>
</xs:complexType>
....
</xs:schema>

pojo.xsd
<xs:schema xmlns="http://www.klistret.com/cmdb/ci/pojo"
targetNamespace="http://www.klistret.com/cmdb/ci/pojo"
xmlns:commons="http://www.klistret.com/cmdb/ci/commons"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">

     <xs:import namespace=http://www.klistret.com/cmdb/ci/commons schemaLocation="commons.xsd" />
.....

     <xs:complexType name="Element">
          .....
          <xs:element name="configuration" type="commons:Element" maxOccurs="1" minOccurs="1" />
          ....

</xs:complexType>

</xs:schema>