Hi,
I changed the mapping.xml and it seems to work a little. but a problem.
convertUponGet() method in myHandler is called three times.
The first time, when it is called, it prints the correct date
as in the XML. the next two times, it prints the current date and
time.
Any Idea why it calls this method three times and why it calls
with the current date and time in the second and third call?
Thanks,
Raj
public java.lang.Object convertUponGet(java.lang.Object value){
Calendar c = (Calendar)value;
Date d = c.getTime();
System.out.println("Date " +d);
SimpleDateFormat formatter = new SimpleDateFormat ("yyyy/MM/dd");
String s = formatter.format(d);
return s;
}
-----Original Message-----
From: Keith Visco [mailto:kvisco@;intalio.com]
Sent: Thursday, November 14, 2002 12:09 PM
To: [EMAIL PROTECTED]
Subject: Re: [castor-dev] FieldHandler question
Hi Rajkumar,
You need to specify the type that your handler is expecting to recieve:
<field name="BirthDate" type="string" handler="myHander"/>
Your special FieldHandler will convert the string into the Date I
assume.
--Keith
"Alagesan, Rajkumar" wrote:
>
> Going by the message it appears that the castor tries to
> construct the calendar object(and since it's an abstract class,
> it can't create one). But, I wonder why would castor even
> try instantiating when I have the field handler written for
> the field. Is it that my field handler never gets called before
> castor tries to create an instance of that type?
>
> Rajkumar
>
> -----Original Message-----
> From: Alagesan, Rajkumar
> Sent: Wednesday, November 13, 2002 3:12 PM
> To: [EMAIL PROTECTED]
> Subject: [castor-dev] FieldHandler question
>
> Hi,
>
> I try to use java.util.Collection for an xml field 'Birthdate' and wrote
my
> Field
> Handler.
>
> I have written a mapping file that looks like
>
> <class name="org.ets.enterprise.profile.valueobject.PersonValueObject" >
> <field name="LanguageTypeCode" type="string"/>
> <field name="BirthDate" type="java.util.Calendar" handler="myHandler"/>
> </class>
>
> When I try to unmarshal the Xml, I get the following error
>
> java.lang.IllegalStateException: Java schema change: Class
> java.util.Calendar can no longer be const
> ructed: java.util.Calendar{file: [not available]; line: 3; column: 16}
> java.lang.NullPointerException
>
> my xml data file looks like this:-
>
> <?xml version="1.0" encoding="UTF-8"?>
> <person-value-object>
> <BirthDate>2002-10-3 11:10:50</BirthDate>
> <languagetypecode>1</languagetypecode>
> </personvalueobject>
>
> myHandler.java code
>
> import org.exolab.castor.mapping.GeneralizedFieldHandler;
> import java.text.SimpleDateFormat;
> import java.util.Date;
> import java.util.Calendar;
> public class myHandler extends GeneralizedFieldHandler{
> public java.lang.Class getFieldType(){
> return java.util.Calendar.class;
> }
> public java.lang.Object convertUponSet(java.lang.Object value){
> Calendar c = null;
> try{
> SimpleDateFormat formatter = new SimpleDateFormat ("yyyy-MM-yy
> hh:mm:ss");
> Date d = formatter.parse((String)value);
> c= Calendar.getInstance();
> c.setTime(d);
> }
> catch(Exception e){
> System.out.println("setvalue"+e);
> }
> return c;
>
> }
> public java.lang.Object convertUponGet(java.lang.Object value){
> Calendar c = (Calendar)value;
> Date d = c.getTime();
> SimpleDateFormat formatter = new SimpleDateFormat ("yyyy-MM-yy
> hh:mm:ss");
> String s = formatter.format(d);
> return s;
>
> }
> }
>
> Let me know where I am going wrong?
>
> Thanks,
> Raj
>
> **************************************************************************
> This e-mail and any files transmitted with it may contain privileged or
> confidential information. It is solely for use by the individual for whom
> it is intended, even if addressed incorrectly. If you received this e-mail
> in error, please notify the sender; do not disclose, copy, distribute, or
> take any action in reliance on the contents of this information; and
delete
> it from your system. Any other use of this e-mail is prohibited. Thank you
> for your compliance.
>
> -----------------------------------------------------------
> If you wish to unsubscribe from this mailing, send mail to
> [EMAIL PROTECTED] with a subject of:
> unsubscribe castor-dev
>
> **************************************************************************
> This e-mail and any files transmitted with it may contain privileged or
> confidential information. It is solely for use by the individual for whom
> it is intended, even if addressed incorrectly. If you received this e-mail
> in error, please notify the sender; do not disclose, copy, distribute, or
> take any action in reliance on the contents of this information; and
delete
> it from your system. Any other use of this e-mail is prohibited. Thank you
> for your compliance.
>
> -----------------------------------------------------------
> 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
**************************************************************************
This e-mail and any files transmitted with it may contain privileged or
confidential information. It is solely for use by the individual for whom
it is intended, even if addressed incorrectly. If you received this e-mail
in error, please notify the sender; do not disclose, copy, distribute, or
take any action in reliance on the contents of this information; and delete
it from your system. Any other use of this e-mail is prohibited. Thank you
for your compliance.
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev