Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Can i get an XMI model from a DSL textual file?
icon9.gif  Can i get an XMI model from a DSL textual file? [message #903756] Sat, 25 August 2012 10:32 Go to next message
Georg Treska is currently offline Georg Treska
Messages: 12
Registered: August 2012
Junior Member
Hello everyone,

I m new in XText and I would really need some Answers to the following Questions:

1. How can i get an XMI model from a DSL textual file?
2. How can I do that? (in MWE2 file or somewhere else????)
3. How can I have 2 SEPARATED Files (XMI Model and DSL File) which are always syncronized with oneananother???(meaning if I make a change in one file, this will be automatically reflected to the other)...

I wrote a program which I read the DSL file and generate a new Metamodel instance (xmi) file...That is fine but the problem is that are no syncronized with one-and-another...

Cheers!!
Geo
Re: Can i get an XMI model from a DSL textual file? [message #903757 is a reply to message #903756] Sat, 25 August 2012 10:44 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6130
Registered: July 2009
Senior Member
Hi,

this first thing is an counter question? why do you need an xmi?

for the actual doing

(1) read the model standalone (e.g. as described in the faq)
(2) add the contents of the xtext resource to and xmi resource and save the xmi resource

~Christian
Re: Can i get an XMI model from a DSL textual file? [message #903758 is a reply to message #903757] Sat, 25 August 2012 10:58 Go to previous messageGo to next message
Georg Treska is currently offline Georg Treska
Messages: 12
Registered: August 2012
Junior Member
Hi Christian,

Thanks for the reply....

The purpose of this separation between these 2 Files is: I need 2 views for the same instance, meaning:

Some people like to write TEXT in the Editor (Textual View), and
others like to go to the "Sample Metamodel" View and add things by just
clicking and pressing the "Add" button....

That is exactly why I need 2 seperate Files/Views (1 Textual, 1 Model) and I want them to be syncronized so the user can choose either to write a text or to add items in the model...

What I did was the following:

I added a new class which contains the following source code:

Injector injector = new MyDslStandaloneSetup().createInjectorAndDoEMFRegistration();

XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class);

URI uri = URI.createURI("test.mydsl");
// Resource xtextResource = resourceSet.createResource(uri);
Resource xtextResource = resourceSet.getResource(uri, true);
EcoreUtil.resolveAll(xtextResource);

Resource xmiResource = resourceSet.createResource(URI.createURI("test2.xmi"));
xmiResource.getContents().add(xtextResource.getContents().get(0));
try {
xmiResource.save(null);
} catch (IOException e) {
e.printStackTrace();


And it works just fine when I execute it....

The problem is that in the end I have 2 separate files but NOT SYNCRONIZED WITH ONE-AN-ANOTHER....

Is there any way to have the "same instance" for both files? Or is there any easier
solution which does not require source code..?


Cheers !!!
Georg
Re: Can i get an XMI model from a DSL textual file? [message #903759 is a reply to message #903758] Sat, 25 August 2012 11:08 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6130
Registered: July 2009
Senior Member
Hi,

still the question: why dont you edit the xtext resource from your view?

Re: Can i get an XMI model from a DSL textual file? [message #903761 is a reply to message #903759] Sat, 25 August 2012 11:16 Go to previous messageGo to next message
Georg Treska is currently offline Georg Treska
Messages: 12
Registered: August 2012
Junior Member
Hi Christian

Thanks for the reply,

I dont understand what U mean...

How can I edit the xtext resource from my view?

If you mean open the DSL File with Sample Reflector View, I know I can do that,
my problem is how I can separate this both views? do you know how can I do that?

There isnt any particular reason why I want that, I was just asked from my supervisor to do that because they have another tool which does something similar and they want the same for the new editor which I m developing....

If you know any way how to do that please give me a feedback...

I try to find something in Internet without a success...

Cheers!!!!
Georg
Re: Can i get an XMI model from a DSL textual file? [message #903762 is a reply to message #903761] Sat, 25 August 2012 11:25 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6130
Registered: July 2009
Senior Member
Hi

i am not quite sure what you problem is.
what do you mean with "separate"?

~Christian
Re: Can i get an XMI model from a DSL textual file? [message #903764 is a reply to message #903762] Sat, 25 August 2012 11:49 Go to previous messageGo to next message
Georg Treska is currently offline Georg Treska
Messages: 12
Registered: August 2012
Junior Member
Hi Christian,

Please have a look at the attached picture...

I mean the following:

As you see in the mydsl.png picture We have a normal xtext editor test.mydsl (which we can define components and interfaces and so on)....

Now what I want is to generate an model file out of it: test.xmi (look xmi.png)....

And I want both of them to be syncronized, which means for example:

If I define a new component in test.mydsl, then this component to appear automatically in test.xmi....Or the opposite if I define a new component in test.xmi to be automatically in test.mydsl....

Cheers
Georg
  • Attachment: mydsl.png
    (Size: 27.69KB, Downloaded 68 times)
  • Attachment: xmi.png
    (Size: 21.26KB, Downloaded 71 times)
Re: Can i get an XMI model from a DSL textual file? [message #903765 is a reply to message #903764] Sat, 25 August 2012 12:06 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6130
Registered: July 2009
Senior Member
Hi,

as i said before this is not a valid usecase in my opinion. edit the .mydsl file directly and not the xmi.
Re: Can i get an XMI model from a DSL textual file? [message #903771 is a reply to message #903765] Sat, 25 August 2012 14:35 Go to previous messageGo to next message
Georg Treska is currently offline Georg Treska
Messages: 12
Registered: August 2012
Junior Member
Hi Christian,

Maybe you are right, but the point is I need a solution about this specific problem,

If you or anyone else in this Forum knows anything about this, or can help me with this then I would appreciate it very much!

Best Regards and thank you for Ur help!

Cheers
Georg
Re: Can i get an XMI model from a DSL textual file? [message #903847 is a reply to message #903771] Sun, 26 August 2012 07:34 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25918
Registered: July 2009
Senior Member
Georg,

It's certainly possible to have EMF's tree view populated directly from
the model you parse out of a Xtext serialization. After all, that's
exactly what the reflective editor is doing. The "standard" EMF
properties view can also be supported from that or directly from
selections in source mapped to the model element. As an example, the
Xcore editor supports the exactly properties view you normally get in
EMF's Generator editor and I've written some infrastructure so that when
a command is executed to modify a property value, I convert the result
to annotations in the Xcore source. In your case, if you're directly
editing the model instance derived from the source, you could use the
Xtext serializer to update the source view from the modified serialized
model instance. You definitely don't need and should avoid having two
different serializations of the same model. Best you support direct
model-based editing of the in-memory instance you read from an Xtext
serialization and serialize those changes back to an Xtext
representation to update the source view. Of course this isn't entirely
a trivial exercise but you could have a look at Xcore editor to see how
we do something somewhat similar there. Setting up an EMF command stack
and using a listener as a prompt for updating the source view is the key
idea.

Of course it's not clear if just having an outline view that looks like
EMF's tree view is your goal. That should be possible just by
specializing the outline view.


On 25/08/2012 8:35 PM, Georg Treska wrote:
> Hi Christian,
>
> Maybe you are right, but the point is I need a solution about this
> specific problem,
>
> If you or anyone else in this Forum knows anything about this, or can
> help me with this then I would appreciate it very much!
>
> Best Regards and thank you for Ur help!
>
> Cheers
> Georg
Re: Can i get an XMI model from a DSL textual file? [message #905350 is a reply to message #903847] Thu, 30 August 2012 04:08 Go to previous messageGo to next message
Michael Vorburger is currently offline Michael Vorburger
Messages: 62
Registered: July 2009
Member
FYI: My blog2.vorburger.ch/2012/07/xtext-xml.html is somewhat related to this discussion, although for a quite different use case.

If you don't actually need any "physical" XML, then a much better road is certainly what Ed is describing.
Re: Can i get an XMI model from a DSL textual file? [message #905545 is a reply to message #905350] Thu, 30 August 2012 11:45 Go to previous messageGo to next message
Georg Treska is currently offline Georg Treska
Messages: 12
Registered: August 2012
Junior Member
Hi Michael,

Thank you very much for your reply,
I think your solution is more near to what I want to achieve,

I will have a deeper look soon!

And I will come back to you very soon....

Cheers
Georg
Re: Can i get an XMI model from a DSL textual file? [message #905549 is a reply to message #905545] Thu, 30 August 2012 11:52 Go to previous messageGo to next message
Michael Vorburger is currently offline Michael Vorburger
Messages: 62
Registered: July 2009
Member
Georg, just to be crystal clear: Depending on what you are actually trying to achieve, i.e. do you just want to have two editors in the IDE synchronized on the same model VS. if you actually have a real need for an external XMI/XML file, my approach may not be the most suitable for your need.
Re: Can i get an XMI model from a DSL textual file? [message #905551 is a reply to message #905549] Thu, 30 August 2012 11:58 Go to previous messageGo to next message
Georg Treska is currently offline Georg Treska
Messages: 12
Registered: August 2012
Junior Member
Hi Michael,

As you mentioned I need to have 2 editors in the IDE synchronized, thats exactly my goal...

I think your solution should be exactly what I want to achieve...

Thank you very much for your help, I very appreciate it!

Cheers
Georg
Re: Can i get an XMI model from a DSL textual file? [message #906035 is a reply to message #905350] Fri, 31 August 2012 09:51 Go to previous messageGo to next message
Georg Treska is currently offline Georg Treska
Messages: 12
Registered: August 2012
Junior Member
HI Michael,

I m looking at your sample project now, and I wanted to ask
if you have any simpler project that I can start with, I would really appreciate your help...

I just generated my own XText Project, and I would like to know how can I integrate parts from your project into mine...


Cheers
Georg
Re: Can i get an XMI model from a DSL textual file? [message #906036 is a reply to message #906035] Fri, 31 August 2012 09:53 Go to previous messageGo to next message
Michael Vorburger is currently offline Michael Vorburger
Messages: 62
Registered: July 2009
Member
Georg unfortunately that example is as simple as it gets - I don't have anything simpler.
Re: Can i get an XMI model from a DSL textual file? [message #906038 is a reply to message #906036] Fri, 31 August 2012 09:55 Go to previous message
Georg Treska is currently offline Georg Treska
Messages: 12
Registered: August 2012
Junior Member
Hi Michael,

no problem I will have a look,

thanks for your effort!

Cheers
Georg
Previous Topic:errors from 2.3.1
Next Topic:Content assist for qualifiedName as exists for ID
Goto Forum:
  


Current Time: Fri Jul 25 06:39:10 EDT 2014

Powered by FUDForum. Page generated in 0.03403 seconds