Hi Rajesh,

I've made some changes to ValidationException and
submitted them to Castor for review on Jan. 15 and 
described these changes in great detail on Jan. 3 (you
can look up these e-mails in the archive if you're
interested).

I'm still waiting to see if these changes will be
accepted by Castor or not but I think my changes may
be useful to you.

I've basically added 4 instance variables (field name,
field value, error type and value restriction) to
ValidationException and populated them in the
constructors upon every instantiation of
ValidationException due to bad user input rather than
anything else such as bad schema definition.

In your case, I think field name would be "billing
name" and the field value "Bill2003".

These changes were intended to do the following:
.    consistently return the field name in the
exception;
.    create a mechanism to allow multilingual support
for error messages;
.    allow the Business to easily use their own
wording
of error messages on a per field basis instead of the
default English messages

I can send you the .jar of my changes if you are
interested.

Regards,
Joyce

--- Rajesh Ranjan hotmail <[EMAIL PROTECTED]>
wrote:
> Hi ,
>   I am trying to catch and give some user friendly
> messages after validation failure. Although it looks
> like it is throwing ValidationException and
> IllegalArgumentException but when I am trying to
> catch it it doesn't go into that block .
> I want to print the message "'Bill2003' is
>  not a valid BillingSystemType" which is there in
> the printTrace.
> 
> Please help.. I am quite new to Castor but it looks
> like a great tool.
> 
> Below is the sample code and error messages.
> Regards,
> Rajesh.
>     
> Xml Schema sample for billling_system
> 
> <xsd:element name="billing_system">
>    <xsd:simpleType>
>     <xsd:restriction base="xsd:string">
>      <xsd:enumeration value="Bill2000"/>
>      <xsd:enumeration value="Bill2001"/>
>     </xsd:restriction>
>    </xsd:simpleType>
>   </xsd:element>
> 
> But in xml file , I am giving value Bill2003 so that
> I can produce a validation error.
> 
> I have a simple java program for  unmarshalling ...
> here is the relevent code.
> 
> try {
>  String filename = "billing.xml";               
> FileReader reader = new FileReader (filename);
>  BillingSystem bill =
> BillingSystem.unmarshal(reader);
> }catch (IllegalArgumentException ia) {
>   System.out.println("IllegalArgumentException");
>  }catch (ValidationException ve) {
>              System.out.println("Validation
> Exception");
>               System.out.println(ve);
>  } catch (Exception e) {
>             e.printStackTrace();       
>  }
> 
> 
> 
> org.xml.sax.SAXException: unable to add
> 'billing_system' to <requestHeaderInfo>
> due to the following exception:
> >>>--- Begin Exception ---<<<
> java.lang.IllegalStateException:
> java.lang.IllegalArgumentException: 'Bill2003' is
>  not a valid BillingSystemType
>         at
>
org.exolab.castor.xml.handlers.EnumFieldHandler.setValue(EnumFieldHan
> dler.java:170)
>         at
>
org.exolab.castor.xml.UnmarshalHandler.endElement(UnmarshalHandler.ja
> va:478)
>         at
>
org.apache.xerces.parsers.AbstractSAXParser.endElement(AbstractSAXPar
> ser.java:425)
>         at
>
org.apache.xerces.impl.xs.XMLSchemaValidator.endElement(XMLSchemaVali
> dator.java:504)
>         at
>
org.apache.xerces.impl.XMLNamespaceBinder.endElement(XMLNamespaceBind
> er.java:629)
>         at
>
org.apache.xerces.impl.dtd.XMLDTDValidator.handleEndElement(XMLDTDVal
> idator.java:2731)
>         at
>
org.apache.xerces.impl.dtd.XMLDTDValidator.endElement(XMLDTDValidator
> .java:900)
>         at
>
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.handleEndElemen
> t(XMLDocumentFragmentScannerImpl.java:1136)
>         at
>
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanEndElement(
> XMLDocumentFragmentScannerImpl.java:978)
>         at
>
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContent
>
Dispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1437)
>         at
>
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(XM
> LDocumentFragmentScannerImpl.java:328)
>         at
>
org.apache.xerces.parsers.StandardParserConfiguration.parse(StandardP
> 
> Thanks in advance..
> Rajesh
> 


______________________________________________________________________ 
Web-hosting solutions for home and business! http://website.yahoo.ca

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

Reply via email to