Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Classloader problems
Classloader problems [message #436473] Fri, 09 September 2005 01:39 Go to next message
Eclipse UserFriend
Originally posted by: jclark.21csi.com

I'm having an issue with using Reflection and Classloaders. Let me outline
the situation first.

I have a plugin that contains some base application architecture. Part of
this architecture is a class, lets call it Computer. We also have a base
interface called Part. You can make the call Computer.add(Part);

So we have

class Computer{
...
void add(Part part);

}


There is also an object called PartCreator

class PartCreator{

...
Part createPart(String classString);

}


where classString is the full source path of the class. PartCreator uses
Reflection to create the Part object and return it.


Now, I create another plugin the depends on the base Architecture Plugin.

In my new plugin, I create a Part, say,

package com.newplugin.parts;

class VideoCard implements Part{

public VideoCard();

...
}

Now, if I call PartCreator.createPart(com.newplugin.parts.VideoCard);

reflection gives me a ClassNotFoundEx.

Is there a way to resolve this issue so Reflection is able to create the
class?

Thanks,

Jason
Re: Classloader problems [message #436483 is a reply to message #436473] Fri, 09 September 2005 11:59 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Jason Clark wrote:
> [... snip ...]
> Now, I create another plugin the depends on the base Architecture Plugin.
>
> In my new plugin, I create a Part, say,
>
> package com.newplugin.parts;
>
> class VideoCard implements Part{
>
> public VideoCard();
> ...
> }
>
> Now, if I call PartCreator.createPart(com.newplugin.parts.VideoCard);
>
> reflection gives me a ClassNotFoundEx.
>
> Is there a way to resolve this issue so Reflection is able to create the
> class?

I think the short answer is no ... your architecture plugin can't see
classes from your dependant plugin.

I know that when eclipse core plugins create classes from other plugins
(executable extensions), the core plugin asks the other plugin to
actually load the requested class because it can't.


You could fake it out if your really wanted to ...

1. your architecture class holds a registry of "config" objects

2. your dependant plugin contributes a config object that can load your
dependant plugin classes

3. then you can ask your architecture for the classes that you want,
which would be loaded through the config object which can from the same
plugin that defines the class you want ... see why it's not done very
often :-)


Or in eclipse, you can have your architecture plugin create an extension
point, and your dependant plugin can contribute it's classes that way
(use the eclipse core mechanisms).


Later,
PW


Re: Classloader problems [message #436491 is a reply to message #436473] Fri, 09 September 2005 13:26 Go to previous message
Eclipse UserFriend
Originally posted by: alr.agelid.com

Hi,
I would suggest you to add an extension point called "part" for instance
in your architecture plugin, such extension may contains a class name for
the tag ATT_CLASS.

To add an extension point use the wizard in your plugin.
Other plugins, then should have the extension point created in the wizard
list.

some code snipet, to use the extension point in your architecture plugin:

// retrieved all extensions registered for the 'extensionPointID'
IExtension[] extensions = Platform.getExtensionRegistry()
.getExtensionPoint(extensionPointID)
.getExtensions();
...
// parse them to retain only some...(based on attribute's value for
instance)
IConfigurationElement[] configElements = extensions[i]
.getConfigurationElements();
...
// parse them to retain only some...(case of tree structure for instance)
configElem = configElements [k];
// create the instance through the configElement.
Object instance = configElem.createExecutableExtension(ATT_CLASS);
Previous Topic:Vote for UTF-8 as the default character set for all new text files
Next Topic:How to set caretPosition in a Text on Linux
Goto Forum:
  


Current Time: Mon Dec 09 03:56:17 GMT 2024

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

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

Back to the top