David,
could you please file a bug report/feature request at
http://jira.codehaus.org/browse/CASTOR, more or less copying the
content of this email to the issue body ?
Thannks
Werner
On Thu, 4 Aug 2005 20:40:42 +0100, David Easley wrote:
>Problem description
>===================
>
>This relates to Castor 0.9.7
>
>When using a binding file to specify that certain primitive fields should be
>wrapped (rather than using the Castor properties file to specify that ALL
>primitives should be wrapped) the 'descriptor' class will still contain a
>call to the field's delete method and therefore won't compile because there
>won't be such a delete method in the actual binding class ('has' and
>'delete' methods are omitted when primitive wrapper classes are used).
>
>Example:
>
>In the following example the FooDto type has a barId field that references a
>BarDto by id. A Foo doesn't always have an associated Bar, so the barId
>element is defined as minOccurs="0" in the XSD.
>
>Snippet from XSD:
>
> <xs:complexType name="FooDto">
> <xs:sequence>
> <xs:element name="id" type="xs:int"/>
> <xs:element name="name" type="xs:string"/>
> <xs:element name="barId" type="xs:int" minOccurs="0"/>
> </xs:sequence>
> </xs:complexType>
>
>Snippet from the binding file that causes the problem:
>
> <complexTypeBinding name="FooDto">
> <java-class name="FooDto"/>
> <elementBinding name="barId">
> <member wrapper="true"/>
> </elementBinding>
> </complexTypeBinding>
>
>Suggested Fix
>-------------
>
>Line 519 in org\exolab\castor\builder\DescriptorSourceFactory.java:
> if (xsType.isPrimitive() && !_config.usePrimitiveWrapper()) {
>Should be:
> if (xsType.getJType().isPrimitive() && !_config.usePrimitiveWrapper()) {
>I suspect this could now be simplified to:
> if (xsType.getJType().isPrimitive()) {
>
>I've tested this and it works OK for my XSD and binding file.
>(Should XSType.isPrimitive() be deprecated in favour of
>XSType.getJType().isPrimitive()?)
>
>
>Castor feature suggestion
>=========================
>
>In our project we actually want DTO code generated as follows: For primitive
>properties (int, long, etc.) we would like the getters and setters to use
>the equivalent wrapper class (Integer, Long, etc.) if minoccurs="0" and
>maxoccurs="1" in the XSD. If minoccurs="1" and maxoccurs="1" then the
>getters & setters should use the fundamental data type. Where used
>consistently within a particular project/API, this style provides a useful
>strong cue to anyone reading the code. If a getter returns an int, you know
>that a value will always be provided. If on the other hand it returns an
>Integer, you infer that it could return null.
>
>Currently (0.9.7), to achive this we have to use the binding file to specify
>that certain member fields should be wrapped. This tedious and error prone
>as the binding file has to be kept in sync with the 'minoccurs' attributes
>in the XSD file.
>
>In addition to fixing the bug described above, Castor would benefit from an
>option (preferably command line) to support this style of coding.
>
>
>David Easley
>
>
>-------------------------------------------------
>If you wish to unsubscribe from this list, please
>send an empty message to the following address:
>
>[EMAIL PROTECTED]
>-------------------------------------------------
>
-------------------------------------------------
If you wish to unsubscribe from this list, please
send an empty message to the following address:
[EMAIL PROTECTED]
-------------------------------------------------