Hello all

This is a re-post, I sent the original about a week ago but didn't hear
anything back.  I'm sure you people are all very busy but I'm kind of stuck
and would really appreciate any suggestions.

To recap: I am having problems unmarshalling an XML document that uses
reference and ident attributes to share objects (the marshalling seems to be
fine).  The original suggestion from the list was to implement a custom
FieldHandler.  I have done this, am still getting the same exception and
also find it odd that the stack trace (see original message below for full
details)  still includes the basic FieldHandelrImp class rather than my
custom implementation.

Any thoughts?

Many thanks,


Howard


Original Message:

> Thanks for the reply.  Following your suggestion, I have created a custom
> FieldHandler based on an example I found in the mailing archives.  (I have
> appended it at the end of this message.)  I am however still getting the
> following exception when I try to unmarshall the XML document...
>
> java.lang.IllegalArgumentException: Type conversion error: could not set
>   value of connection(com.adaptris.core.AdaptrisConnection) with value of
>   type java.lang.String at
> org.exolab.castor.mapping.loader.FieldHandlerImpl.setValue
>     (FieldHandlerImpl.java:460) at
>   org.exolab.castor.xml.UnmarshalHandler.processAttribute
>     (UnmarshalHandler.java:1334)
>   ...
>
> The first thing that strikes me is that the exception occurs in setValue
in
> org.exolab.castor.mapping.loader.FieldHandlerImp, which I think is the
> default implementation of FieldHandler.  I would have thought that my own
> handler implementation (PtpConnectionHandler) would be being used by the
> unmarshalling process, rather than the default?  I have specified the
> handler to use in the mapping xml file as shown below, do I need to do
> anything else to use my custom Handler?
>
>   <class name="com.adaptris.core.jms.PtpProducer" auto-complete="true">
>      <field
>         name="connection"
>         type="com.adaptris.core.AdaptrisConnection"
>         handler="com.adaptris.core.databinding.PtpConnectionHandler">
>
>         <bind-xml name="connection" reference="true" node="attribute" />
>      </field>
>   </class>
>
>   (ditto for PtpConsumer)
>
>
> Also, I know this mapping file is being parsed because if I put a
> non-existent class in as the Handler imp I get the appropriate Exception.
>
> I have added log statements to my custom Handler (removed in the example
> below) and thus know that it is being used to marshal the objects.  None
of
> these log statements appear when I unmarshal the XML, backing up my idea
> that my custom handler isn't being used by the unmarshalling process.
>
> Any more suggestions?  If you require any clarification / additional
> information just let me know.
>
> many thanks
>
>
>
> Howard
>
>
> Custom handler implementation ----------------------------------------
>
>
> package com.adaptris.core.databinding;
>
> import com.adaptris.core.jms.*;
> import org.exolab.castor.mapping.*;
>
>
> public class PtpConnectionHandler implements FieldHandler {
>
>   public Object newInstance(Object parent) throws IllegalStateException {
>     return new PtpConnection();
>   }
>
>
>   public Object getValue(Object object) throws IllegalStateException {
>     try {
>       // nb JmsService is superclass of PtpProducer
>       return ((JmsService) object).getConnection();
>     } catch (Exception e) {
>       throw new RuntimeException(e.getMessage());
>     }
>   }
>
>
>   public void setValue(Object object, Object value)
>     throws IllegalStateException, java.lang.IllegalArgumentException {
>
>     JmsService service = (JmsService) object;
>     JmsConnection connection = (JmsConnection) value;
>
>     service.setConnection(connection);
>   }
>
>
>   public void resetValue(Object obj)
>     throws IllegalStateException, IllegalArgumentException {
>     // ?
>   }
>
>
>   public void checkValidity(Object obj)
>     throws ValidityException, IllegalStateException {
>
>     // do nothing, deprecated
>   }
> }
>
>
> ----- Original Message -----
> From: "Arnaud Blandin" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Thursday, June 20, 2002 4:32 PM
> Subject: Re: [castor-dev] Type conversion error when unmarshalling XML
>
>
> > Hi Howard,
> >
> > >From the error message it seems that Castor needs some information to
> > convert a String to your object. You might need to implement your own
> > FieldHandler and pass it to the handler attribute of the field element
> > of the mapping file.
> > <field name=.... handler="MyHandler"/>
> >
> > You can search the archive for code examples on how to use this
> > attribute.
> > If you are still encountering a problem, please tell us.
> >
> > Arnaud
> >
> > > -----Original Message-----
> > > From: howard fraser [mailto:[EMAIL PROTECTED]]
> > > Sent: Thursday, June 20, 2002 1:51 PM
> > > To: [EMAIL PROTECTED]
> > > Subject: [castor-dev] Type conversion error when unmarshalling XML
> > >
> > > Hello
> > >
> > > I am marshalling a set of objects to XML using reference and identity
> > > attributes to allow object instances to be shared.  The resulting XML
> > looks
> > > correct to me.   I am however running into problems trying to
> > unmarshall
> > > this XML.
> > >
> > > When I try to unmarshall the XML I get the following exception...
> > >
> > > java.lang.IllegalArgumentException: Type conversion error: could not
> > set
> > >   value of connection(com.adaptris.core.AdaptrisConnection) with value
> > of
> > >   type java.lang.String
> > >         at org.exolab.castor.mapping.loader.FieldHandlerImpl.setValue
> > >         (FieldHandlerImpl.java:460)
> > >         ...
> > >
> > > The field connection is a reference to the object that is being
> > shared.
> > > They type of this reference (com.adaptris.core.AdaptrisConnection) is
> > an
> > > interface, the mapping file (excerpted below) contains mappings for
> > the
> > > concrete implementations of this interface (...PtpConnection and
> > > ...PasConnection).
> > >
> > > Has anyone come across this Exception in this situation before?  Any
> > > suggestions?
> > >
> > >
> > >
> > > Mapping file excerpts...
> > >
> > > Mapping for the shared classes (implementations of
> > ..AdaptrisConnection
> > > interface)...
> > >
> > >   <class name="com.adaptris.core.jms.PtpConnection"
> > >          auto-complete="true"
> > >          identity="ident">
> > >
> > >     <field name="ident">
> > >       <bind-xml name="ident" node="attribute" />
> > >     </field>
> > >   </class>
> > >
> > >
> > >
> > > Mapping for the class which has a reference to the shared class...
> > >
> > >   <class name="com.adaptris.core.jms.PtpProducer"
> > >          auto-complete="true">
> > >
> > >     <field name="connection"
> > >            type="com.adaptris.core.AdaptrisConnection">
> > >
> > >       <bind-xml name="connection" reference="true" node="attribute" />
> > >     </field>
> > >   </class>
> > >
> > >
> > > I can post additional code, marshalled XML, complete mappings, etc. if
> > > anyone would like.  Any suggestions most appreciated.
> > >
> > >
> > >
> > > Howard
> > >
> > > -----------------------------------------------------------
> > > If you wish to unsubscribe from this mailing, send mail to
> > > [EMAIL PROTECTED] with a subject of:
> > > unsubscribe castor-dev
> >
> > -----------------------------------------------------------
> > If you wish to unsubscribe from this mailing, send mail to
> > [EMAIL PROTECTED] with a subject of:
> > unsubscribe castor-dev
> >
> >
>
>

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

Reply via email to