Application.getComponent() not working in 4.5

In migrating to the new version we are finding it not possible to access objects in other plugins, e.g.:
Application application = ApplicationManager.getApplication();
TestResourcesComponent testResourcesComponent = (TestResourcesComponent)application.getComponent(TestResourcesComponent.class); no class def TestResourcesComponent(this is the interface which extends ApplicationComponent in another plugin) in 4.5. Works fine in 4.0.3.

Is there some other way to access objects in other plugins?

Comment actions Permalink

Hello, Robin!
You wrote on Thu, 19 Aug 2004 00:40:50 +0400 (MSD):

RB> In migrating to the new version we are finding it not possible to
RB> access objects in other plugins, e.g.:
RB> Application application =
RB> ApplicationManager.getApplication();
RB> TestResourcesComponent testResourcesComponent =
RB> (TestResourcesComponent)application.getComponent(
RB> TestResourcesComponent.class);

You can't get classes from another plugin since 2008 build, but i know that
plugins now is depended, and i thing, that you must set dependensies to
other plugin to perform such lookuping.

Alexey Efimov, Java Developer

Comment actions Permalink

Alexey, thanks, i found the depends element Is this what you meant? What are the attributes/elements of this element? It is not in the dtd.


Comment actions Permalink

depends only works in Irida (5.0) unfortunately.
The reason your pattern with app.getComponent(klass) does not work is that plugins has it's own classloader carefully separated from other plugins thus Smth.class expression give out different java.lang.Class instances in the context of the different plugins.
Summarizing you cannot provide API from the plugin to be used in another plugin. Of course you still can get the desired instance of the application component using one of the following hacks:
1. Application extends UserDataHolder which is somewhat like map and you're able to putUserData the instance there and getUserData in other plugin.
2. call getComponentInterfaces() and choose the class by its name and then call getComponent() with that class.

though I'm not sure you'll go far this way.

P.S. we're currently working on the way for the plugins to provide API to other plugins. The things should be much better in 5.0

Comment actions Permalink

Hi Maxim,

Will Application.getComponent work on Pallada, if i will have interface class in classpath of plugin?

Sure, Rober can't now use that, becouse his classloader can't see class of component of another plugin. Application.getComponent get class type as parameter, but not a string as class name. So Robert must have such interface in his classpath. The idea of this workaround, is make lib for his plugin with interface classes from his depended plugin. IDEA return him object implements interface, but i don't know will it work, or will throw LinkageError exception, becouse classes will loaded through different classloaders.

But it can be tested quickly by himself. Put interfaces jar files from depended plugin into lib of your plugin and try to get component by interface from this jar.



Please sign in to leave a comment.