Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Serializing model(Problem serializing model from external ecore)
Serializing model [message #1783840] Mon, 19 March 2018 05:10 Go to next message
Eclipse UserFriend
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 05:13 Go to previous messageGo to next message
Eclipse UserFriend
can you give more context on
- how you call this code (eclipse/standalone)
- how you create the resource
- what your codes does
Re: Serializing model [message #1783843 is a reply to message #1783841] Mon, 19 March 2018 05:28 Go to previous messageGo to next message
Eclipse UserFriend

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 05:35 Go to previous messageGo to next message
Eclipse UserFriend
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 09:45 Go to previous messageGo to next message
Eclipse UserFriend
can you post a link directly to the handler. did no see it on first glance
Re: Serializing model [message #1784105 is a reply to message #1784007] Thu, 22 March 2018 11:20 Go to previous messageGo to next message
Eclipse UserFriend
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 12:35 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Serializing model [message #1784252 is a reply to message #1784124] Sat, 24 March 2018 15:37 Go to previous message
Eclipse UserFriend
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()
Previous Topic:Using Xbase Expressions in JvmModelInferrer
Next Topic:HyperlinkHelper and proxy resolution
Goto Forum:
  


Current Time: Thu Jun 19 17:40:19 EDT 2025

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

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

Back to the top