I agree.  Option B sounds better.  Adding a
setRootClass(Class) to the Unmarshaller should fix the
problem.

I went ahead and created a new jira issue for this
http://jira.codehaus.org/browse/CASTOR-1879

I think it will be an easy fix.
-Saladin


--- Werner Guttmann <[EMAIL PROTECTED]> wrote:

> Saladin,
> 
> I just had a look at the sources, and there's two
> options. 
> 
> A) Change existing code of
> UnmarshallerfactoryBean.getObject() to allow
> setting e.g. a rootClass parameter on the factory
> bean. Whilst
> technically this is no problem, and allows
> configuration through Spring
> and its context file, this is not the ideal
> solution, as it basically
> means that you'd have to configure multiple
> <unmarshallers> in your
> Spring context file.
> 
> B) Add a setRootClass(Class) method to Unmarshaller
> to allow
> configuration of the class (to be expected to be
> unmarshalled) after
> instantiation of the Unmarshaller. It looks like
> this will be
> achievable, and it would be my preference.
> 
> As suchg, can I please ask you to create a new Jira
> issue (once this is
> possible again) and attach all relevant information
> from this
> conversation.
> 
> Regards
> Werner
> 
> > -----Original Message-----
> > From: S. Sharif [mailto:[EMAIL PROTECTED] 
> > Sent: Mittwoch, 21. Februar 2007 22:27
> > To: [email protected]
> > Subject: Re: [castor-user] Problem when classes
> are 
> > re-ordered in the Castor xml mapping file
> > 
> > 
> > Even though I was able to resolve this
> > programmatically by setting the class type in the
> Unmarshaller
> > 
> > Unmarshaller unmarshaller = new
> > Unmarshaller(RunDvpRequestVO.class);
> > unmarshaller.setMapping(mapping);
> > 
> > 
> > But now I am having a problem doing this through
> the Spring 
> > FactoryBean.  I want to obtain an instance of the 
> > unmarshaller from the Spring FactoryBean.
> > 
> > 
> > Here is the code to get an instance of the
> unmarshaller 
> > through Spring:
> > 
> > Unmarshaller unmarshaller = (Unmarshaller) 
> > applicationContext.getBean("unmarshaller");
> > 
> > 
> > and the following is the entry in the Spring
> configuration file:
> > 
> > <bean id="resolver"
> >
>
class="org.springframework.xml.castor.CastorResolverFactoryBean">
> >   <property name="mappingLocations">
> >     <list>
> >       <value>castor-mapping.xml</value>
> >     </list>
> >   </property>
> > </bean>
> > 
> > <bean id="unmarshaller"
> >
>
class="org.springframework.xml.castor.CastorUnmarshallerFactoryBean">
> >   <property name="resolver" ref="resolver"/>
> </bean>
> > 
> > 
> > But now how do I specify the class type of the
> class that I 
> > want to unmarshall to???
> > 
> > I looked at the online Javadoc for the
> Unmarshaller class, 
> > but there is no
> Unmarshaller.setClass(java.lang.Class c) 
> > method for setting the class type.  The only way I
> can pass 
> > in the class type is via the Unmarshaller's
> constructor. 
> > But I cannot call the constructor because I am
> obtaining an 
> > instance of the unmarshaller through Spring.
> > 
> > Is there another way to pass in the class type,
> maybe via the 
> > Spring config file?  How do I solve this delima?
> > 
> > Thanks.
> > -Saladin
> > 
> > 
> > --- Werner Guttmann <[EMAIL PROTECTED]>
> wrote:
> > 
> > > That's what I thought initially, but then I
> started to 
> > think that the 
> > > problem might be solely related to your usage of
> locations, 
> > and not to 
> > > the way the Unmarshaller is instantiated. Well
> ...
> > > looks like the first
> > > advice has been correct .. ;-).
> > > 
> > > Thanks for the feedback.
> > > 
> > > Werner
> > > 
> > > S. Sharif wrote:
> > > > Actually i think I figured this out.  All of
> my various 
> > input xml's 
> > > > that I want to unmarshall to different java
> objects have a common 
> > > > structure;
> > > they
> > > > are all wrapped insides of a root <Document>
> tag. 
> > > So
> > > > when Castor wants to unmarshall a given xml it
> > > looks
> > > > in the mapping file and grabs the first class
> > > occuring
> > > > with a root <Document> tag.  In this case it
> > > grabbed
> > > > the wrong one.  Then when it looked for the
> next
> > > child
> > > > tag <DVPCRITERIAINPUT_LIST> of the root
> <Document> tag, 
> > it did not 
> > > > find it inside of that class that
> > > it
> > > > grabbed.  As a result, it threw an exception. 
> > > This is
> > > > my speculation on what happend.
> > > > 
> > > > I modified my code to pass in to the
> Unmarshaller constructor the 
> > > > class type of the correct class
> > > that I
> > > > want to unmarshall to:
> > > > 
> > > > 
> > > > unmarshaller = new
> > > > Unmarshaller(RunDvpRequestVO.class);
> > > > unmarshaller.setMapping(mapping);
> > > > 
> > > > 
> > > > And now the code works even when the mapping
> file
> > > is
> > > > not in the correct order.
> > > > 
> > > > -Saladin
> > > > 
> > 
> > 
> >
>
**********************************************************
> > * Saladin Sharif
> > * e-mail:  [EMAIL PROTECTED]
> > * Visit homepage @
> http://gaia.ecs.csus.edu/~sharifs
> >
>
**********************************************************
> > 
> > 
> >  
> >
>
______________________________________________________________
> > ______________________
> > Any questions? Get answers on any topic at 
> > www.Answers.yahoo.com.  Try it now.
> > 
> >
>
---------------------------------------------------------------------
> > 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
> 
> 



 
____________________________________________________________________________________
It's here! Your new message!  
Get new email alerts with the free Yahoo! Toolbar.
http://tools.search.yahoo.com/toolbar/features/mail/

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

    http://xircles.codehaus.org/manage_email

Reply via email to