Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Serializing model(Problem serializing model from external ecore)
Serializing model [message #1783840] Mon, 19 March 2018 09:10 Go to next message
Patrik Nandorf is currently offline Patrik NandorfFriend
Messages: 165
Registered: January 2013
Location: Sweden
Senior Member
Hi,

I'm trying to serialize a model into a DSL file according to my grammar but I get
Caused by: java.lang.ClassCastException: org.example.library.ecore.lib.util.LibResourceImpl cannot be cast to org.eclipse.xtext.resource.XtextResource


I created an xtext project based on an external ecore model and then followed this https://stackoverflow.com/questions/12302206/convert-object-to-xtext-dsl/12302496#12302496 to do the serialization.

If I instead start from a grammar and use the generated ecore file it works. The problem is that I already have the metamodel defined as a legacy XSD so I can't start from scratch.

Any idea how to solve this is very much appreciated.

/Patrik
Re: Serializing model [message #1783841 is a reply to message #1783840] Mon, 19 March 2018 09:13 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12388
Registered: July 2009
Senior Member
can you give more context on
- how you call this code (eclipse/standalone)
- how you create the resource
- what your codes does


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Serializing model [message #1783843 is a reply to message #1783841] Mon, 19 March 2018 09:28 Go to previous messageGo to next message
Patrik Nandorf is currently offline Patrik NandorfFriend
Messages: 165
Registered: January 2013
Location: Sweden
Senior Member

Christian Dietrich wrote on Mon, 19 March 2018 10:13
can you give more context on
- how you call this code (eclipse/standalone)


It is called in org.example.library.importer.handlers.SampleHandler in https://bitbucket.org/patnan/serializing-xtext/src. (Sorry for the ugly code ;-) )

Quote:
- how you create the resource

Using the org.example.library.ecore.editor generated from the ecore/genmodel

Quote:
- what your codes does

I want to 'reverse engineer' legaxy xml files conforming the an XSD into a proper xText DSL.
Re: Serializing model [message #1783991 is a reply to message #1783843] Wed, 21 March 2018 09:35 Go to previous messageGo to next message
Patrik Nandorf is currently offline Patrik NandorfFriend
Messages: 165
Registered: January 2013
Location: Sweden
Senior Member
Any help on convert legacy (xml) files into DSL files is highly appreciated.
Re: Serializing model [message #1784007 is a reply to message #1783991] Wed, 21 March 2018 13:45 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12388
Registered: July 2009
Senior Member
can you post a link directly to the handler. did no see it on first glance

Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Serializing model [message #1784105 is a reply to message #1784007] Thu, 22 March 2018 15:20 Go to previous messageGo to next message
Patrik Nandorf is currently offline Patrik NandorfFriend
Messages: 165
Registered: January 2013
Location: Sweden
Senior Member
Christian Dietrich wrote on Wed, 21 March 2018 14:45
can you post a link directly to the handler. did no see it on first glance


https://bitbucket.org/patnan/serializing-xtext/src/8c8dfaca7501ab772df21cbce7d472d7e78099c9/org.example.library.import/src/org/example/library/importer/handlers/SampleHandler.java?at=master&fileviewer=file-view-default
Re: Serializing model [message #1784124 is a reply to message #1784105] Thu, 22 March 2018 16:35 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12388
Registered: July 2009
Senior Member
you should never ever do strange injector creation from eclipse / a handler
http://koehnlein.blogspot.de/2012/11/xtext-tip-how-do-i-get-guice-injector.html shows how you can obtain an injector from eclipse
what happens if you change that?

can you please post a complete stacktrace?

does it help if you ask the injector for a resourceset.
create a new resource with your dsls file extension
move the original resources contents to the new resource
then call the serializer


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Serializing model [message #1784252 is a reply to message #1784124] Sat, 24 March 2018 19:37 Go to previous message
Neeraj Bhusare is currently offline Neeraj BhusareFriend
Messages: 134
Registered: July 2009
Location: Canada
Senior Member
You could try to get an Injector instance as suggested by Christian or use the following code
final String serialized = ((XtextResource)model.eResource()).getSerializer().serialize(model)
OR
final String serialized = NodeModelUtils.getNode(model).getText()


Twitter : @NeerajBhusare
Blog : https://nbhusare.github.io/
Best regards, Neeraj
Previous Topic:Using Xbase Expressions in JvmModelInferrer
Next Topic:HyperlinkHelper and proxy resolution
Goto Forum:
  


Current Time: Mon Nov 19 04:41:44 GMT 2018

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

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

Back to the top