Rick,

If your custom GeneralizedFieldHandler is returning and converting from
java.lang.String then you should change your mapping to indicate that.

<field name="reviewDate" type="string"
handler="....CalendarFieldHandler"/>

--Keith


[EMAIL PROTECTED] wrote:
> 
> Hello.
> 
> I have Java objects which contain Calendar fields which I would like to map
> to an XML file.
> 
> Basically I would like to treat them as java.util.Date without having to
> modify the original objects:
> 
> I have not been able to get this to work.  Any suggestions would be
> appreciated.
> 
> Here is what I tried.
> 
> I still am not able to get my Calendar fields into my xml file.
> Any suggestions would be appreciated.
> 
> Here is what I tried:
> 
> GeneralInfoRequest.java
> 
> private Calendar reviewDate_;
> public Calendar getReviewDate() { return reviewDate_ ; }
> public void setReviewDate( Calendar cal ) { reviewDate_ = cal; }
> 
> CalendarFieldHandler.java:
> 
> public class CalendarFieldHandler extends GeneralizedFieldHandler {
> public final DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
> 
> public Object convertUponGet(Object value) {
> if ( value instanceof Calendar ) {
> Calendar cal = (Calendar) value;
> 
> return format.format(cal.getTime());
> } else {
> return value;
> }
> 
> }
> 
> public Object convertUponSet(Object value) {
> String dateStr = (String) value;
>  Object result = null;
> try {
> Date date = (Date) format.parse(dateStr);
> Calendar cal = new GregorianCalendar();
> cal.setTime(date);
> result = cal;
> 
> } catch (ParseException e) {
> 
> }
> return result;
> 
> }
> 
> public Class getFieldType() {
> return Calendar.class;
> }
> }
> 
> mapping.xml:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <mapping xmlns="http://castor.exolab.org/"; xmlns:cst="
> http://castor.exolab.org/";>
> <description>Castor generated mapping file</description>
> <class name="services.types.GeneralInfoRequest" >
> <field name="reviewDate" handler
> ="ca.cooperators.tests.xml.mapping.CalendarFieldHandler"
> type="java.util.Date" >
> </field>
> </class>
> </mapping>
> 
> --
> This message has been scanned for viruses and
> dangerous content by MailScanner, and is
> believed to be clean.
> MailScanner thanks transtec Computers for their support.
> 
> -----------------------------------------------------------
> If you wish to unsubscribe from this mailing, send mail to
> [EMAIL PROTECTED] with a subject of:
>         unsubscribe castor-dev

-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
MailScanner thanks transtec Computers for their support.

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

Reply via email to