Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Serialization issues
Serialization issues [message #1687964] Fri, 20 March 2015 01:26 Go to next message
Julien Delange is currently offline Julien DelangeFriend
Messages: 82
Registered: October 2011
Member
Hello,

I am trying to serialize an eobject from my dsl to a string.


I am using the technique described here: http://jevopisdeveloperblog.blogspot.ch/2011/03/implement-tostring-with-xtexts.html

This is my code snippet:
org.eclipse.xtext.parsetree.reconstr.Serializer serializer = Guice.createInjector(
new org.osate.reqspec.ReqSpecRuntimeModule()).getInstance(
org.eclipse.xtext.parsetree.reconstr.Serializer.class);
String s = serializer.serialize(reqSpecModel);


When trying to run this code, I got the following exeception:
java.lang.ArrayStoreException: org.osate.reqspec.ReqSpecRuntimeModule
at org.osate.alisa.workbench.importer.handlers.Word$2.run(Word.java:90)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)

Any idea about the cause? Is there any other way to serialize an eobject? The serializer class seems to be deprecated.


Thanks for any help/suggestion/comment.

Re: Serialization issues [message #1688052 is a reply to message #1687964] Fri, 20 March 2015 04:53 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

IDon't know why you get the arraystore exception. maybe there is something wrong with your classpath setup regarding guice versions.

well first of all you should create the injector the "right" way. For the Standalone usecase:

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


For the UI Usecae: http://koehnlein.blogspot.de/2012/11/xtext-tip-how-do-i-get-guice-injector.html

Regarding the Deprecation: In Your Mwe2 you Decide weather you use the current or the (stoneage) Old Serializer.
If you dont care: simply ask for an org.eclipse.xtext.serializer.ISerializer


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

[Updated on: Fri, 20 March 2015 04:56]

Report message to a moderator

Re: Serialization issues [message #1688312 is a reply to message #1688052] Fri, 20 March 2015 13:13 Go to previous messageGo to next message
Julien Delange is currently offline Julien DelangeFriend
Messages: 82
Registered: October 2011
Member
If I understand correctly, such an approach should be used only if I used a standalone (like a CLI) application, right?

I am in fact serializing within Eclipse and everything is already initialized. Then, I should rather use something like Activator.getInstance().getInjector("") right?
Re: Serialization issues [message #1688315 is a reply to message #1688312] Fri, 20 March 2015 13:17 Go to previous messageGo to next message
Julien Delange is currently offline Julien DelangeFriend
Messages: 82
Registered: October 2011
Member
Update: all the activator are declared in the internal packages. How do I get/use them?

Thanks for any help!
Re: Serialization issues [message #1688316 is a reply to message #1688315] Fri, 20 March 2015 13:19 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

where do you call your code from?

Edit:

And no: you should follow the way described in http://koehnlein.blogspot.de/2012/11/xtext-tip-how-do-i-get-guice-injector.html


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

[Updated on: Fri, 20 March 2015 13:22]

Report message to a moderator

Re: Serialization issues [message #1688381 is a reply to message #1688316] Fri, 20 March 2015 15:39 Go to previous messageGo to next message
Julien Delange is currently offline Julien DelangeFriend
Messages: 82
Registered: October 2011
Member
I call my code within Eclipse. This is called within an Eclipse plugin that is using my dsl. I just want to serialize one eobject.
Re: Serialization issues [message #1688409 is a reply to message #1688381] Fri, 20 March 2015 16:49 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
i mean is it a command? is the command defined in the yourdsl.ui plugin etc?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Serialization issues [message #1688414 is a reply to message #1688409] Fri, 20 March 2015 17:00 Go to previous messageGo to next message
Julien Delange is currently offline Julien DelangeFriend
Messages: 82
Registered: October 2011
Member
the command is defined in yourdsl.ui.analysis
So, the plugin is loaded with the yourdsl.ui plugin, meaning, in the same eclipse instance.
Re: Serialization issues [message #1688418 is a reply to message #1688414] Fri, 20 March 2015 17:13 Go to previous messageGo to next message
Julien Delange is currently offline Julien DelangeFriend
Messages: 82
Registered: October 2011
Member
I then change my code and get the injector fromt he activator. The injector is not null. But when trying to get the serializer, I got the following error related to the class loader. (see below)

Injector injector = org.osate.reqspec.ui.internal.ReqSpecActivator.getInstance().getInjector(
"org.osate.reqspec.ReqSpec");
Serializer serializer = injector.getInstance(Serializer.class);
String s = serializer.serialize(reqSpecModel);
OsateDebug.osateDebug("[WordImport] s=" + s);

An internal error occurred during: "Importing Word Requirements".
loader constraint violation: loader (instance of org/eclipse/osgi/internal/loader/EquinoxClassLoader) previously initiated loading for a different type with name "com/google/inject/Injector"
Re: Serialization issues [message #1688432 is a reply to message #1688418] Fri, 20 March 2015 17:36 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

it would be 10000000 times easier if you move the command (handler) to the yourdsl.ui plugin.

or

- you guicify your yourdsl.ui.something by create a own module + exceutableextensionfactory + injector in activator in plugin and use the
IResourceServiceProvider.Registry or IGlobalServiceProvider to obtain the serializer

maybe as a short circuit you can try to

IResourceServiceProvider.Registry.INSTANCE.getResourceServiceProvider(URI.createURI("fake.mydsl")).get(ISerializer,class);
but i dont know if this works


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Serialization issues [message #1688439 is a reply to message #1688432] Fri, 20 March 2015 18:00 Go to previous messageGo to next message
Julien Delange is currently offline Julien DelangeFriend
Messages: 82
Registered: October 2011
Member
Unfortunately, I cannot move the command handler to the plugin. Just a matter of development and dependencies.
1. What is meant by "guicifying"? Do you have some code example in mind? I do not really understand what is meant.
2. I will try this solution, at least, I understand this one Smile
Re: Serialization issues [message #1688443 is a reply to message #1688439] Fri, 20 March 2015 18:14 Go to previous messageGo to next message
Julien Delange is currently offline Julien DelangeFriend
Messages: 82
Registered: October 2011
Member
Making progress. Using the code snippet from solution 2 seems to work. But I get a null pointer exception when serializing.

java.lang.NullPointerException
at org.eclipse.xtext.ui.editor.formatting.PreferenceStoreWhitespaceInformationProvider.getLineSeparatorPreference(PreferenceStoreWhitespaceInformationProvider.java:63)
at org.eclipse.xtext.ui.editor.formatting.PreferenceStoreWhitespaceInformationProvider.getLineSeparatorInformation(PreferenceStoreWhitespaceInformationProvider.java:54)
at org.eclipse.xtext.formatting.impl.AbstractDeclarativeFormatter.getLineSeparatorInfo(AbstractDeclarativeFormatter.java:114)
at org.eclipse.xtext.formatting.impl.AbstractDeclarativeFormatter.createFormattingConfig(AbstractDeclarativeFormatter.java:81)
at org.eclipse.xtext.formatting.impl.AbstractDeclarativeFormatter.getConfig(AbstractDeclarativeFormatter.java:92)
at org.eclipse.xtext.formatting.impl.AbstractDeclarativeFormatter.createFormatterStream(AbstractDeclarativeFormatter.java:75)
at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:103)
at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:122)
at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:51)
at org.osate.alisa.workbench.importer.handlers.Word$2.run(Word.java:93)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
Re: Serialization issues [message #1688447 is a reply to message #1688443] Fri, 20 March 2015 18:26 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Which Xtext Version do you use?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Serialization issues [message #1688451 is a reply to message #1688447] Fri, 20 March 2015 18:33 Go to previous messageGo to next message
Julien Delange is currently offline Julien DelangeFriend
Messages: 82
Registered: October 2011
Member
2.7.3
Also, I found a workaround: creating a fake resource and putting the eobject in the resource works then! The serializer works now! Thanks a lot!
Re: Serialization issues [message #1688452 is a reply to message #1688447] Fri, 20 March 2015 18:35 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Looks like you actually found a bug in xtext. can you please file a ticket?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:org.eclipse.core.contenttype.contentTypes support
Next Topic:Deadlock during injector initialization
Goto Forum:
  


Current Time: Tue Apr 16 21:04:42 GMT 2024

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

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

Back to the top