Classloader problems [message #436473] |
Fri, 09 September 2005 01:39 |
Eclipse User |
|
|
|
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 |
|
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
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
|
|
|
Re: Classloader problems [message #436491 is a reply to message #436473] |
Fri, 09 September 2005 13:26 |
Eclipse User |
|
|
|
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);
|
|
|
Powered by
FUDForum. Page generated in 0.02867 seconds