Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » XtextResource to XMI
XtextResource to XMI [message #62859] Wed, 22 July 2009 16:50 Go to next message
Eclipse UserFriend
Originally posted by: panajotes.gmx.de

Hi,

Is there an easy way to serialize an EMF model represented by an
XtestResource to XMI? I really would like to use Xtext in order to describe
my ecore models in a textual way but still store it as XMI (or as a text
file depending on the user). Do I need to write a custom Serializer in order
to achieve that?

Regards,
Thomas.
Re: XtextResource to XMI [message #62885 is a reply to message #62859] Wed, 22 July 2009 19:52 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Thomas,

something like this should work:

XtextResource xtextRes = ...;
XmiResource xmiRes = new XmiResourceFactoryImpl().createResource(..);
xmiRes.getContents().add(xtextRes.getContents().get(0));
xmiRes.save(..);

Hope that helps,
Sebastian

--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 22.07.2009 18:50 Uhr, schrieb Thomas:
> Hi,
>
> Is there an easy way to serialize an EMF model represented by an
> XtestResource to XMI? I really would like to use Xtext in order to
> describe my ecore models in a textual way but still store it as XMI (or
> as a text file depending on the user). Do I need to write a custom
> Serializer in order to achieve that?
>
> Regards,
> Thomas.
Re: XtextResource to XMI [message #62898 is a reply to message #62885] Thu, 23 July 2009 06:15 Go to previous messageGo to next message
Michael  Mühlberg is currently offline Michael MühlbergFriend
Messages: 33
Registered: July 2009
Member
Hello Sebastian,

as far as I understood it, in this case, every graphical information, or,
everything, which is not modelled, like comments, line breaks, spaces, is
not serialized and therefore lost.

Is that correct?

Ciao, Michael



"Sebastian Zarnekow" <Sebastian.Zarnekow@itemis.de> wrote in message
news:h47qlu$k27$2@build.eclipse.org...
> Hi Thomas,
>
> something like this should work:
>
> XtextResource xtextRes = ...;
> XmiResource xmiRes = new XmiResourceFactoryImpl().createResource(..);
> xmiRes.getContents().add(xtextRes.getContents().get(0));
> xmiRes.save(..);
>
> Hope that helps,
> Sebastian
>
> --
> Need professional support for Eclipse Modeling?
> Go visit: http://xtext.itemis.com
>
> Am 22.07.2009 18:50 Uhr, schrieb Thomas:
>> Hi,
>>
>> Is there an easy way to serialize an EMF model represented by an
>> XtestResource to XMI? I really would like to use Xtext in order to
>> describe my ecore models in a textual way but still store it as XMI (or
>> as a text file depending on the user). Do I need to write a custom
>> Serializer in order to achieve that?
>>
>> Regards,
>> Thomas.
Re: XtextResource to XMI [message #62899 is a reply to message #62898] Thu, 23 July 2009 06:33 Go to previous messageGo to next message
Miles Parker is currently offline Miles ParkerFriend
Messages: 1341
Registered: July 2009
Senior Member
You might want to take look at the docs section under hidden terminal
symbols, as well as look at the bits on whitespace. By modifying that
stuff you can make any of these typically ignored tokens semantic and
thus have them included in your model. Of course at some point then you
may as well have your model in plain text. :) But I can see where it
makes sense to do this kind of thing if you want to be able to
reconstruct an entire piece of user code from a well structured
artifact.

hth, Miles

On 2009-07-22 23:15:59 -0700, "Michael Mühlberg"
<michael.muehlberg@sap.com> said:

> Hello Sebastian,
>
> as far as I understood it, in this case, every graphical information, or,
> everything, which is not modelled, like comments, line breaks, spaces, is
> not serialized and therefore lost.
>
> Is that correct?
>
> Ciao, Michael
>
>
>
> "Sebastian Zarnekow" <Sebastian.Zarnekow@itemis.de> wrote in message
> news:h47qlu$k27$2@build.eclipse.org...
>> Hi Thomas,
>>
>> something like this should work:
>>
>> XtextResource xtextRes = ...;
>> XmiResource xmiRes = new XmiResourceFactoryImpl().createResource(..);
>> xmiRes.getContents().add(xtextRes.getContents().get(0));
>> xmiRes.save(..);
>>
>> Hope that helps,
>> Sebastian
>>
>> --
>> Need professional support for Eclipse Modeling?
>> Go visit: http://xtext.itemis.com
>>
>> Am 22.07.2009 18:50 Uhr, schrieb Thomas:
>>> Hi,
>>>
>>> Is there an easy way to serialize an EMF model represented by an
>>> XtestResource to XMI? I really would like to use Xtext in order to
>>> describe my ecore models in a textual way but still store it as XMI (or
>>> as a text file depending on the user). Do I need to write a custom
>>> Serializer in order to achieve that?
>>>
>>> Regards,
>>> Thomas.
Re: XtextResource to XMI [message #62903 is a reply to message #62898] Thu, 23 July 2009 08:27 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Michael,

this is correct. As whitespace and comments are not part of typical
semantic models, they get lost when you serialize your model as XMI.
You may try to serialize the attached node model as xmi to keep all this
information. Have a look at NodeUtil.getNodeAdapter(eObject).

Regards,
Sebastian

--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 23.07.2009 8:15 Uhr, schrieb Michael Mühlberg:
> Hello Sebastian,
>
> as far as I understood it, in this case, every graphical information, or,
> everything, which is not modelled, like comments, line breaks, spaces, is
> not serialized and therefore lost.
>
> Is that correct?
>
> Ciao, Michael
>
>
>
> "Sebastian Zarnekow"<Sebastian.Zarnekow@itemis.de> wrote in message
> news:h47qlu$k27$2@build.eclipse.org...
>> Hi Thomas,
>>
>> something like this should work:
>>
>> XtextResource xtextRes = ...;
>> XmiResource xmiRes = new XmiResourceFactoryImpl().createResource(..);
>> xmiRes.getContents().add(xtextRes.getContents().get(0));
>> xmiRes.save(..);
>>
>> Hope that helps,
>> Sebastian
>>
>> --
>> Need professional support for Eclipse Modeling?
>> Go visit: http://xtext.itemis.com
>>
>> Am 22.07.2009 18:50 Uhr, schrieb Thomas:
>>> Hi,
>>>
>>> Is there an easy way to serialize an EMF model represented by an
>>> XtestResource to XMI? I really would like to use Xtext in order to
>>> describe my ecore models in a textual way but still store it as XMI (or
>>> as a text file depending on the user). Do I need to write a custom
>>> Serializer in order to achieve that?
>>>
>>> Regards,
>>> Thomas.
>
>
Re: XtextResource to XMI [message #62946 is a reply to message #62885] Thu, 23 July 2009 18:24 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: panajotes.gmx.de

Hi,

where do I get the XtextResource instance from? I tried the following in the
UI-plugin but did not succeed:

private XtextResource
getXtextResource(org.eclipse.core.ressources.IResource resource) throws
IOException{
XtextResource xtextRes = new XtextResource();
xtextRes.load(new FileInputStream(resource.getLocation.toFile()), new
HashMap<String,String>());
return xtextRes;
}

The problem is that the parser is not injected into the XtextResource which
results in a NullPointerException in the "doLoad" method.

Do you have a hint for me?

Regards,
Thomas.

"Sebastian Zarnekow" <Sebastian.Zarnekow@itemis.de> wrote in message
news:h47qlu$k27$2@build.eclipse.org...
> Hi Thomas,
>
> something like this should work:
>
> XtextResource xtextRes = ...;
> XmiResource xmiRes = new XmiResourceFactoryImpl().createResource(..);
> xmiRes.getContents().add(xtextRes.getContents().get(0));
> xmiRes.save(..);
>
> Hope that helps,
> Sebastian
>
> --
> Need professional support for Eclipse Modeling?
> Go visit: http://xtext.itemis.com
>
> Am 22.07.2009 18:50 Uhr, schrieb Thomas:
>> Hi,
>>
>> Is there an easy way to serialize an EMF model represented by an
>> XtestResource to XMI? I really would like to use Xtext in order to
>> describe my ecore models in a textual way but still store it as XMI (or
>> as a text file depending on the user). Do I need to write a custom
>> Serializer in order to achieve that?
>>
>> Regards,
>> Thomas.
Re: XtextResource to XMI [message #62948 is a reply to message #62946] Thu, 23 July 2009 19:42 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Thomas,

from the usage of an IResource, I assume you are executing your code
inside of Eclipse. All you need to do to instantiate a resource, is to
create a resource set and use #getResource(URI).

XtextResourceSet set = new XtextResourceSet();
return set.getResource(.., true);

Xtext used EMF and google guice to do some difficult stuff, like
injecting the parser or finding the right resource factory for your file
extension.

Hope that helps,
Sebastian

--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 23.07.2009 20:24 Uhr, schrieb Thomas:
> Hi,
>
> where do I get the XtextResource instance from? I tried the following in
> the UI-plugin but did not succeed:
>
> private XtextResource
> getXtextResource(org.eclipse.core.ressources.IResource resource) throws
> IOException{
> XtextResource xtextRes = new XtextResource();
> xtextRes.load(new FileInputStream(resource.getLocation.toFile()), new
> HashMap<String,String>());
> return xtextRes;
> }
>
> The problem is that the parser is not injected into the XtextResource
> which results in a NullPointerException in the "doLoad" method.
>
> Do you have a hint for me?
>
> Regards,
> Thomas.
>
> "Sebastian Zarnekow" <Sebastian.Zarnekow@itemis.de> wrote in message
> news:h47qlu$k27$2@build.eclipse.org...
>> Hi Thomas,
>>
>> something like this should work:
>>
>> XtextResource xtextRes = ...;
>> XmiResource xmiRes = new XmiResourceFactoryImpl().createResource(..);
>> xmiRes.getContents().add(xtextRes.getContents().get(0));
>> xmiRes.save(..);
>>
>> Hope that helps,
>> Sebastian
>>
>> --
>> Need professional support for Eclipse Modeling?
>> Go visit: http://xtext.itemis.com
>>
>> Am 22.07.2009 18:50 Uhr, schrieb Thomas:
>>> Hi,
>>>
>>> Is there an easy way to serialize an EMF model represented by an
>>> XtestResource to XMI? I really would like to use Xtext in order to
>>> describe my ecore models in a textual way but still store it as XMI (or
>>> as a text file depending on the user). Do I need to write a custom
>>> Serializer in order to achieve that?
>>>
>>> Regards,
>>> Thomas.
>
Re: XtextResource to XMI [message #62988 is a reply to message #62948] Fri, 24 July 2009 13:31 Go to previous message
Eclipse UserFriend
Originally posted by: panajotes.gmx.de

Great, that did the trick.

Thanks,
Thomas.

"Sebastian Zarnekow" <Sebastian.Zarnekow@itemis.de> wrote in message
news:h4aefo$mpa$1@build.eclipse.org...
> Hi Thomas,
>
> from the usage of an IResource, I assume you are executing your code
> inside of Eclipse. All you need to do to instantiate a resource, is to
> create a resource set and use #getResource(URI).
>
> XtextResourceSet set = new XtextResourceSet();
> return set.getResource(.., true);
>
> Xtext used EMF and google guice to do some difficult stuff, like injecting
> the parser or finding the right resource factory for your file extension.
>
> Hope that helps,
> Sebastian
>
> --
> Need professional support for Eclipse Modeling?
> Go visit: http://xtext.itemis.com
>
> Am 23.07.2009 20:24 Uhr, schrieb Thomas:
>> Hi,
>>
>> where do I get the XtextResource instance from? I tried the following in
>> the UI-plugin but did not succeed:
>>
>> private XtextResource
>> getXtextResource(org.eclipse.core.ressources.IResource resource) throws
>> IOException{
>> XtextResource xtextRes = new XtextResource();
>> xtextRes.load(new FileInputStream(resource.getLocation.toFile()), new
>> HashMap<String,String>());
>> return xtextRes;
>> }
>>
>> The problem is that the parser is not injected into the XtextResource
>> which results in a NullPointerException in the "doLoad" method.
>>
>> Do you have a hint for me?
>>
>> Regards,
>> Thomas.
>>
>> "Sebastian Zarnekow" <Sebastian.Zarnekow@itemis.de> wrote in message
>> news:h47qlu$k27$2@build.eclipse.org...
>>> Hi Thomas,
>>>
>>> something like this should work:
>>>
>>> XtextResource xtextRes = ...;
>>> XmiResource xmiRes = new XmiResourceFactoryImpl().createResource(..);
>>> xmiRes.getContents().add(xtextRes.getContents().get(0));
>>> xmiRes.save(..);
>>>
>>> Hope that helps,
>>> Sebastian
>>>
>>> --
>>> Need professional support for Eclipse Modeling?
>>> Go visit: http://xtext.itemis.com
>>>
>>> Am 22.07.2009 18:50 Uhr, schrieb Thomas:
>>>> Hi,
>>>>
>>>> Is there an easy way to serialize an EMF model represented by an
>>>> XtestResource to XMI? I really would like to use Xtext in order to
>>>> describe my ecore models in a textual way but still store it as XMI (or
>>>> as a text file depending on the user). Do I need to write a custom
>>>> Serializer in order to achieve that?
>>>>
>>>> Regards,
>>>> Thomas.
>>
>
>
Previous Topic:Xtext Editor as a standalone application?
Next Topic:Workspace aware epackage registry available for download?
Goto Forum:
  


Current Time: Wed Nov 06 03:13:24 GMT 2024

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

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

Back to the top