I had a similar question, and here is what Keith wrote -
 
--- snip ----------------
The xs:date type is handled by org.exolab.castor.types.Date. It has a
built in descriptor class, org.exolab.castor.types.DateDescriptor. It
can't be mapped very well with the mapping file, which is why we
provided the built-in descriptor.

If you really want to use a mapping file and not the built-in
descriptors, you can write your own custom FieldHandler that handles the
conversion to and from a string (by simply deferring to the Date.parse()
and Date.toString() methods).

----------------------------

HTH

-Nischala

 

 


 
 

        -----Original Message----- 
        From: Colin Harris [mailto:[EMAIL PROTECTED] 
        Sent: Thu 7/1/2004 8:30 AM 
        To: [EMAIL PROTECTED] 
        Cc: 
        Subject: Re: [castor-user] java.lang.IllegalArgument when mapping 
java.util.Date to constructor argument
        
        


        Thanks Anne,
        
        I need to keep the java.util.Date implementation though. I wonder if it
        is a bug in Castor, or there is something I am doing wrong/
        misunderstanding.
        
        Colin.
        
        Meade, Anne wrote:
        
        > Hi Colin,
        >
        > In my experience, I had to convert my java.util.Date type to
        > org.exolab.castor.types.Date.
        >
        > Here is the castor date type:
        > http://www.castor.org/javadoc/org/exolab/castor/types/Date.html
        >
        > You need to import org.exolab.castor.types.Date;
        >
        > This is my code:
        >
        >               Date date = new Date();
        >               short[] dateVals = {20,04,06,23};  //this date is
        > 2004-06-23
        >               date.setValues(dateVals);
        >
        >               item.setShipDate(date);
        >
        > Hope this helps,
        > Anne
        >
        >
        > -----Original Message-----
        > From: Colin Harris [mailto:[EMAIL PROTECTED]
        > Sent: Thursday, July 01, 2004 6:32 AM
        > To: [EMAIL PROTECTED]
        > Subject: [castor-user] java.lang.IllegalArgument when mapping
        > java.util.Date to constructor argument
        >
        >
        >
        > Hi,
        >
        > I have a simple class Trial with constructor
        >
        > /** Creates a new instance of Trial */
        >      public Trial(String trialName, String deviceFilename, String
        >
        > usageFilename, Date start, Date end) {
        >          this.trialName = trialName;
        >          this.deviceFilename = deviceFilename;
        >          this.usageFilename = usageFilename;
        >          this.start = start;
        >          this.end = end;
        >      }
        >
        > I am mapping the instance variables to the constructor arguments using
        > the mapping below. However, I get the exception
        >
        > org.xml.sax.SAXException: unable to instantiate
        > com.colinharris.pm.analysis.Trial; java.lang.IllegalArgumentException:
        > argument type mismatch
        >
        > when I include the two java.util.Date arguments. It works fine when I
        > only have the three String arguments. Am I doing something wrong?
        >
        > thanks in advance
        >
        > Colin.
        >
        > <class name="com.colinharris.pm.analysis.Trial">
        >    <field name="trialName" set-method="%1" get-method="getTrialName"
        > type="string">
        >      <bind-xml node="attribute"/>
        >    </field>
        >    <field name="deviceFilename" set-method="%2"
        > get-method="getDeviceFilename" type="string">
        >      <bind-xml node="attribute"/>
        >    </field>
        >    <field name="usageFilename" set-method="%3"
        > get-method="getUsageFilename" type="string">
        >      <bind-xml node="attribute"/>
        >    </field>
        >    <field name="start" set-method="%4" get-method="getStart"
        > type="date">
        >      <bind-xml node="attribute"/>
        >    </field>
        >
        >    <field name="end"  set-method="%5" get-method="getEnd" type="date">
        >      <bind-xml node="attribute"/>
        >    </field>
        >
        > </class>
        >
        >
        >
        > -----------------------------------------------------------
        > If you wish to unsubscribe from this mailing, send mail to
        > [EMAIL PROTECTED] with a subject of:
        >         unsubscribe castor-user
        >
        >
        >
        > ------------------------------------------------------------------------
        >
        > -----------------------------------------------------------
        > If you wish to unsubscribe from this mailing, send mail to
        > [EMAIL PROTECTED] with a subject of:
        >         unsubscribe castor-user
        
        
        
        -----------------------------------------------------------
        If you wish to unsubscribe from this mailing, send mail to
        [EMAIL PROTECTED] with a subject of:
                unsubscribe castor-user
        

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

Reply via email to