Here is how I save the XML  to the file policy.xml:

                  FileWriter file = new FileWriter("policy.xml");
                  PolicyType policy = new PolicyType();
                  policy.setInfo(infoRequest_);
                  policy.setVehicles( new VehicleRequest [] {
vehicleRequest_, vehicleRequest_ } );
                  Mapping mapping = new Mapping();
                  mapping.loadMapping("mapping.xml");
                  Marshaller marshaller =  new Marshaller(file);
                  marshaller.setMapping(mapping);
                  marshaller.marshal(policy, file);

Rick Bos
ext 2780


                                                                                       
                                              
                      Keith Visco                                                      
                                              
                      <[EMAIL PROTECTED]        To:       [EMAIL PROTECTED]            
                                           
                      om>                      cc:                                     
                                              
                                               Subject:  Re: [castor-dev] Mapping 
Calendar fields                                    
                      03/02/2004 03:26                                                 
                                              
                      PM                                                               
                                              
                      Please respond to                                                
                                              
                      castor-dev                                                       
                                              
                                                                                       
                                              
                                                                                       
                                              







That would indicate that the mapping is being loaded, but not used.

How, exactly, are you calling the Marshaller or Unmarshaller?

--Keith


[EMAIL PROTECTED] wrote:
>
> Thanks Keith
>
> I changed the type to string.
>
> The only method that is being called in my CalendarFieldHandler is the
> getFieldType method.
>
> The convertUponGet and convertUponSet methods are not called.
>
> Rick Bos
> ext 2780
>
>
>                       Keith Visco
>                       <[EMAIL PROTECTED]        To:
[EMAIL PROTECTED]
>                       om>                      cc:
>                                                Subject:  Re: [castor-dev]
Mapping Calendar fields
>                       03/02/2004 02:23
>                       PM
>                       Please respond to
>                       castor-dev
>
>
>
> 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
>
> --
> 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







-- 
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