Scott Venter wrote:
> 
> 2) In my code I implied the class to be marshalled, instantiated that
> specifc class, and passed it to the Unmarshaller to unmarshall data into
> like this.
> 
> //create response parser
> res.xml7001.Transactflex vResponse = new res.xml7001.Transactflex();
> //create error parser
> res.xmlerror.Transactflex vErrorResponse = new res.xmlerror.Transactflex();
> 
> I then instantiated the Unmarshaller and passed it the relevent Castor
> generated class like this:
> 
>         //got valid response. now process
>         org.exolab.castor.xml.Unmarshaller vUnmarshaller = new
> 
> org.exolab.castor.xml.Unmarshaller(vResponse);
> 
> The point being that I could then use my reference to vResponse to obtain
> the relevent returned data.
> 
> How do I obtain the relevent class that the data was unmarshalled into using
> your method?


You'll have to use instanceof to determine the type returned by the
Unmarshaller if you don't know it ahead of time...

Object obj = unmarshaller.unmarshal(reader);

if (obj instanceof res.xmlerror.Transactflex) {

}

or if all your objects use a base class you can cast to the base class:

TransactflexBase transactflex = (TransactflexBase)
unmarshaller.unmarshal(reader);


--Keith


> ----- Original Message -----
> From: "Keith Visco" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Tuesday, July 02, 2002 5:47 PM
> Subject: Re: [castor-dev] Unmarshall a xml stream
> 
> >
> > Scott,
> >
> > Why not simply pass in no class at all and let Castor figure it out. As
> > long as your schema files don't have any conflicting element names then
> > Castor should be able to automatically choose the correct class.
> >
> > Unmarshaller = new Unmarshaller((class)null);
> >
> > You can also implement (or extend the default one) a
> > ClassDescriptorResolver and pass that into Castor. Castor uses the
> > ClassDescriptorResolver to find all ClassDescriptors, by implementing
> > your own or extending the default one you can control which
> > ClassDescriptors are used and therefore the entire object model that
> > will get created.
> >
> > --Keith
> >
> > -----------------------------------------------------------
> > 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