Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » M2M Transformation
M2M Transformation [message #417204] Fri, 29 February 2008 13:47 Go to next message
Eclipse UserFriend
Originally posted by: invone2000.yahoo.de

Hmm cryptic:

I have two IEditingDomainProvider instances at hand. i opened the
corresponding editors and casted them to IEditingDomain.

IEditingDomainProvider src = ...
IEditingDomainProvider target = ...

Now I search one node in the target and one in the source.
Overview:
source:
-root
+-container
+-value

target:
-root

Now I travers through the source to get the container and then I traverse
through the target to get the root.
In my next step I want to "create" a new container as copy of the
container from the source in the target and I use the following:

EObject targetRoot = ...
EObject sourceContainer = ...
Command cmd =AddCommand.create(target.getEditingdomain(), targetRoot,
null, sourceContainer);
target.getEditingDomain().getCommandStack().execute(cmd);

Until now: Everything okay ;)
But then I check the opened editors. The target one is now like:
-root
+-container
+-value (superb)
But the source model does not have the container anymore it looks like
this:
-root
Seems that the container "went over"!
But now the curious thingy: I close the source editor and open it again
and the original content is there (with container and value)...

Any ideas why?

Cheers
harkon
Re: M2M Transformation [message #417205 is a reply to message #417204] Fri, 29 February 2008 14:10 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Karkon,

Comments below.

harkon wrote:
> Hmm cryptic:
>
> I have two IEditingDomainProvider instances at hand. i opened the
> corresponding editors and casted them to IEditingDomain.
>
> IEditingDomainProvider src = ...
> IEditingDomainProvider target = ...
>
> Now I search one node in the target and one in the source.
> Overview:
> source:
> -root
> +-container
> +-value
>
> target:
> -root
>
> Now I travers through the source to get the container and then I
> traverse through the target to get the root.
> In my next step I want to "create" a new container as copy of the
> container from the source in the target and I use the following:
>
> EObject targetRoot = ...
> EObject sourceContainer = ...
> Command cmd =AddCommand.create(target.getEditingdomain(), targetRoot,
> null, sourceContainer);
> target.getEditingDomain().getCommandStack().execute(cmd);
Where's the copy command? What you've done here will take the existing
object and add it to the target, and of course if this is a containment
reference, that means it will be removed from the source.
>
> Until now: Everything okay ;)
> But then I check the opened editors. The target one is now like:
> -root
> +-container
> +-value (superb)
> But the source model does not have the container anymore it looks like
> this:
> -root
> Seems that the container "went over"!
It did exactly that.
> But now the curious thingy: I close the source editor and open it
> again and the original content is there (with container and value)...
The original resource wasn't changed, so when it's reloaded, the
children will be exactly as before.
>
> Any ideas why?
>
> Cheers
> harkon
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: M2M Transformation [message #417233 is a reply to message #417205] Mon, 03 March 2008 09:27 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: invone2000.yahoo.de

Thanx - I now manage this problem by the following:
I create a copy of the to be added alement and the source model won't be
altered anymore...

But now one other thing:
I use ResourceSet for XMI loading:

URI uri = URI.createFileURI(modelFileName);
Resource res = resourceSet.getResource(uri, true);

Then I fetch the complete content and store it in a List<EObject>

TreeIterator<EObject> iter = res.getAllContents();
List<EObject> ret = new ArrayList<EObject>();
while (iter.hasNext()) {
ret.add(iter.next());
}

Now: When I change the content of a model (AddCommand etc.) The model
contains more elements then before.
When I recall the load method (see above) the content is the same as
before.
Okay, I use the open editor's command stack for Commands and after
transformations I call the doSave() (now it works with syncExec()). The
editor contains the new info and the XMI file is updated as well. But when
I load the content again the old state is fetched.

Workflow:
1. Open editor with model
2. load resources via ResourceSet
3. Alter model via Commands
4. Save Editor
5. load resources via ResourceSet => Bang! Always the same content...

Any hint?

harkon
Re: M2M Transformation [message #417235 is a reply to message #417233] Mon, 03 March 2008 12:14 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.
--------------030408060700060501080507
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Karkon,

Comments below.


harkon wrote:
> Thanx - I now manage this problem by the following:
> I create a copy of the to be added alement and the source model won't
> be altered anymore...
>
> But now one other thing:
> I use ResourceSet for XMI loading:
>
> URI uri = URI.createFileURI(modelFileName);
> Resource res = resourceSet.getResource(uri, true);
I guess you are running this outside of an Eclipse workspace?
>
> Then I fetch the complete content and store it in a List<EObject>
>
> TreeIterator<EObject> iter = res.getAllContents();
> List<EObject> ret = new ArrayList<EObject>();
> while (iter.hasNext()) {
> ret.add(iter.next());
> }
I always prefer this pattern to limit the scope of the the iterator to
the context that uses it.

for (TreeIterator<EObject> iter = res.getAllContents();
iter.hasNext(); ) {
//...
}

>
> Now: When I change the content of a model (AddCommand etc.) The model
> contains more elements then before.
> When I recall the load method (see above) the content is the same as
> before.
> Okay, I use the open editor's command stack for Commands and after
> transformations I call the doSave() (now it works with syncExec()).
> The editor contains the new info and the XMI file is updated as well.
> But when I load the content again the old state is fetched.
Are you using a workspace? The createFileURI seems a bit of a concern
to me. I'd expect the use of createPlatformResourceURI based on the
iFile's getFullPath.
>
> Workflow:
> 1. Open editor with model
> 2. load resources via ResourceSet
> 3. Alter model via Commands
> 4. Save Editor
> 5. load resources via ResourceSet => Bang! Always the same content...
Check carefully the file you're saving to, which you say has actually
changed, verses the file you're loading from, which apparently has the
old contents and hence can't possibly be the same one you've confirmed
has changed.
>
> Any hint?
>
> harkon
>


--------------030408060700060501080507
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Karkon,<br>
<br>
Comments below.<br>
<br>
<br>
harkon wrote:
<blockquote
cite="mid:659de647824dadaa9913137ddfcfa1af$1@www.eclipse.org"
type="cite">Thanx - I now manage this problem by the following:
<br>
I create a copy of the to be added alement and the source model won't
be altered anymore...
<br>
<br>
But now one other thing:
<br>
I use ResourceSet for XMI loading:
<br>
<br>
URI uri = URI.createFileURI(modelFileName);
<br>
Resource res = resourceSet.getResource(uri, true);
<br>
</blockquote>
I guess you are running this outside of an Eclipse workspace?<br>
<blockquote
cite="mid:659de647824dadaa9913137ddfcfa1af$1@www.eclipse.org"
type="cite"><br>
Then I fetch the complete content and store it in a List&lt;EObject&gt;
<br>
<br>
TreeIterator&lt;EObject&gt; iter = res.getAllContents();
<br>
List&lt;EObject&gt; ret = new ArrayList&lt;EObject&gt;();
<br>
while (iter.hasNext()) {
<br>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: M2M Transformation [message #417310 is a reply to message #417235] Wed, 05 March 2008 06:06 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: invone2000.yahoo.de

Okay: just to be sure - here is the progress described
1. I open an ecore editor from a launch configuration and store the
IEditingDomainProvider instance with the appropriate URI with the
following statements (I use a dialog to select the model):

//Get resource for path name of model file
IResource selectedResource =
ResourcesPlugin.getWorkspace().getRoot().findMember(pathName );
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
//open editor and get
IEditingDomainProvider editor =
(IEditingDomainProvider)IDE.openEditor(page, (IFile) selectedResource,
true);

Now I store the editor AND the URI with:
URI fileUri = ((IFile) selectedResource).getLocationURI();

2. I start an RMI server which provides the corresponding file path name
of the currently opened editor. This delivers the URI in string
representation:

String fileName = fileUri.getPath();

3. I connect with an RMI client and get the file name and then I open the
file on the client side also, with:

ResourceSet resourceSet = new ResourceSetImpl();
// Enable loading of XMI files
resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put( "*",
new XMIResourceFactoryImpl());
//register epackages...
URI uri = URI.createFileURI(fileName); //fetched from RMI server
Resource res = resourceSet.getResource(uri, true);
TreeIterator<EObject> iter = res.getAllContents();
List<EObject> ret = new ArrayList<EObject>();
while (iter.hasNext()) {
ret.add(iter.next());
}

4. I work myself with the client through the model and perform actions
which are delegated to the server (because EObjects and the rest is not
serializable). The server uses the real instance of the editor
(IEditingDomainProvider) and its command stack.
After each change I perform a doSave on the opened editor. Now the content
of the model must have been changed.
The URI of the target model file is the same but the content is new. When
I reload the content again (Step 4 from Resource res =
resourceSet.getResource() ...) the old content is loaded...

I don't see any change in the file I use and therefore I'm a bit confused.
By the way I formerly used the TreeIterator<EObject> (as you told me) but
I was afraid that the iterator remembers the position in the content.
Therefore I load the complete content just to be sure - but I didn't
help...

any hint or aid would be great - Thx

harkon
Re: M2M Transformation [message #417317 is a reply to message #417310] Wed, 05 March 2008 11:15 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Harkon,

Comments below.

harkon wrote:
> Okay: just to be sure - here is the progress described
> 1. I open an ecore editor from a launch configuration and store the
> IEditingDomainProvider instance with the appropriate URI with the
> following statements (I use a dialog to select the model):
>
> //Get resource for path name of model file
> IResource selectedResource =
> ResourcesPlugin.getWorkspace().getRoot().findMember(pathName );
> IWorkbench workbench = PlatformUI.getWorkbench();
> IWorkbenchPage page =
> workbench.getActiveWorkbenchWindow().getActivePage();
> //open editor and get
> IEditingDomainProvider editor =
> (IEditingDomainProvider)IDE.openEditor(page, (IFile) selectedResource,
> true);
>
> Now I store the editor AND the URI with:
> URI fileUri = ((IFile) selectedResource).getLocationURI();
This doesn't look so good perhaps, depending on what you want to do with
it. I think you might want
URI.createPlatformURI(selectedResource.getFullPath().toStrin g(), true)
which is what EMF uses within the resource set.
>
> 2. I start an RMI server which provides the corresponding file path
> name of the currently opened editor. This delivers the URI in string
> representation:
>
> String fileName = fileUri.getPath();
>
> 3. I connect with an RMI client and get the file name and then I open
> the file on the client side also, with:
>
> ResourceSet resourceSet = new ResourceSetImpl();
> // Enable loading of XMI files
> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put( "*",
> new XMIResourceFactoryImpl());
> //register epackages...
> URI uri = URI.createFileURI(fileName); //fetched from RMI server
> Resource res = resourceSet.getResource(uri, true);
> TreeIterator<EObject> iter = res.getAllContents();
> List<EObject> ret = new ArrayList<EObject>();
> while (iter.hasNext()) {
> ret.add(iter.next());
> }
Is this running stand alone? I guess so. I suppose that's why you need
direct access to the file: URI rather than to the platform:/resource URI.
>
> 4. I work myself with the client through the model and perform actions
> which are delegated to the server (because EObjects and the rest is
> not serializable). The server uses the real instance of the editor
> (IEditingDomainProvider) and its command stack. After each change I
> perform a doSave on the opened editor. Now the content of the model
> must have been changed.
It's best to verify all assertions. So verify that you have indeed
changes the contents.
> The URI of the target model file is the same but the content is new.
> When I reload the content again (Step 4 from Resource res =
> resourceSet.getResource() ...) the old content is loaded...
So clearly it's finding old content somewhere.
>
> I don't see any change in the file I use and therefore I'm a bit
> confused. By the way I formerly used the TreeIterator<EObject> (as you
> told me) but I was afraid that the iterator remembers the position in
> the content. Therefore I load the complete content just to be sure -
> but I didn't help...
>
> any hint or aid would be great - Thx
Verify your assumptions. You can monitor the contents of the file
system during your actions. The debugger is your best friend and doesn't
mind being mercilessly exploited.
>
> harkon
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: M2M Transformation [message #417352 is a reply to message #417317] Thu, 06 March 2008 05:54 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: invone2000.yahoo.de

Okay, I now want to use your mentioned changes:

- I get from the selected resource the org.eclipse.emf.common.util.URI

org.eclipse.emf.common.util.URI modelUri =
org.eclipse.emf.common.util.URI.createPlatformResourceURI(se lectedResource.getFullPath().toString(),
true);

[I previously used java.net.URI ...]

with the content during debug:
"platform:/resource/test/src/source.transformator"

- I deliver the file name to the RMI client:

String fileName = sourceModelUri.toPlatformString(true);

with the content during debug:
"/test/src/source.transformator"

- I use the ResourceSet on the client side to load and I use the file name
as follows:
URI uri = URI.createPlatformResourceURI(fileName, true);

with the content during debug:
"platform:/resource/test/src/source.transformator"

So far the both URI's seem to be identical. But I get the following
exception:

Exception in thread "main"
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1Diagnos ticWrappedException:
java.io.IOException: The path '/test/src/source.transformator' is unmapped
at
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.handleDe mandLoadException(ResourceSetImpl.java:316)
at
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLo adHelper(ResourceSetImpl.java:275)
at
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResou rce(ResourceSetImpl.java:398)
at
de.fernunihagen.mda.transformator.concrete.model.impl.Defaul tModelLoader.getContent(DefaultModelLoader.java:45)
at
de.fernunihagen.mda.transformator.concrete.impl.DefaultTrans formator.getSourceObjects(DefaultTransformator.java:64)
at
de.fernunihagen.mda.transformator.concrete.impl.DefaultTrans formator.performTransformation(DefaultTransformator.java:82)
at main.Main.main(Main.java:44)
Caused by: java.io.IOException: The path '/test/src/source.transformator'
is unmapped
at
org.eclipse.emf.ecore.resource.impl.URIConverterImpl.createP latformResourceInputStream(URIConverterImpl.java:648)
at
org.eclipse.emf.ecore.resource.impl.URIConverterImpl.createI nputStream(URIConverterImpl.java:538)
at
org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:1152)
at
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLo ad(ResourceSetImpl.java:256)
at
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLo adHelper(ResourceSetImpl.java:271)
... 5 more
ERROR: JDWP Unable to get JNI 1.2 environment, jvm->GetEnv() return code =
-2
JDWP exit error AGENT_ERROR_NO_JNI_ENV(183):
[../../../src/share/back/util.c:820]


Hmm, now what?

Cheers
harkon
Re: M2M Transformation [message #417361 is a reply to message #417352] Thu, 06 March 2008 13:31 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Harkon,

Comments below.

harkon wrote:
> Okay, I now want to use your mentioned changes:
>
> - I get from the selected resource the org.eclipse.emf.common.util.URI
>
> org.eclipse.emf.common.util.URI modelUri =
> org.eclipse.emf.common.util.URI.createPlatformResourceURI(se lectedResource.getFullPath().toString(),
> true);
>
> [I previously used java.net.URI ...]
>
> with the content during debug:
> "platform:/resource/test/src/source.transformator"
>
> - I deliver the file name to the RMI client:
>
> String fileName = sourceModelUri.toPlatformString(true);
>
> with the content during debug:
> "/test/src/source.transformator"
>
> - I use the ResourceSet on the client side to load and I use the file
> name as follows:
> URI uri = URI.createPlatformResourceURI(fileName, true);
>
> with the content during debug:
> "platform:/resource/test/src/source.transformator"
>
> So far the both URI's seem to be identical. But I get the following
> exception:
>
> Exception in thread "main"
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1Diagnos ticWrappedException:
> java.io.IOException: The path '/test/src/source.transformator' is
> unmapped
> at
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.handleDe mandLoadException(ResourceSetImpl.java:316)
>
> at
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLo adHelper(ResourceSetImpl.java:275)
>
> at
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResou rce(ResourceSetImpl.java:398)
>
> at
> de.fernunihagen.mda.transformator.concrete.model.impl.Defaul tModelLoader.getContent(DefaultModelLoader.java:45)
>
> at
> de.fernunihagen.mda.transformator.concrete.impl.DefaultTrans formator.getSourceObjects(DefaultTransformator.java:64)
>
> at
> de.fernunihagen.mda.transformator.concrete.impl.DefaultTrans formator.performTransformation(DefaultTransformator.java:82)
>
> at main.Main.main(Main.java:44)
> Caused by: java.io.IOException: The path
> '/test/src/source.transformator' is unmapped
> at
> org.eclipse.emf.ecore.resource.impl.URIConverterImpl.createP latformResourceInputStream(URIConverterImpl.java:648)
>
> at
> org.eclipse.emf.ecore.resource.impl.URIConverterImpl.createI nputStream(URIConverterImpl.java:538)
>
> at
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:1152)
>
> at
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLo ad(ResourceSetImpl.java:256)
>
> at
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLo adHelper(ResourceSetImpl.java:271)
>
> ... 5 more
> ERROR: JDWP Unable to get JNI 1.2 environment, jvm->GetEnv() return
> code = -2
> JDWP exit error AGENT_ERROR_NO_JNI_ENV(183):
> [../../../src/share/back/util.c:820]
>
>
> Hmm, now what?
As I mentioned in my previous reply, I did understand that the RMI
client wasn't running a workspace and hence needs to access the file
directly via the file URI. It is important for you to keep in mind that
the two ends are using different URIs to access the same underlying
content.

So it's best to ensure you focus on the mystery of where the contents
are being saved and loaded. The URI converter is where input and
output streams are created, so setting breakpoints there to monitor this
activity is a good approach.
>
> Cheers
> harkon
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: M2M Transformation [message #417600 is a reply to message #417361] Mon, 17 March 2008 11:14 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: invone2000.yahoo.de

Okay, solved ;)
But now something else:

I have the reference to the open editor which displays the previously
selected model.
The RMI client changes now the file physically (using dynamic EMF and then
I save the new content...).
What am I supposed to do in order to update the editors view?
I want to call some method on the server like updatedEditor().
But how do I update an already opened file viewd in an editor.
When I press F5 on the file the editor will be updated...

But programatically ???

Cheers
harkon
Re: M2M Transformation [message #417602 is a reply to message #417600] Mon, 17 March 2008 14:13 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Karkon,

Does it change the underlying file such that the file needs to be
reloaded? Or is it directly changing the model displayed by the
editor. I suspect the former, and in that case, it sound like you need
to do a refreshLocal on the IFile(s) being edited.


harkon wrote:
> Okay, solved ;)
> But now something else:
>
> I have the reference to the open editor which displays the previously
> selected model.
> The RMI client changes now the file physically (using dynamic EMF and
> then I save the new content...).
> What am I supposed to do in order to update the editors view?
> I want to call some method on the server like updatedEditor().
> But how do I update an already opened file viewd in an editor.
> When I press F5 on the file the editor will be updated...
>
> But programatically ???
>
> Cheers
> harkon
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Exception is not handled by the provider classes of the generated Edit plugin
Next Topic:EMF Adapters
Goto Forum:
  


Current Time: Fri Apr 26 12:04:36 GMT 2024

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

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

Back to the top