loading a plugin dynamically [message #157247] |
Tue, 04 May 2004 20:40 |
Neil Goldsmith Messages: 68 Registered: July 2009 |
Member |
|
|
Within our application, we have a basic core class called treeItem that
lives in our core plugin that any plugin can extend. Another plugin might
come along and extend it to become something trivial like
specializedTreeItem. When you save this, the code that lives in our core
plugin will save all the treeitems to an XML File (giving each derived
treeItem a chance to write its own custom XML data as well).
When we load back this XML file, the core plugin won't understand how to
load derived tree items, so it must defer to the plugin that created it.
However, the core plugin has no reference to these other plugins because
it's wide open who can come along and derive a new tree item, the core
doesn't care and shouldn't care.
When we pull the XML data out of the file, we do something like:
Class itemClass = Class.forName(className);
object = itemClass.newInstance();
Using the className found in the XML data. Considering the className may
be in a different plugin, this will fail if the class isn't found in the
core. It looks like we will also need to keep track of the plugin within
the XML data, but with that info, how do we code the core to load the
other plugin and instantiate the class so that we can tell it to load its
XML data?
thanks
|
|
|
Re: loading a plugin dynamically [message #157289 is a reply to message #157247] |
Wed, 05 May 2004 09:11 |
Eclipse User |
|
|
|
Originally posted by: thomas_maeder.ch.ibm.com
You'll have to define an extension point in your core plugin. I would
allow the "derived" plugins to register factories for certain class
names. For example, each factory extension would have a "class"
attribute giving the class of items it's responsible for creating. Once
you have located the proper factory extension for a treeItem class, you
can instantiate it (see
IConfigurationElement.createExecutableExtension()) and use it to create
your tree items.
Thomas
N. G. wrote:
> Within our application, we have a basic core class called treeItem that
> lives in our core plugin that any plugin can extend. Another plugin might
> come along and extend it to become something trivial like
> specializedTreeItem. When you save this, the code that lives in our core
> plugin will save all the treeitems to an XML File (giving each derived
> treeItem a chance to write its own custom XML data as well).
>
> When we load back this XML file, the core plugin won't understand how to
> load derived tree items, so it must defer to the plugin that created it.
> However, the core plugin has no reference to these other plugins because
> it's wide open who can come along and derive a new tree item, the core
> doesn't care and shouldn't care.
>
> When we pull the XML data out of the file, we do something like:
> Class itemClass = Class.forName(className);
> object = itemClass.newInstance();
>
> Using the className found in the XML data. Considering the className may
> be in a different plugin, this will fail if the class isn't found in the
> core. It looks like we will also need to keep track of the plugin within
> the XML data, but with that info, how do we code the core to load the
> other plugin and instantiate the class so that we can tell it to load its
> XML data?
>
> thanks
>
|
|
|
Powered by
FUDForum. Page generated in 0.02270 seconds