Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » copy ResourceSet containing metamodel and model
copy ResourceSet containing metamodel and model [message #468018] Mon, 03 August 2009 16:08 Go to next message
Christian Saad is currently offline Christian SaadFriend
Messages: 39
Registered: July 2009
Member
Hi everybody,

I've encountered a problem when using the Copier from the ECoreUtil class
to copy a resourceset with two (dynamic EMF) resources, one of which is
the metamodel of the other, i.e. the .eClass() properties of the objects
in resource X point to the EClass objects contained in resource Y.

I tried adding all objects to a list and then invoking copyAll() on this
list, but this gives me the result of a copy of the EClass objects Z (as
desired) but the .eClass() of the copied model objects is set to the
original classes Y instead of Z.

I already tried redirecting the getTarget() method in the Copier to use
the copied classes, but this raises an exception (the feature ... is not a
valid changeable feature). As far as I can tell this is because the
GenericSuperType isn't set and therefore the objects don't have access to
inherited features.

Is there a way around this?

Thanks in advance,
Chris
Re: copy ResourceSet containing metamodel and model [message #468019 is a reply to message #468018] Mon, 03 August 2009 16:13 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Chris,

Comments below.

C. Saad wrote:
> Hi everybody,
>
> I've encountered a problem when using the Copier from the ECoreUtil
> class to copy a resourceset with two (dynamic EMF) resources, one of
> which is the metamodel of the other, i.e. the .eClass() properties of
> the objects in resource X point to the EClass objects contained in
> resource Y.
>
> I tried adding all objects to a list and then invoking copyAll() on
> this list, but this gives me the result of a copy of the EClass
> objects Z (as desired) but the .eClass() of the copied model objects
> is set to the original classes Y instead of Z.
>
> I already tried redirecting the getTarget() method in the Copier to
> use the copied classes, but this raises an exception (the feature ...
> is not a valid changeable feature). As far as I can tell this is
> because the GenericSuperType isn't set and therefore the objects don't
> have access to inherited features.
>
> Is there a way around this?
Did you override both getTarget methods? You could make use of the
Copier's map... Presumably the Ecore models are copied before the
instances are copied so I'd expect them to be complete by that point
(and hence I don't understand the comment about the super types).
>
> Thanks in advance,
> Chris
>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: copy ResourceSet containing metamodel and model [message #468028 is a reply to message #468019] Mon, 03 August 2009 17:09 Go to previous messageGo to next message
Christian Saad is currently offline Christian SaadFriend
Messages: 39
Registered: July 2009
Member
Ed Merks wrote:

> Did you override both getTarget methods? You could make use of the
> Copier's map... Presumably the Ecore models are copied before the
> instances are copied so I'd expect them to be complete by that point
> (and hence I don't understand the comment about the super types).

Thanks for your quick reply. My modifications to the copier look like this:
@Override
protected EClass getTarget(EClass eClass)
{
if (keySet().contains(eClass))
{
// return copy instead of original
return (EClass) get(eClass);
}

return super.getTarget(eClass);
}


protected EStructuralFeature getTarget(EStructuralFeature
eStructuralFeature)
{
if (keySet().contains(eStructuralFeature.eContainer()))
{
EClass copyEClass = (EClass) get(eStructuralFeature.eContainer());

for (EStructuralFeature feature : copyEClass
.getEAllStructuralFeatures())
{
if (feature.getName().equals(eStructuralFeature.getName()))
{
// return feature at copy
return feature;
}
}
}
return eStructuralFeature;
}

Strangely, the EClass copy accessed in the getTarget(EClass) does not have
its eGenericSuperTypes() set but does so after the copyAll() method has
finished.
Re: copy ResourceSet containing metamodel and model [message #468031 is a reply to message #468028] Mon, 03 August 2009 17:26 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Chris,

Comments below.

C. Saad wrote:
> Ed Merks wrote:
>
>> Did you override both getTarget methods? You could make use of the
>> Copier's map... Presumably the Ecore models are copied before the
>> instances are copied so I'd expect them to be complete by that point
>> (and hence I don't understand the comment about the super types).
>
> Thanks for your quick reply. My modifications to the copier look like
> this:
> @Override
> protected EClass getTarget(EClass eClass)
> {
> if (keySet().contains(eClass))
> {
> // return copy instead of original
> return (EClass) get(eClass);
> }
>
> return super.getTarget(eClass);
> }
>
>
> protected EStructuralFeature getTarget(EStructuralFeature
> eStructuralFeature)
> {
> if (keySet().contains(eStructuralFeature.eContainer()))
> {
> EClass copyEClass = (EClass)
> get(eStructuralFeature.eContainer());
>
> for (EStructuralFeature feature : copyEClass
> .getEAllStructuralFeatures())
> {
> if (feature.getName().equals(eStructuralFeature.getName()))
> {
> // return feature at copy
> return feature;
> }
> }
> }
> return eStructuralFeature;
I expect the features to be in the map as well so this method should
look just like the EClass version...
> }
>
> Strangely, the EClass copy accessed in the getTarget(EClass) does not
> have its eGenericSuperTypes() set but does so after the copyAll()
> method has finished.
Well yes, because the cross references are copied later in the
processing after all the containment references are copied. That's why
I mentioned copying the whole Ecore model (including cross references)
before starting to copy the instance.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: copy ResourceSet containing metamodel and model [message #468216 is a reply to message #468031] Tue, 04 August 2009 14:54 Go to previous message
Christian Saad is currently offline Christian SaadFriend
Messages: 39
Registered: July 2009
Member
Thanks for your help, seems to work now :)

I had to change the copyAttribute() method a bit because the copied EEnum
attribute cannot be set to the original EEnumLiteral:

// special handling for enum
if (eAttribute.getEType() instanceof EEnum)
{
EEnumLiteral origEEnumLiteral = (EEnumLiteral) eObject
.eGet(eAttribute);

if (origEEnumLiteral != null)
{
EEnum copyEEnum = (EEnum) get(origEEnumLiteral
.getEEnum());
EEnumLiteral copyEEnumLiteral = copyEEnum
.getEEnumLiteral(origEEnumLiteral.getValue());

copyEObject.eSet(getTarget(eAttribute),
copyEEnumLiteral);
}
}
// default
else
{
copyEObject.eSet(getTarget(eAttribute), eObject
.eGet(eAttribute));
}
Previous Topic:How to invoke the code generation programmatically
Next Topic:Open resource set for view instead of editor
Goto Forum:
  


Current Time: Thu Apr 18 09:11:19 GMT 2024

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

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

Back to the top