castor
  1. castor
  2. CASTOR-1445

SourceGenerator fails for simpletype/restriction/enumertion with values 'm' and 'M'

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.0
    • Fix Version/s: 1.1 M1
    • Component/s: XML code generator
    • Labels:
      None
    • Environment:
      Castor 1.0
      Xerces 1.4.4
      Java 1.4.2_11
      Eclipse 3.0.2
    • Number of attachments :
      5

      Description

      The following part of the schema is not correctly translated. I assume the problem is that we have a value 'm' and 'M' in the list of restrictions:

      XSD extract :

      <xs:attribute name='DURATION_UNIT'>
      <xs:simpleType>
      <xs:restriction base='xs:string'>
      <xs:enumeration value='Y' />
      <xs:enumeration value='M' />
      <xs:enumeration value='D' />
      <xs:enumeration value='h' />
      <xs:enumeration value='m' />
      <xs:enumeration value='s' />
      </xs:restriction>
      </xs:simpleType>
      </xs:attribute>

      Generated code extract :

      private static java.util.Hashtable init()

      { Hashtable members = new Hashtable(); members.put("Y", Y); members.put("M", M); members.put("D", D); members.put("h", H); members.put("s", S); return members; }

      //-- java.util.Hashtable init()

      1. 20061209_PROCESSDEFINITIONDURATION_UNITType.java
        5 kB
        Frederik Uyttersprot
      2. patch.c1445.20060609.txt
        8 kB
        Werner Guttmann
      3. patch.c1445.20060618.txt
        347 kB
        Werner Guttmann
      4. patch.c1445.sample.20060618.txt
        4 kB
        Werner Guttmann

        Issue Links

          Activity

          Hide
          Werner Guttmann added a comment -

          I'd really appreciate if the attached XSD could be simplified as much as possible, so that it contains structures relevant to the problem only. Thanks in advance ....

          Show
          Werner Guttmann added a comment - I'd really appreciate if the attached XSD could be simplified as much as possible, so that it contains structures relevant to the problem only. Thanks in advance ....
          Hide
          Frederik Uyttersprot added a comment -

          This should do to recreate the problem :

          The Java code I used :

          public class CreateSourceCode {

          private final static String xsd = "data/test.xsd";

          private final static String src = "company.test.model";

          public static void main(String[] args) {

          SourceGenerator srcGen = new SourceGenerator();

          try

          { srcGen.setDestDir("c:/temp/src"); srcGen.generateSource(xsd, src); System.out.println("done"); }

          catch (FileNotFoundException e)

          { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }

          }
          }

          The XSD file :

          <xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>
          <xs:element name='PROCESSDEFINITION'>
          <xs:complexType>
          <xs:attribute name='NAME'/>
          <xs:attribute name='DESCRIPTION'/>
          <xs:attribute name='DURATION_UNIT'>
          <xs:simpleType>
          <xs:restriction base='xs:string'>
          <xs:enumeration value='Y'/>
          <xs:enumeration value='M'/>
          <xs:enumeration value='D'/>
          <xs:enumeration value='h'/>
          <xs:enumeration value='m'/>
          <xs:enumeration value='s'/>
          </xs:restriction>
          </xs:simpleType>
          </xs:attribute>
          </xs:complexType>
          </xs:element>
          </xs:schema>

          Show
          Frederik Uyttersprot added a comment - This should do to recreate the problem : The Java code I used : public class CreateSourceCode { private final static String xsd = "data/test.xsd"; private final static String src = "company.test.model"; public static void main(String[] args) { SourceGenerator srcGen = new SourceGenerator(); try { srcGen.setDestDir("c:/temp/src"); srcGen.generateSource(xsd, src); System.out.println("done"); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } The XSD file : <xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'> <xs:element name='PROCESSDEFINITION'> <xs:complexType> <xs:attribute name='NAME'/> <xs:attribute name='DESCRIPTION'/> <xs:attribute name='DURATION_UNIT'> <xs:simpleType> <xs:restriction base='xs:string'> <xs:enumeration value='Y'/> <xs:enumeration value='M'/> <xs:enumeration value='D'/> <xs:enumeration value='h'/> <xs:enumeration value='m'/> <xs:enumeration value='s'/> </xs:restriction> </xs:simpleType> </xs:attribute> </xs:complexType> </xs:element> </xs:schema>
          Hide
          Werner Guttmann added a comment -

          Lovely ..

          Show
          Werner Guttmann added a comment - Lovely ..
          Hide
          Werner Guttmann added a comment -

          Initial patch, highlighting the (assumed) changes to SourceFactory and the required modifications to the binding XML Schema instance.

          Show
          Werner Guttmann added a comment - Initial patch, highlighting the (assumed) changes to SourceFactory and the required modifications to the binding XML Schema instance.
          Hide
          Werner Guttmann added a comment -

          Updated patch, providing the ability to define <enumBinding>s within a binding file.

          Show
          Werner Guttmann added a comment - Updated patch, providing the ability to define <enumBinding>s within a binding file.
          Hide
          Werner Guttmann added a comment -

          Sample XML Schema (plus small JUnit test case) including a binding file to showcase the use of the aforementioned <enumBinding> element.

          Show
          Werner Guttmann added a comment - Sample XML Schema (plus small JUnit test case) including a binding file to showcase the use of the aforementioned <enumBinding> element.
          Hide
          Werner Guttmann added a comment -

          FYI, I just made up my mind to break this issue into several separate sub-tasks (as this will ease the required efforts to test the individual steps).

          Show
          Werner Guttmann added a comment - FYI, I just made up my mind to break this issue into several separate sub-tasks (as this will ease the required efforts to test the individual steps).
          Hide
          Werner Guttmann added a comment -

          This is a result of problems in the area of regeneration of the binding file classes as a result of these changes. I do apologize for this delay, but somehow I am running into problems that are not 'nice' ... .

          Show
          Werner Guttmann added a comment - This is a result of problems in the area of regeneration of the binding file classes as a result of these changes. I do apologize for this delay, but somehow I am running into problems that are not 'nice' ... .
          Hide
          Werner Guttmann added a comment -

          Turns out that the binding.xsd specified elementForm to be 'unqualified' .. ;-(. Well, picking this up again ....

          Show
          Werner Guttmann added a comment - Turns out that the binding.xsd specified elementForm to be 'unqualified' .. ;-(. Well, picking this up again ....
          Hide
          Werner Guttmann added a comment -

          Some follow-up comments at CASTOR-1491 ....

          Show
          Werner Guttmann added a comment - Some follow-up comments at CASTOR-1491 ....
          Hide
          Werner Guttmann added a comment -

          Just to let you know that I just deployed a new Maven snapshot release of Castor 1.0.6 at

          http://snapshots.repository.codehaus.org/org/codehaus/castor/castor/1.0.6-SNAPSHOT/

          that includes the patch as committed as part of this Jira issue.

          Show
          Werner Guttmann added a comment - Just to let you know that I just deployed a new Maven snapshot release of Castor 1.0.6 at http://snapshots.repository.codehaus.org/org/codehaus/castor/castor/1.0.6-SNAPSHOT/ that includes the patch as committed as part of this Jira issue.
          Hide
          Frederik Uyttersprot added a comment -

          Good Evening Werner. I tried the snapshot castor-1.0.6-20061209.124158-4.jar but wasn't able to make things work. I used the original code and XSD from this ticket to test it in Eclipse 3.1.2 with Java 1.4.2_11. Maybe I'm doing things not correctly. Should I define anything special to make this work ?

          I'll attach the result I get using this snapshot.

          Thanks.

          Show
          Frederik Uyttersprot added a comment - Good Evening Werner. I tried the snapshot castor-1.0.6-20061209.124158-4.jar but wasn't able to make things work. I used the original code and XSD from this ticket to test it in Eclipse 3.1.2 with Java 1.4.2_11. Maybe I'm doing things not correctly. Should I define anything special to make this work ? I'll attach the result I get using this snapshot. Thanks.
          Hide
          Frederik Uyttersprot added a comment -

          Result when using snapshot : castor-1.0.6-20061209.124158-4.jar

          Show
          Frederik Uyttersprot added a comment - Result when using snapshot : castor-1.0.6-20061209.124158-4.jar
          Hide
          Werner Guttmann added a comment -

          Frederik, are you aware that you'll need to supply an <enumBinding for your scenario to get this going? I know that documentation still needs to be added, but have a look at the newly added CTF test cases, available at

          http://svn.castor.codehaus.org/browse/castor/castor/trunk/src/tests/xml/MasterTestSuite/sourcegenerator/Binding

          especially the binding file specified in this folder.

          Show
          Werner Guttmann added a comment - Frederik, are you aware that you'll need to supply an <enumBinding for your scenario to get this going? I know that documentation still needs to be added, but have a look at the newly added CTF test cases, available at http://svn.castor.codehaus.org/browse/castor/castor/trunk/src/tests/xml/MasterTestSuite/sourcegenerator/Binding especially the binding file specified in this folder.
          Hide
          Frederik Uyttersprot added a comment -

          I was not aware of that. I'll give this a try later on. If you could copy/paste a quick example of such a file that works with the above test case - that would be great .

          Show
          Frederik Uyttersprot added a comment - I was not aware of that. I'll give this a try later on. If you could copy/paste a quick example of such a file that works with the above test case - that would be great .
          Hide
          Werner Guttmann added a comment -

          Frederik, in the directory referenced above, you'll find everything needed, XML schema, binding file, sample XML document instance. What else would you need ?

          Show
          Werner Guttmann added a comment - Frederik, in the directory referenced above, you'll find everything needed, XML schema, binding file, sample XML document instance. What else would you need ?
          Hide
          Frederik Uyttersprot added a comment -

          Nothing, maybe a nice cold beer and a week of holiday. I'm just being lazy I know.
          I'll test again later this week.

          Show
          Frederik Uyttersprot added a comment - Nothing, maybe a nice cold beer and a week of holiday. I'm just being lazy I know. I'll test again later this week.
          Show
          Werner Guttmann added a comment - Actually, have a look at http://svn.castor.codehaus.org/browse/castor/castor/trunk/src/tests/xml/MasterTestSuite/sourcegenerator/Binding/enumBinding/binding.xml?r=6490 in particular.
          Hide
          Werner Guttmann added a comment -

          Hmm, fancy coming to Vienna ? I am sure nice cold beer is to be found here easily ......

          Show
          Werner Guttmann added a comment - Hmm, fancy coming to Vienna ? I am sure nice cold beer is to be found here easily ......
          Hide
          Frederik Uyttersprot added a comment -

          Verified on my side. Thanks for the work and the solution .

          Show
          Frederik Uyttersprot added a comment - Verified on my side. Thanks for the work and the solution .

            People

            • Assignee:
              Werner Guttmann
              Reporter:
              Frederik Uyttersprot
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - 9 hours, 30 minutes
                9h 30m
                Remaining:
                Time Spent - 1 hour, 45 minutes Remaining Estimate - 7 hours, 45 minutes
                7h 45m
                Logged:
                Time Spent - 1 hour, 45 minutes Remaining Estimate - 7 hours, 45 minutes
                1h 45m