Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Problems loading classes from extending Plugins
Problems loading classes from extending Plugins [message #107960] Thu, 07 August 2003 13:50 Go to next message
Florian Georg is currently offline Florian GeorgFriend
Messages: 34
Registered: July 2009
Member
Hello,

I've got the following problem :

My Plugin "BaseUIPlugin" defines an extension Point "custom.ui.point".

The Plugins "JavaUIPlugin" and "CobolUIPlugin" contribute to that point
(that is, they specify different implementation of some UI-class) and
both depend on "BasePlugin", e.g.:
=======
<extension point="custom.ui.point">
<UI class="my.custom.java.ui.JavaUIClass" />
</extension>
=======

In my "MainPlugin", I lookup all extensions to the extension point in
the PluginRegistry, and try to instantiate the classes.
That isn't that easy, because the classes are located in other Plugins,
which means they are not visible to the ClassLoader of "MainPlugin".

So first,I get the contributing Plugins, take it's classloader and try
to "loadClass (className)"
=======
IExtension[] extensions =
Platform.getPluginRegistry().getExtensionPoint("custom.ui.point ").getExtensions();
//
for (int i = 0; i < extensions.length;i++)
{
String ID =
extensions[i].getDeclaringPluginDescriptor().getUniqueIdenti fier();
Classloader loader =
Platform.getPluginRegistry().getPluginDescriptor(ID).getPlug inClassLoader();

MyUIInterface interface = (MyUIInterface)loader.loadClass
("....").newInstance();

....
}
=======



That seemed works fine, since the ClassLoaders of the
"Java-/CobolUIPlugin" *can* load their classes.

But now I get some strange errors :
After instantiation of the UI-class, my "Main" Plugin seems to be
confused : it can't find e.g. SWT classes anymore and other strange
things....

What happened here ?
Is the above the right way to instantiate classes provided by my
extensions ?
Did I miss something ?


Any help would be greatly appreciated.

greetings
Florian
Re: Problems loading classes from extending Plugins [message #108033 is a reply to message #107960] Thu, 07 August 2003 14:34 Go to previous messageGo to next message
Jeff Hunter is currently offline Jeff HunterFriend
Messages: 73
Registered: July 2009
Member
Florian Georg wrote:

<snip>

> In my "MainPlugin", I lookup all extensions to the extension point in
> the PluginRegistry, and try to instantiate the classes.
> That isn't that easy, because the classes are located in other Plugins,
> which means they are not visible to the ClassLoader of "MainPlugin".
>
> So first,I get the contributing Plugins, take it's classloader and try
> to "loadClass (className)"
> =======
> IExtension[] extensions =
> Platform.getPluginRegistry().getExtensionPoint("custom.ui.point ").getExtensions();
>
> //
> for (int i = 0; i < extensions.length;i++)
> {
> String ID =
> extensions[i].getDeclaringPluginDescriptor().getUniqueIdenti fier();
> Classloader loader =
> Platform.getPluginRegistry().getPluginDescriptor(ID).getPlug inClassLoader();
>
>
> MyUIInterface interface = (MyUIInterface)loader.loadClass
> ("....").newInstance();
>
> ...
> }

After you call IExtensionPoint.getExtensions(), you need to iterate over
the IExtensions and call getConfigurationElements() for each one. Then
you can use IConfigurationElement.createExecutableExtension() to
instantiate the class.

There is a good example of this in the 6/16/03 draft of the Gamma and
Beck Eclipse book. Look at the bottom of page 55:

http://groups.yahoo.com/group/contributingtoeclipse/files/

Jeff
Re: Re: Problems loading classes from extending Plugins [message #108201 is a reply to message #108033] Thu, 07 August 2003 16:11 Go to previous messageGo to next message
Florian Georg is currently offline Florian GeorgFriend
Messages: 34
Registered: July 2009
Member
Hello Jeff,
Thanks for your quick help.

I now instantiate my classes via "createExecutableExtension()" correctly.
But the problem remains the same :-(
I think it has something to do with the delegating ClassLoader or
something, because my object looks fine until I try to call some methods
on it :
====
MyObject object = (MyObject) element.createExecutableExtension("class");
// works fine !

object.createUI (composite, some-other-params);
// java.lang.NoClassDefFoundError: org/eclipse/swt/widgets/Control
====

The stacktrace shows me no additional information and the debugger steps
into some mysterious DelegatingClassloader, which seems to be unable to
find SWT classes...

Any ideas ?

thanks in advance
Florian

Jeff Hunter wrote:
> Florian Georg wrote:
>
> <snip>
>
>> In my "MainPlugin", I lookup all extensions to the extension point in
>> the PluginRegistry, and try to instantiate the classes.
>> That isn't that easy, because the classes are located in other
>> Plugins, which means they are not visible to the ClassLoader of
>> "MainPlugin".
>>
>> So first,I get the contributing Plugins, take it's classloader and try
>> to "loadClass (className)"
>> =======
>> IExtension[] extensions =
>> Platform.getPluginRegistry().getExtensionPoint("custom.ui.point ").getExtensions();
>>
>> //
>> for (int i = 0; i < extensions.length;i++)
>> {
>> String ID =
>> extensions[i].getDeclaringPluginDescriptor().getUniqueIdenti fier();
>> Classloader loader =
>> Platform.getPluginRegistry().getPluginDescriptor(ID).getPlug inClassLoader();
>>
>>
>> MyUIInterface interface = (MyUIInterface)loader.loadClass
>> ("....").newInstance();
>>
>> ...
>> }
>
>
> After you call IExtensionPoint.getExtensions(), you need to iterate over
> the IExtensions and call getConfigurationElements() for each one. Then
> you can use IConfigurationElement.createExecutableExtension() to
> instantiate the class.
>
> There is a good example of this in the 6/16/03 draft of the Gamma and
> Beck Eclipse book. Look at the bottom of page 55:
>
> http://groups.yahoo.com/group/contributingtoeclipse/files/
>
> Jeff
>
Re: Problems loading classes from extending Plugins [message #108381 is a reply to message #108201] Thu, 07 August 2003 20:53 Go to previous message
Eclipse UserFriend
Originally posted by: richkulp.NOSPAM.us.ibm.com

Does your plugin where where JavaUIClass is defined and your BasePlugin
have the org.eclipse.ui plugin as a required plugin?

Rich
Previous Topic:External strings in plugin.xml
Next Topic:Combo box on the Workbench toolbar
Goto Forum:
  


Current Time: Fri Aug 16 16:00:45 GMT 2024

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

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

Back to the top