Fausto,

I will reply through the Jira issue to keep you updated on any progress we make.

Werner

Fausto wrote:
Hi there,

I found what the issue is in this case.
One of the Schema's constructor (the one which runs from all others) adds a namespace with prefix="" and value="http://www.w3.org/2001/XMLSchema";.

While creating the root Schema on the SchemaUnmarshaller constructor, we have this:

        _schema = new Schema();
        //--initialize the schema to ensure that the default namespace
        //--is not set
        _schema.removeNamespace("");

While resolving the imports, the ImportUnmarshaller class creates a Schema using:

importedSchema = new Schema();

But does not remove the namespace with prefix="".

W3C defined that we must not implement a simpleType on the http://www.w3.org/2001/XMLSchema namespace and the code that implements this verification is doing it fine for me.

Problem is that in case we have an element declared like this:

    <xs:simpleType name="ElectronicAddressString">
        <xs:restriction base="xs:string">
            <xs:maxLength value="100"/>
        </xs:restriction>
    </xs:simpleType>

the "public XMLType getType(String typeName)" method on Schema class will find no prefix on "ElectronicAddressString" element name and so, take the namespace with prefix="", by doing this:

        String localName = typeName;
        String prefix = "";
        String ns = null;
int colon = typeName.indexOf(':'); if (colon >= 0) {
            localName = typeName.substring(colon + 1);
            prefix = typeName.substring(0,colon);
            ns = _namespaces.getNamespaceURI(prefix);
            if (ns == null)  {
                String err = "Schema#getType: ";
                err += "Namespace prefix not recognised '"+typeName+"'";
                throw new IllegalArgumentException(err);
            }
        }
/* //-- use default namespace if necessary
        if (ns == null) {
            ns = _namespaces.getNamespaceURI(prefix);
        }*/

By doing this, on the imported schema, it gets ns being http://www.w3.org/2001/XMLSchema. This ns variable is passed to the getSimpleType method, which is where the exception is thrown, by this:

        else if (namespace.equals(_schemaNamespace)) {
            /*result= simpleTypesFactory.getBuiltInType(name);*/
            if (result == null)  {
                String err = "getSimpleType: the simple type '"+name+
"' is not a built-in type as defined in XML Schema specification.";
                    throw new IllegalArgumentException(err);
            }
        }

This getBuiltInType will return null as there is not a ElectronicAddressString on built-in types.

To test it, you probably will make it if you import a Schema that has no targetNamespace and declares simpleTypes with no prefixes.

Hope this helps.

I created the jira ticket and added all this info on there.

Thank you.
Fausto.

On Thu, Mar 13, 2008 at 6:23 AM, Werner Guttmann <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>> wrote:

    Sure.

    Werner

    Fausto wrote:
     > Ok.
     >
     > I will get the code and try to work that around... then I come to you
     > with possible solutions, ok?
     >
     > On Wed, Mar 12, 2008 at 11:15 AM, Ralf Joachim
    <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
     > <mailto:[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>>>
    wrote:
     >
     >     Hi Fausto,
     >
     >     anybody is allowed to do an anonymous checkout of castor.
    Take a look
     >     at: http://castor.codehaus.org/scm.html
     >
     >     Regards
     >     Ralf
     >
     >
     >     Fausto schrieb:
     >      > Ok, I will try to do that.
     >      > Do I have access to the entire codebase, anyway? Or can I do
     >     something
     >      > to have it?
     >      >
     >      > On Tue, Mar 11, 2008 at 6:07 PM, Werner Guttmann
     >      > <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
    <mailto:[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>>
     >     <mailto:[EMAIL PROTECTED]
    <mailto:[EMAIL PROTECTED]> <mailto:[EMAIL PROTECTED]
    <mailto:[EMAIL PROTECTED]>>>>
     >     wrote:
     >      >
     >      >     Fausto,
     >      >
     >      >     can you please create a new Jira issue at
     >      >
     >      >     http://jira.codehaus.org/browse/CASTOR
     >      >
     >      >     and attach a working JUnit test case that I can use to
    replay
     >     your
     >      >     problem ? I am not sure whether we are looking at a bug or
     >     not, but I'd
     >      >     need something to 'play with' to get an educated opinion.
     >      >
     >      >     Regards
     >      >     Werner
     >      >
     >      >     Fausto wrote:
     >      >     > I am having a problem while reading a schema which
    includes
     >     other
     >      >     schema.
     >      >     > I cannot send the schema information due to business
     >     policies, but
     >      >     I can
     >      >     > create samples.
     >      >     >
     >      >     > My schema goes like this:
     >      >     >
     >      >     > On SchemaOne.xsd:
     >      >     >
     >      >     > <xs:schema xmlns:careq="http://my.schema.SchemaOne.xsd
     >      >     > <http://my.schema.schemaone.xsd/>"
     >      >     > xmlns:xs="http://www.w3.org/2001/XMLSchema";
     >      >     > targetNamespace="http://my.schema.one
    <http://my.schema.one/>"
     >      >     > elementFormDefault="unqualified
     >      >     > " attributeFormDefault="unqualified" version="1.0">
     >      >     >     <xs:include schemaLocation="SchemaTwo.xsd"/>
     >      >     >
     >      >     > On SchemaTwo.xsd:
     >      >     >
     >      >     > <xs:schema xmlns:mv="http://my.schema.SchemaTwo.xsd
     >      >     > <http://my.schema.schematwo.xsd/>"
     >      >     > xmlns:xs="http://www.w3.org/2001/XMLSchema";
     >      >     > elementFormDefault="unqualified"
     >     attributeFormDefault="unqualified"
     >      >     > version="1.0">
     >      >     > (...)
     >      >     >     <xs:simpleType name="MySimpleType">
     >      >     >         <xs:annotation>
     >      >     >
     >     <xs:documentation>------------------</xs:documentation>
     >      >     >
     >     <xs:documentation>------------------</xs:documentation>
     >      >     >         </xs:annotation>
     >      >     >         <xs:restriction base="xs:string">
     >      >     >             <xs:maxLength value="100"/>
     >      >     >         </xs:restriction>
     >      >     >     </xs:simpleType>
     >      >     > (...)
     >      >     >
     >      >     > SchemaOne.xsd does not use the MySimpleType.
     >      >     >
     >      >     > When I try the method read() from a SchemaReader, I get
     >     this error:
     >      >     >
     >      >     > org.exolab.castor.xml.schema.SchemaException: An error
     >     occured at
     >      >     line:
     >      >     > 53: getSimpleType: the simple type 'MySimpleType' is
    not a
     >      >     built-in type
     >      >     > as defined in XML Schema specification.
     >      >     >     at
     >      >     >
     >      >
> org.exolab.castor.xml.schema.reader.ImportUnmarshaller.<init>(ImportUnmarshaller.java:203)
     >      >     >     at
     >      >     >
     >      >
> org.exolab.castor.xml.schema.reader.SchemaUnmarshaller.startElement(SchemaUnmarshaller.java:519)
     >      >     >     at
     >      >     >
     >      >
> org.exolab.castor.xml.schema.reader.Sax2ComponentReader.startElement(Sax2ComponentReader.java:255)
     >      >     >     at
> > org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown
     >      >     > Source)
     >      >     >     at
     >      >     >
     >      >
> org.apache.xerces.parsers.AbstractXMLDocumentParser.emptyElement(Unknown
     >      >     > Source)
     >      >     >     at
     >      >     >
     >      >
> org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown
     >      >     > Source)
     >      >     >     at
     >      >     >
     >      >
> org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown
     >      >     > Source)
     >      >     >     at
     >      >     >
     >      >
> org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown
     >      >     > Source)
     >      >     >     at
     >     org.apache.xerces.parsers.XML11Configuration.parse(Unknown
     >      >     Source)
     >      >     >     at
     >     org.apache.xerces.parsers.XML11Configuration.parse(Unknown
     >      >     Source)
     >      >     >     at org.apache.xerces.parsers.XMLParser.parse(Unknown
     >     Source)
     >      >     >     at
     >     org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown
     >      >     Source)
     >      >     >     at
     >      >     >
     >      >
> org.exolab.castor.xml.schema.reader.SchemaReader.read(SchemaReader.java:248)
     >      >     > ( front-end stack trace )
     >      >     > Caused by:
    org.exolab.castor.xml.schema.SchemaException: An
     >     error
     >      >     > occured at line: 53: getSimpleType: the simple type
     >      >     > 'ElectronicAddressString' is not a built-in type as
    defined
     >     in XML
     >      >     > Schema specification.
     >      >     >     at
     >      >     >
     >      >
> org.exolab.castor.xml.schema.reader.Sax2ComponentReader.startElement(Sax2ComponentReader.java:258)
     >      >     >     at
> > org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown
     >      >     > Source)
     >      >     >     at
     >      >     >
     >      >
> org.apache.xerces.parsers.AbstractXMLDocumentParser.emptyElement(Unknown
     >      >     > Source)
     >      >     >     at
     >      >     >
     >      >
> org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown
     >      >     > Source)
     >      >     >     at
     >      >     >
     >      >
> org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown
     >      >     > Source)
     >      >     >     at
     >      >     >
     >      >
> org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown
     >      >     > Source)
     >      >     >     at
     >     org.apache.xerces.parsers.XML11Configuration.parse(Unknown
     >      >     Source)
     >      >     >     at
     >     org.apache.xerces.parsers.XML11Configuration.parse(Unknown
     >      >     Source)
     >      >     >     at org.apache.xerces.parsers.XMLParser.parse(Unknown
     >     Source)
     >      >     >     at
     >     org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown
     >      >     Source)
     >      >     >     at
     >      >     >
     >      >
> org.exolab.castor.xml.schema.reader.ImportUnmarshaller.<init>(ImportUnmarshaller.java:197)
     >      >     >     ... 41 more
     >      >     >
     >      >     >
     >      >     > I've looked at internet and found something like
    "this happens
     >      >     when the
     >      >     > schema namespace is the same as
     >     http://www.w3.org/2001/XMLSchema";, but
     >      >     > this is not what happens.
     >      >     >
     >      >     > However, the SchemaTwo.xsd does not have a
    targetNamespace
     >     defined
     >      >     and I
     >      >     > was thinking that if this could be a bug.
     >      >     >
     >      >     > I do not have access to the entire codebase, but I could
     >     find this on
     >      >     > fisheye.codhaus.org <http://fisheye.codhaus.org>
    <http://fisheye.codhaus.org>
     >     <http://fisheye.codhaus.org>
     >      >     <http://fisheye.codhaus.org/>:
     >      >     >
     >      >     >         SimpleType result = null;
     >      >     >         if (ns == null) {
     >      >     >
     >      >     >             //-- first check user-defined types
     >      >     >             result = (SimpleType)_simpleTypes.get(name);
     >      >     >             if (result != null) {
     >      >     >                 //-- resolve deferred type if necessary
     >      >     >                 if (result.getType() != result) {
     >      >     >                     //-- can result.getType ever
    return null?
     >      >     >                     //-- We can check, just in case.
     >      >     >                     if (result.getType() != null) {
     >      >     >                         result =
    (SimpleType)result.getType();
     >      >     >                         result.setParent(this);
     >      >     >                         _simpleTypes.put(name, result);
     >      >     >                     }
     >      >     >                 }
     >      >     >             }
     >      >     >             //-- otherwise try built-in types
     >      >     >             else {
     >      >     >                 result=
     >     simpleTypesFactory.getBuiltInType(name);
     >      >     >                 //if we have a built-in type not
    declared
     >     in the good
     >      >     > namespace -> Exception
     >      >     > *                if ( (result != null) &&
     >      >     > (_namespaces.contains(DEFAULT_SCHEMA_NS))) {
     >      >     >                     String err = "getSimpleType: the
    simple
     >     type
     >      >     '"+name+
     >      >     >                                 "' has not been
    declared in
     >     XML Schema
     >      >     > namespace.";*
     >      >     >                     throw new
    IllegalArgumentException(err);
     >      >     >                 }
     >      >     >             }
     >      >     >         }
     >      >     >         else if (ns.equals(_schemaNamespace)) {
     >      >     >             result=
     >     simpleTypesFactory.getBuiltInType(canonicalName);
     >      >     >            * if (result == null)  {*
     >      >     > *                 String err = "getSimpleType: the
    simple type
     >      >     > '"+canonicalName+
     >      >     >                                 "' is not a built-in
    type as
     >      >     defined in
     >      >     > XML Schema specification.";*
     >      >     >                     throw new
    IllegalArgumentException(err);
     >      >     >                 }
     >      >     >         }
     >      >     >
     >      >     > There might be a bug with the xsd having no
    namespace? In what
     >      >     cases the
     >      >     > result is null?
     >      >     > Do you need more information?
     >      >     >
     >      >     > I need to solve this as soon as I can, because even
    setting
     >      >     > setValidation(false); on the reader does not work.
     >      >     >
     >      >     > Thank you,
     >      >     > Fausto.
     >      >
     >      >
     >      >
> ---------------------------------------------------------------------
     >      >     To unsubscribe from this list, please visit:
     >      >
     >      >        http://xircles.codehaus.org/manage_email
     >      >
     >      >
     >      >
     >      >
     >      >
     >      > --
     >      >
     >      > Obrigado,
     >      > Fausto.
     >
     >     --
     >
     >     Syscon Ingenieurbüro für Meß- und Datentechnik GmbH
     >     Ralf Joachim
     >     Raiffeisenstraße 11
     >     72127 Kusterdingen
     >     Germany
     >
     >     Tel.   +49 7071 3690 52
     >     Mobil: +49 173 9630135
     >     Fax    +49 7071 3690 98
     >
     >     Internet: www.syscon.eu
     >     E-Mail: [EMAIL PROTECTED]
    <mailto:[EMAIL PROTECTED]> <mailto:[EMAIL PROTECTED]
    <mailto:[EMAIL PROTECTED]>>
     >
     >     Sitz der Gesellschaft: D-72127 Kusterdingen
     >     Registereintrag: Amtsgericht Stuttgart, HRB 382295
     >     Geschäftsleitung: Jens Joachim, Ralf Joachim
     >
> ---------------------------------------------------------------------
     >     To unsubscribe from this list, please visit:
     >
     >        http://xircles.codehaus.org/manage_email
     >
     >
     >
     >
     >
     > --
     >
     > Obrigado,
     > Fausto.



    ---------------------------------------------------------------------
    To unsubscribe from this list, please visit:

       http://xircles.codehaus.org/manage_email





--

Obrigado,
Fausto.


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email


Reply via email to