Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Ecore file from Xtext instance Models(How to obtain an ecore file from Xtext Instance models)
Ecore file from Xtext instance Models [message #1263480] Tue, 04 March 2014 14:20 Go to next message
Salome Maro is currently offline Salome MaroFriend
Messages: 15
Registered: January 2014
Junior Member
Hi,

I have an xtext grammar that works fine and I can create an instance model from it. Now I would like to get an ecore version of this instance model. How can I do that? The model can be opened using the eclipse sample reflective ecore model editor and displays a tree view, but when trying to use this model in other transformations it gives an error "org.eclipse.emf.ecore.xmi.XMIException: org.xml.sax.SAXParseException: Content is not allowed in prolog."

Does someone know how to do this?

Embarrassed
regards,

Salome
Re: Ecore file from Xtext instance Models [message #1263565 is a reply to message #1263480] Tue, 04 March 2014 15:50 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

i thinks your "other transformation tools" are not build that well.
never the less you could try to read the model and serialize it as xmi.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Ecore file from Xtext instance Models [message #1263609 is a reply to message #1263480] Tue, 04 March 2014 16:31 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Your terminology is either very vague of you're doing something stupid.
And since we have no clue what transformation tool you use or what an
instance model of an Xtext grammar is and how that could possibly be
Ecore, who knows?

"Content is not allowed in prolog" always means that your input is not
being interpreted as XML.

Regards

Ed Willink

On 04/03/2014 14:20, Salome Maro wrote:
> Hi,
>
> I have an xtext grammar that works fine and I can create an instance
> model from it. Now I would like to get an ecore version of this
> instance model. How can I do that? The model can be opened using the
> eclipse sample reflective ecore model editor and displays a tree view,
> but when trying to use this model in other transformations it gives an
> error "org.eclipse.emf.ecore.xmi.XMIException:
> org.xml.sax.SAXParseException: Content is not allowed in prolog."
>
> Does someone know how to do this?
>
> :blush: regards,
>
> Salome
Re: Ecore file from Xtext instance Models [message #1264459 is a reply to message #1263609] Wed, 05 March 2014 08:37 Go to previous messageGo to next message
Salome Maro is currently offline Salome MaroFriend
Messages: 15
Registered: January 2014
Junior Member
I realized the error means that the model is not an xmi model. I am using ATL for transformation and my instance model made from Xtext is my source model.(sorry for being vague earlier).

@ Christian, you are right that I need to read the model and serialize it but at the moment I don't know how to do that, can you give me some pointers please? A link to reading material will be highly appreciated.

Thanks,

Salome
Re: Ecore file from Xtext instance Models [message #1264547 is a reply to message #1264459] Wed, 05 March 2014 10:01 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

i thought there where already 100 threads on that topic, never the less following standlone code may help

	public static void main(String[] args) throws IOException {
		Injector injector = new MyDslStandaloneSetup().createInjectorAndDoEMFRegistration();
		ResourceSet rs = injector.getInstance(ResourceSet.class);
		Resource r1 = rs.getResource(URI.createURI("test.mydsl"), true);
		r1.load(null);
		Resource r2 = rs.createResource(URI.createURI("test.xmi"));
		r2.getContents().add(r1.getContents().get(0));
		r2.save(null);

	}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Ecore file from Xtext instance Models [message #1265810 is a reply to message #1264547] Thu, 06 March 2014 15:41 Go to previous messageGo to next message
Salome Maro is currently offline Salome MaroFriend
Messages: 15
Registered: January 2014
Junior Member
Hi Christian,

Thanks, the code works and I get the resulting xmi. However when I open it, it has gives this error "Package with uri 'http://www.xtext.org/example/mydsl1/MyDsl' not found. (platform:/resource/org.xtext.example.mydsl1/test.xmi, 2, 194)"

When I check the project for the path given is correct but I don't know why it cannot be found.

Also I have a problem if I use the code in an Xtext project where the ecore is imported, i get an error "Unresolved proxy. Make sure the EPackage has been registered. I tried registering the package with the code below in MyDslStandaloneSetup.java but the error still persists.
Any ideas on how to properly do an EMF registration for models that are imported and not auto generated by Xtext? (sorry if this is too basic, I am new to Xtext and spent the whole day searching but no solution worked)

@override
public Injector createInjectorAndDoEMFRegistration() {
myPackagePackageImpl.init();
return super.createInjectorAndDoEMFRegistration();

}
Re: Ecore file from Xtext instance Models [message #1265812 is a reply to message #1265810] Thu, 06 March 2014 15:45 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

sorry i have no idea what you are doing. if you import an existing ecore you have to care for registration yourself. have a look what xtext generated if it uses a derived metamodel


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Ecore file from Xtext instance Models [message #1265815 is a reply to message #1265812] Thu, 06 March 2014 15:47 Go to previous messageGo to next message
Salome Maro is currently offline Salome MaroFriend
Messages: 15
Registered: January 2014
Junior Member
Thanks! I will do that
Re: Ecore file from Xtext instance Models [message #1265855 is a reply to message #1265810] Thu, 06 March 2014 16:48 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
---

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Thu, 06 March 2014 17:27]

Report message to a moderator

Re: Ecore file from Xtext instance Models [message #1710122 is a reply to message #1264547] Sun, 04 October 2015 18:10 Go to previous messageGo to next message
farah Mising name is currently offline farah Mising nameFriend
Messages: 58
Registered: July 2009
Member
No Message Body

[Updated on: Sun, 04 October 2015 19:04]

Report message to a moderator

Re: Ecore file from Xtext instance Models [message #1710123 is a reply to message #1710122] Sun, 04 October 2015 18:31 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
simpy, create a java class in the a.b.c.mydsl project

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Parsing an IProject and returning parsed model to another plugin within Eclipse
Next Topic:introducing typedef and const in java
Goto Forum:
  


Current Time: Thu Apr 25 04:01:18 GMT 2024

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

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

Back to the top