Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Using xText with existing model and Resource
Using xText with existing model and Resource [message #994066] Wed, 26 December 2012 09:48 Go to next message
Ashwani Kr Sharma is currently offline Ashwani Kr SharmaFriend
Messages: 118
Registered: July 2009
Location: Bangalore, India
Senior Member

Hi,

I want to use xText in following scenario:

I have existing EMF models which are persisted to a local file (using Resource) (as xml)
sfs (semantic file system) takes that content to a backend using REST and handled on backend using ResourceHandlers.

I am targeting to create a DSL for the EMF Model but finally wants to push content into xml only.
This also means that i can read existing xml in DSL format.

How should i approach this ?

I went through xText documentation but still don't know how to read xmi into DSL format and save DSL format to xmi.
I also referred to http://blog.efftinge.de/2009/11/xtext-using-existing-ecore-models.html but wasn't able to make it work.
I try to load an existing xmi file using the DSL editor, it shows xmi itself with keywords in my grammer highlighted and i try to save the DSL content and open using some Sample Ecore Editor, i get errors.

Regards,
Ashwani Kr Sharma

[Updated on: Wed, 26 December 2012 09:59]

Report message to a moderator

Re: Using xText with existing model and Resource [message #994219 is a reply to message #994066] Wed, 26 December 2012 19:09 Go to previous messageGo to next message
Al B is currently offline Al BFriend
Messages: 45
Registered: June 2012
Member
Ashwani,

Did you use the Ecore2Xtext wizard to create the DSL from your ecore model?

New -> Xtext -> Xtext Project From Existing Ecore Models

http://vimeo.com/10579056

Regarding saving the DSL format into xmi, Xtext provides an implementation of EMF's resource called the XtextResource. You can find more details in page 101 of the Xtext User Guide document.

http://www.eclipse.org/Xtext/documentation/2.3.0/Documentation.pdf

HTH,
-AJ
Re: Using xText with existing model and Resource [message #994350 is a reply to message #994219] Thu, 27 December 2012 04:16 Go to previous messageGo to next message
Ashwani Kr Sharma is currently offline Ashwani Kr SharmaFriend
Messages: 118
Registered: July 2009
Location: Bangalore, India
Senior Member

Thanks AJ.

I have gone through these links. I am able to generated my grammar generated from Ecore model (using the wizard). Though i have to still edit the grammar to meet my requirements.
I read through XTextResource documentation also. I expected that i can hook into the generated editor code and do something to serialize DSL into xmi. But i am not able to figure out where to start.
Also my target is to read the xmi files serialized by other XMLResource and present it in the DSL form according to my grammer.

Quote:
Updating comment to specify the requirement more clearly:
I have existing editors that persist values into XML format. I can't change the persistency format. I want to provide alternate dsl editor for the existing use cases. The existing XML have to be read as dsl format and content from dsl editor have to be persisted into XML format.


Are you aware of any code snippet\example which showcases this ?

Regards,
Ashwani Kr Sharma

[Updated on: Thu, 27 December 2012 14:58]

Report message to a moderator

Re: Using xText with existing model and Resource [message #995610 is a reply to message #994350] Sun, 30 December 2012 17:03 Go to previous messageGo to next message
Ashwani Kr Sharma is currently offline Ashwani Kr SharmaFriend
Messages: 118
Registered: July 2009
Location: Bangalore, India
Senior Member

Hi,

I currently found a way that i will load the xmi of existing model (using XMIResource) and take the EOBject and move it to another XTextResource. If i save XTextResource it persists it as DSL format. Now on each save of XTextResource i have to sync its content to the xmi file.

I have no option to create another file for DSL format and keep its content in sync with xmi format.

What do you guys feel about this approach ?

Regards,
Ashwani Kr Sharma
Re: Using xText with existing model and Resource [message #995916 is a reply to message #995610] Mon, 31 December 2012 14:03 Go to previous message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2501
Registered: July 2009
Senior Member
On 2012-30-12 18:03, Ashwani Kr Sharma wrote:
> Hi,
>
> I currently found a way that i will load the xmi of existing model
> (using XMIResource) and take the EOBject and move it to another
> XTextResource. If i save XTextResource it persists it as DSL format. Now
> on each save of XTextResource i have to sync its content to the xmi file.
>
> I have no option to create another file for DSL format and keep its
> content in sync with xmi format.
>
> What do you guys feel about this approach ?
> Regards,
> Ashwani Kr Sharma

That approach works.
You can use the builder framework and "build" the XMI version from the
DSL version. What you want to do depends on how you want to handle
conflicts - both files edited etc. Or if you want to make the DSL the
master if one exists and always overwrite the XMI.

With the builder framework you do not have to keep track of resources as
they change (there are many ways resources can change besides saving it
in an editor).

Hope that helps.
Regards
- henrik
Previous Topic:Captured feature values for Case Insensitive Keywords are not Case Insensitive during serialization
Next Topic:Check nature of XExpression
Goto Forum:
  


Current Time: Fri Dec 19 03:21:19 GMT 2014

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

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