Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » Cloning with Stereotypes
Cloning with Stereotypes [message #478191] Thu, 12 February 2009 16:06 Go to next message
Peter Mising name is currently offline Peter Mising nameFriend
Messages: 95
Registered: July 2009
Member
Hello,
i uses oAW to make some M2M Transformations and need to clone UML
Elements. They uses a Java Extension with this Code to clone Elements.

public static Object clone(Object original) {
EObject context = (EObject) original;
EcoreUtil.Copier copier = new EcoreUtil.Copier();
EObject copy = copier.copy(context);
copier.copyReferences();
return copy;
}

Unfortunately the Stereotypes get lost.
Is it possible to clone UML Elements with Stereotypes and the
corresponding Tagged Values?
Thank you
Peter
Re: Cloning with Stereotypes [message #478193 is a reply to message #478191] Fri, 13 February 2009 21:58 Go to previous message
Eclipse UserFriend
Originally posted by: cdamus.zeligsoft.com

Hi, Peter,

The Copier can copy a collection of EObjects in one operation, which
results in also copying the cross-references between them.

So, if you retrieve the stereotypes instances applied to your element
(using Element::getStereotypeApplications()) and add those to a
collection along with the base element, then copy the lot, you'll get
what you expect.

The only trick, then, is to find a place to store the new stereotype
applications (usually they are attached directly to the resource that
contains the base element).

HTH,

Christian


Peter wrote:
> Hello,
> i uses oAW to make some M2M Transformations and need to clone UML
> Elements. They uses a Java Extension with this Code to clone Elements.
>
> public static Object clone(Object original) {
> EObject context = (EObject) original;
> EcoreUtil.Copier copier = new EcoreUtil.Copier();
> EObject copy = copier.copy(context);
> copier.copyReferences();
> return copy;
> }
>
> Unfortunately the Stereotypes get lost.
> Is it possible to clone UML Elements with Stereotypes and the
> corresponding Tagged Values?
> Thank you
> Peter
Re: Cloning with Stereotypes [message #627393 is a reply to message #478191] Fri, 13 February 2009 21:58 Go to previous message
Eclipse UserFriend
Originally posted by: cdamus.zeligsoft.com

Hi, Peter,

The Copier can copy a collection of EObjects in one operation, which
results in also copying the cross-references between them.

So, if you retrieve the stereotypes instances applied to your element
(using Element::getStereotypeApplications()) and add those to a
collection along with the base element, then copy the lot, you'll get
what you expect.

The only trick, then, is to find a place to store the new stereotype
applications (usually they are attached directly to the resource that
contains the base element).

HTH,

Christian


Peter wrote:
> Hello,
> i uses oAW to make some M2M Transformations and need to clone UML
> Elements. They uses a Java Extension with this Code to clone Elements.
>
> public static Object clone(Object original) {
> EObject context = (EObject) original;
> EcoreUtil.Copier copier = new EcoreUtil.Copier();
> EObject copy = copier.copy(context);
> copier.copyReferences();
> return copy;
> }
>
> Unfortunately the Stereotypes get lost.
> Is it possible to clone UML Elements with Stereotypes and the
> corresponding Tagged Values?
> Thank you
> Peter
Previous Topic:Transformation
Next Topic:Reverse engineering tool
Goto Forum:
  


Current Time: Sat Apr 20 02:13:00 GMT 2024

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

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

Back to the top