Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Save model from GEF-App with EMF
Save model from GEF-App with EMF [message #536628] Sat, 29 May 2010 00:50 Go to next message
jojo  is currently offline jojo Friend
Messages: 2
Registered: May 2010
Junior Member
Hello Forum-users,

i have question on how to save my model generated by an GEF-app with the use of EMF.

What i have right now, is a simple GEF-editor which generates me a model-structure with one "central" object, lets call it "myModel" which holds everything together.

Now i want to save this model with the help of EMF. I already implemented a save function in this way.

Here is the snippet which saves the data to a file (seems to be standard in GEF)

InputStream stream = openContentStream(myModel);
			if (file.exists()) {
				file.setContents(stream, true, true, m);
			} else {
				file.create(stream, true, m);
			}
			stream.close();


and i have a function which creates me an EMF ressource and shall return an InputStream

private InputStream openContentStream(Map myModel) {

Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
java.util.Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("Map", new XMIResourceFactoryImpl());
		
// Obtain a new resource set
ResourceSet resSet = new ResourceSetImpl();

// Create a resource
Resource resource = resSet.createResource(URI.createURI("Map"));
// add the map to the ressource 
resource.getContents().add(myModel);

return ...;
}


So far everything works fine and i get no errors, BUT how do i transfer the ressource into an InputStream which i then can write to a file??

Hopefully somebody can help me.

Kind regards and thanks for your time

Jojo
Re: Save model from GEF-App with EMF [message #536658 is a reply to message #536628] Sat, 29 May 2010 12:37 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------050704010503090604090304
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Jojo,

Try generating the EMF editor to see how it loads and saves. You really
shouldn't be changing the global registry when running an Eclipse
application because you'll mess up other applications. Also look at the
FAQ:

2.44 How do I map between an EMF Resource and an Eclipse IFile?
< http://wiki.eclipse.org/index.php/EMF/FAQ#How_do_I_map_betwe en_an_EMF_Resource_and_an_Eclipse_IFile.3F>


jojo wrote:
> Hello Forum-users,
>
> i have question on how to save my model generated by an GEF-app with
> the use of EMF.
>
> What i have right now, is a simple GEF-editor which generates me a
> model-structure with one "central" object, lets call it "myModel"
> which holds everything together.
>
> Now i want to save this model with the help of EMF. I already
> implemented a save function in this way.
>
> Here is the snippet which saves the data to a file (seems to be
> standard in GEF)
>
>
> InputStream stream = openContentStream(myModel);
> if (file.exists()) {
> file.setContents(stream, true, true, m);
> } else {
> file.create(stream, true, m);
> }
> stream.close();
>
>
> and i have a function which creates me an EMF ressource and shall
> return an InputStream
>
>
> private InputStream openContentStream(Map myModel) {
>
> Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
> java.util.Map<String, Object> m = reg.getExtensionToFactoryMap();
> m.put("Map", new XMIResourceFactoryImpl());
>
> // Obtain a new resource set
> ResourceSet resSet = new ResourceSetImpl();
>
> // Create a resource
> Resource resource = resSet.createResource(URI.createURI("Map"));
> // add the map to the ressource resource.getContents().add(myModel);
>
> return ...;
> }
>
>
> So far everything works fine and i get no errors, BUT how do i
> transfer the ressource into an InputStream which i then can write to a
> file??
>
> Hopefully somebody can help me.
>
> Kind regards and thanks for your time
>
> Jojo

--------------050704010503090604090304
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Jojo,<br>
<br>
Try generating the EMF editor to see how it loads and saves.  You
really shouldn't be changing the global registry when running an
Eclipse application because you'll mess up other applications.  Also
look at the FAQ:<br>
<blockquote><a
href=" http://wiki.eclipse.org/index.php/EMF/FAQ#How_do_I_map_betwe en_an_EMF_Resource_and_an_Eclipse_IFile.3F"><span
class="tocnumber">2.44</span> <span class="toctext">How do I map
between an EMF Resource and an Eclipse IFile?</span></a><br>
</blockquote>
<br>
jojo wrote:
<blockquote cite="mid:htpoct$pbg$1@build.eclipse.org" type="cite">Hello
Forum-users,
<br>
<br>
i have question on how to save my model generated by an GEF-app with
the use of EMF.
<br>
<br>
What i have right now, is a simple GEF-editor which generates me a
model-structure with one "central" object, lets call it "myModel" which
holds everything together.
<br>
<br>
Now i want to save this model with the help of EMF. I already
implemented a save function in this way.
<br>
<br>
Here is the snippet which saves the data to a file (seems to be
standard in GEF)
<br>
<br>
<br>
InputStream stream = openContentStream(myModel);
<br>
            if (file.exists()) {
<br>
                file.setContents(stream, true, true, m);
<br>
            } else {
<br>
                file.create(stream, true, m);
<br>
            }
<br>
            stream.close();
<br>
<br>
<br>
and i have a function which creates me an EMF ressource and shall
return an InputStream
<br>
<br>
<br>
private InputStream openContentStream(Map myModel) {
<br>
<br>
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
<br>
java.util.Map&lt;String, Object&gt; m = reg.getExtensionToFactoryMap();
<br>
m.put("Map", new XMIResourceFactoryImpl());
<br>
        <br>
// Obtain a new resource set
<br>
ResourceSet resSet = new ResourceSetImpl();
<br>
<br>
// Create a resource
<br>
Resource resource = resSet.createResource(URI.createURI("Map"));
<br>
// add the map to the ressource resource.getContents().add(myModel);
<br>
<br>
return ...;
<br>
}
<br>
<br>
<br>
So far everything works fine and i get no errors, BUT how do i transfer
the ressource into an InputStream which i then can write to a file??
<br>
<br>
Hopefully somebody can help me.
<br>
<br>
Kind regards and thanks for your time
<br>
<br>
Jojo
<br>
</blockquote>
</body>
</html>

--------------050704010503090604090304--


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:[Teneo] Composite key in dynamic EMF model
Next Topic:Checks for Generic EMF Form Editor using Xtend in combination with Java method
Goto Forum:
  


Current Time: Thu Apr 18 13:40:38 GMT 2024

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

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

Back to the top