Hi,
I think I've found a bug in the way Castor's source generator generates
code for enumerations: the class for any element whose type is an
enumeration restriction of a simpleType is effectively a no-op. All
actual functions are performed in the class for the type of the element
and the containing element never references the enumeration element's
class. An example to illustrate:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="root">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="variable" type="metasyn"
maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:simpleType name="metasyn">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="foo"/>
<xsd:enumeration value="bar"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>
Source generator creates six classes from this: Root, Variable, Metasyn
and their *Descriptors. (Metasyn goes into the subpackage 'types'.)
The odd behavior is that Root never refers to Variable -- it has an
addVariable method, but that takes a Metasyn object. This behavior
exists in Castor 0.9.4 and 0.9.3.21.
If you look at the code for Variable, you can see why: Variable has no
way to set a value, so it could never be unmarshaled from a file or
used programmatically in a useful way. This happens whether
org.exolab.castor.builder.javaclassmapping is set to 'type' or 'class'.
It happens whether the type is named (as in the example) or
anonymous/inline.
It seems to me the Variable class is probably created to handle the
case where the element variable extends (via
complexType/simpleContent/extension) the enumerated type, instead of
just instantiating it. In that case, it seems like the solution should
be to create a Variable class which extends from the Metasyn class and
alter addVariable, etc., in Root to take instances of this Variable
class instead of Metasyn.
Okay, I just tried it and that's not exactly what Castor does, but I
can see where the implemented solution is better than mine for that
case. One option to fix this would be to create the Variable class for
schema like the one above just is if it were an extension -- just with
no additional elements or attributes.
The other option would be not to generate the Variable class at all
when it isn't used (at least in the javaclassmapping=type mode). This
would be the most direct.
Apologies for the longwindedness. Thanks to all the developers for all
your work on what is on balance an excellent labor-saving tool.
Rhett Sutphin
=====================================================
| Rhett Sutphin
| Research Assistant (Software)
| Coordinated Laboratory for Computational Genomics
| and the Center for Macular Degeneration
| University of Iowa - Iowa City, IA 52242 - USA
| 4111 MEBRF - email: [EMAIL PROTECTED]
=====================================================
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev
