castor
  1. castor
  2. CASTOR-1839

Schema with imported simpletypes generates incorrect Java code

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.0.5
    • Fix Version/s: 1.1 M3
    • Component/s: XML code generator
    • Labels:
      None
    • Number of attachments :
      5

      Description

      A schema which defines a simpletype using a restriction-base from an imported schema generates incorrect Java-code.

      In the attached schema look at the LanguageCode, which is of a simpletype defined in the same schema. this type is based on a LanguageCodeType from an imported schema.

      <xsd:complexType name="BusinessObjectDocumentType">
      <xsd:attribute name="languageCode" type="LanguageCodeType" use="optional" default="en-US"> </xsd:attribute>
      </xsd:complexType>

      <xsd:simpleType name="LanguageCodeType">
      <xsd:restriction base="qdt:LanguageCodeType"/>
      </xsd:simpleType>

      This generated javacode looks like:
      private java.lang.Object _languageCode = new java.lang.Object("en-US");

      1. patch.c1839.20071217.txt
        1.0 kB
        Werner Guttmann
      2. patch.c1839.tests.20070118.txt
        54 kB
        Werner Guttmann

        Activity

        Hide
        Daniel Nilsson added a comment -

        A typo was entered above.
        The typename should be LanguageCodeTypeE not LanguageCodeType. The trailing E is to distinguish it from the imported typename.

        The type SystemEnvironmentCodeContentType also generated incorrect code. (interesting with this is that the name is the same as in the imported typename)

        Also the incorrect code can be found in BusinessObjectDocumentType.java

        Show
        Daniel Nilsson added a comment - A typo was entered above. The typename should be LanguageCodeTypeE not LanguageCodeType. The trailing E is to distinguish it from the imported typename. The type SystemEnvironmentCodeContentType also generated incorrect code. (interesting with this is that the name is the same as in the imported typename) Also the incorrect code can be found in BusinessObjectDocumentType.java
        Werner Guttmann made changes -
        Field Original Value New Value
        Assignee Werner Guttmann [ wguttmn ]
        Hide
        Werner Guttmann added a comment -

        Daniel, would you please be able to attach a sample XML document that you'd want to successfully unmarhal against the classes generated ?

        Show
        Werner Guttmann added a comment - Daniel, would you please be able to attach a sample XML document that you'd want to successfully unmarhal against the classes generated ?
        Hide
        Werner Guttmann added a comment -

        Okay, after some serious debugging, here's an early analysis. Right now, TypeConversion .convertType(Simpletype ....) perfectly traverses the inheritance hierarchy for simple restrictions. Unfortunately, the same does not apply for inheritance hierarchies if UNIONs are involved. I think I have a patch read (which I will attach in a second), but let me try to test a few more things. Strangely enough, all tests finish.

        In other words, whether a simple type is imported or not, does not make a difference. It's just that the code is incomplete with regards to handling 'union hierarchies'.

        Show
        Werner Guttmann added a comment - Okay, after some serious debugging, here's an early analysis. Right now, TypeConversion .convertType(Simpletype ....) perfectly traverses the inheritance hierarchy for simple restrictions. Unfortunately, the same does not apply for inheritance hierarchies if UNIONs are involved. I think I have a patch read (which I will attach in a second), but let me try to test a few more things. Strangely enough, all tests finish. In other words, whether a simple type is imported or not, does not make a difference. It's just that the code is incomplete with regards to handling 'union hierarchies'.
        Hide
        Werner Guttmann added a comment -

        Initial patch for review. As already mentioned, all CTF tests complete without any hiccups .....

        Show
        Werner Guttmann added a comment - Initial patch for review. As already mentioned, all CTF tests complete without any hiccups .... .
        Werner Guttmann made changes -
        Attachment patch.c1839.20071217.txt [ 25263 ]
        Werner Guttmann made changes -
        Remaining Estimate 4 hours [ 14400 ]
        Fix Version/s 1.1 [ 13113 ]
        Original Estimate 4 hours [ 14400 ]
        Werner Guttmann logged work - 17/Jan/07 5:52 AM
        • Time Spent:
          1 hour, 30 minutes
           
          Debugging the code generation from the sample XMl schema given.
        Werner Guttmann made changes -
        Remaining Estimate 4 hours [ 14400 ] 2 hours, 30 minutes [ 9000 ]
        Time Spent 1 hour, 30 minutes [ 5400 ]
        Werner Guttmann logged work - 17/Jan/07 5:53 AM
        • Time Spent:
          20 minutes
           
          Patch creation && initial testing.
        Werner Guttmann made changes -
        Remaining Estimate 2 hours, 30 minutes [ 9000 ] 2 hours, 10 minutes [ 7800 ]
        Time Spent 1 hour, 30 minutes [ 5400 ] 1 hour, 50 minutes [ 6600 ]
        Hide
        Edward Kuns added a comment -

        Looks good to me.

        Show
        Edward Kuns added a comment - Looks good to me.
        Hide
        Werner Guttmann added a comment -

        Daniel, any objections against using the sample XML schemas to enhance our test suite ?

        Show
        Werner Guttmann added a comment - Daniel, any objections against using the sample XML schemas to enhance our test suite ?
        Werner Guttmann made changes -
        Resolution Fixed [ 1 ]
        Status Open [ 1 ] Resolved [ 5 ]
        Hide
        Daniel Nilsson added a comment -

        Hi!
        You are the king Werner!
        I don't have any objections that you include the sample XML. And the OAGI schemas should be free so there shouldn't be any problems with thoose either. The more tests and scenarions the better.

        Show
        Daniel Nilsson added a comment - Hi! You are the king Werner! I don't have any objections that you include the sample XML. And the OAGI schemas should be free so there shouldn't be any problems with thoose either. The more tests and scenarions the better.
        Hide
        Werner Guttmann added a comment -

        Thank you so much for the compliments. I'd still need a (valid) sample document that matches the XML schemas you've attached so that I can complete the test case successfully. The reason why I asked 'for permission' is simple: it could have been that there's custom extension of yours that you might not like to see 'exposed' as part of an open source framework.

        Show
        Werner Guttmann added a comment - Thank you so much for the compliments. I'd still need a (valid) sample document that matches the XML schemas you've attached so that I can complete the test case successfully. The reason why I asked 'for permission' is simple: it could have been that there's custom extension of yours that you might not like to see 'exposed' as part of an open source framework.
        Hide
        Werner Guttmann added a comment -

        Initial patch for review. I'd still like to use a 'real' XML document rather than a knocked up ..... .

        Show
        Werner Guttmann added a comment - Initial patch for review. I'd still like to use a 'real' XML document rather than a knocked up ..... .
        Werner Guttmann made changes -
        Attachment patch.c1839.tests.20070118.txt [ 25276 ]
        Hide
        Werner Guttmann added a comment -

        Daniel ?

        Show
        Werner Guttmann added a comment - Daniel ?
        Hide
        Daniel Nilsson added a comment -

        Sorry for the delay.
        Attached is an initial workinprogress of the schemas I am to create the sources for I created a sample document with Alatova XML spy which

        There is anyhow a part which looks like this:

        Show
        Daniel Nilsson added a comment - Sorry for the delay. Attached is an initial workinprogress of the schemas I am to create the sources for I created a sample document with Alatova XML spy which There is anyhow a part which looks like this:
        Daniel Nilsson made changes -
        Attachment castor_example.zip [ 25361 ]
        Hide
        Daniel Nilsson added a comment -

        hmm, and that is what happens when you accedently hit Enter...

        Ok, to complete the previous message:

        I created a sample xml-document with XmlSpy from the xsd since I don't have any other samples at this moment.
        There is also a section in the xsd looking like:
        <xsd:complexType name="UserAreaType" block="restriction">
        <xsd:sequence>
        <xsd:any namespace="##any" processContents="strict" minOccurs="0" maxOccurs="unbounded"/>
        </xsd:sequence>
        </xsd:complexType>
        which I havn't tried with castor. If it doesnät work let me know and I can strip that part out from the sample.

        Show
        Daniel Nilsson added a comment - hmm, and that is what happens when you accedently hit Enter... Ok, to complete the previous message: I created a sample xml-document with XmlSpy from the xsd since I don't have any other samples at this moment. There is also a section in the xsd looking like: <xsd:complexType name="UserAreaType" block="restriction"> <xsd:sequence> <xsd:any namespace="##any" processContents="strict" minOccurs="0" maxOccurs="unbounded"/> </xsd:sequence> </xsd:complexType> which I havn't tried with castor. If it doesnät work let me know and I can strip that part out from the sample.
        Hide
        Daniel Nilsson added a comment -

        removed some unnecassary binding-files

        Show
        Daniel Nilsson added a comment - removed some unnecassary binding-files
        Daniel Nilsson made changes -
        Attachment castor_example.zip [ 25362 ]
        Hide
        Werner Guttmann added a comment -

        Daniel, with the last archive you attached, code generation completes with errors. Any idea why ?

        Show
        Werner Guttmann added a comment - Daniel, with the last archive you attached, code generation completes with errors. Any idea why ?
        Hide
        Werner Guttmann added a comment -

        Actually, found the problem. Just committed the new CTF test case (based upon your sample), and included a small patch to JDescriptorClass to fix an issue related to incorrect import statements for descriptor classes that extend another descriptor, and not XMLClassDescriptorImpl.

        Show
        Werner Guttmann added a comment - Actually, found the problem. Just committed the new CTF test case (based upon your sample), and included a small patch to JDescriptorClass to fix an issue related to incorrect import statements for descriptor classes that extend another descriptor, and not XMLClassDescriptorImpl.
        Ralf Joachim made changes -
        Status Resolved [ 5 ] Closed [ 6 ]

          People

          • Assignee:
            Werner Guttmann
            Reporter:
            Daniel Nilsson
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Time Tracking

              Estimated:
              Original Estimate - 4 hours
              4h
              Remaining:
              Time Spent - 1 hour, 50 minutes Remaining Estimate - 2 hours, 10 minutes
              2h 10m
              Logged:
              Time Spent - 1 hour, 50 minutes Remaining Estimate - 2 hours, 10 minutes
              1h 50m