Skip to main content



      Home
Home » Eclipse Projects » Plugin Development Environment (PDE) » Extensions and Extension Points
Extensions and Extension Points [message #31173] Wed, 05 November 2008 05:57 Go to next message
Eclipse UserFriend
Hi everybody,

I have recently moved from Netbeans RCP over to Eclipse RCP and was
wondering if someone could fill me in on a small but rather important
piece of information.

My application consists of several plugins each offering an additional
service to the user. The service framework offered in Netbeans allowed
for this in that I created an interface and implementation for some
functionality then offered up the implementation as a service. When the
module was loaded by Netbeans, the implementation instance was loaded
into a registry and I could get at it by looking it up.

I understand that the closest approximations to this functionality in
Eclipse is either OSGi services or extensions / extension points. I have
opted for the latter.

Plugin A offers extension point detailing a class that implements a
known interface.

Plugin B
When something happens (button pressed for example), I wish to get the
implementation conforming to the known interface. Currently, this is
what I do.

String extPointID = "skeleton.domainObject";

try
{
IExtensionPoint extPoint =
Platform.getExtensionRegistry().getExtensionPoint(extPointID );
if (extPoint == null)
{
return null;
}

IExtension[] extensions = extPoint.getExtensions();
for (int i = 0; i < extensions.length; ++i)
{
IConfigurationElement[] configElements =
extensions[i].getConfigurationElements();
for (int j = 0; j < configElements.length; j++)
{
IConfigurationElement element = configElements[j];
IDomainObject domain = (IDomainObject)
element.createExecutableExtension("class");
return domain.getInstance();
}
}
}
catch (Exception ex)
{
// Do something useful with this
}

As you see, I use "IConfigurationElement.createExecutableExtension" to
first create a class conforming to that denoted by the tag "class". Once
I have this class, I throw it away in favour of a singleton instance
that may or may not already have been created by Plugin A.

This process is very useful for creating a brand new class conforming to
the extension point. However, is there a simpler way of finding already
instantiated classes, in the vein of services. Does eclipse have a
registry of classes already instantiated by virtue of the plugins activated?

Is OSGi services the preferred way to go with this maybe?

Any help much appreciated.

Regards

Paul
Re: Extensions and Extension Points [message #31590 is a reply to message #31173] Thu, 06 November 2008 14:41 Go to previous message
Eclipse UserFriend
Hi Paul,

If I understand what you are explaining - I think what you want to do is
to basically cache the singleton instance of "class" in plugin A when it
is initially created. This could be as simple as a Map or List of simple
proxy objects. Then, instead of creating an object every time with
..creteExecutableExtension, first look for it in your cache. If found,
return it, otherwise, create it (and cache it) from the extension registry
(if it is there).

You'll need to also listen to extension registry changes if you want to be
truly dynamic (i.e. support bundles being loaded and unloaded), but you
can be fairly dumb about this (at least initially). See the
org.eclipse.core.runtime.dynamichelpers.ExtensionTracker class for more
information. You can also refer to my EclipseCON presentation from last
year as there is a good bit of information in the notes as well
(http://www.eclipsecon.org/2008/?page=sub/&id=388).

Feel free to email me if you have any other questions - I may be
misinterpreting what you are trying to achieve.

Regards,
Mark.

On Wed, 05 Nov 2008 05:57:10 -0500, phantomjinx
<p.g.richardson@phantomjinx.co.uk> wrote:

> Hi everybody,
>
> I have recently moved from Netbeans RCP over to Eclipse RCP and was
> wondering if someone could fill me in on a small but rather important
> piece of information.
>
> My application consists of several plugins each offering an additional
> service to the user. The service framework offered in Netbeans allowed
> for this in that I created an interface and implementation for some
> functionality then offered up the implementation as a service. When the
> module was loaded by Netbeans, the implementation instance was loaded
> into a registry and I could get at it by looking it up.
>
> I understand that the closest approximations to this functionality in
> Eclipse is either OSGi services or extensions / extension points. I have
> opted for the latter.
>
> Plugin A offers extension point detailing a class that implements a
> known interface.
>
> Plugin B
> When something happens (button pressed for example), I wish to get the
> implementation conforming to the known interface. Currently, this is
> what I do.
>
> String extPointID = "skeleton.domainObject";
>
> try
> {
> IExtensionPoint extPoint =
> Platform.getExtensionRegistry().getExtensionPoint(extPointID );
> if (extPoint == null)
> {
> return null;
> }
>
> IExtension[] extensions = extPoint.getExtensions();
> for (int i = 0; i < extensions.length; ++i)
> {
> IConfigurationElement[] configElements =
> extensions[i].getConfigurationElements();
> for (int j = 0; j < configElements.length; j++)
> {
> IConfigurationElement element = configElements[j];
> IDomainObject domain = (IDomainObject)
> element.createExecutableExtension("class");
> return domain.getInstance();
> }
> }
> }
> catch (Exception ex)
> {
> // Do something useful with this
> }
>
> As you see, I use "IConfigurationElement.createExecutableExtension" to
> first create a class conforming to that denoted by the tag "class". Once
> I have this class, I throw it away in favour of a singleton instance
> that may or may not already have been created by Plugin A.
>
> This process is very useful for creating a brand new class conforming to
> the extension point. However, is there a simpler way of finding already
> instantiated classes, in the vein of services. Does eclipse have a
> registry of classes already instantiated by virtue of the plugins
> activated?
>
> Is OSGi services the preferred way to go with this maybe?
>
> Any help much appreciated.
>
> Regards
>
> Paul
Re: Extensions and Extension Points [message #584487 is a reply to message #31173] Thu, 06 November 2008 14:41 Go to previous message
Eclipse UserFriend
Hi Paul,

If I understand what you are explaining - I think what you want to do is
to basically cache the singleton instance of "class" in plugin A when it
is initially created. This could be as simple as a Map or List of simple
proxy objects. Then, instead of creating an object every time with
..creteExecutableExtension, first look for it in your cache. If found,
return it, otherwise, create it (and cache it) from the extension registry
(if it is there).

You'll need to also listen to extension registry changes if you want to be
truly dynamic (i.e. support bundles being loaded and unloaded), but you
can be fairly dumb about this (at least initially). See the
org.eclipse.core.runtime.dynamichelpers.ExtensionTracker class for more
information. You can also refer to my EclipseCON presentation from last
year as there is a good bit of information in the notes as well
(http://www.eclipsecon.org/2008/?page=sub/&id=388).

Feel free to email me if you have any other questions - I may be
misinterpreting what you are trying to achieve.

Regards,
Mark.

On Wed, 05 Nov 2008 05:57:10 -0500, phantomjinx
<p.g.richardson@phantomjinx.co.uk> wrote:

> Hi everybody,
>
> I have recently moved from Netbeans RCP over to Eclipse RCP and was
> wondering if someone could fill me in on a small but rather important
> piece of information.
>
> My application consists of several plugins each offering an additional
> service to the user. The service framework offered in Netbeans allowed
> for this in that I created an interface and implementation for some
> functionality then offered up the implementation as a service. When the
> module was loaded by Netbeans, the implementation instance was loaded
> into a registry and I could get at it by looking it up.
>
> I understand that the closest approximations to this functionality in
> Eclipse is either OSGi services or extensions / extension points. I have
> opted for the latter.
>
> Plugin A offers extension point detailing a class that implements a
> known interface.
>
> Plugin B
> When something happens (button pressed for example), I wish to get the
> implementation conforming to the known interface. Currently, this is
> what I do.
>
> String extPointID = "skeleton.domainObject";
>
> try
> {
> IExtensionPoint extPoint =
> Platform.getExtensionRegistry().getExtensionPoint(extPointID );
> if (extPoint == null)
> {
> return null;
> }
>
> IExtension[] extensions = extPoint.getExtensions();
> for (int i = 0; i < extensions.length; ++i)
> {
> IConfigurationElement[] configElements =
> extensions[i].getConfigurationElements();
> for (int j = 0; j < configElements.length; j++)
> {
> IConfigurationElement element = configElements[j];
> IDomainObject domain = (IDomainObject)
> element.createExecutableExtension("class");
> return domain.getInstance();
> }
> }
> }
> catch (Exception ex)
> {
> // Do something useful with this
> }
>
> As you see, I use "IConfigurationElement.createExecutableExtension" to
> first create a class conforming to that denoted by the tag "class". Once
> I have this class, I throw it away in favour of a singleton instance
> that may or may not already have been created by Plugin A.
>
> This process is very useful for creating a brand new class conforming to
> the extension point. However, is there a simpler way of finding already
> instantiated classes, in the vein of services. Does eclipse have a
> registry of classes already instantiated by virtue of the plugins
> activated?
>
> Is OSGi services the preferred way to go with this maybe?
>
> Any help much appreciated.
>
> Regards
>
> Paul
Previous Topic:"No ClassLoader" error, how to fix it ?
Next Topic:Run/Debug Perspective Preference setting for plugin
Goto Forum:
  


Current Time: Fri Apr 25 19:33:41 EDT 2025

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

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

Back to the top