Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Epsilon » EOL: How to create a stereotype in an existing UML profile
EOL: How to create a stereotype in an existing UML profile [message #1731626] Sun, 08 May 2016 09:11 Go to next message
Alireza Rouhi is currently offline Alireza RouhiFriend
Messages: 148
Registered: December 2015
Senior Member
Hi,

I would like to add a stereotype like "foo" (which extends the <<metaclass>> Class here) to an existing UML profile named "MyProfile" in the following code:
var stereotype: Stereotype;
var elementImport: ElementImport;
var extension: Extension;
	
if (not Stereotype.all.exists(s|s.name = "foo"))
	{
		// define a new stereotype named with the classifier name
		stereotype = Stereotype.createInstance();
		stereotype.name = "foo";
		stereotype.package = MyProfile;
    }
else
	{
		("foo already exists!").println();
	}

if (not ElementImport.all.exists(e|e.importingNamespace = MyProfile))
	{
		elementImport = ElementImport.createInstance();
		elementImport.importingNamespace = MyProfile;
		elementImport.target = UML!Class; // Error: Undefined variable, type or model: 'UML!Class'	
	}			

if (not Extension.all.exists(e | e.package = MyProfile))
	{
		extension = Extension.createInstance();
		extension.package = MyProfile;
		extension.metaclass = elementImport.target; // Error: The feature 'metaclass' is not a valid changeable feature
		extension.endType.add(stereotype); // these statements must relate the stereotype and the element import, but do not work as I expect
		extension.endType.add(elementImport.target);
	}


But it does not work as I expect! The usage of the "target", "metaclass" properties are erroneous. How to use and arrange these statements to associate the imported element <<metaclass>> Class and the stereotype "foo"?

Best regards,
Alireza

[Updated on: Tue, 17 May 2016 12:20]

Report message to a moderator

Re: EOL: How to create a stereotype in an existing UML profile [message #1731937 is a reply to message #1731626] Wed, 11 May 2016 08:15 Go to previous messageGo to next message
Antonio Garcia-Dominguez is currently offline Antonio Garcia-DominguezFriend
Messages: 594
Registered: January 2010
Location: Birmingham, UK
Senior Member

"UML!Class" is just a type name, and doesn't refer to any actual objects. If you want to refer to the EClass, you'd have to load the UML metamodel as a model itself. Within your launch configuration, you could use the "Registered EMF EPackage", and then look through its EClasses to find the one named "Class".

Alternatively, a quick and dirty method could be:

var throwaway = new UML!Class;
var classType = throwaway.eClass;


As for "metaclass", if you look at the Extension EClass through the "EPackage Registry" view, you'll see that it's in italics. That means it is a derived feature, which cannot be changed directly. You have to change the features that it is derived from. If you look at the source code of ExtensionImpl and follow some method calls from getMetaclass(), you'll see that it's derived from this OCL expression:

result = metaclassEnd().type.oclAsType(Class)


metaclassEnd() is another OCL query, which according to the UML source code is defined like this:

result = (memberEnd->reject(p | ownedEnd->includes(p.oclAsType(ExtensionEnd)))->any(true))


It looks like you'll have to set memberEnd or ownedEnd in some way.

[Updated on: Wed, 11 May 2016 08:18]

Report message to a moderator

Re: EOL: How to create a stereotype in an existing UML profile [message #1731938 is a reply to message #1731937] Wed, 11 May 2016 08:20 Go to previous messageGo to next message
Alireza Rouhi is currently offline Alireza RouhiFriend
Messages: 148
Registered: December 2015
Senior Member
Dear Antonio,

Hi,

Thanks a a lot for your solution and reply. How can I load the UML metamodel in EOL code?

Best regards,
Alireza
Re: EOL: How to create a stereotype in an existing UML profile [message #1731940 is a reply to message #1731938] Wed, 11 May 2016 08:25 Go to previous messageGo to next message
Antonio Garcia-Dominguez is currently offline Antonio Garcia-DominguezFriend
Messages: 594
Registered: January 2010
Location: Birmingham, UK
Senior Member

Are you running your EOL code from the "Run" launch configurations, or from your own Java code?

EOL itself doesn't allow for loading new models while it's running: you load models either through the launch configuration, or from the Java code setting up the EolModule's model repository.
Re: EOL: How to create a stereotype in an existing UML profile [message #1731943 is a reply to message #1731940] Wed, 11 May 2016 08:31 Go to previous messageGo to next message
Alireza Rouhi is currently offline Alireza RouhiFriend
Messages: 148
Registered: December 2015
Senior Member
No, I'm running from my EOL "Run" launch configurations. Just like "loading the PrimitiveTypes library which I use to change properties datatypes like Integer, String, etc." [1], is there any way to load UML metamodel to use its objects like Class, Operation, etc?

[1] https://git.eclipse.org/c/epsilon/org.eclipse.epsilon.git/tree/examples/org.eclipse.epsilon.examples.uml.library

[Updated on: Wed, 11 May 2016 08:35]

Report message to a moderator

Re: EOL: How to create a stereotype in an existing UML profile [message #1731946 is a reply to message #1731943] Wed, 11 May 2016 08:35 Go to previous messageGo to next message
Antonio Garcia-Dominguez is currently offline Antonio Garcia-DominguezFriend
Messages: 594
Registered: January 2010
Location: Birmingham, UK
Senior Member

Yes, use the "Registered EMF Package" model type in the "Models" tab of your launch configuration, as I mentioned in my previous message. Alternatively, assign "new Class" to a variable (UML!Class won't work, since UML is treated as a model name) and then extract the .eClass from it.
Re: EOL: How to create a stereotype in an existing UML profile [message #1732012 is a reply to message #1731946] Wed, 11 May 2016 16:53 Go to previous messageGo to next message
Alireza Rouhi is currently offline Alireza RouhiFriend
Messages: 148
Registered: December 2015
Senior Member
Hi,

I used the "Registered EMF Package" model type and selected "http://www.eclipse.org/uml2/5.0.0/UML" in the Meta-model URI. Instead of setting the target property of the elementImport, I used the importedElement property to set the imported metaclass Class with the following code:
elementImport.importedElement = UML.allInstances().selectOne(e | e.eClass.name = "EClass" and e.name = "Class");


This causes the following exception error:
org.eclipse.emf.ecore.impl.EClassImpl cannot be cast to org.eclipse.uml2.uml.PackageableElement

The expected importedElement must be:
Class [name=Class, qualifiedName=UML::Class, visibility=public, isLeaf=false, isAbstract=false, isFinalSpecialization=false, isActive=false, ]


Is there any trick to resolve this exception?

Best regards,
Alireza
Re: EOL: How to create a stereotype in an existing UML profile [message #1732265 is a reply to message #1732012] Sat, 14 May 2016 07:59 Go to previous messageGo to next message
Antonio Garcia-Dominguez is currently offline Antonio Garcia-DominguezFriend
Messages: 594
Registered: January 2010
Location: Birmingham, UK
Senior Member

Sorry for the delay. The problem is that an EClass is not a PackageableElement. I think you want to assign an instance of UML!Class there rather than the UML!Class type itself.
Re: EOL: How to create a stereotype in an existing UML profile [message #1732267 is a reply to message #1732265] Sat, 14 May 2016 08:21 Go to previous messageGo to next message
Alireza Rouhi is currently offline Alireza RouhiFriend
Messages: 148
Registered: December 2015
Senior Member
Hi Antonio,

Thanks a lot.
You're right. But none of the createInstance() method and the new operator are not applicable here:

new UML.allInstances().selectOne(e | e.eClass.name = "EClass" and e.name = "Class"); // Erroneous
or
UML.allInstances().selectOne(e | e.eClass.name = "EClass" and e.name = "Class").createInstance(); // Erroneous


Do you suggest any solution to create and assign an instance of the above UML!Class type here?

Best regards,
Alireza

[Updated on: Sat, 14 May 2016 08:22]

Report message to a moderator

Re: EOL: How to create a stereotype in an existing UML profile [message #1732442 is a reply to message #1732267] Tue, 17 May 2016 11:37 Go to previous messageGo to next message
Antonio Garcia-Dominguez is currently offline Antonio Garcia-DominguezFriend
Messages: 594
Registered: January 2010
Location: Birmingham, UK
Senior Member

"new" takes a type, not an EClass instance:

var newClass = new Class;


Perhaps this example could help? It shows how to use the "new" keyword:

http://www.eclipse.org/epsilon/examples/index.php?example=org.eclipse.epsilon.examples.buildooinstance
Re: EOL: How to create a stereotype in an existing UML profile [message #1732448 is a reply to message #1732442] Tue, 17 May 2016 11:55 Go to previous message
Alireza Rouhi is currently offline Alireza RouhiFriend
Messages: 148
Registered: December 2015
Senior Member
Hi Antonio,

Thanks a lot for your more clarification and suggested solution. I will try this.

Best regards,
Alireza
Previous Topic:How to add a new UML Property as subset of an UML Class in EML
Next Topic:EVL: Defining more than one context with the same name in a module
Goto Forum:
  


Current Time: Fri Mar 29 15:19:58 GMT 2024

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

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

Back to the top