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


Reply via email to