I attached a patch file that fixed this problem for me.  It also fixes a
second problem where Castor does not handle the case were a complexType
extends xs:anyType.

This diff is based on a CVS version of Schema.java from 2 weeks ago.  I
planned to do a bit more testing then submit this to Bugzilla.  But here it
is until then.

Regards,
  Dave Carlson

----- Original Message -----
From: "Perryn Fowler" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, June 14, 2002 2:37 AM
Subject: [castor-dev] Status of imported schema's with Castor Source
Generator?


>
> I have recently run into a problem when trying to generate Java classes
from
> a schema
> which uses <xsd:import> to import another schema containing components
from
> another namespace.
>
> Basically Castor doesnt seem to recognize that these components are
imported
> when they are referenced
> and complains that they are not built-in types.
>
> I have seen a number of other post to this list about this problem
recently
> and was wondering what the status
> of this problem is? Is there a bug raised for it? This is unfortunately a
> showstopper for us wrt Castor so
> Im looking for a handle on whats happening with it.
>
> Cheers
> Perryn
>
>
> For reference I have produced the problem using the 'report' example from
> the W3C Schema Primer:
>
> In ipo.xsd:
> <schema targetNamespace="http://www.example.com/IPO";
>         xmlns="http://www.w3.org/2001/XMLSchema";
>         xmlns:ipo="http://www.example.com/IPO";>
>
> <!-- SNIP -->
>
>  <simpleType name="SKU">
>   <restriction base="string">
>    <pattern value="\d{3}-[A-Z]{2}"/>
>   </restriction>
>  </simpleType>
>
> </schema>
>
>
> In report.xsd:
> <schema targetNamespace="http://www.example.com/Report";
>         xmlns="http://www.w3.org/2001/XMLSchema";
>         xmlns:r="http://www.example.com/Report";
>         xmlns:xipo="http://www.example.com/IPO";
>         elementFormDefault="qualified">
>
> <import schemaLocation="ipo.xsd" namespace="http://www.example.com/IPO"; />
>
> <!-- SNIP -->
>
>  <complexType name="RegionsType">
>   <sequence>
>    <element name="zip" maxOccurs="unbounded">
>     <complexType>
>      <sequence>
>       <element name="part" maxOccurs="unbounded">
>        <complexType>
>           <attribute name="number"   type="xipo:SKU"/>          <---------
>
>           <attribute name="quantity" type="positiveInteger"/>
>        </complexType>
>       </element>
>      </sequence>
>      <attribute name="code" type="positiveInteger"/>
>     </complexType>
>    </element>
>   </sequence>
>  </complexType>
> </schema>
>
> then an attempt to generate from report.xsd produces:
>
> Exception in thread "main" java.lang.IllegalArgumentException:
> getSimpleType: the simple type 'SKU' is not a built-in type as defined in
> XML Schema specification.
>
Index: src/main/org/exolab/castor/xml/schema/Schema.java
===================================================================
RCS file: /cvs/castor/castor/src/main/org/exolab/castor/xml/schema/Schema.java,v
retrieving revision 1.50
diff -u -r1.50 Schema.java
--- src/main/org/exolab/castor/xml/schema/Schema.java   5 May 2002 01:07:00 -0000      
 1.50
+++ src/main/org/exolab/castor/xml/schema/Schema.java   31 May 2002 14:55:30 -0000
@@ -856,7 +856,11 @@
         else {
             Schema schema = getImportedSchema(ns);
             if (schema!=null)
-                result = schema.getSimpleType(canonicalName);
+                //result = schema.getSimpleType(canonicalName);
+                // Modified by Dave Carlson.
+                // The canonicalName (without prefix) will look for XSD built-in
+                // types when XSD is the default ns.
+                result = schema.getSimpleType(name);
         }
 
         //-- Result could be a deferredSimpleType => getType will resolve it
@@ -1211,6 +1215,29 @@
      */
     public XMLType getType(String typeName)
     {
+       /*
+        * Modified by Dave Carlson
+        * Causes error when complexType extends anyType
+        * (copied this from class TypeReference)
+        */
+        //-- is AnyType? resolve namespace if necessary
+        //-- and check for 'anyType'.
+        String canonicalName = typeName;
+        String nsPrefix = "";
+        int colon = typeName.indexOf(':');
+        if (colon >= 0) {
+            canonicalName = typeName.substring(colon + 1);
+            nsPrefix = typeName.substring(0,colon);
+        }
+        String ns = (String) getNamespace(nsPrefix);
+        
+        if (getSchemaNamespace().equals(ns)) {
+            if (canonicalName.equals(SchemaNames.ANYTYPE)) {
+                return new AnyType(this);
+            }
+        }
+        /* END MODIFICATION BY Dave Carlson */
+        
         XMLType result= getSimpleType(typeName);
         if (result == null)
             result = getComplexType(typeName);

Reply via email to