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