简体   繁体   English

Papyrus UML:使用配置文件(元模型扩展)将类型添加到属性

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

I'm defining a profile using Papyrus UML in Eclipse . 我正在Eclipse中使用Papyrus UML定义配置文件。 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 . 示例:我想在基本Java Type中未定义的HashMap类型的类中具有一个属性。 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. 我可以在配置文件中定义一个<<Primitive Type>>类,将其命名为“ HashMap”,但我不清楚我需要扩展哪个UML元类。

Please provide me a step by step example of profile definition if you have time. 如果您有时间,请提供一个有关配置文件定义的分步示例。 Thanks a lot! 非常感谢!

You don't need to extend existing UML metaclass to create new type. 您不需要扩展现有的UML元类来创建新类型。 In UML metamodel, it is defined that an attribute (a Property ) is linked to a Type by the reference type . 在UML元模型中,定义了一个属性(一个Property )通过引用type链接到Type A Type that can be attached to a property can be an Inteface/Class/PrimitiveType... instance . 可以附加到属性的Type可以是Inteface/Class/PrimitiveType... 实例 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). 实际上,一部分UML基本类型只是在导入的其他模型中定义的PrimitiveType实例(请在您的UML模型XMI中查找packageImport )。

When you set the type of a Property to Integer , you set the type of your Property instance to the PrimitiveType instance named Integer . Property的类型设置为Integer ,将Property实例的类型设置为名为IntegerPrimitiveType实例。 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. 因此,如果您要使用HashMap类型,则只需创建一个名为HashMapPrimitiveType实例(已完成)即可。

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). 但是,当您将模型“绑定”到Java时,我怀疑您可能希望对通用类型进行建模(例如HashMap<String, Integer> )。 To do that, you will have to handle UML templates. 为此,您将必须处理UML模板。

http://www.uml-diagrams.org/template.html 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. 在这种情况下,您将必须使用两个名为HashMap形式参数创建可模板化的Class并将其绑定,以生成绑定类型。 Then, you will be able to use the bound type as type for a Property instance (no need for UML metamodel extension either). 然后,您将能够使用绑定类型作为Property实例的类型(也不需要UML元模型扩展)。

Note : PrimitiveType is a UML metaclass. 注意PrimitiveType是UML元类。 You can extend it using stereotype (let's say A here) in order to create a more refined PrimitiveType metaclass. 您可以使用构造型 (在这里说A )扩展它,以创建更完善的PrimitiveType元类。 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. 如果执行此操作,则可以在UML模型中创建A实例,但不希望将A用作Property类型。 The only objects you will be able to use will be the created A instances. 您将只能使用创建的A实例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM