(I am not familiar with Axis, so I could be off base here.)
Source generator does not generate classes for simpleTypes (except enumerations) as you have discovered. It does support length restrictions, however -- they are enforced by the *Descriptor classes. In fact, almost all (or maybe all) of the simpleType restriction facets are supported this way by Castor. (An aside: the restrictions are only checked when the generated class' validate() method is called. Castor automatically calls it when you marshal your object.)
For your schema, source generator will create an Event class with a property named "location" whose type is java.lang.String. If somehow Axis is creating an Event class with a property named "location" whose type is yourpackage.String200 and then trying to unmarshal it with Castor, Castor will be confused. It doesn't support unmarshalling a raw character string directly into an object other than one of the builtins (like String, Date, int, etc.).
So my take on your question ("What is the correct way to use Castor to limit an xml field to a certain length?") is this: don't generate any special classes. Make sure your descriptors are compiled and Castor will take care of the rest.
Rhett
Liu, Scott wrote:
Hi, I just start to use castor in one of my projects. I am using castor and apache Axis in creating a web service.The SourceGenerator worked fine with complexTypes and elements. I wanted to use castor to validate a xml string field with max length defined in a simpleType (“String200” as below). According to the instruction the SourceGenerator did not create any class on the simpleType “String200”. The “String200” class was created using apache Axis tools instead. The problem happened when the web service was launched. It failed at marshalling between XML and Castor Objects:
“org.xml.sax.SAXException: Unable to marshall between XML and Castor Objects :Illegal Text data found as child of: location value:”
What is the correct way to use Castor to limit an xml field to a certain length?
All suggestions are appreciated. Thanks.
Scott Liu
P.S. The relevant schema:
<xsd:simpleType name="String200">
<xsd:si
<xsd:restriction base="xsd:token">
<xsd:maxLength value="200"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:element name="Event">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="location" minOccurs="0" maxOccurs="1" nullalbe="true" type="String200"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
and error stack trace:
org.xml.sax.SAXException: Unable to marshall between XML and Castor Objects :Illegal Text data found as child of: location value: "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678"</faultstring>
<detail>
<ns1:stackTrace xmlns:ns1="http://xml.apache.org/axis/">org.xml.sax.SAXException: Unable to marshall between XML and Castor Objects :Illegal Text data found as child of: location value: "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678"
 at org.apache.axis.encoding.ser.castor.CastorDeserializer.onEndElement(CastorDeserializer.java:108)
 at org.apache.axis.encoding.DeserializerImpl.endElement(DeserializerImpl.java:534)
 at org.apache.axis.encoding.DeserializationContextImpl.endElement(DeserializationContextImpl.java:1015)
 at org.apache.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.java:204)
 at org.apache.axis.message.MessageElement.publishToHandler(MessageElement.java:722)
 at org.apache.axis.message.RPCElement.deserialize(RPCElement.java:233)
 at org.apache.axis.message.RPCElement.getParams(RPCElement.java:347)
 at
----------------------------------------------------------- If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev
