Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [Persistence] Customize Resource Persistence(Customize the implementation of resource management to have my own persistence way)
[Persistence] Customize Resource Persistence [message #658933] Thu, 10 March 2011 13:48 Go to next message
Antoine  is currently offline Antoine Friend
Messages: 22
Registered: February 2011
Location: Toulouse, France
Junior Member
Hello everybody !

I'm developping a Metamodel EMF and I generated ModelCode, Edit and Editor to populate a model with imported data (ModelCode) and display this model with the Editor.

To have a default persistence, I used the method that is in the EMF book Second Edition, i.e. :

[...]
ResourceSet resourceSet = new ResourceSetImpl();
URI fileURI = URI.createPlatformResourceURI(myIFile.getFullPath().toString(), true);
Resource resource = resourceSet.createResource(fileURI);
[...]
populateModel(rootObject);
resource.getContents().add(rootObject);
[...]
Map<Object, Object> options = new HashMap<Object, Object>();
resource.save(options);


This works fine and I can open an Editor (the basic one generated by EMF). But I want to have another persistence way, I want to customize this mechanism to create a persistence in an Excel File for example, or a simple text file. I read the chapter of the EMF Book Second Edition concerning that but I haven't any idea of where I have to start to customize the model persistence.

If anybody knows how to do this, thank you for helping me !!!

Antoine
Re: [Persistence] Customize Resource Persistence [message #658934 is a reply to message #658933] Thu, 10 March 2011 14:01 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Antoine,

Comments below.

Antoine wrote:
> Hello everybody !
>
> I'm developping a Metamodel EMF and I generated ModelCode, Edit and
> Editor to populate a model with imported data (ModelCode) and display
> this model with the Editor.
>
> To have a default persistence, I used the method that is in the EMF
> book Second Edition, i.e. :
>
>
> [...]
> ResourceSet resourceSet = new ResourceSetImpl();
> URI fileURI =
> URI.createPlatformResourceURI(myIFile.getFullPath().toString (), true);
> Resource resource = resourceSet.createResource(fileURI);
> [...]
> populateModel(rootObject);
> resource.getContents().add(rootObject);
> [...]
> Map<Object, Object> options = new HashMap<Object, Object>();
> resource.save(options);
>
>
> This works fine and I can open an Editor (the basic one generated by
> EMF). But I want to have another persistence way, I want to customize
> this mechanism to create a persistence in an Excel File for example,
> or a simple text file.
Likely the Xtext project would help with this. You'd be able to specify
the grammar and it would be able to read and write instances conforming
to that grammar.
> I read the chapter of the EMF Book Second Edition concerning that but
> I haven't any idea of where I have to start to customize the model
> persistence.
It's "as simple as" specializing ResourceImpl.doSave/doLoad. Look at
BinaryResourceImpl as a simpler example than XMLResourceImpl.
>
> If anybody knows how to do this, thank you for helping me !!!
>
> Antoine
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [Persistence] Customize Resource Persistence [message #659144 is a reply to message #658933] Fri, 11 March 2011 09:30 Go to previous messageGo to next message
Antoine  is currently offline Antoine Friend
Messages: 22
Registered: February 2011
Location: Toulouse, France
Junior Member
Hello Ed,

I tried that you say, I think I understand how we can do that. But now, to create my OwnResourceImpl, I can't use the ResourceSetImpl because it returns an XMIResourceImpl that I can't cast into OwnResourceImpl...

So I'm afraid that I will not able to use all the EMF mechanism, i.e. in my case I must "bypass" the ResourceSet...

Did I have to create a class that extends ResourceSetImpl to be able to use this mechanism ?

Thank you for answering,

Regards,

Antoine

PS : sorry for my english, I'm french !
Re: [Persistence] Customize Resource Persistence [message #659220 is a reply to message #659144] Fri, 11 March 2011 14:48 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Antoine,

Comments below.

Antoine wrote:
> Hello Ed,
>
> I tried that you say, I think I understand how we can do that. But
> now, to create my OwnResourceImpl, I can't use the ResourceSetImpl
> because it returns an XMIResourceImpl that I can't cast into
> OwnResourceImpl...
>
> So I'm afraid that I will not able to use all the EMF mechanism, i.e.
> in my case I must "bypass" the ResourceSet...
>
> Did I have to create a class that extends ResourceSetImpl to be able
> to use this mechanism ?
No, you can register a resource factory for creating your type of
resource. The easiest is to do so by extension. The XMI plugins
contain these (where '"*" is why you're seeing the default you're seeing).

<extension point="org.eclipse.emf.ecore.extension_parser">
<parser type="*"
class="org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl " />
</extension>

<extension point="org.eclipse.emf.ecore.extension_parser">
<parser type="ecore"
class="org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl " />
</extension>

>
> Thank you for answering,
>
> Regards,
>
> Antoine
>
> PS : sorry for my english, I'm french !


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [Persistence] Customize Resource Persistence [message #659775 is a reply to message #658933] Tue, 15 March 2011 14:46 Go to previous messageGo to next message
Antoine  is currently offline Antoine Friend
Messages: 22
Registered: February 2011
Location: Toulouse, France
Junior Member
Hello Ed and thank you for your answer !

As you say, I tried to understand how works BinaryResourceImpl and I write my OwnResourceImpl like this. This seems to work because he write data like I want but when I try to open the file with my editor I have an exception :
com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 2 of 2-byte UTF-8 sequence.
[...]


To be sure, I tested directly with a BinaryResourceImpl and the doSave works but I can't open it with the editor because of the same exception...
I'm not sure that I understand fine but I thought that model and his persistence was disinct... I mean that I can show my model in the editor (the one generated by EMF) and have another persistence than XMI...

Am I right ?
How can I open it with the editor ?

Thank you for answering,

Regards,

Antoine
Re: [Persistence] Customize Resource Persistence [message #659790 is a reply to message #659775] Tue, 15 March 2011 15:40 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Antoine,

Comments below.

Antoine wrote:
> Hello Ed and thank you for your answer !
>
> As you say, I tried to understand how works BinaryResourceImpl and I
> write my OwnResourceImpl like this. This seems to work because he
> write data like I want but when I try to open the file with my editor
> I have an exception :
> com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequ enceException:
> Invalid byte 2 of 2-byte UTF-8 sequence.
> [...]
Certainly a binary resource's output, as the name implies is binary. It
can't be edited or view with a text editor and will definitely make an
XML parser puke.
>
> To be sure, I tested directly with a BinaryResourceImpl and the doSave
> works but I can't open it with the editor because of the same
> exception...
I'd expect that yes.
> I'm not sure that I understand fine but I thought that model and his
> persistence was disinct... I mean that I can show my model in the
> editor (the one generated by EMF) and have another persistence than
> XMI...
>
> Am I right ?
A textual serialization like XMI is intended to be editable in a text
editor. But editing binary is like trying to edit a zip file with a
text editor; it's meaningless noise.
> How can I open it with the editor ?
With a binary resource, as an example, you could only show a structural
view of the EMF objects you load from the resource. I.e., the generated
editor would work fine because it will write binary and read that same
binary back in again. Just don't try to view it with a text editor.
>
> Thank you for answering,
>
> Regards,
>
> Antoine


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [Persistence] Customize Resource Persistence [message #659794 is a reply to message #658933] Tue, 15 March 2011 15:59 Go to previous messageGo to next message
Antoine  is currently offline Antoine Friend
Messages: 22
Registered: February 2011
Location: Toulouse, France
Junior Member
But I don't speak about a text editor, I speak about the EMF Editor, generated from my MetaModel... Even with this editor, it doesn't works...

My question is: can we have in the same time
- another persistence than XMI (or XML) for example Binary, or anything that we can imagine,
- and the "Model view" with the objects of my model (consistent with my Metamodel) that I can see in my EMF Editor, that you named: "a structural
view of the EMF objects" I think

For your understanding, my problematic is:
- I have a formatted Excel file, wrote with our convention
- I want to have a model view of this file, so I can import it, by creating objects of my EMF factory... all this is ok
- But I lost my Excel organisation, I have a physic XMI file now...
- But I would have both : Excel physic file, and a model view of this file... So with an appropriate doLoad and doSave, I hope I can do this...

Sorry, I don't know this part of EMF because before I always use the default ResourceImpl...

[Updated on: Tue, 15 March 2011 16:18]

Report message to a moderator

Re: [Persistence] Customize Resource Persistence [message #659806 is a reply to message #659794] Tue, 15 March 2011 16:20 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Antoine,

Comments below.

Antoine wrote:
> But I don't speak about a text editor, I speak about the EMF Editor,
> generated from my MetaModel...
You didn't show much of a stack trace, though it seems clear you're
trying to parse XML which makes no sense if you're producing binary.
> This editor is a tree editor of objects in the model.
> My question is: can we have in the same time
> - another persistence than XMI (or XML) for example Binary, or
> anything that we can imagine,
I answered that already; specialize doLoad and doSave.
> - and the "Model view" with the objects of my model (consistent with
> my Metamodel) that I can see in my EMF Editor.
>
> For your understanding, my problematic is:
> - I have a formatted Excel file, write with our convention
So you'll need something that reads and writes that format.
> - I want to have a model view of this file, so I can import it, by
> creating objects of my EMF factory... all this is ok
> - But I lost my Excel organisation, I have a physic XMI file now...
Which resource implementation did you specialize? You've specialized
both doSave and doLoad?
> - But I would have both : Excel physic file, and a model view of this
> file... So with an appropriate doLoad and doSave, I hope I can do this...
Yes.
>
> Sorry, I don't know this part of EMF because before I always use the
> default ResourceImpl...
That's all you need.


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Shared Editing Domain
Next Topic:[CDO] Win7 DbStore starts OK but CDO Explorer cannot connect
Goto Forum:
  


Current Time: Thu Mar 28 13:30:04 GMT 2024

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

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

Back to the top