Search code examples
eclipseumlmetamodelpapyrus

Papyrus UML: add a type to a property using a Profile (Metamodel Extension)


I'm defining a profile using Papyrus UML in Eclipse. I extended metaclass "Class" and "Property" with several Stereotype classes. I can see new Stereotypes in my actual model correctly. I want to do the same defining my own types in my profile to use them for properties inside classes in my model.

Example: i want to have a property in a class with the type HashMap that is not defined inside basic Java Type. I can define a <<Primitive Type>> class in my profile naming it "HashMap" but it's not clear to me which UML metaclass I need to extend.

Please provide me a step by step example of profile definition if you have time. Thanks a lot!


Solution

  • You don't need to extend existing UML metaclass to create new type. In UML metamodel, it is defined that an attribute (a Property) is linked to a Type by the reference type. A Type that can be attached to a property can be an Inteface/Class/PrimitiveType... instance. Actually, part of the UML basic types are just PrimitiveType instances defined in an other model which is imported (look for packageImport in your UML model XMI).

    When you set the type of a Property to Integer, you set the type of your Property instance to the PrimitiveType instance named Integer. So if you want a HashMap type, you just have to create an instance of PrimitiveType named HashMap (as you have done) and that's all.

    However, as you are "binding" your model to Java, I suspect that you will probably want to model generic types (HashMap<String, Integer> for example). To do that, you will have to handle UML templates.

    http://www.uml-diagrams.org/template.html

    In that case, you will have to create a templateable Class with two formal parameters named HashMap and to bind it in order to produce the bound type. Then, you will be able to use the bound type as type for a Property instance (no need for UML metamodel extension either).

    Note: PrimitiveType is a UML metaclass. You can extend it using stereotype (let's say A here) in order to create a more refined PrimitiveType metaclass. If you do this, in your UML model, you will be able to create A instances, but you will not be abe to use A as a Property type. The only objects you will be able to use will be the created A instances.