Home » Modeling » UML2 » Tag value element looses owner
Tag value element looses owner [message #503741] |
Tue, 15 December 2009 15:13 |
Martynas L Messages: 16 Registered: July 2009 |
Junior Member |
|
|
This is a multi-part message in MIME format.
------=_NextPart_000_0543_01CA7DA9.F67A84D0
Content-Type: text/plain;
format=flowed;
charset="windows-1257";
reply-type=original
Content-Transfer-Encoding: 7bit
Hello,
Suppose I have an element and assign it as a stereotype value:
1) If stereotype property aggregation is None, or Shared everything is ok.
2) If stereotype property aggregation is Composite, the element is removed
from its owner.
I've attached the code sample.
Is it a bug, "feature", or something else?
UML: 2.0.4 (2007/07/13), 3.0.1 (2009/08/28), 3.1.0M4 (2009/12/14)
Thanks,
Martynas
------=_NextPart_000_0543_01CA7DA9.F67A84D0
Content-Type: application/octet-stream;
name="TestTag.java"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="TestTag.java"
package test;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.common.util.WrappedException;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.URIConverter;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.uml2.uml.*;
import org.eclipse.uml2.uml.Class;
import org.eclipse.uml2.uml.resource.UMLResource;
import java.io.IOException;
public class TestTag
{
private static ResourceSet RESOURCE_SET =3D new ResourceSetImpl();
public static void main(String[] args)
{
String saveLocation =3D ...;
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( )
.put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
String resourcesJarPath =3D ...;
URI uri =3D URI.createURI("archive:file:/" + resourcesJarPath + "!/");
URIConverter.URI_MAP.put(URI.createURI(UMLResource.LIBRARIES _PATHMAP), =
getUri(uri, "libraries"));
=
URIConverter.URI_MAP.put(URI.createURI(UMLResource.METAMODEL S_PATHMAP), =
getUri(uri, "metamodels"));
URIConverter.URI_MAP.put(URI.createURI(UMLResource.PROFILES_ PATHMAP), =
getUri(uri, "profiles"));
Profile profile =3D UMLFactory.eINSTANCE.createProfile();
profile.setName("testProfile");
Stereotype stereotype =3D =
profile.createOwnedStereotype("testStereotype", false);
Model uml2Metamodel =3D (Model) =
load(URI.createURI(UMLResource.UML_METAMODEL_URI));
Class classMetaclass =3D (Class) =
uml2Metamodel.getOwnedType(UMLPackage.eINSTANCE.getClass_(). getName());
profile.createMetaclassReference(classMetaclass);
Property compositeAttribute =3D =
stereotype.createOwnedAttribute("testCompositeTag", classMetaclass, 0, =
1);
compositeAttribute.setAggregation(AggregationKind.COMPOSITE_ LITERAL);
Property sharedAttribute =3D =
stereotype.createOwnedAttribute("testSharedTag", classMetaclass, 0, 1);
sharedAttribute.setAggregation(AggregationKind.SHARED_LITERA L);
stereotype.createExtension(classMetaclass, false);
profile.define();
Model model =3D UMLFactory.eINSTANCE.createModel();
model.setName("testModel");
Class stereotypedClass =3D model.createOwnedClass("stereotypedClass", =
false);
Class tagValueComposite =3D =
model.createOwnedClass("tagValueComposite", false);
Class tagValueShared =3D model.createOwnedClass("tagValueShared", =
false);
model.getPackagedElements().add(stereotypedClass);
model.getPackagedElements().add(tagValueComposite);
model.getPackagedElements().add(tagValueShared);
Resource resource =3D createResource(model, =
URI.createFileURI(saveLocation)
=
..appendSegment("testModel").appendFileExtension(UMLResource.FILE_EXTENSIO=
N));
model.applyProfile(profile);
stereotypedClass.applyStereotype(stereotype);
System.out.println("before tagValueShared.getOwner() =3D " + =
tagValueShared.getOwner());
stereotypedClass.setValue(stereotype, sharedAttribute.getName(), =
tagValueShared);
System.out.println("after tagValueShared.getOwner() =3D " + =
tagValueShared.getOwner());
System.out.println("before tagValueComposite.getOwner() =3D " + =
tagValueComposite.getOwner());
stereotypedClass.setValue(stereotype, compositeAttribute.getName(), =
tagValueComposite);
System.out.println("after tagValueComposite.getOwner() =3D " + =
tagValueComposite.getOwner());
Class sharedValue =3D (Class) stereotypedClass.getValue(stereotype, =
sharedAttribute.getName());
System.out.println("sharedValue =3D " + sharedValue);
Class compositeValue =3D (Class) stereotypedClass.getValue(stereotype, =
compositeAttribute.getName());
System.out.println("compositeValue =3D " + compositeValue);
save(profile, =
URI.createFileURI(saveLocation).appendSegment("testProfile").appendFileEx=
tension(
UMLResource.PROFILE_FILE_EXTENSION));
save(resource);
}
private static URI getUri(URI base, String what)
{
return base.appendSegment(what).appendSegment("");
}
private static Resource createResource(org.eclipse.uml2.uml.Package =
package_, URI uri)
{
Resource resource =3D RESOURCE_SET.createResource(uri);
resource.getContents().add(package_);
return resource;
}
private static org.eclipse.uml2.uml.Package load(URI uri)
{
org.eclipse.uml2.uml.Package package_ =3D null;
try
{
Resource resource =3D RESOURCE_SET.getResource(uri, true);
package_ =3D (org.eclipse.uml2.uml.Package) =
EcoreUtil.getObjectByType(
resource.getContents(), UMLPackage.eINSTANCE.getPackage());
resource.getErrors();
}
catch (WrappedException we)
{
we.printStackTrace();
System.exit(1);
}
return package_;
}
private static void save(org.eclipse.uml2.uml.Package package_, URI =
uri)
{
save(createResource(package_, uri));
}
private static void save(Resource resource)
{
try
{
resource.save(null);
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
}
}
------=_NextPart_000_0543_01CA7DA9.F67A84D0--
|
|
|
Re: Tag value element looses owner [message #503763 is a reply to message #503741] |
Tue, 15 December 2009 11:14 |
|
--=-t/s1wj4R7cMzE4v9Iu7/
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
Hi, Martynas,
Your stereotype is doing exactly what you told it to do. Designating
the stereotype property as a composite aggregation means that the
stereotype owns the objects in that property. So, if you add an element
from your model to that stereotype property, the element becomes owned
by that stereotype instance. Thus it is no longer owned by the model
element that contained it previously.
Probably this particular stereotype property should not be a composite
aggregation.
HTH,
Christian
On Tue, 2009-12-15 at 17:13 +0200, Martynas Lelevicius wrote:
> Hello,
>
> Suppose I have an element and assign it as a stereotype value:
> 1) If stereotype property aggregation is None, or Shared everything is ok.
> 2) If stereotype property aggregation is Composite, the element is removed
> from its owner.
>
> I've attached the code sample.
> Is it a bug, "feature", or something else?
>
> UML: 2.0.4 (2007/07/13), 3.0.1 (2009/08/28), 3.1.0M4 (2009/12/14)
>
> Thanks,
> Martynas
--=-t/s1wj4R7cMzE4v9Iu7/
Content-Type: text/html; charset="utf-8"
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
<META NAME="GENERATOR" CONTENT="GtkHTML/3.24.1.1">
</HEAD>
<BODY>
Hi, Martynas,<BR>
<BR>
Your stereotype is doing exactly what you told it to do. Designating the stereotype property as a composite aggregation means that the stereotype owns the objects in that property. So, if you add an element from your model to that stereotype property, the element becomes owned by that stereotype instance. Thus it is no longer owned by the model element that contained it previously.<BR>
<BR>
Probably this particular stereotype property should not be a composite aggregation.<BR>
<BR>
HTH,<BR>
<BR>
Christian<BR>
<BR>
<BR>
On Tue, 2009-12-15 at 17:13 +0200, Martynas Lelevicius wrote:
<BLOCKQUOTE TYPE=CITE>
<PRE>
Hello,
Suppose I have an element and assign it as a stereotype value:
1) If stereotype property aggregation is None, or Shared everything is ok.
2) If stereotype property aggregation is Composite, the element is removed
from its owner.
I've attached the code sample.
Is it a bug, "feature", or something else?
UML: 2.0.4 (2007/07/13), 3.0.1 (2009/08/28), 3.1.0M4 (2009/12/14)
Thanks,
Martynas
</PRE>
</BLOCKQUOTE>
</BODY>
</HTML>
--=-t/s1wj4R7cMzE4v9Iu7/--
|
|
|
Re: Tag value element looses owner [message #628123 is a reply to message #503741] |
Tue, 15 December 2009 15:55 |
|
--=-t/s1wj4R7cMzE4v9Iu7/
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
Hi, Martynas,
Your stereotype is doing exactly what you told it to do. Designating
the stereotype property as a composite aggregation means that the
stereotype owns the objects in that property. So, if you add an element
from your model to that stereotype property, the element becomes owned
by that stereotype instance. Thus it is no longer owned by the model
element that contained it previously.
Probably this particular stereotype property should not be a composite
aggregation.
HTH,
Christian
On Tue, 2009-12-15 at 17:13 +0200, Martynas Lelevicius wrote:
> Hello,
>
> Suppose I have an element and assign it as a stereotype value:
> 1) If stereotype property aggregation is None, or Shared everything is ok.
> 2) If stereotype property aggregation is Composite, the element is removed
> from its owner.
>
> I've attached the code sample.
> Is it a bug, "feature", or something else?
>
> UML: 2.0.4 (2007/07/13), 3.0.1 (2009/08/28), 3.1.0M4 (2009/12/14)
>
> Thanks,
> Martynas
--=-t/s1wj4R7cMzE4v9Iu7/
Content-Type: text/html; charset="utf-8"
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
<META NAME="GENERATOR" CONTENT="GtkHTML/3.24.1.1">
</HEAD>
<BODY>
Hi, Martynas,<BR>
<BR>
Your stereotype is doing exactly what you told it to do. Designating the stereotype property as a composite aggregation means that the stereotype owns the objects in that property. So, if you add an element from your model to that stereotype property, the element becomes owned by that stereotype instance. Thus it is no longer owned by the model element that contained it previously.<BR>
<BR>
Probably this particular stereotype property should not be a composite aggregation.<BR>
<BR>
HTH,<BR>
<BR>
Christian<BR>
<BR>
<BR>
On Tue, 2009-12-15 at 17:13 +0200, Martynas Lelevicius wrote:
<BLOCKQUOTE TYPE=CITE>
<PRE>
Hello,
Suppose I have an element and assign it as a stereotype value:
1) If stereotype property aggregation is None, or Shared everything is ok.
2) If stereotype property aggregation is Composite, the element is removed
from its owner.
I've attached the code sample.
Is it a bug, "feature", or something else?
UML: 2.0.4 (2007/07/13), 3.0.1 (2009/08/28), 3.1.0M4 (2009/12/14)
Thanks,
Martynas
</PRE>
</BLOCKQUOTE>
</BODY>
</HTML>
--=-t/s1wj4R7cMzE4v9Iu7/--
|
|
|
Goto Forum:
Current Time: Wed Sep 25 14:26:46 GMT 2024
Powered by FUDForum. Page generated in 0.05824 seconds
|