Making an EMF-Application extensible / non-standard way to access plug-in executableExtensions [message #416625] |
Fri, 08 February 2008 14:10 |
Stefan Winkler Messages: 307 Registered: July 2009 Location: Germany |
Senior Member |
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body bgcolor="#ffffff" text="#000000">
Hi,<br>
<br>
What is the best way to get the package eInstance of an arbitrary
(user-provided) EMF package from an extension?<br>
<br>
I want to define an extension point where plug-ins can provide model
packages to work with in my application. (I need the package.eINSTANCE
because I have to register the package to CDO before I am working with
models based on the package).<br>
<br>
So my idea was to declare the extension point and use<br>
<br>
<title></title>
<style type="text/css">
<!--code { font-family: Courier New, Courier; font-size: 10pt; margin: 0px; }-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!-- ======================================================== -->
<!-- = Java Sourcecode to HTML automatically converted code = --><!-- = Java2Html Converter 5.0 [2006-02-26] by Markus Gebhard markus@jave.de = -->
<!-- = Further information: http://www.java2html.de = -->
<div class="java" align="left">
<title></title>
<style type="text/css">
<!--code { font-family: Courier New, Courier; font-size: 10pt; margin: 0px; }-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!-- ======================================================== --><!-- = Java Sourcecode to HTML automatically converted code = --><!-- = Java2Html Converter 5.0 [2006-02-26] by Markus Gebhard markus@jave.de = -->
<!-- = Further information: http://www.java2html.de = -->
<div class="java" align="left">
<table bgcolor="#ffffff" border="0" cellpadding="3" cellspacing="0">
<tbody>
<tr>
<!-- start source code --> <td align="left" nowrap="nowrap"
valign="top"> <code><font color="#ffffff"> </font><font
color="#000000">IExtensionRegistry pr = Platform.getExtensionRegistry </font><font
color="#000000">()</font><font color="#000000">;</font><br>
<font color="#ffffff"> </font><font color="#000000">IExtensionPoint pt = pr.getExtensionPoint </font><font
color="#000000">(</font><br>
<font color="#ffffff"> </font><font color="#000000">EXTENSION_NS,</font><br>
<font color="#ffffff"> </font><font color="#000000">EXTENSION_NAME_CDOPACKAGE</font><font
color="#000000">)</font><font color="#000000">;</font><br>
<font color="#ffffff"> </font><font color="#000000">IExtension</font><font
color="#000000">[] </font><font color="#000000">extensions = pt.getExtensions</font><font
color="#000000">()</font><font color="#000000">;</font><br>
<font color="#ffffff"></font><br>
<font color="#ffffff"> </font><font color="#7f0055"><b>for</b></font><font
color="#000000">(</font><font color="#000000">IExtension ext: extensions</font><font
color="#000000">) {</font><br>
<font color="#ffffff"> </font><font color="#000000">IConfigurationElement</font><font
color="#000000">[] </font><font color="#000000">confElements = ext.getConfigurationElements </font><font
color="#000000">()</font><font color="#000000">;</font><br>
<font color="#ffffff"> </font><font color="#7f0055"><b>for </b></font><font
color="#000000">(</font><font color="#000000">IConfigurationElement element : confElements </font><font
color="#000000">) {</font><br>
<font color="#ffffff"> </font><font color="#3f7f5f"> // -> package = element.createExecutableExtension (EPACKAGE_NAME); </font><br>
<font color="#ffffff"> </font><font color="#000000">cdoPackageRegistry.putEPackage</font><font
color="#000000">(</font><font color="#7f0055"><b>package</b></font><font
color="#000000">)</font><font color="#000000">;</font><br>
<font color="#ffffff"> </font><font color="#000000">}</font><br>
<font color="#ffffff"> </font><font color="#000000">}</font></code>
</td>
<!-- end source code --> </tr>
</tbody>
</table>
</div>
<!-- = END of automatically generated HTML code = -->
<!-- ======================================================== --></div>
<!-- = END of automatically generated HTML code = -->
<!-- ======================================================== --><br>
Where the property referred to by EPACKAGE_NAME denotes the contributed
package.<br>
But, naturally, this won't work, as what I want is not a new instance
of a package but in fact <i><b>the</b></i> package.eINSTANCE. <br>
Has anyone done something like this somewhere before?<br>
<br>
I guess, I would have to get access to eINSTANCE myself using
Class.forName and reflection. But I am not sure, as I haven't done this
before inside Eclipse and I am not sure wheter it is so simple to
bypass the internal Eclipse mechanisms (plugin-activation, classloading
etc).<br>
<br>
The alternative would of course be to create a provider class for the
packages which could be used as in:<br>
<code><font color="#7f0055"><b></b></font></code>
<title></title>
<style type="text/css">
<!--code { font-family: Courier New, Courier; font-size: 10pt; margin: 0px; }-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!-- ======================================================== -->
<!-- = Java Sourcecode to HTML automatically converted code = --><!-- = Java2Html Converter 5.0 [2006-02-26] by Markus Gebhard markus@jave.de = -->
<!-- = Further information: http://www.java2html.de = -->
<div class="java" align="left">
<table bgcolor="#ffffff" border="0" cellpadding="3" cellspacing="0">
<tbody>
<tr>
<!-- start source code --> <td align="left" nowrap="nowrap"
valign="top"><code><font color="#7f0055"><b> // ...<br>
for</b></font><font color="#000000">(</font><font color="#000000">IExtension ext: extensions</font><font
color="#000000">) {</font><br>
<font color="#ffffff"> </font><font color="#000000">IConfigurationElement</font><font
color="#000000">[] </font><font color="#000000">confElements = ext.getConfigurationElements </font><font
color="#000000">()</font><font color="#000000">;</font><br>
<font color="#ffffff"> </font><font color="#7f0055"><b>for </b></font><font
color="#000000">(</font><font color="#000000">IConfigurationElement element : confElements </font><font
color="#000000">) {</font><br>
<font color="#ffffff"> </font><font color="#000000"> IPackageProvider packageProvider = element.createExecutab leExtension </font><font
color="#000000">(</font><font color="#000000">EPACKAGE_NAME</font><font
color="#000000">)</font><font color="#000000">;</font><br>
<font color="#ffffff"> </font><font color="#000000">packageRegistry.putEPackage</font><font
color="#000000">(</font><font color="#000000">packageProvider.getPackageInstance</font> <font
color="#000000">())</font><font color="#000000">;</font><br>
<font color="#ffffff"> </font><font color="#000000">}</font><br>
<font color="#ffffff"> </font><font color="#000000">}</font></code>
</td>
<!-- end source code --> </tr>
</tbody>
</table>
</div>
<!-- = END of automatically generated HTML code = -->
<!-- ======================================================== --><br>
But that way I need to create an additional class in the otherwise
completely generated EMF model package, so if there's an alternative
which eliminates the need for such a class, I would very much like to
know.<br>
<br>
I hope my question was clear enough - I don't really know where to post
the question, because this is both a platform-thing and an EMF-thing,
so sorry for crossposting...<br>
<br>
Cheers,<br>
Stefan<br>
</body>
</html>
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02596 seconds