5 Replies Latest reply on Nov 2, 2005 6:46 AM by aloubyansky

    Strange annotations

      Another reason not to use Xerces is that it is broken? :-)

      For some reason it thinks that plainValueType has four annotations (it has one):

      765 TRACE [XsdBinder] binding complex type {urn:jboss:bean-deployer}plainValueType
      765 TRACE [XsdBinder] bound complex type {urn:jboss:bean-deployer}plainValueType
      765 TRACE [XsdBinder] {urn:jboss:bean-deployer}plainValueType attributes 1
      765 TRACE [XsdBinder] binding attribute class for {urn:jboss:bean-deployer}plainValueType
      766 TRACE [XsdBinder] class attribute annotation
      772 TRACE [SaxJBossXBParser] startElement enter http://www.w3.org/2001/XMLSchema:annotation
      773 TRACE [ObjectModelBuilder] accepted http://www.w3.org/2001/XMLSchema:xsd:annotation
      773 TRACE [SaxJBossXBParser] startElement exit http://www.w3.org/2001/XMLSchema:annotation
      773 TRACE [SaxJBossXBParser] startElement enter http://www.w3.org/2001/XMLSchema:appinfo
      773 TRACE [ObjectModelBuilder] accepted http://www.w3.org/2001/XMLSchema:xsd:appinfo
      773 TRACE [SaxJBossXBParser] startElement exit http://www.w3.org/2001/XMLSchema:appinfo
      773 TRACE [SaxJBossXBParser] startElement enter http://www.jboss.org/xml/ns/jbxb:property
      773 TRACE [ObjectModelBuilder] ignored http://www.jboss.org/xml/ns/jbxb:jbxb:property
      773 TRACE [SaxJBossXBParser] startElement exit http://www.jboss.org/xml/ns/jbxb:property
      773 TRACE [SaxJBossXBParser] endElement enter http://www.jboss.org/xml/ns/jbxb:property
      773 TRACE [SaxJBossXBParser] endElement exit http://www.jboss.org/xml/ns/jbxb:property
      774 TRACE [SaxJBossXBParser] endElement enter http://www.w3.org/2001/XMLSchema:appinfo
      774 TRACE [SaxJBossXBParser] endElement exit http://www.w3.org/2001/XMLSchema:appinfo
      774 TRACE [SaxJBossXBParser] endElement enter http://www.w3.org/2001/XMLSchema:annotation
      774 TRACE [SaxJBossXBParser] endElement exit http://www.w3.org/2001/XMLSchema:annotation
      774 TRACE [XsdBinder] bound attribute class property=type, collectionType=null
      
      Why 4?
      
      774 TRACE [XsdBinder] {urn:jboss:bean-deployer}plainValueType annotations 4
      782 TRACE [SaxJBossXBParser] startElement enter http://www.w3.org/2001/XMLSchema:annotation
      782 TRACE [ObjectModelBuilder] accepted http://www.w3.org/2001/XMLSchema:xsd:annotation
      782 TRACE [SaxJBossXBParser] startElement exit http://www.w3.org/2001/XMLSchema:annotation
      782 TRACE [SaxJBossXBParser] startElement enter http://www.w3.org/2001/XMLSchema:documentation
      782 TRACE [ObjectModelBuilder] ignored http://www.w3.org/2001/XMLSchema:xsd:documentation
      782 TRACE [SaxJBossXBParser] startElement exit http://www.w3.org/2001/XMLSchema:documentation
      783 TRACE [SaxJBossXBParser] endElement enter http://www.w3.org/2001/XMLSchema:documentation
      783 TRACE [SaxJBossXBParser] endElement exit http://www.w3.org/2001/XMLSchema:documentation
      784 TRACE [SaxJBossXBParser] startElement enter http://www.w3.org/2001/XMLSchema:appinfo
      784 TRACE [ObjectModelBuilder] accepted http://www.w3.org/2001/XMLSchema:xsd:appinfo
      784 TRACE [SaxJBossXBParser] startElement exit http://www.w3.org/2001/XMLSchema:appinfo
      784 TRACE [SaxJBossXBParser] startElement enter http://www.jboss.org/xml/ns/jbxb:class
      784 TRACE [ObjectModelBuilder] accepted http://www.jboss.org/xml/ns/jbxb:jbxb:class
      784 TRACE [SaxJBossXBParser] startElement exit http://www.jboss.org/xml/ns/jbxb:class
      784 TRACE [SaxJBossXBParser] endElement enter http://www.jboss.org/xml/ns/jbxb:class
      784 TRACE [SaxJBossXBParser] endElement exit http://www.jboss.org/xml/ns/jbxb:class
      784 TRACE [SaxJBossXBParser] startElement enter http://www.jboss.org/xml/ns/jbxb:characters
      785 TRACE [ObjectModelBuilder] accepted http://www.jboss.org/xml/ns/jbxb:jbxb:characters
      785 TRACE [SaxJBossXBParser] startElement exit http://www.jboss.org/xml/ns/jbxb:characters
      785 TRACE [SaxJBossXBParser] startElement enter http://www.jboss.org/xml/ns/jbxb:property
      785 TRACE [ObjectModelBuilder] ignored http://www.jboss.org/xml/ns/jbxb:jbxb:property
      785 TRACE [SaxJBossXBParser] startElement exit http://www.jboss.org/xml/ns/jbxb:property
      785 TRACE [SaxJBossXBParser] endElement enter http://www.jboss.org/xml/ns/jbxb:property
      785 TRACE [SaxJBossXBParser] endElement exit http://www.jboss.org/xml/ns/jbxb:property
      785 TRACE [SaxJBossXBParser] startElement enter http://www.jboss.org/xml/ns/jbxb:value
      785 TRACE [ObjectModelBuilder] accepted http://www.jboss.org/xml/ns/jbxb:jbxb:value
      785 TRACE [SaxJBossXBParser] startElement exit http://www.jboss.org/xml/ns/jbxb:value
      786 TRACE [SaxJBossXBParser] endElement enter http://www.jboss.org/xml/ns/jbxb:value
      786 TRACE [SaxJBossXBParser] endElement exit http://www.jboss.org/xml/ns/jbxb:value
      786 TRACE [SaxJBossXBParser] endElement enter http://www.jboss.org/xml/ns/jbxb:characters
      786 TRACE [SaxJBossXBParser] endElement exit http://www.jboss.org/xml/ns/jbxb:characters
      786 TRACE [SaxJBossXBParser] endElement enter http://www.w3.org/2001/XMLSchema:appinfo
      786 TRACE [SaxJBossXBParser] endElement exit http://www.w3.org/2001/XMLSchema:appinfo
      786 TRACE [SaxJBossXBParser] endElement enter http://www.w3.org/2001/XMLSchema:annotation
      786 TRACE [SaxJBossXBParser] endElement exit http://www.w3.org/2001/XMLSchema:annotation
      
      A plainValueType is not annotated to use AbstractParameterMetaData!!!!
      
      786 TRACE [XsdBinder] complex type plainValueType: impl=org.jboss.test.xml.pojoserver.metadata.AbstractParameterMetaData
      787 TRACE [XsdBinder] complex type plainValueType: characters bound to value
      787 TRACE [XsdBinder] complex type plainValueType: characters unmarshalMethod=org.jboss.test.xml.pojoserver.metadata.DataTypeConverter.unmar
      shalStringValue, marshalMethod=null
      


      The annotations appear to be accumulating from derived types later in the xsd?
      Except it is not that simple because I don't see all annotations from all derived
      types (later or otherwise) and a simple test *doesn't* reproduce the problem.

      <?xml version="1.0" encoding="UTF-8"?>
      
      <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
       targetNamespace="urn:xerces:bug"
       xmlns="urn:xerces:bug"
       elementFormDefault="qualified"
       attributeFormDefault="unqualified"
       version="1.0"
      >
      
       <xsd:complexType name="baseType" mixed="true">
       <xsd:annotation>
       <xsd:documentation>
       <![CDATA[
       baseType
       ]]>
       </xsd:documentation>
       </xsd:annotation>
       </xsd:complexType>
      
       <xsd:complexType name="derivedType" mixed="true">
       <xsd:annotation>
       <xsd:documentation>
       <![CDATA[
       derivedType
       ]]>
       </xsd:documentation>
       </xsd:annotation>
       <xsd:complexContent>
       <xsd:extension base="baseType"/>
       </xsd:complexContent>
       </xsd:complexType>
      
      </xsd:schema>
      
       String name = "xml/xerces-bug.xsd";
       URL xsdUrl = Thread.currentThread().getContextClassLoader().getResource(name);
      
       DefaultSchemaResolver resolver = new DefaultSchemaResolver();
       resolver.setBaseURI(xsdUrl.toString());
       XSImplementation impl = getXSImplementation();
       XSLoader schemaLoader = impl.createXSLoader(null);
       setResourceResolver(schemaLoader, resolver);
       setDOMErrorHandler(schemaLoader);
       XSModel model = schemaLoader.loadURI(xsdUrl.toString());
      
       XSNamedMap types = model.getComponents(XSConstants.TYPE_DEFINITION);
       for(int i = 0; i < types.getLength(); ++i)
       {
       XSTypeDefinition type = (XSTypeDefinition)types.item(i);
       if(!Constants.NS_XML_SCHEMA.equals(type.getNamespace()))
       {
       if (type.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE)
       {
       XSComplexTypeDefinition typeDef = (XSComplexTypeDefinition) type;
       XSObjectList annotations = typeDef.getAnnotations();
       assertEquals(1, annotations.getLength());
       }
       }
       }
      


      I need a second pair of eyes! :-)

        • 1. Re: Strange annotations
          anil.saldhana

          I have seen that the Xerces implementation support of annotations is not complete. I think it is one area that is not tested well. To some extent, the annotation implementation is not complete.

          I guess they are just waiting for bug reports to see demand for annotations.

          • 2. Re: Strange annotations
            aloubyansky

            This is interesting. The annotations in the order they appear are

            <xsd:annotation xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:jboss:bean-deployer" xmlns:jbxb="http://www.jboss.org/xml/ns/jbxb" >
            <xsd:documentation>
             [CDATA[
             A parameter is used to define the constructor, factory
             and lifecycle method usage.
            
             e.g. Using number of parameters when this is unique enough
             <bean ...>
             <constructor>
             <parameter>1st Parameter</parameter>
             <parameter>2nd Parameter</parameter>
             </constructor>
             </bean>
            
             e.g. Explicitly stating the parameter type to resolve overloading
             <bean ...>
             <constructor>
             <parameter>1st Parameter</parameter>
             <parameter class="java.lang.String">2nd Parameter</parameter>
             </constructor>
             </bean>
            
             e.g. To override the injected type use <value/>
             <bean ...>
             <constructor>
             <parameter>1st Parameter</parameter>
             <!-- Parameter is java.lang.Object, but we inject a String -->
             <parameter class="java.lang.Object">
             <value class="java.lang.String">2nd Parameter</value>
             </parameter>
             </constructor>
             </bean>
             ]]
             </xsd:documentation><xsd:appinfo>
             <jbxb:class impl="org.jboss.test.xml.pojoserver.metadata.AbstractParameterMetaData"></jbxb:class>
             <jbxb:characters>
             <jbxb:property name="value"></jbxb:property>
             <jbxb:value unmarshalMethod="org.jboss.test.xml.pojoserver.metadata.DataTypeConverter.unmarshalStringValue"></jbxb:value>
             </jbxb:characters>
             </xsd:appinfo>
            </xsd:annotation>

            Defined in parameterType.

            <xsd:annotation xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:jboss:bean-deployer" xmlns:jbxb="http://www.jboss.org/xml/ns/jbxb" >
            <xsd:documentation>
             [CDATA[
             A value that can take annotations.
             TODO: This is currently unimplemented.
             ]]
             </xsd:documentation>
            </xsd:annotation>
            

            Defined in annotatedType.

            <xsd:annotation xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:jboss:bean-deployer" xmlns:jbxb="http://www.jboss.org/xml/ns/jbxb" >
            <xsd:documentation>
             [CDATA[
             A value that can take other values, i.e. properties and parameters.
            
             e.g.
             <parameter><value class="com.acme.MyClass">xxx</value></parameter>
             ]]
             </xsd:documentation>
            </xsd:annotation>

            Defined in valueType.

            And the last one is actually the one that is defined in plainValueType.

            The inheritance hierarchy of these types is
            parameterType extends annotatedType
            annotatedType extends valueType
            valueType extends plainValueType

            So, it looks like plainValueType gets annotations from all its subtypes. I'll create a smaller testcase and ask on the xerces' list.

            • 3. Re: Strange annotations
              aloubyansky

              If I comment out the parameterType definition then each type has 1 annotation, otherwise it reproduces the problem we can see with the current bean-deployer xsd.

              <?xml version="1.0" encoding="UTF-8"?>
              <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
               targetNamespace="urn:jboss:bean-deployer"
               xmlns="urn:jboss:bean-deployer"
               elementFormDefault="qualified"
               attributeFormDefault="unqualified"
               version="1.0">
              
               <!-- comment this type out to fix annotations -->
               <xsd:complexType name="parameterType">
               <xsd:annotation>
               </xsd:annotation>
               <xsd:complexContent>
               <xsd:extension base="annotatedValueType"/>
               </xsd:complexContent>
               </xsd:complexType>
              
               <xsd:complexType name="plainValueType">
               <xsd:annotation>
               </xsd:annotation>
               </xsd:complexType>
              
               <xsd:complexType name="valueType">
               <xsd:annotation>
               </xsd:annotation>
               <xsd:complexContent>
               <xsd:extension base="plainValueType"/>
               </xsd:complexContent>
               </xsd:complexType>
              
               <xsd:complexType name="annotatedValueType">
               <xsd:annotation>
               </xsd:annotation>
               <xsd:complexContent>
               <xsd:extension base="valueType"/>
               </xsd:complexContent>
               </xsd:complexType>
              </xsd:schema>


              • 4. Re: Strange annotations

                The problem is ordering.

                If I move parameterType to after annotatedType (its base class)
                the problem goes away (or at least shows another out of order problem).

                I committed a test for this.

                • 5. Re: Strange annotations
                  aloubyansky

                  Right. I wrote to Xerces' user list and here is the respose

                  "Michael" wrote:
                  Hi Alexey,

                  You've found a bug. It arises when a sub-type appears before its base type
                  in the schema document and was caused by a field which wasn't being
                  cleared. It's a one line fix. Just checked it into SVN. You can work
                  around the problem when using 2.7.0 by moving the type declaration for
                  "parameterType" to the bottom of the schema document.

                  Thanks.

                  Michael Glavassevich
                  XML Parser Development
                  IBM Toronto Lab


                  http://mail-archives.apache.org/mod_mbox/xerces-j-users/200511.mbox/browser