Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Xcore and Ecore references
Xcore and Ecore references [message #726896] Mon, 19 September 2011 20:35 Go to next message
Hallvard Traetteberg is currently offline Hallvard TraettebergFriend
Messages: 673
Registered: July 2009
Location: Trondheim, Norway
Senior Member
Hi,

I'm using Xcore and have a problem with it is combined with MWE. Xcore
allows referencing the standard Ecore EDataTypes like EInt, EBoolean
etc. When serializing, the references are encoded with platform:/plugin
URIs instead of the http:// variant, as if the EcorePackage was loaded
from Ecore.ecore instead refering to the global instance. Loading the
model into an editor works fine, but when using MWE to run a generator
(xtend2) the references do not resolve, so I end up with proxy EDataType
objects without instanceClass or instanceClassName. I have to manually
replace the platform:/plugin URIs with the http:// variant in the ecore
file to make it work.

I know there are cases when a platform:/plugin is preferable to the
http:// variant, e.g. when the latter isn't registered and the former
does actually refer to the ecore file. But in this case, I cannot see
why Xcore would want to load the model, rather than refer to the global one.

Hallvard
Re: Xcore and Ecore references [message #726913 is a reply to message #726896] Mon, 19 September 2011 21:53 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Hallvard,

Is this something that could/should be solved with some additional
registration/mapping in the standalone stepup for Xcore?


On 19/09/2011 4:35 PM, Hallvard Trætteberg wrote:
> Hi,
>
> I'm using Xcore and have a problem with it is combined with MWE. Xcore
> allows referencing the standard Ecore EDataTypes like EInt, EBoolean
> etc. When serializing, the references are encoded with
> platform:/plugin URIs instead of the http:// variant, as if the
> EcorePackage was loaded from Ecore.ecore instead refering to the
> global instance. Loading the model into an editor works fine, but when
> using MWE to run a generator (xtend2) the references do not resolve,
> so I end up with proxy EDataType objects without instanceClass or
> instanceClassName. I have to manually replace the platform:/plugin
> URIs with the http:// variant in the ecore file to make it work.
>
> I know there are cases when a platform:/plugin is preferable to the
> http:// variant, e.g. when the latter isn't registered and the former
> does actually refer to the ecore file. But in this case, I cannot see
> why Xcore would want to load the model, rather than refer to the
> global one.
>
> Hallvard


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Xcore and Ecore references [message #727013 is a reply to message #726913] Tue, 20 September 2011 07:47 Go to previous messageGo to next message
Hallvard Traetteberg is currently offline Hallvard TraettebergFriend
Messages: 673
Registered: July 2009
Location: Trondheim, Norway
Senior Member
On 19.09.11 23.53, Ed Merks wrote:
>
> Is this something that could/should be solved with some additional
> registration/mapping in the standalone stepup for Xcore?

I don't think this setup is used after the ecore is created, so the
change of URI has to be done either inside (and throughout) Xcore or in
the converter action.

I tried changing the URI in XcoreImportedNamespaceAwareScopeProvider,
but that seemed to break lots of things. I then changed
ConvertToEcoreActionDelegate as follows:

new WorkspaceModifyOperation()
{
@Override
protected void execute(IProgressMonitor progressMonitor)
{
try
{
progressMonitor.beginTask("", 1);

....


if (ecoreXcore != null)
{
....
}

// new code added to save with different URI
Resource ecoreResource =
resourceSet.getResource(URI.createURI("platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore"),
false);
if (ecoreResource != null) {
ecoreResource.setURI(URI.createURI(EcorePackage.eNS_URI));
}

I.e. I rename the Ecore.ecore resources (just before the content is
added and the resource is saved). This seems to have the desired effect
on the saved ecore and genmodel file.

BTW, to minor issues:
1) The genmodel opens in the reflective editor and not the EMF Generator
editor.
2) It would be great to have an option in the xcore editor to do this
conversion on each save, or a button for the action.

Hallvard
Re: Xcore and Ecore references [message #727014 is a reply to message #727013] Tue, 20 September 2011 07:59 Go to previous messageGo to next message
Hallvard Traetteberg is currently offline Hallvard TraettebergFriend
Messages: 673
Registered: July 2009
Location: Trondheim, Norway
Senior Member
On 20.09.11 09.47, Hallvard Trætteberg wrote:
>
> BTW, to minor issues:
> 1) The genmodel opens in the reflective editor and not the EMF Generator
> editor.

Fix for issue 1), change the contentType key to
"org.eclipse.emf.codegen.genmodel":
workbenchPage.openEditor(new
FileEditorInput(genModelFile),
workbenchWindow.getWorkbench().getEditorRegistry().getDefaultEditor(genModelFile.getFullPath().toString(),
Platform.getContentTypeManager().getContentType("org.eclipse.emf.codegen.genmodel")).getId());

Hallvard
Re: Xcore and Ecore references [message #727084 is a reply to message #727013] Tue, 20 September 2011 11:19 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Hallvard,

Comments below.

On 20/09/2011 3:47 AM, Hallvard Trætteberg wrote:
> On 19.09.11 23.53, Ed Merks wrote:
>>
>> Is this something that could/should be solved with some additional
>> registration/mapping in the standalone stepup for Xcore?
>
> I don't think this setup is used after the ecore is created, so the
> change of URI has to be done either inside (and throughout) Xcore or
> in the converter action.
I though it was using the Xcore directly that was the problem...
>
> I tried changing the URI in XcoreImportedNamespaceAwareScopeProvider,
> but that seemed to break lots of things. I then changed
> ConvertToEcoreActionDelegate
So it's in the result of the converter that's a problem...
> as follows:
>
> new WorkspaceModifyOperation()
> {
> @Override
> protected void execute(IProgressMonitor progressMonitor)
> {
> try
> {
> progressMonitor.beginTask("", 1);
>
> ...
>
>
> if (ecoreXcore != null)
> {
> ...
> }
>
> // new code added to save with different URI
> Resource ecoreResource =
> resourceSet.getResource(URI.createURI("platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore"),
> false);
> if (ecoreResource != null) {
>
> ecoreResource.setURI(URI.createURI(EcorePackage.eNS_URI));
> }
>
> I.e. I rename the Ecore.ecore resources (just before the content is
> added and the resource is saved). This seems to have the desired
> effect on the saved ecore and genmodel file.
I think the fix should be to ensure that MWE can properly find the
serialized version of Ecore that has an associated GenModel. Models
that extend Ecore (they shouldn't but people still do) will need that
version.
>
> BTW, to minor issues:
> 1) The genmodel opens in the reflective editor and not the EMF
> Generator editor.
Yes, I noticed the wrong editor opens. We could be more explicit about
which one we want opened...
> 2) It would be great to have an option in the xcore editor to do this
> conversion on each save, or a button for the action.
Like a builder or something. But we really want folks to be able to use
*.xcore directly for that purpose with no need for *.genmodel or *.ecore
resources to exist...
>
> Hallvard


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Xcore and Ecore references [message #727088 is a reply to message #727013] Tue, 20 September 2011 11:19 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Hallvard,

Comments below.

On 20/09/2011 3:47 AM, Hallvard Trætteberg wrote:
> On 19.09.11 23.53, Ed Merks wrote:
>>
>> Is this something that could/should be solved with some additional
>> registration/mapping in the standalone stepup for Xcore?
>
> I don't think this setup is used after the ecore is created, so the
> change of URI has to be done either inside (and throughout) Xcore or
> in the converter action.
I though it was using the Xcore directly that was the problem...
>
> I tried changing the URI in XcoreImportedNamespaceAwareScopeProvider,
> but that seemed to break lots of things. I then changed
> ConvertToEcoreActionDelegate
So it's in the result of the converter that's a problem...
> as follows:
>
> new WorkspaceModifyOperation()
> {
> @Override
> protected void execute(IProgressMonitor progressMonitor)
> {
> try
> {
> progressMonitor.beginTask("", 1);
>
> ...
>
>
> if (ecoreXcore != null)
> {
> ...
> }
>
> // new code added to save with different URI
> Resource ecoreResource =
> resourceSet.getResource(URI.createURI("platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore"),
> false);
> if (ecoreResource != null) {
>
> ecoreResource.setURI(URI.createURI(EcorePackage.eNS_URI));
> }
>
> I.e. I rename the Ecore.ecore resources (just before the content is
> added and the resource is saved). This seems to have the desired
> effect on the saved ecore and genmodel file.
I think the fix should be to ensure that MWE can properly find the
serialized version of Ecore that has an associated GenModel. Models
that extend Ecore (they shouldn't but people still do) will need that
version.
>
> BTW, to minor issues:
> 1) The genmodel opens in the reflective editor and not the EMF
> Generator editor.
Yes, I noticed the wrong editor opens. We could be more explicit about
which one we want opened...
> 2) It would be great to have an option in the xcore editor to do this
> conversion on each save, or a button for the action.
Like a builder or something. But we really want folks to be able to use
*.xcore directly for that purpose with no need for *.genmodel or *.ecore
resources to exist...
>
> Hallvard


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Xcore and Ecore references [message #727710 is a reply to message #727084] Wed, 21 September 2011 20:48 Go to previous messageGo to next message
Hallvard Traetteberg is currently offline Hallvard TraettebergFriend
Messages: 673
Registered: July 2009
Location: Trondheim, Norway
Senior Member
On 20.09.11 13.19, Ed Merks wrote:
> Hallvard,
>
> Comments below.
>
> On 20/09/2011 3:47 AM, Hallvard Trætteberg wrote:
>
>>
>> I.e. I rename the Ecore.ecore resources (just before the content is
>> added and the resource is saved). This seems to have the desired
>> effect on the saved ecore and genmodel file.
> I think the fix should be to ensure that MWE can properly find the
> serialized version of Ecore that has an associated GenModel. Models that
> extend Ecore (they shouldn't but people still do) will need that version.

The debugger reveals that it tries to resolve the EBoolean type and
correctly finds the Ecore.ecore Resource in the ResourceSet. However,
this resource is empty, presumably because the platform:/plugin/... URI
isn't supported in standalone mode.

Using a URI mapping to redirect the platform:/plugin/... URI to the
correct Ecore jar sounds tricky.

After some experimentation, I ended up with the following trick (xtend
syntax):

val ecorePluginUri =
URI::createURI("platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore")
for (res : resourceSet.resources) {
if (ecorePluginUri.equals(res.URI) && res.contents.size == 0) {
res.contents.add(EcoreUtil::copy(EcorePackage::eINSTANCE as
EPackage))
}
}
I.e. I make a copy of the ecore package and insert it into the
Ecore.ecore resource.

>> BTW, to minor issues:
>> 1) The genmodel opens in the reflective editor and not the EMF
>> Generator editor.
> Yes, I noticed the wrong editor opens. We could be more explicit about
> which one we want opened...

Yes, use a different content type key (as shown in an earlier message).

>But we really want folks to be able to use
> *.xcore directly for that purpose with no need for *.genmodel or *.ecore
> resources to exist...

I completely agree.

Hallvard
Re: Xcore and Ecore references [message #727811 is a reply to message #727710] Thu, 22 September 2011 01:55 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Hallvard,<br>
<br>
Comments below.<br>
<br>
<br>
On 21/09/2011 4:48 PM, Hallvard Tr&aelig;tteberg wrote:
<blockquote cite="mid:j5dhsh$nk9$1@news.eclipse.org" type="cite">On
20.09.11 13.19, Ed Merks wrote:
<br>
<blockquote type="cite">Hallvard,
<br>
<br>
Comments below.
<br>
<br>
On 20/09/2011 3:47 AM, Hallvard Tr&aelig;tteberg wrote:
<br>
<br>
<blockquote type="cite">
<br>
I.e. I rename the Ecore.ecore resources (just before the
content is
<br>
added and the resource is saved). This seems to have the
desired
<br>
effect on the saved ecore and genmodel file.
<br>
</blockquote>
I think the fix should be to ensure that MWE can properly find
the
<br>
serialized version of Ecore that has an associated GenModel.
Models that
<br>
extend Ecore (they shouldn't but people still do) will need that
version.
<br>
</blockquote>
<br>
The debugger reveals that it tries to resolve the EBoolean type
and correctly finds the Ecore.ecore Resource in the ResourceSet.
However, this resource is empty, presumably because the
platform:/plugin/... URI isn't supported in standalone mode.
<br>
<br>
Using a URI mapping to redirect the platform:/plugin/... URI to
the correct Ecore jar sounds tricky.
<br>
</blockquote>
Not really.&nbsp;&nbsp; EcorePlugin.INSTANCE.getBaseURL() should return the
appropriate URL, e.g.,<br>
<blockquote><a class="moz-txt-link-freetext" href="jar:file:/C:/sandbox/eclipse-modeling-indigo-csa/eclipse/plugins/org.eclipse.emf.ecore_2.7.0.v20110605-0747.jar!/">jar:file:/C:/sandbox/eclipse-modeling-indigo-csa/eclipse/plugins/org.eclipse.emf.ecore_2.7.0.v20110605-0747.jar!/</a><br>
</blockquote>
So you could remap platform:/plugin/org.eclipse.emf.ecore/ to that
URL.&nbsp; That should properly redirect any references to things in the
Ecore plugin to things in the jar.<br>
<blockquote cite="mid:j5dhsh$nk9$1@news.eclipse.org" type="cite">
<br>
After some experimentation, I ended up with the following trick
(xtend syntax):
<br>
<br>
val ecorePluginUri =
URI::createURI("platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore")<br>
for (res : resourceSet.resources) {
<br>
&nbsp;&nbsp; if (ecorePluginUri.equals(res.URI) &amp;&amp; res.contents.size
== 0) {
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; res.contents.add(EcoreUtil::copy(EcorePackage::eINSTANCE as
EPackage))
<br>
&nbsp;&nbsp; }
<br>
}
<br>
I.e. I make a copy of the ecore package and insert it into the
Ecore.ecore resource.
<br>
<br>
<blockquote type="cite">
<blockquote type="cite">BTW, to minor issues:
<br>
1) The genmodel opens in the reflective editor and not the EMF
<br>
Generator editor.
<br>
</blockquote>
Yes, I noticed the wrong editor opens. We could be more explicit
about
<br>
which one we want opened...
<br>
</blockquote>
<br>
Yes, use a different content type key (as shown in an earlier
message).
<br>
<br>
<blockquote type="cite">But we really want folks to be able to use
<br>
*.xcore directly for that purpose with no need for *.genmodel or
*.ecore
<br>
resources to exist...
<br>
</blockquote>
<br>
I completely agree.
<br>
<br>
Hallvard
<br>
</blockquote>
</body>
</html>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Xcore and Ecore references [message #728492 is a reply to message #727811] Fri, 23 September 2011 10:41 Go to previous message
Eclipse UserFriend
Originally posted by:

On 22.09.11 03.55, Ed Merks wrote:
> Hallvard,
>
>> Using a URI mapping to redirect the platform:/plugin/... URI to the
>> correct Ecore jar sounds tricky.
> Not really. EcorePlugin.INSTANCE.getBaseURL() should return the
> appropriate URL, e.g.,
>
> jar:file:/C:/sandbox/eclipse-modeling-indigo-csa/eclipse/plugins/org.eclipse.emf.ecore_2.7.0.v20110605-0747.jar!/
>
> So you could remap platform:/plugin/org.eclipse.emf.ecore/ to that URL.
> That should properly redirect any references to things in the Ecore
> plugin to things in the jar.

That's certainly a useful method (and advice). The following seemed to
work, when put in my DSL's standalone setup:

String baseEcoreUrl = EcorePlugin.INSTANCE.getBaseURL().toExternalForm();

ExtensibleURIConverterImpl.URI_MAP.put(URI.createURI("platform:/plugin/org.eclipse.emf.ecore/"),
URI.createURI(baseEcoreUrl));

Thanks!

Hallvard
Previous Topic:[CDO]: How to start the CDO-Server from a command shell without eclipse
Next Topic:[XPand/MWE] Update sites for latest Juno versions
Goto Forum:
  


Current Time: Fri Apr 19 19:45:16 GMT 2024

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

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

Back to the top