Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » instantiating a class from another plugin
instantiating a class from another plugin [message #307756] Wed, 30 August 2006 17:51 Go to next message
Eclipse UserFriend
Originally posted by: vik_ram.hotmail.com

Hi,

Is it possible to instantiate a class from another plugin without
defining a dependency on that plugin.

The way our product is bundled is that we may ship plugin A alone OR
plugin A and plugin B. plugin B depends on plugin A but plugin A can run
independently. We want to define a documentProvider common to both
plugins - so we define it in plugin A. The problem is that the
documentProvider class should be able to invoke classes in both A and B
depending on certain criteria ( strategy pattern ) . But as it is
defined in plugin A , it cannot instantiate classes in plugin B.

Thanks,
Vikram
Re: instantiating a class from another plugin [message #307758 is a reply to message #307756] Wed, 30 August 2006 18:06 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

That's what extensions are for.

See:

http://www.eclipse.org/articles/Article-Plug-in-architecture /plugin_architecture.html#3.


--
Thanks,
Rich Kulp
Re: instantiating a class from another plugin [message #307759 is a reply to message #307756] Wed, 30 August 2006 18:08 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

vikram wrote:
> Hi,
>
> Is it possible to instantiate a class from another plugin without
> defining a dependency on that plugin.
>
> The way our product is bundled is that we may ship plugin A alone OR
> plugin A and plugin B. plugin B depends on plugin A but plugin A can run
> independently. We want to define a documentProvider common to both
> plugins - so we define it in plugin A. The problem is that the
> documentProvider class should be able to invoke classes in both A and B
> depending on certain criteria ( strategy pattern ) . But as it is
> defined in plugin A , it cannot instantiate classes in plugin B.

That is the most common use for the extension points/extensions.

ex: plugin A creates a "document provider" extension point and the
interface class, com.example.text.IDocumentProvider. If it also comes
with a document provider, plugin A implements the extension as well:

<documentProvider name="MyDocs"
class="com.example.a.text.MyDocsProvider"/>

Then plugin B creates the extension for its document provider:

<documentProvider name="RedDocs"
class="com.example.b.text.RedDocsProvider"/>

In plugin A, your extension point processing code walks through
IConfigurationElements ... you can use
createExecutableExtension("class") to instantiate a document provider,
and never have to depend on its plugin.

Later,
PW


Re: instantiating a class from another plugin [message #307760 is a reply to message #307756] Wed, 30 August 2006 18:30 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Vikram,

I agree with Rich's good advice.

But here's a way you could load classes without using an extension point.

Bundle xsdPlugin = Platform.getBundle("org.eclipse.xsd");
if (xsdPlugin != null)
{
try
{
Class theGeneratorClass =
xsdPlugin.loadClass
("org.eclipse.xsd.ecore.Ecore" + type + "SchemaBuilder");


vikram wrote:

> Hi,
>
> Is it possible to instantiate a class from another plugin without
> defining a dependency on that plugin.
>
> The way our product is bundled is that we may ship plugin A alone OR
> plugin A and plugin B. plugin B depends on plugin A but plugin A can
> run independently. We want to define a documentProvider common to
> both plugins - so we define it in plugin A. The problem is that the
> documentProvider class should be able to invoke classes in both A and
> B depending on certain criteria ( strategy pattern ) . But as it is
> defined in plugin A , it cannot instantiate classes in plugin B.
>
> Thanks,
> Vikram
Re: instantiating a class from another plugin [message #307761 is a reply to message #307760] Wed, 30 August 2006 19:05 Go to previous message
Eclipse UserFriend
Originally posted by: vik_ram.hotmail.com

Rich, Paul and Ed,
Thanks for the responses.






Ed Merks wrote:

> Vikram,
>
> I agree with Rich's good advice.
> But here's a way you could load classes without using an extension point.
>
> Bundle xsdPlugin = Platform.getBundle("org.eclipse.xsd");
> if (xsdPlugin != null)
> {
> try
> {
> Class theGeneratorClass =
> xsdPlugin.loadClass
> ("org.eclipse.xsd.ecore.Ecore" + type + "SchemaBuilder");
>
>
> vikram wrote:
>
>> Hi,
>>
>> Is it possible to instantiate a class from another plugin without
>> defining a dependency on that plugin.
>>
>> The way our product is bundled is that we may ship plugin A alone OR
>> plugin A and plugin B. plugin B depends on plugin A but plugin A can
>> run independently. We want to define a documentProvider common to
>> both plugins - so we define it in plugin A. The problem is that the
>> documentProvider class should be able to invoke classes in both A and
>> B depending on certain criteria ( strategy pattern ) . But as it is
>> defined in plugin A , it cannot instantiate classes in plugin B.
>>
>> Thanks,
>> Vikram
>
>
Previous Topic:Common Navigator Framework
Next Topic:Monitor build status
Goto Forum:
  


Current Time: Sat Oct 05 07:20:51 GMT 2024

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

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

Back to the top