Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » how to extract metamodel specific classes from a model
how to extract metamodel specific classes from a model [message #724828] Tue, 13 September 2011 10:04 Go to next message
Sébastien  Gandon is currently offline Sébastien GandonFriend
Messages: 184
Registered: July 2009
Senior Member
Hello,
sorry for the title I did not know how to put it.
Here is my problem.
I use CWM (OMG standard) metamodel converted from xsd.
We have extended this metamodel with our own classes that derive from the CMW.
We persist our models as xmi.
We have a requirement to persist this model with only CWM related information, like a CMW export (or extraction) of the model.
Any help on how this can be done?
I can imagine it to be done by some sort of M2M trasformation like ATL but I sense there is a simpler way using EMF only.

Thanks.
Re: how to extract metamodel specific classes from a model [message #724967 is a reply to message #724828] Tue, 13 September 2011 15:33 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Comment below.

On 13/09/2011 3:04 AM, S wrote:
> Hello,
> sorry for the title I did not know how to put it.
> Here is my problem.
> I use CWM (OMG standard) metamodel converted from xsd.
> We have extended this metamodel with our own classes that derive from
> the CMW.
> We persist our models as xmi.
> We have a requirement to persist this model with only CWM related
> information, like a CMW export (or extraction) of the model.
> Any help on how this can be done?
Perhaps you could accomplish what you want by specializing
XMLSaveImpl's shouldSaveFeature to not save any feature from anything
but the base model, i.e., return false if
feature.getEContainingClass().getEPackage() != CWMPackage.eINSTANCE.
You'd also need to ensure that xsi/xmi types aren't saved referring to
the derived model using OPTION_SAVE_TYPE_INFORMATION.

> I can imagine it to be done by some sort of M2M trasformation like ATL
> but I sense there is a simpler way using EMF only.
>
> Thanks.
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: how to extract metamodel specific classes from a model [message #786293 is a reply to message #724967] Mon, 30 January 2012 08:32 Go to previous messageGo to next message
Sébastien  Gandon is currently offline Sébastien GandonFriend
Messages: 184
Registered: July 2009
Senior Member
Thanks but using this method only checks for features and not for types or I really want the model to be only super model classes.
I am aware that this can not be achieved because class may inherit from multiple super classes so it would not be possible to choose which one to take for persistence but in my case I have simple inheritance so I have started to override a few method from XMIResource to XMLSaveImpl as I cannot find other way.
Re: how to extract metamodel specific classes from a model [message #786310 is a reply to message #786293] Mon, 30 January 2012 08:50 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
The option OPTION_SAVE_TYPE_INFORMATION provides a hook for deciding if
xsi/xmi:type is needed.

On 30/01/2012 9:32 AM, Sébastien Gandon wrote:
> Thanks but using this method only checks for features and not for
> types or I really want the model to be only super model classes.
> I am aware that this can not be achieved because class may inherit
> from multiple super classes so it would not be possible to choose
> which one to take for persistence but in my case I have simple
> inheritance so I have started to override a few method from
> XMIResource to XMLSaveImpl as I cannot find other way.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: how to extract metamodel specific classes from a model [message #786318 is a reply to message #786310] Mon, 30 January 2012 09:09 Go to previous messageGo to next message
Sébastien  Gandon is currently offline Sébastien GandonFriend
Messages: 184
Registered: July 2009
Senior Member
I have tried it but without success
        XMLTypeInfo xmlTypeInfo = new XMLSave.XMLTypeInfo() {

            @Override
            public boolean shouldSaveType(EClass objectType, EClass featureType, EStructuralFeature feature) {
                return feature.getEContainingClass().getEPackage().equals(CommonPackage.eINSTANCE);
            }

            @Override
            public boolean shouldSaveType(EClass objectType, EClassifier featureType, EStructuralFeature feature) {
                return feature.getEContainingClass().getEPackage().equals(CommonPackage.eINSTANCE);
            }
        };
        Map<String, Object> options = new HashMap<String, Object>();
        options.put(XMLResource.OPTION_SAVE_TYPE_INFORMATION, xmlTypeInfo);
        resource.save(outputStream, options);

The 2 implemented methods are never called when I serialize my objects.
When I debug EMF code the method org.eclipse.emf.ecore.xmi.impl.XMISaveImpl.writeTopObjects(List<? extends EObject>) only calls helper.getQName() and I can't find any code for checking if type should be persisted or not and what would be it's persisted type.
Re: how to extract metamodel specific classes from a model [message #786356 is a reply to message #786318] Mon, 30 January 2012 10:10 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Sébastien,

I recall someone else complaining that the option isn't used to help
with decisions for the root element. I thought there was a bugzilla for
it, but I can't find it.


On 30/01/2012 10:09 AM, Sébastien Gandon wrote:
> I have tried it but without success
>
> XMLTypeInfo xmlTypeInfo = new XMLSave.XMLTypeInfo() {
>
> @Override
> public boolean shouldSaveType(EClass objectType, EClass
> featureType, EStructuralFeature feature) {
> return
> feature.getEContainingClass().getEPackage().equals(CommonPackage.eINSTANCE);
> }
>
> @Override
> public boolean shouldSaveType(EClass objectType,
> EClassifier featureType, EStructuralFeature feature) {
> return
> feature.getEContainingClass().getEPackage().equals(CommonPackage.eINSTANCE);
> }
> };
> Map<String, Object> options = new HashMap<String, Object>();
> options.put(XMLResource.OPTION_SAVE_TYPE_INFORMATION,
> xmlTypeInfo);
> resource.save(outputStream, options);
>
> The 2 implemented methods are never called when I serialize my objects.
> When I debug EMF code the method
> org.eclipse.emf.ecore.xmi.impl.XMISaveImpl.writeTopObjects(List<?
> extends EObject>) only calls helper.getQName() and I can't find any
> code for checking if type should be persisted or not and what would be
> it's persisted type.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: how to extract metamodel specific classes from a model [message #786362 is a reply to message #786356] Mon, 30 January 2012 10:19 Go to previous messageGo to next message
Sébastien  Gandon is currently offline Sébastien GandonFriend
Messages: 184
Registered: July 2009
Senior Member
Do you want me to fill one bugzilla issue for this ?
I'll be glad to do it, it is not everyday you can pretend to issue a bug on the EMF framework Wink
This is framework is working so well and it so stable.
Re: how to extract metamodel specific classes from a model [message #786371 is a reply to message #786362] Mon, 30 January 2012 10:34 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Sébastien,

Yes, feel free to do so.


On 30/01/2012 11:19 AM, Sébastien Gandon wrote:
> Do you want me to fill one bugzilla issue for this ?
> I'll be glad to do it, it is not everyday you can pretend to issue a
> bug on the EMF framework ;)
> This is framework is working so well and it so stable.


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:How to use new Conversion Delegates
Next Topic:Can't create ecore from XSD under Helios if XSD is in workspace
Goto Forum:
  


Current Time: Thu Apr 25 10:06:33 GMT 2024

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

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

Back to the top