| loading a Class object from an extension point [message #298274] |
Fri, 27 January 2006 10:57  |
Eclipse User |
|
|
|
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  |
Eclipse User |
|
|
|
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("<plugin-ID> ").loadClass("<name-of-class-visible-in-that-plugin> ");</small><br>
</blockquote>
In EMF we often create "descriptors" to avoid plugin loading as long as
possible:<br>
<blockquote><small> public static class PluginClassDescriptor <br>
{<br>
protected IConfigurationElement element;<br>
protected String attributeName;<br>
<br>
public PluginClassDescriptor(IConfigurationElement element, String
attributeName)<br>
{<br>
this.element = element;<br>
this.attributeName = attributeName;<br>
}<br>
<br>
public Object createInstance()<br>
{<br>
try<br>
{<br>
return element.createExecutableExtension(attributeName);<br>
}<br>
catch (CoreException e)<br>
{<br>
throw new WrappedException(e);<br>
}<br>
}<br>
}</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. 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. 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.
<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. 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? 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--
|
|
|
Powered by
FUDForum. Page generated in 0.03395 seconds