Hi again,

On 09.03.2011 12:02, 吕晓一 wrote:
> Hi Werner,
> 
> Thanks for your great work!
> 
> I just downloaded Castor 1.3.1 and found some problems,
> 
> 1. I define a <field-handler>, it can be used in only  one  <class/>
As already mentioned, this does not work (as intended) with Castor
1.3.1, and will be fixed in Castor 1.3.2 (due to be released within a
few days).

Once Castor 1.3.2 will have been released, it will be possible to define
a field handler once and use it multiple times.

> 2. if the <field-handler> is defined in a mapping file, and this file
> is included by another main mapping file, marshal the java bean will
> throw exception.
If this is till an issue with Castor 1.3.2, please file a bug report and
attach a working test case so that we can reproduce this easily.

Having said that, feel free to cross-check with the 1.3.2 snapshot
release and report back.

Kind Regards
Werner
> 
> 
> Regards
> 
> Joey
> 
> 
> 
> 
>> -----邮件原件----- 发件人: Werner Guttmann [mailto:[email protected]] 发
>> 送时间: 2011年3月9日 18:26 收件人: [email protected] 抄送: 吕晓一 主题: Re:
>> [castor-user] 答复: [castor-user] how to reuse the field-handler 
>> defined in mapping file?
>> 
>> Hi Joey,
>> 
>> to keep things apart a little bit, yes, with Castor 1.3.2 it will
>> be possible to define a field handler once and reference it
>> multiple times from within field mappings. This feature is already
>> present with Castor 1.3.1, but due to a bug is didn't work as
>> intended, and has been fixed for Castor 1.3.2.
>> 
>> I am in the process of releasing 1.3.2 within a short period, but I
>> am facing problems with the Codehaus Nexus infrastructure right
>> now.
>> 
>> If you wanted, you could try this feature with the latest 1.3.2
>> SNAPSHOT release.
>> 
>> Regards Werner
>> 
>> On 09.03.2011 10:48, 吕晓一 wrote:
>>> Sorry, my English is poor, I try my best to make everyone
>>> understand what I
>> wrote.
>>> 
>>> In fact, I want to ask :  is it possible to define one
>>> <field-handler/> and use it
>> in everywhere ?
>>> 
>>> Joey
>>> 
>>>> -----邮件原件----- 发件人: avner21J [mailto:[email protected]] 发送时
>>>> 间: 2011年3月9日 17:28 收件人: [email protected] 主题: Re:
>>>> [castor-user] how to reuse the field-handler defined in
>>>> mapping
>> file?
>>>> 
>>>> 
>>>> Joey,
>>>> 
>>>> How does this post of yours relate to the original problem?
>>>> 
>>>> Don't clutter with unrelated posts and make it difficult for
>>>> others to understand.
>>>> 
>>>> 
>>>> 
>>>> 吕晓一 wrote:
>>>>> 
>>>>> Hi, my project use Castor, and I have one question.
>>>>> 
>>>>> I created a field handler named TimeHander.java like this:
>>>>> 
>>>>> public class TimeHandler extends GeneralizedFieldHandler {
>>>>> 
>>>>> private SimpleDateFormat formatter = new
>>>> SimpleDateFormat("yyyyMMdd");
>>>>> 
>>>>> public TimeHandler() { super(); }
>>>>> 
>>>>> public void setConfiguration(Properties config) throws 
>>>>> ValidityException { String pattern =
>>>>> config.getProperty("date-format"); if (pattern == null) { 
>>>>> throw new ValidityException("need parameter
>>>> \"date-format\"");
>>>>> } try { formatter = new SimpleDateFormat(pattern); } catch
>>>>> (IllegalArgumentException e) { throw new
>>>>> ValidityException("the parameter \"" + pattern
>> +
>>>> "\"
>>>>> invalid"); } }
>>>>> 
>>>>> 
>>>>> public Object convertUponGet(Object value) { if (value ==
>>>>> null) return null; Date date = (Date) value; return
>>>>> formatter.format(date);
>>>>> 
>>>>> }
>>>>> 
>>>>> public Object convertUponSet(Object value) { Date date =
>>>>> null; try { if (StringUtils.isEmpty((String) value)) { return
>>>>> date; } date = formatter.parse((String) value); } catch
>>>>> (ParseException px) { throw new
>>>>> IllegalArgumentException(px.getMessage()); } return date;
>>>>> 
>>>>> }
>>>>> 
>>>>> public Class getFieldType() { return Date.class; }
>>>>> 
>>>>> 
>>>>> public Object newInstance(Object parent) throws
>> IllegalStateException
>>>>> { return null; } }
>>>>> 
>>>>> 
>>>>> and my Java bean has two java.util.Date type fields, to make
>>>>> Castor work correctly, I have to define two <field-handler/>
>>>>> in mapping file like this: ... ... <field-handler
>>>>> name="timeHandler1" class="TimeHandler">
>>>>> 
>>>>> </field-handler> <field-handler name="timeHandler2"
>>>>> class="TimeHandler">
>>>>> 
>>>>> </field-handler> ... ... <class name="Mybean "> <map-to
>>>>> xml="MyBean"/> <field name="time1" type="java.lang.String"
>> handler="timeHandler1">
>>>>> <bind-xml name="Time1" node="element"/> </field> <field
>>>>> name="time2" type="java.lang.String"
>> handler="timeHandler2">
>>>>> <bind-xml name="Time2" node="element"/> </field> </class> 
>>>>> ....
>>>>> 
>>>>> that's mean: one field , one  <field-handler/> , even the
>>>>> same processing logic.
>>>>> 
>>>>> But my project has dozens of Java beans, and has dozens of
>>>>> Date-type fileds, so, I have to define dozens of
>>>>> <field-handler/>, it is so terrible....
>>>>> 
>>>>> Is there any advices?
>>>>> 
>>>>> Regards
>>>>> 
>>>>> Joey
>>>>> 
>>>>> 2011-3-9
>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>> 
>>>> -- View this message in context:
>>>> 
>> http://old.nabble.com/UnmarshalException-for-xml-created-by-Castor-Marshal
>>>>
>> 
ler-tp31097277p31104647.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
>>>> 
>>> 

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to