Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » Making an EMF-Application extensible / non-standard way to access plug-in executableExtensions
Making an EMF-Application extensible / non-standard way to access plug-in executableExtensions [message #111912] Fri, 08 February 2008 14:10 Go to next message
Stefan Winkler is currently offline Stefan WinklerFriend
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"> // -&gt; 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>
Re: Making an EMF-Application extensible / non-standard way to access plug-in ex [message #111915 is a reply to message #111912] Fri, 08 February 2008 15:24 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
Hi Stefan,

Can it be the case that you're not aware of the global
EPackage.Registry.eINSTANCE of EMF? It already solves the problem of
accessing singleton EPackage instances that are contributed by plugins via
the generated_package extension point.

In the context of CDO you might face another challenge: How to discover
which of the contributed EPackages has been generated for CDO? I suggest
that you dig into
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.emf/org .eclipse.emf.cdo/plugins/org.eclipse.emf.cdo/src/org/eclipse /emf/cdo/util/CDOUtil.java?revision=1.35&root=Modeling_P roject&view=markup
which might best give yoiu a clue and possibly already the solution you're
looking for.

Enjoy your weekend
/Eike


Re: Making an EMF-Application extensible / non-standard way to access plug-in ex [message #111916 is a reply to message #111915] Fri, 08 February 2008 15:28 Go to previous message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
Forgot to point you to this method in CDOUtil:

/**
* Can only be used with Eclipse running!
*/
public static synchronized Map<String, CDOPackageType> getPackageTypes()
{
if (packageTypes == null)
{
packageTypes = analyzePackageTypes();
}

return packageTypes;
}

private static HashMap<String, CDOPackageType> analyzePackageTypes()
{
...


The returned Map contains all package URIs of the global EPackage.Registry
as keys and with values that indicate the CDO relevant type of the package.

Cheers
/Eike


Re: Making an EMF-Application extensible / non-standard way to access plug-in ex [message #615465 is a reply to message #111912] Fri, 08 February 2008 15:24 Go to previous message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
Hi Stefan,

Can it be the case that you're not aware of the global
EPackage.Registry.eINSTANCE of EMF? It already solves the problem of
accessing singleton EPackage instances that are contributed by plugins via
the generated_package extension point.

In the context of CDO you might face another challenge: How to discover
which of the contributed EPackages has been generated for CDO? I suggest
that you dig into
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.emf/org .eclipse.emf.cdo/plugins/org.eclipse.emf.cdo/src/org/eclipse /emf/cdo/util/CDOUtil.java?revision=1.35&root=Modeling_P roject&view=markup
which might best give yoiu a clue and possibly already the solution you're
looking for.

Enjoy your weekend
/Eike


Re: Making an EMF-Application extensible / non-standard way to access plug-in ex [message #615466 is a reply to message #111915] Fri, 08 February 2008 15:28 Go to previous message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
Forgot to point you to this method in CDOUtil:

/**
* Can only be used with Eclipse running!
*/
public static synchronized Map<String, CDOPackageType> getPackageTypes()
{
if (packageTypes == null)
{
packageTypes = analyzePackageTypes();
}

return packageTypes;
}

private static HashMap<String, CDOPackageType> analyzePackageTypes()
{
...


The returned Map contains all package URIs of the global EPackage.Registry
as keys and with values that indicate the CDO relevant type of the package.

Cheers
/Eike


Previous Topic:[Temporality][CDO][Teneo]Delegating EStore and Root extends class
Next Topic:[Teneo] Exploring... Can I use teneo mapped EMF with legacy EnitityManagerCode ?
Goto Forum:
  


Current Time: Thu Apr 25 02:13:02 GMT 2024

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

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

Back to the top