Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » loading a Class object from an extension point
loading a Class object from an extension point [message #298274] Fri, 27 January 2006 10:57 Go to next message
Eclipse UserFriend
We have an extension for which we'd like to allow an extension point to
give us the name of a class in their plugin, and we'd get the instance
of java.lang.Class corresponding to that class while we are processing
their extension point. There doesn't seem to be a way to do this, directly.

Here's what we're doing today as a workaround.

In our extension, we require that the name of a factory class be passed
in as one of the extension point element attributes. We then use
IConfigurationElement.createExecutableExtension() to have the factory
created. That factory is required to implement a method which basically
just does a Class.forName(). Quite yucky, because it requires our users
to create this stupid class which just does a Class.forName(); and
requires an additional attribute in the extension point.

I guess what I'd like to see is a peer of createExecutableExtension()
called, say, loadClass() that would just load the class and return the
instance of java.lang.Class. Which is clearly part of what
createExecutableExtension() is already doing today.

I would be willing to add some bundle-y goop to my plugin that defines
the extension, to get this to work, but I don't want to force my
downstream uses (folks that use our extension via extension points) to
HAVE to use bundle-y goop.

Any other alternatives, since our workaround is rather ... untasty? Or
shall I make a new feature request via Bugzilla, or is the issue moot
because of other reasons (WE'LL NEVER EVER DO THIS BECAUSE OF x, y, z!)

--
Patrick Mueller - pmuellr@yahoo.com

Oblique Strategies: A very small object - It's centre
Re: loading a Class object from an extension point [message #298275 is a reply to message #298274] Fri, 27 January 2006 11:11 Go to previous message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

This is a multi-part message in MIME format.
--------------060906030906020405000406
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Patrick,

This approach is what's happening under the covers:

Platform.getBundle("<plugin-ID>").loadClass("<name-of-class-visible-in-that-plugin >");

In EMF we often create "descriptors" to avoid plugin loading as long as
possible:

public static class PluginClassDescriptor
{
protected IConfigurationElement element;
protected String attributeName;

public PluginClassDescriptor(IConfigurationElement element,
String attributeName)
{
this.element = element;
this.attributeName = attributeName;
}

public Object createInstance()
{
try
{
return element.createExecutableExtension(attributeName);
}
catch (CoreException e)
{
throw new WrappedException(e);
}
}
}


Patrick Mueller wrote:

> We have an extension for which we'd like to allow an extension point
> to give us the name of a class in their plugin, and we'd get the
> instance of java.lang.Class corresponding to that class while we are
> processing their extension point. There doesn't seem to be a way to
> do this, directly.
>
> Here's what we're doing today as a workaround.
>
> In our extension, we require that the name of a factory class be
> passed in as one of the extension point element attributes. We then
> use IConfigurationElement.createExecutableExtension() to have the
> factory created. That factory is required to implement a method which
> basically just does a Class.forName(). Quite yucky, because it
> requires our users to create this stupid class which just does a
> Class.forName(); and requires an additional attribute in the extension
> point.
>
> I guess what I'd like to see is a peer of createExecutableExtension()
> called, say, loadClass() that would just load the class and return the
> instance of java.lang.Class. Which is clearly part of what
> createExecutableExtension() is already doing today.
>
> I would be willing to add some bundle-y goop to my plugin that defines
> the extension, to get this to work, but I don't want to force my
> downstream uses (folks that use our extension via extension points) to
> HAVE to use bundle-y goop.
>
> Any other alternatives, since our workaround is rather ... untasty?
> Or shall I make a new feature request via Bugzilla, or is the issue
> moot because of other reasons (WE'LL NEVER EVER DO THIS BECAUSE OF x,
> y, z!)
>


--------------060906030906020405000406
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Patrick,<br>
<br>
This approach is what's happening under the covers:<br>
<blockquote><small>Platform.getBundle("&lt;plugin-ID&gt; ").loadClass("&lt;name-of-class-visible-in-that-plugin&gt; ");</small><br>
</blockquote>
In EMF we often create "descriptors" to avoid plugin loading as long as
possible:<br>
<blockquote><small>&nbsp; public static class PluginClassDescriptor <br>
&nbsp; {<br>
&nbsp;&nbsp;&nbsp; protected IConfigurationElement element;<br>
&nbsp;&nbsp;&nbsp; protected String attributeName;<br>
<br>
&nbsp;&nbsp;&nbsp; public PluginClassDescriptor(IConfigurationElement element, String
attributeName)<br>
&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.element = element;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.attributeName = attributeName;<br>
&nbsp;&nbsp;&nbsp; }<br>
<br>
&nbsp;&nbsp;&nbsp; public Object createInstance()<br>
&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; return element.createExecutableExtension(attributeName);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; catch (CoreException e)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; throw new WrappedException(e);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; }<br>
&nbsp; }</small><br>
</blockquote>
<br>
Patrick Mueller wrote:
<blockquote cite="middrdfst$9bi$1@utils.eclipse.org" type="cite">We
have an extension for which we'd like to allow an extension point to
give us the name of a class in their plugin, and we'd get the instance
of java.lang.Class corresponding to that class while we are processing
their extension point.&nbsp; There doesn't seem to be a way to do this,
directly.
<br>
<br>
Here's what we're doing today as a workaround.
<br>
<br>
In our extension, we require that the name of a factory class be passed
in as one of the extension point element attributes.&nbsp; We then use
IConfigurationElement.createExecutableExtension() to have the factory
created.&nbsp; That factory is required to implement a method which
basically just does a Class.forName().&nbsp; Quite yucky, because it
requires our users to create this stupid class which just does a
Class.forName(); and requires an additional attribute in the extension
point.
<br>
<br>
I guess what I'd like to see is a peer of createExecutableExtension()
called, say, loadClass() that would just load the class and return the
instance of java.lang.Class.&nbsp; Which is clearly part of what
createExecutableExtension() is already doing today.
<br>
<br>
I would be willing to add some bundle-y goop to my plugin that defines
the extension, to get this to work, but I don't want to force my
downstream uses (folks that use our extension via extension points) to
HAVE to use bundle-y goop.
<br>
<br>
Any other alternatives, since our workaround is rather ... untasty?&nbsp; Or
shall I make a new feature request via Bugzilla, or is the issue moot
because of other reasons (WE'LL NEVER EVER DO THIS BECAUSE OF x, y, z!)
<br>
<br>
</blockquote>
<br>
</body>
</html>

--------------060906030906020405000406--
Previous Topic:Derby Eclipse-plugin that is useful by other plugins.
Next Topic:eclipse update archive site
Goto Forum:
  


Current Time: Thu Nov 06 10:45:46 EST 2025

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

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

Back to the top