Re: [morph-user] ClassCastException... (fwd)
Brought to you by:
orangeherbert,
sgarlatm
|
From: Hernan S. <hsi...@pd...> - 2005-03-09 18:39:04
|
Clever workaround, it worked and will be fine in the short term on the project
I'm working on.
Thanks... Hernan
On Wed, 9 Mar 2005, Matt Sgarlata wrote:
> Hi Hernan,
>
> I think the problem is probably that the components property of the
> DelegatingTransformer is of type Component[], so when Spring populates
> the property, it create an array with runtime type Component[]. The
> DelegatingTransformer is expecting a runtime type of Transformer[].
> This would explain why you can setup your transformer programmatically
> but not using Spring.
>
> I guess the easiest quick fix would probably be for you to subclass the
> DelegatingTransformer and expose a Transformer[] setTransformers method
> so that Spring creates an array with the correct runtime type. Long
> term, I'm planning on replacing the components property with a Map of
> String transformer names to Transformer objects. This will make it
> easier to work with the DelegatingTransformer programmatically if you
> want to, for example, replace only a single transformer.
>
> Does this short-term fix work for you?
>
> Matt
>
> Hernan Silberman wrote:
>
> >I failed to mention:
> >
> >I'm using Morph 0.8.3
> >
> >thnx...
> >hernan
> >
> >---------- Forwarded message ----------
> >Date: Tue, 8 Mar 2005 14:55:57 -0800 (PST)
> >From: Hernan Silberman <hsi...@pd...>
> >To: mor...@li...
> >Subject: ClassCastException...
> >
> >
> >I'm sure I'm doing something wrong here... I'm trying to build a graph
> >transformer using a simple Spring context that defines this bean:
> >
> ><bean
> > id="graphTransformer"
> > class="net.sf.morph.transform.transformers.DelegatingTransformer">
> > <property name="components">
> > <list>
> > <ref bean="immutableTypesOnlyIdentityConverter"/>
> > <ref bean="timeCopier"/>
> > <ref bean="collectionCopier"/>
> > <ref bean="propertyNameMatchingCopier"/>
> > <ref bean="containerCopier"/>
> > </list>
> > </property>
> ></bean>
> >
> >
> >All of the reference beans are very simple bean definitions, for example:
> >
> ><bean
> > name="collectionCopier"
> > class="net.sf.morph.transform.copiers.CollectionCopier"/>
> >
> >The context loads up fine as a FileSystemXmlApplicationContext. When I
> >try to do the following simple conversion in my Test case:
> >
> >public void testSimpleConvert()
> >{
> > String theSource = new String("Hello");
> > String theDest =
> > (String)myGraphTransformer.convert( String.class, theSource );
> > assertNotNull(theDest);
> > assertEquals(theSource,theDest);
> >}
> >
> >...I get the exception below. I don't get this exception when I build this
> >DepegatingTransformer programmatically. Also, I don't get the exception
> >when I leave off the "components" property definition for the graphTransformer
> >bean. I can see DelegatingTransformer is doing a case to Transformer[] which is
> >failing.
> >
> >Please let me know if you spot my error... thanks in advance... Hernan
> >
> >
> >net.sf.morph.transform.TransformationException: Could not initialize transformer
> >net.sf.morph.transform.transformers.DelegatingTransformer@e6f7d2 (class
> >net.sf.morph.transform.transformers.DelegatingTransformer)
> > at
> >net.sf.morph.transform.transformers.BaseTransformer.initialize(BaseTransformer.java:193)
> > at
> >net.sf.morph.transform.transformers.BaseTransformer.getDestinationClasses(BaseTransformer.java:149)
> > at
> >net.sf.morph.util.TransformerUtils.isImplicitlyTransformable(TransformerUtils.java:53)
> > at
> >net.sf.morph.transform.transformers.BaseTransformer.isTransformable(BaseTransformer.java:105)
> > at
> >net.sf.morph.transform.transformers.BaseTransformer.convert(BaseTransformer.java:216)
> > at
> >net.sf.morph.transform.transformers.BaseTransformer.convert(BaseTransformer.java:237)
> > at
> >tests.morph.MorphContextTest.testSimpleConvert(MorphContextTest.java:59)
> >...(Click for full stack trace)...
> >Caused by: java.lang.ClassCastException
> > at
> >net.sf.morph.transform.transformers.DelegatingTransformer.getTransformers(DelegatingTransformer.java:260)
> > at
> >net.sf.morph.transform.transformers.DelegatingTransformer.getSourceClassesImpl(DelegatingTransformer.java:136)
> > at
> >net.sf.morph.transform.transformers.BaseTransformer.initialize(BaseTransformer.java:171)
> > ... 21 more
> >
> >
> >
> >
> >-------------------------------------------------------
> >SF email is sponsored by - The IT Product Guide
> >Read honest & candid reviews on hundreds of IT Products from real users.
> >Discover which products truly live up to the hype. Start reading now.
> >http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
> >_______________________________________________
> >morph-user mailing list
> >mor...@li...
> >https://lists.sourceforge.net/lists/listinfo/morph-user
> >
> >
> >
>
>
>
>
>
> -------------------------------------------------------
> SF email is sponsored by - The IT Product Guide
> Read honest & candid reviews on hundreds of IT Products from real users.
> Discover which products truly live up to the hype. Start reading now.
> http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
> _______________________________________________
> morph-user mailing list
> mor...@li...
> https://lists.sourceforge.net/lists/listinfo/morph-user
>
--
Hernan Silberman
PDI/Dreamworks
ext.29162 / 650-562-9162 / cell 415-810-5809
text pager: pag...@an...
|