History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: CASTOR-2141
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Blocker Blocker
Assignee: Matthias Epheser
Reporter: Ron Corcuera
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
castor

Castor snapshot 1.1.3 source generator enum default values not being set correctly.

Created: 05/Sep/07 01:45 PM   Updated: 14/Mar/08 06:41 AM
Component/s: XML code generator
Affects Version/s: 1.2
Fix Version/s: 1.2

Time Tracking:
Not Specified

File Attachments: 1. XML File MyUser.xsd (1.0 kb)
2. Text File patch.c2141.20070906.txt (10 kb)

Environment: Windows using Intellij Idea. Java 1.5.


 Description  « Hide
I just tried out the snapshot release of Castor 1.1.3 and found what seems to be a bug. My schema has an element, screenSize, that is an enumeration that consists of the values Small, Medium, and Large. I set the enumeration to have the default value of Medium. screenSize is an element in a complex type typeMyUser. The source generator created the classes TypeMyUser.java and ScreenSizeType.java. TypeMyUser.java has a member variable called _screenSize with a default value being set. The problem is the way the default value is being set. It has something like

private ScreenSizeType _screenSize = ScreenSizeType.valueOf("Medium");

The problem is the enum constant name that it is passing into the valueOf method does not exist. The enum constants that were created were SMALL, MEDIUM, and LARGE (all caps). So, the line above should have passed the all caps enum constant name instead:

private ScreenSizeType _screenSize = ScreenSizeType.valueOf("MEDIUM");



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Werner Guttmann - 06/Sep/07 03:50 AM
Just to make sure that I get a few things right:
  • you want Java 5.0 code to be generated, right ?
  • you want an enum to be generated for the screenSizeType definition ?

Actually, why not attach the castorbuilder.properties you are using, in case you are using one ?


Werner Guttmann - 06/Sep/07 03:50 AM
Matthias, assigning this to yourself as you've been working on this recently.

Werner Guttmann - 06/Sep/07 03:52 AM
Btw, can you please attach a XML document instance that - in your view - should successfully unmarshal ?

Werner Guttmann - 06/Sep/07 03:57 AM
Matthias, by the looks of it, the way we generate default values needs to be changed much in the same way as everything else .. to cater for (extended) Java 5 enums.

Matthias Epheser - 06/Sep/07 04:03 AM
Yes, I was about to write the same. I'm currently looking for the place where the default values are created.
We then need to use the FROMVALUE method instead of the VALUEOF method for extended java5 enums.

The fromValue method takes the "Medium" value from the xsd and maps it to the "MEDIUM" enum constant instance that represents this value.


Matthias Epheser - 06/Sep/07 04:14 AM
I found the right place in MemberFactory line 558
We need to check if we are creating complex java5 enums there. I'm working on a patch.

Matthias Epheser - 06/Sep/07 04:55 AM
Patch includes fix for correct default value call, as well as testcases for xmlctf (java4_default and java5_default).

Please review, your problem should be solved with this patch.


Werner Guttmann - 06/Sep/07 11:14 AM
Will make available a snapshot release as time permits.