|Re: Why reflection doesn't work in rap [message #507635 is a reply to message #507596]
||Thu, 14 January 2010 08:23
| Rüdiger Herrmann
Registered: July 2009
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 . 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).
On 14.01.2010 01:59, email@example.com wrote:
> 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();
> dpClass = (Class<? extends DataProcessing>)
> 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
Powered by FUDForum
. Page generated in 0.02598 seconds