Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » Why reflection doesn't work in rap
Why reflection doesn't work in rap [message #507596] Thu, 14 January 2010 00:59 Go to next message
jason is currently offline jasonFriend
Messages: 2
Registered: January 2010
Junior Member
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] Thu, 14 January 2010 04:27 Go to previous messageGo to next message
jason is currently offline jasonFriend
Messages: 2
Registered: January 2010
Junior Member
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 08:23 Go to previous message
Rüdiger Herrmann is currently offline Rüdiger HerrmannFriend
Messages: 581
Registered: July 2009
Senior Member
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: Thu Mar 28 08:50:35 GMT 2024

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

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

Back to the top