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

Key: CASTOR-2053
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Blocker Blocker
Assignee: Matthias Epheser
Reporter: Ben Irwin
Votes: 0
Watchers: 1
Operations

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

Generated code does not compile when a complex element has a default value.

Created: 20/Jul/07 03:58 PM   Updated: 14/Mar/08 06:41 AM
Component/s: XML code generator
Affects Version/s: 1.1.2.1
Fix Version/s: 1.2

Time Tracking:
Issue & Sub-Tasks
Issue Only
Not Specified

File Attachments: 1. XML File abc.xsd (0.6 kb)
2. Text File patch.c2053.20070802.txt (2 kb)
3. Text File patch.c2053.20070922.txt (17 kb)
4. Text File patch.c2053.20071008.txt (27 kb)
5. Java Source File Root.java (4 kb)
6. Java Source File X.java (5 kb)

Issue Links:
Duplicate
 

Sub-Tasks  All   Open   

 Description  « Hide
When a complex type has attributes and a simple contents, it may also have a default value for that simple contents. When an element is a complex type, it gets only an empty constructor. But because the element has a default value, the element it is contained by attempts to pass the default as a constructor argument. The net result is that javac cannot find an appropriate constructor because one does not exist.

As far as I can tell, there is no solution to this problem other than not constructing schemas in this way.

Included is the simplest XSD file which I know causes the problem as well as the generated java source.



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Werner Guttmann - 22/Jul/07 01:18 PM
Looks like we have to change the way we deal with default values in special cases like this.

Ben Irwin - 30/Jul/07 02:21 PM
I have just started working with castor, so I was wondering what a typical response time for this kind of bug is. IE are small patches released every couple weeks, or every couple months.

Also, I would appreciate if anyone knows any work-arounds that don't involve modification of the schema.

Thanks!


Werner Guttmann - 01/Aug/07 03:57 PM
Ben, I assume that (given there's timer available for any of us), it wouldn't take longer than to days to implement a solution. Problem is that time for at least myself is somewhat limited right. now. Iow, a fix should be shipped with 1.2. Normally, we ship minor releases every six to 10 weeks. Would that meet your requirements ?

Ben Irwin - 01/Aug/07 04:18 PM
it looks like 1.1.2.1 was released at the end of June. It sounds like end of August or early September is a reasonable estimate for when 1.1.2.2 will be released. I believe I can wait about 4 weeks for this fix.

Thank you for the prompt responses.


Werner Guttmann - 01/Aug/07 04:37 PM
You are welcome.

Matthias Epheser - 02/Aug/07 08:38 AM
I started to look at your issue recently and I think the place to add the additional constructor during source generation is the SourceFactory's createSourceCode method.

This first INCOMPLETE patch generates a constructor like this (if we have an element that contains a complexType with a simpleContent):

public X(final java.lang.String defaultValue) {
this._content = defaultValue;
}

This patch is still incomplete because of the lack of type conversion inside the contructor. We need to cast from String to BigDecimal in your case.

I looked at the create(From/To)JavaObjectCode methods of XsType, but they don't do what we want here. I'm currently searching the sources to find some reusable piece of code that does the classcasting for us.

Please stand by, I will comment about my results soon.


Werner Guttmann - 22/Aug/07 05:41 AM
Matthias, any progress on your side ?

Matthias Epheser - 09/Sep/07 12:11 PM
Looking at the casting issue again and again during the last weeks, I tried several code code parts in the castor codebase. My goal was is to reuse some implementation that produces code that casts a string to the a object instance.

The most fitting method for this wolud be imho XSType.createToJavaObjectCode(). This method is overridden by the sibclasses like XSInteger to produce this code. I thought I found the solution fpr our problem here, but having a closer look into all implementations of XSType, I discovered some inconsistency. There are several XSTypes that produce only

BigDecimal value = stringValue.

this is not a valid cast. Classes I found are XSDate, XSDatetime, XSG*, XSTime, XSDecimal, XSUnsignedLong.
In fact, all these classes are using either a castor specific Date wrapper class or java.math.BigDecimal. every other numeric type (eg. XSInteger) works ok.

So my question is: Is the createToJavaObjectCode in XSDecimal and XSUnsignedLong buggy or am I missing some point?


Werner Guttmann - 11/Sep/07 06:15 AM
Matthias and I (Werner) have had a short discussion on this subject yesterday. We sort of agree that for some XML schema types, this does not work at all. I have asked Matthias to provide me with one or two test cases that highlight the incorrect behavior. Once that has been done, we'll be able to make some progress on this issue.

Matthias Epheser - 22/Sep/07 07:55 AM
  • adds the default value constructor (in SourceFactory)
  • adds a createDefaultValueWithString to XSType
  • per default, this method returns new " + getJType() + "(" + variableName + ")
  • all subclasses that need special treatment (because no String constructor is avlailable, eg. primitive numeric types and boolean) override this method. see XSBoolean or XSInteger as example

Werner Guttmann - 06/Oct/07 02:16 PM
Matthias, can you please attach a new CTF test - based upon the XML schema provided - that checks for consistency. Given that a default value is given, it would be nice to marshal only and compare against a gold file.

Werner Guttmann - 06/Oct/07 02:17 PM
Matthias, did you ever try to run the CTF with this. I am getting 1 error and 14 failures .. can you please double-check ?

Matthias Epheser - 08/Oct/07 08:46 AM
jepp sorry, I overlooked one nullpointercheck.

The new patch fixes this as well as adds a new test to the xmlctf.