Hi Werner,
The xml looks like ,
<Restrictn>
<CategRestr/>
<restrDesc> </restrDesc>
<Vendor> </Vendor>
<Violatn>Y</Violatn>
<SubTyp>Buy</SubTyp>
<Qualify>MinDol</Qualify>
<Amt>0</Amt>
<Notes> </Notes>
<ID> </ID>
<StartDt>1967-08-13</StartDt>
<EndDt>1967-08-13</EndDt>
<Actn>A</Actn>
</Restrictn>
the mappings are like,
<class name="com.xyz.common.datatypes.RestrictnImpl" auto-complete="false">
<map-to xml="Restrictn"/>
<field name="categRestr" type="string" required="false"
direct="false" transient="false">
<bind-xml name="CategRestr" node="element" reference="false"/>
</field>
<field name="Vendor" type="string" required="false"
direct="false" transient="false">
<bind-xml name="RestrVendor" node="element"
location="Classification" reference="false"/>
</field>
<field name="InViolatn" type="boolean" required="false"
direct="false" transient="false">
<bind-xml name="RestrInViolatn" node="element"
location="Classification" reference="false"/>
</field>
<field name="ID" type="string" required="false"
direct="false" transient="false">
<bind-xml name="RestrictionID" node="element"
location="Classification" reference="false"/>
</field>
<field name="restrDesc" type="string" required="false"
direct="false" transient="false">
<bind-xml name="RestrDesc" node="element"
location="Classification" reference="false"/>
</field>
<field name="EndDt" type="date" required="false"
direct="false" transient="false">
<bind-xml name="RestrEndDt" node="element"
location="Classification" reference="false"/>
</field>
<field name="StartDt" type="date" required="false"
direct="false" transient="false">
<bind-xml name="RestrStartDt" node="element"
location="Classification" reference="false"/>
</field>
<field name="Amt" type="long" required="false"
direct="false" transient="false">
<bind-xml name="RestrAmt" node="element" reference="false"/>
</field>
<field name="symbol" type="string" required="false"
direct="false" transient="false">
<bind-xml name="symbol" node="element" reference="false"/>
</field>
</class>
MyDateHandler.java looks like,
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.exolab.castor.mapping.GeneralizedFieldHandler;
/**
* The FieldHandler for the Date class
*
*/
public class MyDateHandler
extends GeneralizedFieldHandler
{
private static final String FORMAT = "yyyy-MM-dd";
/**
* Creates a new MyDateHandler instance
*/
public MyDateHandler() {
super();
}
/**
* This method is used to convert the value when the
* getValue method is called. The getValue method will
* obtain the actual field value from given 'parent' object.
* This convert method is then invoked with the field's
* value. The value returned from this method will be
* the actual value returned by getValue method.
*
* @param value the object value to convert after
* performing a get operation
* @return the converted value.
*/
public Object convertUponGet(Object value) {
if (value == null) return null;
SimpleDateFormat formatter = new SimpleDateFormat(FORMAT);
Date date = (Date)value;
return formatter.format(date);
}
/**
* This method is used to convert the value when the
* setValue method is called. The setValue method will
* call this method to obtain the converted value.
* The converted value will then be used as the value to
* set for the field.
*
* @param value the object value to convert before
* performing a set operation
* @return the converted value.
*/
public Object convertUponSet(Object value) {
SimpleDateFormat formatter = new SimpleDateFormat(FORMAT);
Date date = null;
try {
date = formatter.parse((String)value);
}
catch(ParseException px) {
throw new IllegalArgumentException(px.getMessage());
}
return date;
}
/**
* Returns the class type for the field that this
* GeneralizedFieldHandler converts to and from. This
* should be the type that is used in the
* object model.
*
* @return the class type of of the field
*/
public Class getFieldType() {
return Date.class;
}
/**
* Creates a new instance of the object described by
* this field.
*
* @param parent The object for which the field is created
* @return A new instance of the field's value
* @throws IllegalStateException This field is a simple
* type and cannot be instantiated
*/
public Object newInstance( Object parent )
throws IllegalStateException
{
//-- Since it's marked as a string...just return null,
//-- it's not needed.
return null;
}
}
Regards,
Pramod
Werner Guttmann-6 wrote:
>
> Hi,
>
> what is the actual <date> field looking like in your XML document ? Can
> you provide us with a sample ?
>
> And are you using a mapping, or did you start with an XML schema ?
>
> Cheers
> Werner
>
> PS In general, please do provide more information about the problem at
> hand, such as XML document (fragments), mapping file (fragments), ....
> otherwise it will be very hard to help you.
>
> On 23.02.2010 12:20, ptyagi108 wrote:
>>
>> Hi ,
>>
>> I am getting an error parsing a Date field like
>> java.lang.IllegalStateException: Bad DateTime format: 1967-08-13
>> DateTime is not long enough.I found similar bug not resloved yet in
>> castor
>> Jira.. can anyone pls inform me some good work around for the same issue
>> which do not require me to change castor library.
>>
>> http://jira.codehaus.org/browse/CASTOR-1878?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_88296
>>
>> Regards,
>> Pramod
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
> http://xircles.codehaus.org/manage_email
>
>
>
>
--
View this message in context:
http://old.nabble.com/convertUponSet-method-of-MyDateHandler-extending-GeneralizedFieldHandler-is-not-getting-called-tp27701790p27714111.html
Sent from the Castor - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email