Hi,

can you please raise a new Jira issue at

http://jira.codehaus.org/browse/CASTOR

and attach all relevant files.

Thanks
Werner

> java.lang.IllegalStateException {
>         Date date = null;
> 
>         if (value == null || value instanceof Date) {
>             date = (Date) value;
>         } else {
>             try {
>                 date = parse(value.toString(), _options);
>                 // -- java.sql.Date?
>                 if (_useSQLDate && date != null) {
>                     date = new java.sql.Date(date.getTime());
>                 }
>             } catch (java.text.ParseException px) {
>                 // -- invalid dateTime
>                 throw new IllegalStateException(px.getMessage());
>             }
>         }
> 
>         _handler.setValue(target, date);
>     } // -- setValue
> 
> parse() method will throw the Bad Date Exception because it does not know
> how to handle custom field, but our Handler knows how to .. so, I guess ..
> we should directly delegate the call to _handler.setValue() ..
> 
> ** Please let me know if its a bug or I am doing something wrong, we are
> doing POC with caster but its not going well at all. 
> 
> Karephul
> 
> 
> 
> karephul wrote:
>>
>> .. mapping ..
>>        <class name="com.Person" auto-complete="true">
>>              <map-to xml="Person" />
>>              <field name="name" type="java.lang.String">
>>                      <bind-xml name="name" node="element" />
>>              </field>
>>              <field name="dob" type="java.util.Date"
>>                      handler="com.common.xmljava.handlers.MyDateHandler">
>>                      <bind-xml name="dob" node="element" />
>>              </field>
>>      </class>
>>
>> MyDateHandler with following methods
>>     
>> public Object getValue( Object object )
>>         throws IllegalStateException
>>     {
>>         Person root = (Person)object;
>>         Date value = root.getDob();
>>         if (value == null) return null;
>>         SimpleDateFormat formatter = new SimpleDateFormat(FORMAT);
>>         Date date = (Date)value;
>>         return formatter.format(date);
>>     }
>>     public void setValue( Object object, Object value )
>>         throws IllegalStateException, IllegalArgumentException
>>     {
>>         Person root = (Person)object;
>>         SimpleDateFormat formatter = new SimpleDateFormat(FORMAT);
>>         Date date = null;
>>         try {
>>             date = formatter.parse((String)value);
>>         }
>>         catch(ParseException px) {
>>             throw new IllegalArgumentException(px.getMessage());
>>         }
>>         root.setDob(date);
>>
>>     }
>>
>> ------------------------------------ Reading Writing --------------
>>
>>      public <T> void readObject(T obj, String fromXML) {
>>              try {
>>                      Reader reader = new FileReader(fromXML);
>>
>>                      if (manager.getContext() == null) {
>>                              obj = (T)Unmarshaller.unmarshal(obj.getClass(), 
>> reader);
>>                      }
>>                      
>>                      Unmarshaller unMarshaller = 
>> manager.getContext().createUnmarshaller();
>>                      obj = (T)unMarshaller.unmarshal(reader);
>>                      
>>              } catch (IOException e) {
>>                      e.printStackTrace();
>>              }catch (ValidationException e) {
>>                      e.printStackTrace();
>>              }catch(MarshalException e){
>>                      e.printStackTrace();
>>              }
>>      }
>>
>>      public <T> void writeObject(T obj, String toXML) {
>>
>>              try {
>>                      Writer writer = new FileWriter(toXML);
>>
>>                      if (manager.getContext() == null) {
>>                              Marshaller.marshal(obj, writer);
>>                              return;
>>                      } else {
>>                              
>>                              Marshaller marshaller = 
>> manager.getContext().createMarshaller();
>>                              marshaller.setWriter(writer);
>>                              marshaller.marshal(obj);
>>                              // Marshaller.marshal(order, writer);
>>                      }
>>
>>              } catch (IOException e) {
>>                      e.printStackTrace();
>>              }catch (ValidationException e) {
>>                      e.printStackTrace();
>>              }catch(MarshalException e){
>>                      e.printStackTrace();
>>              }
>>      }
>>
>> manager is a singleton which holds to the context. 
>>
>> Thanks for your quick response, please let me know if you need more
>> information to reproduce this.
>>
>> Regards,
>> Karephul
>> -------------
>>
>>
>> Werner Guttmann wrote:
>>> That's odd, as there's plenty of integration tests in our test suite
>>> that use FieldHandler.
>>>
>>> How about showing us the relevant parts of your mapping file, for example
>>> ?
>>>
>>> Werner
>>>
>>> karephul wrote:
>>>> Werner,
>>>>
>>>> Thanks for the quick response. I just tried using FileHandler instead of
>>>> GeneralizedFieldHandler. It seem to have the same problem [it Marshalls
>>>> properly but throws exception while UnMarshalling.]
>>>> I debuged the code and noticed that my execution thread goes to 
>>>> public Object getValue( Object object ){} while writing to XML, but
>>>> never
>>>> enters public void setValue( Object object, Object value )  {} while
>>>> writing
>>>> to object.
>>>>
>>>> Bottom line, it does not have the right instance of FieldHandler and
>>>> uses
>>>> default DateHandler which eventually throws exception.
>>>>
>>>> Can you suggest me a way to achieve this or point me to some working
>>>> example.
>>>>
>>>> Thanks,
>>>> Karephul
>>>>
>>>>
>>>> Werner Guttmann wrote:
>>>>> Hi,
>>>>>
>>>>> there's an issue with the use of GeneralizedFieldHandler at the moment.
>>>>> This has been reported before already.
>>>>>
>>>>> Regards
>>>>> Werner
>>>>>
>>>>> karephul wrote:
>>>>>> I am using the same example as shown in the documentation 
>>>>>> [http://www.castor.org/reference/html-single/index.html#d0e2586].
>>>>>>
>>>>>> XML produced was what I expected .. 
>>>>>>          <person>
>>>>>>          <name>Karephul</name>
>>>>>>          <dob>1982-03-05</dob>
>>>>>>  </person> 
>>>>>> ....
>>>>>>
>>>>>> but while Unmarshalling, it throws an exception:
>>>>>>
>>>>>> -----------------------------------------------------------------------
>>>>>>
>>>>>> DEBUG [main] (ResolveHelpers.java:143) - Ignored problem at loading
>>>>>> class:
>>>>>> java.util.DateDescriptor through class loader:
>>>>>> sun.misc.launcher$appclassloa...@a39137, exception:
>>>>>> java.lang.ClassNotFoundException: java.util.DateDescriptor
>>>>>> DEBUG [main] (ResolveHelpers.java:143) - Ignored problem at loading
>>>>>> class:
>>>>>> java.util.descriptors.DateDescriptor through class loader:
>>>>>> sun.misc.launcher$appclassloa...@a39137, exception:
>>>>>> java.lang.ClassNotFoundException: java.util.descriptors.DateDescriptor
>>>>>> DEBUG [main] (XMLClassDescriptorResolverImpl.java:626) - Called
>>>>>> addAllDescriptors with null or empty descriptor map
>>>>>> DEBUG [main] (XMLClassDescriptorResolverImpl.java:546) - Get
>>>>>> descriptor
>>>>>> for:
>>>>>> java.util.Date found: null
>>>>>> DEBUG [main] (AbstractResolverClassCommand.java:50) - Now in method:
>>>>>> org.exolab.castor.xml.util.resolvers.ByIntrospection resolving:
>>>>>> java.util.Date
>>>>>> DEBUG [main] (ByIntrospection.java:93) - Found descriptor:
>>>>>> org.exolab.castor.xml.descriptors.dateclassdescrip...@1f06dc3;
>>>>>> descriptor
>>>>>> for class: Date; xml name: date
>>>>>> org.exolab.castor.xml.MarshalException: Bad DateTime format:
>>>>>> 1982-03-05
>>>>>> DateTime is not long enough{File: [not available]; line: 2; column:
>>>>>> 402}
>>>>>>  at
>>>>>> org.exolab.castor.xml.Unmarshaller.convertSAXExceptionToMarshalException(Unmarshaller.java:794)
>>>>>>  at
>>>>>> org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:760)
>>>>>>  at
>>>>>> org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:626)
>>>>>> DEBUG [main] (XMLClassDescriptorResolverImpl.java:507) - Adding
>>>>>> descriptor
>>>>>> class for: java.util.Date descriptor:
>>>>>> org.exolab.castor.xml.descriptors.dateclassdescrip...@1f06dc3;
>>>>>> descriptor
>>>>>> for class: Date; xml name: date
>>>>>> DEBUG [main] (XMLClassDescriptorResolverImpl.java:546) - Get
>>>>>> descriptor
>>>>>> for:
>>>>>> java.util.Date found:
>>>>>> org.exolab.castor.xml.descriptors.dateclassdescrip...@1f06dc3;
>>>>>> descriptor
>>>>>> for class: Date; xml name: date
>>>>>> DEBUG [main] (UnmarshalHandler.java:528) - #characters: 1982-03-05
>>>>>> DEBUG [main] (UnmarshalHandler.java:624) - #endElement: dob
>>>>>>  at
>>>>>> com.manh.doms.app.common.xmljava.Converter.readObject(Converter.java:28)
>>>>>>  at com.manh.MainTest.main(MainTest.java:37)
>>>>>> Caused by: java.lang.IllegalStateException: Bad DateTime format:
>>>>>> 1982-03-05
>>>>>> DateTime is not long enough
>>>>>>  at
>>>>>> org.exolab.castor.xml.handlers.DateFieldHandler.setValue(DateFieldHandler.java:173)
>>>>>>  at
>>>>>> org.exolab.castor.xml.UnmarshalHandler.endElement(UnmarshalHandler.java:1070)
>>>>>>  at
>>>>>> org.exolab.castor.xml.UnmarshalHandler.endElement(UnmarshalHandler.java:1161)
>>>>>>  at
>>>>>> com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:633)
>>>>>>  at
>>>>>> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1241)
>>>>>>  at
>>>>>> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1685)
>>>>>>  at
>>>>>> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:368)
>>>>>>  at
>>>>>> com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:834)
>>>>>>  at
>>>>>> com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
>>>>>>  at
>>>>>> com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:148)
>>>>>>  at
>>>>>> com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1242)
>>>>>>  at
>>>>>> org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:748)
>>>>>>  ... 3 more
>>>>>> Caused by: java.lang.IllegalStateException: Bad DateTime format:
>>>>>> 1982-03-05
>>>>>> DateTime is not long enough
>>>>>>  at
>>>>>> org.exolab.castor.xml.handlers.DateFieldHandler.setValue(DateFieldHandler.java:173)
>>>>>>  at
>>>>>> org.exolab.castor.xml.UnmarshalHandler.endElement(UnmarshalHandler.java:1070)
>>>>>>  at
>>>>>> org.exolab.castor.xml.UnmarshalHandler.endElement(UnmarshalHandler.java:1161)
>>>>>>  at
>>>>>> com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:633)
>>>>>>  at
>>>>>> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1241)
>>>>>>  at
>>>>>> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1685)
>>>>>>  at
>>>>>> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:368)
>>>>>>  at
>>>>>> com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:834)
>>>>>>  at
>>>>>> com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
>>>>>>  at
>>>>>> com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:148)
>>>>>>  at
>>>>>> com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1242)
>>>>>>  at
>>>>>> org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:748)
>>>>>>  at
>>>>>> org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:626)
>>>>>>  at
>>>>>> com.manh.doms.app.common.xmljava.Converter.readObject(Converter.java:28)
>>>>>>  at com.manh.MainTest.main(MainTest.java:37)
>>>>>> Caused by: java.lang.IllegalStateException: Bad DateTime format:
>>>>>> 1982-03-05
>>>>>> DateTime is not long enough
>>>>>>
>>>>>>
>>>>>> ----------------------------------------------------------------------------------
>>>>>>  
>>>>>>
>>>>>> I am using the same "mapping.xml" and hence the XMLContext to create
>>>>>> Marshaller and UnMarshaller. 
>>>>>> While Unmarshalling the XML to Object, Caster is not using the handler
>>>>>> ..
>>>>>> this is a bug.
>>>>>>
>>>>>> I am using below jars in my classpath:
>>>>>> castor-1.3rc1-xml.jar
>>>>>> castor-1.3rc1-core.jar
>>>>>>
>>>>>> Can you please advice.
>>>>>>
>>>>>> Thanks,
>>>>>> Karephul
>>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> 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
>>>
>>>
>>>
>>>
>>
> 

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

    http://xircles.codehaus.org/manage_email


Reply via email to