Hi,
again, it is me. After going through the SourceGenerator code, it seems that this is
not a bug but the "enumeration" facet is basicly not supported for xsd:int (and other
decimal types). The corresponding code is TypeConversion.convertTypes(...).
In case of xsd:string, the enumeration facet is handled and leads to the correct
generation of a type class.
case SimpleTypesFactory.STRING_TYPE:
{
//-- Enumeration ?
if (simpleType.hasFacet(Facet.ENUMERATION)) {
String typeName = simpleType.getName();
//-- anonymous type
if (typeName == null) {
Structure parent = simpleType.getParent();
if (parent instanceof ElementDecl) {
typeName = ((ElementDecl)parent).getName();
}
else if (parent instanceof AttributeDecl) {
typeName = ((AttributeDecl)parent).getName();
}
typeName = typeName + "Type";
}
String className
= JavaNaming.toJavaClassName(typeName);
if (packageName == null) {
String ns = simpleType.getSchema().getTargetNamespace();
packageName = _config.lookupPackageByNamespace(ns);
}
if ((packageName != null) && (packageName .length() > 0))
packageName = packageName + '.' + TYPES_PACKAGE;
else
packageName = TYPES_PACKAGE;
className = packageName + '.' + className;
xsType = new XSClass(new JClass(className));
xsType.setAsEnumerated(true);
} //- End Enumeration
In case of xsd:int (and others), no additional type class is generated:
case SimpleTypesFactory.INTEGER_TYPE:
{
XSInteger xsInteger = new XSInteger(useWrapper);
if (!simpleType.isBuiltInType())
xsInteger.setFacets(simpleType);
return xsInteger;
}
//-- int
case SimpleTypesFactory.INT_TYPE:
{
XSInt xsInt = new XSInt(useWrapper);
if (!simpleType.isBuiltInType())
xsInt.setFacets(simpleType);
return xsInt;
}
It would be helpful if someone (maybe the castor crew) could point out to me which
schema features are supported and which not. On the website, it says that the
enumeration facet is supported which seems to be wrong :-(
cheers nick
-----Urspr�ngliche Nachricht-----
Von: Nick Laqua
Gesendet: Dienstag, 13. April 2004 10:32
An: [EMAIL PROTECTED]
Betreff: Re: [castor-dev] sourcegenerator bug ??
Hi,
I have to correct myself. When using an explicit type and referencing it from an
element definition, the class code for the type is generated correctly but for the
element, still an int is returned instead of an Object. So it also doesn't work with
this approach.
xsd:
<xsd:element name = "Price">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref = "PriceValue" minOccurs = "0" maxOccurs =
"unbounded"/>
<xsd:element name = "PriceUnit" type="PriceUnitType"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:simpleType name="PriceUnitType">
<xsd:restriction base = "xsd:int">
<xsd:enumeration value = "1"/>
<xsd:enumeration value = "10"/>
<xsd:enumeration value = "100"/>
<xsd:enumeration value = "1000"/>
</xsd:restriction>
</xsd:simpleType>
java:
/**
* Sets the value of field 'priceUnit'.
*
* @param priceUnit the value of field 'priceUnit'.
*/
public void setPriceUnit(int priceUnit)
{
this._priceUnit = priceUnit;
this._has_priceUnit = true;
} //-- void setPriceUnit(int)
Nick
-----Urspr�ngliche Nachricht-----
Von: Nick Laqua
Gesendet: Dienstag, 13. April 2004 10:01
An: [EMAIL PROTECTED]
Betreff: [castor-dev] sourcegenerator bug ??
Hi,
after upgrading to 0.9.5.3 and regenerating our xml classes, it seems that castor
doesn't generate correct code for type definitions using restrictions for xsd:int. The
xml fragment looks like this:
<xsd:element name = "PriceUnit" default="1" >
<xsd:simpleType>
<xsd:restriction base = "xsd:int">
<xsd:enumeration value = "1"/>
<xsd:enumeration value = "10"/>
<xsd:enumeration value = "100"/>
<xsd:enumeration value = "1000"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
Obviously, this only fails when using anonymous types (as above), when creating
explicitly a PriceUnitType based on xsd:int, then it works perfect. In case of the
example above, castor creates code like this (doesn't compile):
/**
* Field _priceUnit
*/
private int _priceUnit = int.valueOf("1");
/**
* Returns the value of field 'priceUnit'.
*
* @return the value of field 'priceUnit'.
*/
public int getPriceUnit()
{
return this._priceUnit;
} //-- int getPriceUnit()
Thanx in advance
Nick
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev