Skip to main content



      Home
Home » Eclipse Projects » Remote Application Platform (RAP) » Why reflection doesn't work in rap
Why reflection doesn't work in rap [message #507596] Wed, 13 January 2010 19:59 Go to next message
Eclipse UserFriend
Hi,

In rap, I try to use reflection to load a class by its classpath and classname. When I test it in junit, it work good. But when I call this method from UI, it always give me a ClassCastException

My code:

/** The reference to a data processing object, is loaded as an Algorithm (see RunAlgorithm) */
protected DataProcessing dataProcessing;

/** Reference to class of Algorithm used in this activity */
private Class<? extends DataProcessing> dpClass;

AlgorithmLoader algorithmLoader = new AlgorithmLoader();
algorithmLoader.addPath(dpClassPath);
dpClass = (Class<? extends DataProcessing>) algorithmLoader.loadClass(dpClassName);
dataProcessing = dpClass.newInstance();

Exception is :
java.lang.ClassCastException: ianalyst.algorithm.dataprocessing.rowoperation.Sampling cannot be cast to ianalyst.algorithm.dataprocessing.DataProcessing
..............
............

algorithmLoader extend from URLClassLoader.
Sampling extend from DataProcessing.


Can some one give me some idea, thank you very much
Re: Why reflection doesn't work in rap [message #507611 is a reply to message #507596] Wed, 13 January 2010 23:27 Go to previous messageGo to next message
Eclipse UserFriend
Some one tell me it is because rap uses different classloader, is it?
Re: Why reflection doesn't work in rap [message #507635 is a reply to message #507596] Thu, 14 January 2010 03:23 Go to previous message
Eclipse UserFriend
RAP is based on Equinox, the Eclipse OSGi implementation. In OSGi each
bundle has its own class loader, this is probably what causes the trouble.
If you are working with class loaders, make sure that you understand the
technologies that are involved [1]. Searching for "osgi class loading"
should bring up enough material.

The reason why the unit tests are working is that they are executed as a
plain Java application (no OSGi involved).

HTH
Rüdiger

[1] http://eclipse.org/rap/documentation.php#resources
--
Rüdiger Herrmann
http://eclipsesource.com

On 14.01.2010 01:59, chen_jiahang@hotmail.com wrote:
> Hi,
> In rap, I try to use reflection to load a class by its classpath and
> classname. When I test it in junit, it work good. But when I call this
> method from UI, it always give me a ClassCastException
>
> My code:
>
> /** The reference to a data processing object, is loaded as an Algorithm
> (see RunAlgorithm) */
> protected DataProcessing dataProcessing;
>
> /** Reference to class of Algorithm used in this activity */
> private Class<? extends DataProcessing> dpClass;
>
> AlgorithmLoader algorithmLoader = new AlgorithmLoader();
> algorithmLoader.addPath(dpClassPath);
> dpClass = (Class<? extends DataProcessing>)
> algorithmLoader.loadClass(dpClassName);
> dataProcessing = dpClass.newInstance();
>
> Exception is : java.lang.ClassCastException:
> ianalyst.algorithm.dataprocessing.rowoperation.Sampling cannot be cast
> to ianalyst.algorithm.dataprocessing.DataProcessing
> ..............
> ............
>
> algorithmLoader extend from URLClassLoader.
> Sampling extend from DataProcessing.
>
>
> Can some one give me some idea, thank you very much
>
Previous Topic:Best place to shutdown Ehcache
Next Topic:Eclipse e4 and RAP.
Goto Forum:
  


Current Time: Tue Jul 08 07:03:49 EDT 2025

Powered by FUDForum. Page generated in 0.05333 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top