Change save options [message #1850110] |
Wed, 16 February 2022 05:42  |
Eclipse User |
|
|
|
I'm trying to find an easy way to change the resource save option in Sirius.
More specifically I would like to active the default value serialization with the option OPTION_KEEP_DEFAULT_CONTENT.
I found a way to do it using the generated EMF editor but it is not used by Sirius to save the resources.
Any suggestion?
Martial
|
|
|
|
|
Re: Change save options [message #1850168 is a reply to message #1850164] |
Fri, 18 February 2022 18:57   |
Eclipse User |
|
|
|
Hi Martial,
I can't find a tutorial so far ( I guess it is not really common to change the doSave), but I don't think it should be that painful. Once you have added the extension to your plugin, you just need to create a class that extends SessionFactoryImpl. In your class, I think you should only need to override createSession so instead of returning a new DAnalysisSessionImpl, you return your own class that overrides DAnalysisSessionImpl. In that class, you will just override the doSave method. 1 extension point, 2 classes, 2 methods :)
If I follow correctly your serialization issue, if in your metamodel you have an EAttribute typed EBoolean with a default value false, you want that information to be serialize in your model even if for an element it is valued as true? That seems redundant with the metamodel, but I do not know how your M2M tool. I really think that is an issue that could (and probably should) be handled on the EMF side. I have not done this kind of tweak in a while, but for instance once I wanted to change the serialization of references from being index based to being based on elements URI and I had done it in the genmodel or with some custom code in the generated files (I can't remember at the moment).
Best regards,
Steve
|
|
|
Re: Change save options [message #1850228 is a reply to message #1850168] |
Tue, 22 February 2022 05:33  |
Eclipse User |
|
|
|
Hi Steve,
Quote:I can't find a tutorial so far ( I guess it is not really common to change the doSave), but I don't think it should be that painful. Once you have added the extension to your plugin, you just need to create a class that extends SessionFactoryImpl. In your class, I think you should only need to override createSession so instead of returning a new DAnalysisSessionImpl, you return your own class that overrides DAnalysisSessionImpl. In that class, you will just override the doSave method. 1 extension point, 2 classes, 2 methods :)
OK I'll look at it.
Quote:If I follow correctly your serialization issue, if in your metamodel you have an EAttribute typed EBoolean with a default value false, you want that information to be serialize in your model even if for an element it is valued as true?
Not exactly. If the EAttribute is not set, the serialized value is the default one, meaning false in your example. If the EAttribute is set, the serialized value is the set one, meaning false or true in your example. In the default EMF behavior, the EAttribute value is serialized only if it is set. You need to load the option OPTION_KEEP_DEFAULT_CONTENT to have unset EAttributes to be serialized with the default value.
Quote:That seems redundant with the metamodel, but I do not know how your M2M tool.
That's totally true if your M2M tool is taking the model schema as an input because the default values will be available. But it's not always the case.
Quote:I really think that is an issue that could (and probably should) be handled on the EMF side. I have not done this kind of tweak in a while, but for instance once I wanted to change the serialization of references from being index based to being based on elements URI and I had done it in the genmodel or with some custom code in the generated files (I can't remember at the moment).
One other option is to override the shouldSaveFeature() method.
|
|
|
Powered by
FUDForum. Page generated in 0.06488 seconds