Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » Load EMF model from memory
Load EMF model from memory [message #87149] Fri, 22 June 2007 17:55 Go to next message
Eclipse UserFriend
Originally posted by: dkrebs.tibco.com

Hi,
I've been looking at the tests plugin that is generated as an example of
how to load/unload emf models, these examples are loading/saving the files
to a location on the file system. I have an application that wants to
load/save emf models as strings in a database. So what I have is a string
of the model in memory and want to load the root EObject from that. I'm
getting hungup on what to supply as the URI when trying to use the example
code in the tests plugin, can anyone point me in the right direction?
Re: Load EMF model from memory [message #87185 is a reply to message #87149] Fri, 22 June 2007 19:15 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

This is a multi-part message in MIME format.
--------------050301020306060000080506
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Duncan,

Here's a generic example that saves to a StringWriter and then loads a
new resource from that string:

Resource resource =
resourceSet.createResource(URI.createURI("http:///My.library"));
DocumentRoot documentRoot =
LibraryFactory.eINSTANCE.createDocumentRoot();
EObject root = EcoreFactory.eINSTANCE.createEObject();
documentRoot.setA(root);
resource.getContents().add(documentRoot);
resource.save(System.out, null);

StringWriter out = new StringWriter();
resource.save(new URIConverter.WriteableOutputStream(out,
"UTF-8"), null);

Resource resource2 =
resourceSet.createResource(URI.createURI("*.library"));
resource2.load(new
URIConverter.ReadableInputStream(out.toString()), null);
resource2.save(System.err, null);

None of the URIs really matter in this type of scenario, except in so
far as they are used to create the right type of resource based on the
file extension. If you want to cast to XMLResource, there are APIs that
directly work with StringWriter or an InputSource that can wrap as
StringReader. Please ask general EMF questions in the EMF newsgroup in
the future.


Duncan Krebs wrote:
> Hi, I've been looking at the tests plugin that is generated as an
> example of how to load/unload emf models, these examples are
> loading/saving the files to a location on the file system. I have an
> application that wants to load/save emf models as strings in a
> database. So what I have is a string of the model in memory and want
> to load the root EObject from that. I'm getting hungup on what to
> supply as the URI when trying to use the example code in the tests
> plugin, can anyone point me in the right direction?


--------------050301020306060000080506
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">
Duncan,<br>
<br>
Here's a generic example that saves to a StringWriter and then loads a
new resource from that string:<br>
<small><br>
Re: Load EMF model from memory [message #87214 is a reply to message #87185] Fri, 22 June 2007 20:31 Go to previous message
Eclipse UserFriend
Originally posted by: dkrebs.tibco.com

Ed,
Sorry for posting in this newsgroup, as always thanks so much for the
help. - Duncan
Re: Load EMF model from memory [message #608577 is a reply to message #87149] Fri, 22 June 2007 19:15 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------050301020306060000080506
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Duncan,

Here's a generic example that saves to a StringWriter and then loads a
new resource from that string:

Resource resource =
resourceSet.createResource(URI.createURI("http:///My.library"));
DocumentRoot documentRoot =
LibraryFactory.eINSTANCE.createDocumentRoot();
EObject root = EcoreFactory.eINSTANCE.createEObject();
documentRoot.setA(root);
resource.getContents().add(documentRoot);
resource.save(System.out, null);

StringWriter out = new StringWriter();
resource.save(new URIConverter.WriteableOutputStream(out,
"UTF-8"), null);

Resource resource2 =
resourceSet.createResource(URI.createURI("*.library"));
resource2.load(new
URIConverter.ReadableInputStream(out.toString()), null);
resource2.save(System.err, null);

None of the URIs really matter in this type of scenario, except in so
far as they are used to create the right type of resource based on the
file extension. If you want to cast to XMLResource, there are APIs that
directly work with StringWriter or an InputSource that can wrap as
StringReader. Please ask general EMF questions in the EMF newsgroup in
the future.


Duncan Krebs wrote:
> Hi, I've been looking at the tests plugin that is generated as an
> example of how to load/unload emf models, these examples are
> loading/saving the files to a location on the file system. I have an
> application that wants to load/save emf models as strings in a
> database. So what I have is a string of the model in memory and want
> to load the root EObject from that. I'm getting hungup on what to
> supply as the URI when trying to use the example code in the tests
> plugin, can anyone point me in the right direction?


--------------050301020306060000080506
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">
Duncan,<br>
<br>
Here's a generic example that saves to a StringWriter and then loads a
new resource from that string:<br>
<small><br>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Load EMF model from memory [message #608579 is a reply to message #87185] Fri, 22 June 2007 20:31 Go to previous message
Duncan Krebs is currently offline Duncan KrebsFriend
Messages: 79
Registered: July 2009
Member
Ed,
Sorry for posting in this newsgroup, as always thanks so much for the
help. - Duncan
Previous Topic:Undo of RecordingCommand is done in a strange order...
Next Topic:CDO=R(DB)CP ?
Goto Forum:
  


Current Time: Fri Apr 26 15:43:17 GMT 2024

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

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

Back to the top