Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » accessing a genmodel programmatically
accessing a genmodel programmatically [message #643685] Tue, 07 December 2010 20:22 Go to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
Hi

I'm loading an EPackage programmatically specifying the ecore file,
e.g., "mypatch/to/my.ecore". Now, I'd like to access the corresponding
genmodel file.

Is there a direct way to achieve this? Let's say that I know that the
genmodel is always in the same directory of the ecore file, but how can
I retrieve such information once I have the EPackage (suppose I don't
have the information about the ecore package anymore)?

Besides that, can I simply load the genmodel as a standard resource or
should I use a specific method?

many thanks in advance
Lorenzo

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
ICQ# lbetto, 16080134 (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
http://www.myspace.com/supertrouperabba
BLOGS: http://tronprog.blogspot.com http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net


Re: accessing a genmodel programmatically [message #643713 is a reply to message #643685] Tue, 07 December 2010 23:32 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------080702090704080401040606
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Lorenzo,

Comments below.


Lorenzo Bettini wrote:
> Hi
>
> I'm loading an EPackage programmatically specifying the ecore file,
> e.g., "mypatch/to/my.ecore".
Using an absolute URI hopefully...
> Now, I'd like to access the corresponding genmodel file.

From EcorePlugin:

/**
* Returns a map from {@link EPackage#getNsURI() package namespace
URI} (represented as a String)
* to the location of the GenModel containing a GenPackage for the
package (represented as a {@link URI URI}).
* @return a map from package namespace to GenModel location.
*/
public static Map<String, URI> getEPackageNsURIToGenModelLocationMap()


>
> Is there a direct way to achieve this? Let's say that I know that the
> genmodel is always in the same directory of the ecore file, but how
> can I retrieve such information once I have the EPackage (suppose I
> don't have the information about the ecore package anymore)?
Assuming it's registered, all you need to know is the nsURI of the package.
>
> Besides that, can I simply load the genmodel as a standard resource or
> should I use a specific method?
The right resource factory should be registered to load it normally.
Look closely at what the GenModelEditor does if you really want to use
it to generate something...
>
> many thanks in advance
> Lorenzo
>

--------------080702090704080401040606
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">
Lorenzo,<br>
<br>
Comments below.<br>
<br>
<br>
Lorenzo Bettini wrote:
<blockquote cite="mid:idm4pe$uuc$1@news.eclipse.org" type="cite">Hi
<br>
<br>
I'm loading an EPackage programmatically specifying the ecore file,
e.g., "mypatch/to/my.ecore".&nbsp; </blockquote>
Using an absolute URI hopefully...<br>
<blockquote cite="mid:idm4pe$uuc$1@news.eclipse.org" type="cite">Now,
I'd like to access the corresponding genmodel file.
<br>
</blockquote>
<br>
From EcorePlugin:<br>
<blockquote><small>&nbsp; /**<br>
&nbsp;&nbsp; * Returns a map from {@link EPackage#getNsURI() package namespace
URI} (represented as a String) <br>
&nbsp;&nbsp; * to the location of the GenModel containing a GenPackage for the
package (represented as a {@link URI URI}).<br>
&nbsp;&nbsp; * @return a map from package namespace to GenModel location.<br>
&nbsp;&nbsp; */<br>
&nbsp; public static Map&lt;String, URI&gt;
getEPackageNsURIToGenModelLocationMap()<br>
</small></blockquote>
<br>
<blockquote cite="mid:idm4pe$uuc$1@news.eclipse.org" type="cite"><br>
Is there a direct way to achieve this?&nbsp; Let's say that I know that the
genmodel is always in the same directory of the ecore file, but how can
I retrieve such information once I have the EPackage (suppose I don't
have the information about the ecore package anymore)?
<br>
</blockquote>
Assuming it's registered, all you need to know is the nsURI of the
package.<br>
<blockquote cite="mid:idm4pe$uuc$1@news.eclipse.org" type="cite"><br>
Besides that, can I simply load the genmodel as a standard resource or
should I use a specific method?
<br>
</blockquote>
The right resource factory should be registered to load it normally.&nbsp;
Look closely at what the GenModelEditor does if you really want to use
it to generate something...<br>
<blockquote cite="mid:idm4pe$uuc$1@news.eclipse.org" type="cite"><br>
many thanks in advance
<br>
&nbsp;&nbsp;&nbsp; Lorenzo
<br>
<br>
</blockquote>
</body>
</html>

--------------080702090704080401040606--


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: accessing a genmodel programmatically [message #643800 is a reply to message #643713] Wed, 08 December 2010 10:30 Go to previous messageGo to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
On 12/08/2010 12:32 AM, Ed Merks wrote:
> Lorenzo,
>
> Comments below.
>
>
> Lorenzo Bettini wrote:
>> Hi
>>
>> I'm loading an EPackage programmatically specifying the ecore file,
>> e.g., "mypatch/to/my.ecore".
> Using an absolute URI hopefully...
>> Now, I'd like to access the corresponding genmodel file.
>
> From EcorePlugin:
>
> /**
> * Returns a map from {@link EPackage#getNsURI() package namespace
> URI} (represented as a String)
> * to the location of the GenModel containing a GenPackage for the
> package (represented as a {@link URI URI}).
> * @return a map from package namespace to GenModel location.
> */
> public static Map<String, URI> getEPackageNsURIToGenModelLocationMap()
>
>
>>
>> Is there a direct way to achieve this? Let's say that I know that the
>> genmodel is always in the same directory of the ecore file, but how
>> can I retrieve such information once I have the EPackage (suppose I
>> don't have the information about the ecore package anymore)?
> Assuming it's registered, all you need to know is the nsURI of the package.

Hi Ed

I tried with the following snippet (where model contains an instance of
EPackage):

EPackage ePackage = model.getEPackage();
EPackage.Registry.INSTANCE.put(ePackage.getNsURI(), ePackage);
Map<String, URI> ePackageNsURIToGenModelLocationMap =
EcorePlugin.getEPackageNsURIToGenModelLocationMap();
URI uri = ePackageNsURIToGenModelLocationMap.get(ePackage.getNsURI());
System.out.println(uri);

but it does not work: the map is an empty map... am I missing something?

thanks in advance
Lorenzo

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
ICQ# lbetto, 16080134 (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
http://www.myspace.com/supertrouperabba
BLOGS: http://tronprog.blogspot.com http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net


Re: accessing a genmodel programmatically [message #643834 is a reply to message #643800] Wed, 08 December 2010 13:10 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Lorenzo,

Comments below.


Lorenzo Bettini wrote:
> On 12/08/2010 12:32 AM, Ed Merks wrote:
>> Lorenzo,
>>
>> Comments below.
>>
>>
>> Lorenzo Bettini wrote:
>>> Hi
>>>
>>> I'm loading an EPackage programmatically specifying the ecore file,
>>> e.g., "mypatch/to/my.ecore".
>> Using an absolute URI hopefully...
>>> Now, I'd like to access the corresponding genmodel file.
>>
>> From EcorePlugin:
>>
>> /**
>> * Returns a map from {@link EPackage#getNsURI() package namespace
>> URI} (represented as a String)
>> * to the location of the GenModel containing a GenPackage for the
>> package (represented as a {@link URI URI}).
>> * @return a map from package namespace to GenModel location.
>> */
>> public static Map<String, URI>
>> getEPackageNsURIToGenModelLocationMap()
>>
>>
>>>
>>> Is there a direct way to achieve this? Let's say that I know that the
>>> genmodel is always in the same directory of the ecore file, but how
>>> can I retrieve such information once I have the EPackage (suppose I
>>> don't have the information about the ecore package anymore)?
>> Assuming it's registered, all you need to know is the nsURI of the
>> package.
>
> Hi Ed
>
> I tried with the following snippet (where model contains an instance
> of EPackage):
>
> EPackage ePackage = model.getEPackage();
> EPackage.Registry.INSTANCE.put(ePackage.getNsURI(), ePackage);
Th looks like a bad idea. If the model is registered, the package
should already be in the global registry.
> Map<String, URI> ePackageNsURIToGenModelLocationMap =
> EcorePlugin.getEPackageNsURIToGenModelLocationMap();
> URI uri =
> ePackageNsURIToGenModelLocationMap.get(ePackage.getNsURI());
> System.out.println(uri);
>
> but it does not work: the map is an empty map... am I missing something?
Are you running stand alone or in an Eclipse environment? Plugin
registration only works when running under Equinox.
>
> thanks in advance
> Lorenzo
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: accessing a genmodel programmatically [message #643837 is a reply to message #643834] Wed, 08 December 2010 13:12 Go to previous messageGo to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
On 12/08/2010 02:10 PM, Ed Merks wrote:
> Lorenzo,
>
> Comments below.
>
>
> Lorenzo Bettini wrote:
>> On 12/08/2010 12:32 AM, Ed Merks wrote:
>>> Lorenzo,
>>>
>>> Comments below.
>>>
>>>
>>> Lorenzo Bettini wrote:
>>>> Hi
>>>>
>>>> I'm loading an EPackage programmatically specifying the ecore file,
>>>> e.g., "mypatch/to/my.ecore".
>>> Using an absolute URI hopefully...
>>>> Now, I'd like to access the corresponding genmodel file.
>>>
>>> From EcorePlugin:
>>>
>>> /**
>>> * Returns a map from {@link EPackage#getNsURI() package namespace
>>> URI} (represented as a String)
>>> * to the location of the GenModel containing a GenPackage for the
>>> package (represented as a {@link URI URI}).
>>> * @return a map from package namespace to GenModel location.
>>> */
>>> public static Map<String, URI> getEPackageNsURIToGenModelLocationMap()
>>>
>>>
>>>>
>>>> Is there a direct way to achieve this? Let's say that I know that the
>>>> genmodel is always in the same directory of the ecore file, but how
>>>> can I retrieve such information once I have the EPackage (suppose I
>>>> don't have the information about the ecore package anymore)?
>>> Assuming it's registered, all you need to know is the nsURI of the
>>> package.
>>
>> Hi Ed
>>
>> I tried with the following snippet (where model contains an instance
>> of EPackage):
>>
>> EPackage ePackage = model.getEPackage();
>> EPackage.Registry.INSTANCE.put(ePackage.getNsURI(), ePackage);
> Th looks like a bad idea. If the model is registered, the package should
> already be in the global registry.
>> Map<String, URI> ePackageNsURIToGenModelLocationMap =
>> EcorePlugin.getEPackageNsURIToGenModelLocationMap();
>> URI uri = ePackageNsURIToGenModelLocationMap.get(ePackage.getNsURI());
>> System.out.println(uri);
>>
>> but it does not work: the map is an empty map... am I missing something?
> Are you running stand alone or in an Eclipse environment? Plugin
> registration only works when running under Equinox.

I'm trying this code in a junit test (not a plugin junit test), so this
won't work will it?

thanks
Lorenzo

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
ICQ# lbetto, 16080134 (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
http://www.myspace.com/supertrouperabba
BLOGS: http://tronprog.blogspot.com http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net


Re: accessing a genmodel programmatically [message #643839 is a reply to message #643837] Wed, 08 December 2010 13:16 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Lorenzo,

No, it won't work without the plugin.xml extension point processing.
Best to use a plugin JUnit test.


Lorenzo Bettini wrote:
> On 12/08/2010 02:10 PM, Ed Merks wrote:
>> Lorenzo,
>>
>> Comments below.
>>
>>
>> Lorenzo Bettini wrote:
>>> On 12/08/2010 12:32 AM, Ed Merks wrote:
>>>> Lorenzo,
>>>>
>>>> Comments below.
>>>>
>>>>
>>>> Lorenzo Bettini wrote:
>>>>> Hi
>>>>>
>>>>> I'm loading an EPackage programmatically specifying the ecore file,
>>>>> e.g., "mypatch/to/my.ecore".
>>>> Using an absolute URI hopefully...
>>>>> Now, I'd like to access the corresponding genmodel file.
>>>>
>>>> From EcorePlugin:
>>>>
>>>> /**
>>>> * Returns a map from {@link EPackage#getNsURI() package namespace
>>>> URI} (represented as a String)
>>>> * to the location of the GenModel containing a GenPackage for the
>>>> package (represented as a {@link URI URI}).
>>>> * @return a map from package namespace to GenModel location.
>>>> */
>>>> public static Map<String, URI> getEPackageNsURIToGenModelLocationMap()
>>>>
>>>>
>>>>>
>>>>> Is there a direct way to achieve this? Let's say that I know that the
>>>>> genmodel is always in the same directory of the ecore file, but how
>>>>> can I retrieve such information once I have the EPackage (suppose I
>>>>> don't have the information about the ecore package anymore)?
>>>> Assuming it's registered, all you need to know is the nsURI of the
>>>> package.
>>>
>>> Hi Ed
>>>
>>> I tried with the following snippet (where model contains an instance
>>> of EPackage):
>>>
>>> EPackage ePackage = model.getEPackage();
>>> EPackage.Registry.INSTANCE.put(ePackage.getNsURI(), ePackage);
>> Th looks like a bad idea. If the model is registered, the package should
>> already be in the global registry.
>>> Map<String, URI> ePackageNsURIToGenModelLocationMap =
>>> EcorePlugin.getEPackageNsURIToGenModelLocationMap();
>>> URI uri = ePackageNsURIToGenModelLocationMap.get(ePackage.getNsURI());
>>> System.out.println(uri);
>>>
>>> but it does not work: the map is an empty map... am I missing
>>> something?
>> Are you running stand alone or in an Eclipse environment? Plugin
>> registration only works when running under Equinox.
>
> I'm trying this code in a junit test (not a plugin junit test), so
> this won't work will it?
>
> thanks
> Lorenzo
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: accessing a genmodel programmatically [message #644069 is a reply to message #643839] Thu, 09 December 2010 10:22 Go to previous messageGo to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
Hi Ed

then I probably have to find another way since I'd like to use this code
also in a standalone application (not running in eclipse). There's no
way to use the below code in a standalone application, is there?

thanks
Lorenzo

On 12/08/2010 02:16 PM, Ed Merks wrote:
> Lorenzo,
>
> No, it won't work without the plugin.xml extension point processing.
> Best to use a plugin JUnit test.
>
>
> Lorenzo Bettini wrote:
>> On 12/08/2010 02:10 PM, Ed Merks wrote:
>>> Lorenzo,
>>>
>>> Comments below.
>>>
>>>
>>> Lorenzo Bettini wrote:
>>>> On 12/08/2010 12:32 AM, Ed Merks wrote:
>>>>> Lorenzo,
>>>>>
>>>>> Comments below.
>>>>>
>>>>>
>>>>> Lorenzo Bettini wrote:
>>>>>> Hi
>>>>>>
>>>>>> I'm loading an EPackage programmatically specifying the ecore file,
>>>>>> e.g., "mypatch/to/my.ecore".
>>>>> Using an absolute URI hopefully...
>>>>>> Now, I'd like to access the corresponding genmodel file.
>>>>>
>>>>> From EcorePlugin:
>>>>>
>>>>> /**
>>>>> * Returns a map from {@link EPackage#getNsURI() package namespace
>>>>> URI} (represented as a String)
>>>>> * to the location of the GenModel containing a GenPackage for the
>>>>> package (represented as a {@link URI URI}).
>>>>> * @return a map from package namespace to GenModel location.
>>>>> */
>>>>> public static Map<String, URI> getEPackageNsURIToGenModelLocationMap()
>>>>>
>>>>>
>>>>>>
>>>>>> Is there a direct way to achieve this? Let's say that I know that the
>>>>>> genmodel is always in the same directory of the ecore file, but how
>>>>>> can I retrieve such information once I have the EPackage (suppose I
>>>>>> don't have the information about the ecore package anymore)?
>>>>> Assuming it's registered, all you need to know is the nsURI of the
>>>>> package.
>>>>
>>>> Hi Ed
>>>>
>>>> I tried with the following snippet (where model contains an instance
>>>> of EPackage):
>>>>
>>>> EPackage ePackage = model.getEPackage();
>>>> EPackage.Registry.INSTANCE.put(ePackage.getNsURI(), ePackage);
>>> Th looks like a bad idea. If the model is registered, the package should
>>> already be in the global registry.
>>>> Map<String, URI> ePackageNsURIToGenModelLocationMap =
>>>> EcorePlugin.getEPackageNsURIToGenModelLocationMap();
>>>> URI uri = ePackageNsURIToGenModelLocationMap.get(ePackage.getNsURI());
>>>> System.out.println(uri);
>>>>
>>>> but it does not work: the map is an empty map... am I missing
>>>> something?
>>> Are you running stand alone or in an Eclipse environment? Plugin
>>> registration only works when running under Equinox.
>>
>> I'm trying this code in a junit test (not a plugin junit test), so
>> this won't work will it?
>>
>> thanks
>> Lorenzo
>>


--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
ICQ# lbetto, 16080134 (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
http://www.myspace.com/supertrouperabba
BLOGS: http://tronprog.blogspot.com http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net


Re: accessing a genmodel programmatically [message #644152 is a reply to message #644069] Thu, 09 December 2010 17:11 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Lorenzo,

Well, if I were made of time, I'd look into integrating the patches in
https://bugs.eclipse.org/bugs/show_bug.cgi?id=271253 I wonder though
if it's really entirely impossible to run your application as an Equinox
application?


Lorenzo Bettini wrote:
> Hi Ed
>
> then I probably have to find another way since I'd like to use this
> code also in a standalone application (not running in eclipse).
> There's no way to use the below code in a standalone application, is
> there?
>
> thanks
> Lorenzo
>
> On 12/08/2010 02:16 PM, Ed Merks wrote:
>> Lorenzo,
>>
>> No, it won't work without the plugin.xml extension point processing.
>> Best to use a plugin JUnit test.
>>
>>
>> Lorenzo Bettini wrote:
>>> On 12/08/2010 02:10 PM, Ed Merks wrote:
>>>> Lorenzo,
>>>>
>>>> Comments below.
>>>>
>>>>
>>>> Lorenzo Bettini wrote:
>>>>> On 12/08/2010 12:32 AM, Ed Merks wrote:
>>>>>> Lorenzo,
>>>>>>
>>>>>> Comments below.
>>>>>>
>>>>>>
>>>>>> Lorenzo Bettini wrote:
>>>>>>> Hi
>>>>>>>
>>>>>>> I'm loading an EPackage programmatically specifying the ecore file,
>>>>>>> e.g., "mypatch/to/my.ecore".
>>>>>> Using an absolute URI hopefully...
>>>>>>> Now, I'd like to access the corresponding genmodel file.
>>>>>>
>>>>>> From EcorePlugin:
>>>>>>
>>>>>> /**
>>>>>> * Returns a map from {@link EPackage#getNsURI() package namespace
>>>>>> URI} (represented as a String)
>>>>>> * to the location of the GenModel containing a GenPackage for the
>>>>>> package (represented as a {@link URI URI}).
>>>>>> * @return a map from package namespace to GenModel location.
>>>>>> */
>>>>>> public static Map<String, URI>
>>>>>> getEPackageNsURIToGenModelLocationMap()
>>>>>>
>>>>>>
>>>>>>>
>>>>>>> Is there a direct way to achieve this? Let's say that I know
>>>>>>> that the
>>>>>>> genmodel is always in the same directory of the ecore file, but how
>>>>>>> can I retrieve such information once I have the EPackage (suppose I
>>>>>>> don't have the information about the ecore package anymore)?
>>>>>> Assuming it's registered, all you need to know is the nsURI of the
>>>>>> package.
>>>>>
>>>>> Hi Ed
>>>>>
>>>>> I tried with the following snippet (where model contains an instance
>>>>> of EPackage):
>>>>>
>>>>> EPackage ePackage = model.getEPackage();
>>>>> EPackage.Registry.INSTANCE.put(ePackage.getNsURI(), ePackage);
>>>> Th looks like a bad idea. If the model is registered, the package
>>>> should
>>>> already be in the global registry.
>>>>> Map<String, URI> ePackageNsURIToGenModelLocationMap =
>>>>> EcorePlugin.getEPackageNsURIToGenModelLocationMap();
>>>>> URI uri =
>>>>> ePackageNsURIToGenModelLocationMap.get(ePackage.getNsURI());
>>>>> System.out.println(uri);
>>>>>
>>>>> but it does not work: the map is an empty map... am I missing
>>>>> something?
>>>> Are you running stand alone or in an Eclipse environment? Plugin
>>>> registration only works when running under Equinox.
>>>
>>> I'm trying this code in a junit test (not a plugin junit test), so
>>> this won't work will it?
>>>
>>> thanks
>>> Lorenzo
>>>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: accessing a genmodel programmatically [message #644278 is a reply to message #644152] Fri, 10 December 2010 10:49 Go to previous messageGo to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
I'd like to be able to run it both as an Equinox application and as a
standalone command line application...

thanks
Lorenzo

On 12/09/2010 06:11 PM, Ed Merks wrote:
> Lorenzo,
>
> Well, if I were made of time, I'd look into integrating the patches in
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=271253 I wonder though if
> it's really entirely impossible to run your application as an Equinox
> application?
>
>
> Lorenzo Bettini wrote:
>> Hi Ed
>>
>> then I probably have to find another way since I'd like to use this
>> code also in a standalone application (not running in eclipse).
>> There's no way to use the below code in a standalone application, is
>> there?
>>
>> thanks
>> Lorenzo
>>
>> On 12/08/2010 02:16 PM, Ed Merks wrote:
>>> Lorenzo,
>>>
>>> No, it won't work without the plugin.xml extension point processing.
>>> Best to use a plugin JUnit test.
>>>
>>>
>>> Lorenzo Bettini wrote:
>>>> On 12/08/2010 02:10 PM, Ed Merks wrote:
>>>>> Lorenzo,
>>>>>
>>>>> Comments below.
>>>>>
>>>>>
>>>>> Lorenzo Bettini wrote:
>>>>>> On 12/08/2010 12:32 AM, Ed Merks wrote:
>>>>>>> Lorenzo,
>>>>>>>
>>>>>>> Comments below.
>>>>>>>
>>>>>>>
>>>>>>> Lorenzo Bettini wrote:
>>>>>>>> Hi
>>>>>>>>
>>>>>>>> I'm loading an EPackage programmatically specifying the ecore file,
>>>>>>>> e.g., "mypatch/to/my.ecore".
>>>>>>> Using an absolute URI hopefully...
>>>>>>>> Now, I'd like to access the corresponding genmodel file.
>>>>>>>
>>>>>>> From EcorePlugin:
>>>>>>>
>>>>>>> /**
>>>>>>> * Returns a map from {@link EPackage#getNsURI() package namespace
>>>>>>> URI} (represented as a String)
>>>>>>> * to the location of the GenModel containing a GenPackage for the
>>>>>>> package (represented as a {@link URI URI}).
>>>>>>> * @return a map from package namespace to GenModel location.
>>>>>>> */
>>>>>>> public static Map<String, URI>
>>>>>>> getEPackageNsURIToGenModelLocationMap()
>>>>>>>
>>>>>>>
>>>>>>>>
>>>>>>>> Is there a direct way to achieve this? Let's say that I know
>>>>>>>> that the
>>>>>>>> genmodel is always in the same directory of the ecore file, but how
>>>>>>>> can I retrieve such information once I have the EPackage (suppose I
>>>>>>>> don't have the information about the ecore package anymore)?
>>>>>>> Assuming it's registered, all you need to know is the nsURI of the
>>>>>>> package.
>>>>>>
>>>>>> Hi Ed
>>>>>>
>>>>>> I tried with the following snippet (where model contains an instance
>>>>>> of EPackage):
>>>>>>
>>>>>> EPackage ePackage = model.getEPackage();
>>>>>> EPackage.Registry.INSTANCE.put(ePackage.getNsURI(), ePackage);
>>>>> Th looks like a bad idea. If the model is registered, the package
>>>>> should
>>>>> already be in the global registry.
>>>>>> Map<String, URI> ePackageNsURIToGenModelLocationMap =
>>>>>> EcorePlugin.getEPackageNsURIToGenModelLocationMap();
>>>>>> URI uri =
>>>>>> ePackageNsURIToGenModelLocationMap.get(ePackage.getNsURI());
>>>>>> System.out.println(uri);
>>>>>>
>>>>>> but it does not work: the map is an empty map... am I missing
>>>>>> something?
>>>>> Are you running stand alone or in an Eclipse environment? Plugin
>>>>> registration only works when running under Equinox.
>>>>
>>>> I'm trying this code in a junit test (not a plugin junit test), so
>>>> this won't work will it?
>>>>
>>>> thanks
>>>> Lorenzo
>>>>
>>
>>


Re: accessing a genmodel programmatically [message #644299 is a reply to message #644278] Fri, 10 December 2010 13:04 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Lorenzo,

Note that you can run an Equinox application from the command line.
It's essentially just a fancy way of invoking main()...


Lorenzo Bettini wrote:
> I'd like to be able to run it both as an Equinox application and as a
> standalone command line application...
>
> thanks
> Lorenzo
>
> On 12/09/2010 06:11 PM, Ed Merks wrote:
>> Lorenzo,
>>
>> Well, if I were made of time, I'd look into integrating the patches in
>> https://bugs.eclipse.org/bugs/show_bug.cgi?id=271253 I wonder though if
>> it's really entirely impossible to run your application as an Equinox
>> application?
>>
>>
>> Lorenzo Bettini wrote:
>>> Hi Ed
>>>
>>> then I probably have to find another way since I'd like to use this
>>> code also in a standalone application (not running in eclipse).
>>> There's no way to use the below code in a standalone application, is
>>> there?
>>>
>>> thanks
>>> Lorenzo
>>>
>>> On 12/08/2010 02:16 PM, Ed Merks wrote:
>>>> Lorenzo,
>>>>
>>>> No, it won't work without the plugin.xml extension point processing.
>>>> Best to use a plugin JUnit test.
>>>>
>>>>
>>>> Lorenzo Bettini wrote:
>>>>> On 12/08/2010 02:10 PM, Ed Merks wrote:
>>>>>> Lorenzo,
>>>>>>
>>>>>> Comments below.
>>>>>>
>>>>>>
>>>>>> Lorenzo Bettini wrote:
>>>>>>> On 12/08/2010 12:32 AM, Ed Merks wrote:
>>>>>>>> Lorenzo,
>>>>>>>>
>>>>>>>> Comments below.
>>>>>>>>
>>>>>>>>
>>>>>>>> Lorenzo Bettini wrote:
>>>>>>>>> Hi
>>>>>>>>>
>>>>>>>>> I'm loading an EPackage programmatically specifying the ecore
>>>>>>>>> file,
>>>>>>>>> e.g., "mypatch/to/my.ecore".
>>>>>>>> Using an absolute URI hopefully...
>>>>>>>>> Now, I'd like to access the corresponding genmodel file.
>>>>>>>>
>>>>>>>> From EcorePlugin:
>>>>>>>>
>>>>>>>> /**
>>>>>>>> * Returns a map from {@link EPackage#getNsURI() package namespace
>>>>>>>> URI} (represented as a String)
>>>>>>>> * to the location of the GenModel containing a GenPackage for the
>>>>>>>> package (represented as a {@link URI URI}).
>>>>>>>> * @return a map from package namespace to GenModel location.
>>>>>>>> */
>>>>>>>> public static Map<String, URI>
>>>>>>>> getEPackageNsURIToGenModelLocationMap()
>>>>>>>>
>>>>>>>>
>>>>>>>>>
>>>>>>>>> Is there a direct way to achieve this? Let's say that I know
>>>>>>>>> that the
>>>>>>>>> genmodel is always in the same directory of the ecore file,
>>>>>>>>> but how
>>>>>>>>> can I retrieve such information once I have the EPackage
>>>>>>>>> (suppose I
>>>>>>>>> don't have the information about the ecore package anymore)?
>>>>>>>> Assuming it's registered, all you need to know is the nsURI of the
>>>>>>>> package.
>>>>>>>
>>>>>>> Hi Ed
>>>>>>>
>>>>>>> I tried with the following snippet (where model contains an
>>>>>>> instance
>>>>>>> of EPackage):
>>>>>>>
>>>>>>> EPackage ePackage = model.getEPackage();
>>>>>>> EPackage.Registry.INSTANCE.put(ePackage.getNsURI(), ePackage);
>>>>>> Th looks like a bad idea. If the model is registered, the package
>>>>>> should
>>>>>> already be in the global registry.
>>>>>>> Map<String, URI> ePackageNsURIToGenModelLocationMap =
>>>>>>> EcorePlugin.getEPackageNsURIToGenModelLocationMap();
>>>>>>> URI uri =
>>>>>>> ePackageNsURIToGenModelLocationMap.get(ePackage.getNsURI());
>>>>>>> System.out.println(uri);
>>>>>>>
>>>>>>> but it does not work: the map is an empty map... am I missing
>>>>>>> something?
>>>>>> Are you running stand alone or in an Eclipse environment? Plugin
>>>>>> registration only works when running under Equinox.
>>>>>
>>>>> I'm trying this code in a junit test (not a plugin junit test), so
>>>>> this won't work will it?
>>>>>
>>>>> thanks
>>>>> Lorenzo
>>>>>
>>>
>>>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Opposite reference unset after resolve
Next Topic:EMF Databinding/Undo/Redo
Goto Forum:
  


Current Time: Fri Apr 26 13:45:06 GMT 2024

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

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

Back to the top