How to Define Stereotype and Tagged Values using API

Stereotype is one of the extension mechanisms in the Unified Modeling Language (UML). By defining stereotype, you can extend new notations by deriving from an existing one. You can define new properties to your derived notations using tagged values. In Visual Paradigm, it is not necessary to stereotypes and tagged values using application’s user interface. You can also do this using Open API. This article will show you how to create stereotype and tagged values using Open API.

Create Stereotype

You can create a new stereotype by calling createStereotype() from ModelElementFactory. But this is not yet done. A stereotype is bound to a specific model type. So, after you create a stereotype model, you have to specify what type model element it is bounding to.

IStereotype lStereotype = IModelElementFactory.instance().createStereotype();lStereotype.setName("OpenAPI_Stereotype");
lStereotype.setBaseType(IModelElementFactory.MODEL_TYPE_CLASS);

Create Tagged Values Definition

Once you created the stereotype, you can start defining your custom properties using tagged values definition through the TaggedValueDefinitionContainer. The tagged values definition will be create into tagged value automatically when you apply the stereotype to model element.

lTaggedValueDefinitionContainer = IModelElementFactory.instance().createTaggedValueDefinitionContainer();

Once you created the TaggedValueDefinitionContainer, you have to set it to your target stereotype.

lStereotype.setTaggedValueDefinitions(lTaggedValueDefinitionContainer);

To create tagged values, you can call lTaggedValueDefinitionContainer.createTaggedValueDefinition();

Similar to stereotype, you have define the type once you created it.

There are 7 types of tagged values you can create:

// Single line textual tagged values
lTaggedValueDefinition.setType(ITaggedValueDefinition.TYPE_TEXT);
// Multi-line textual tagged value
lTaggedValueDefinition.setType(ITaggedValueDefinition.TYPE_MULTI_LINE_TEXT);
// Integer tagged value
lTaggedValueDefinition.setType(ITaggedValueDefinition.TYPE_INTEGER);
// Floating point number tagged value
lTaggedValueDefinition.setType(ITaggedValueDefinition.TYPE_FLOATING_POINT_NUMBER);
// Boolean tagged value
lTaggedValueDefinition.setType(ITaggedValueDefinition.TYPE_BOOLEAN);
// Enumeration tagged value
lTaggedValueDefinition.setType(ITaggedValueDefinition.TYPE_ENUMERATION);
// Model element tagged value
lTaggedValueDefinition.setType(ITaggedValueDefinition.TYPE_MODEL_ELEMENT);

For Enumeration tagged value, you can use the setEnumerationValues method to specify the values with a String array.

lTaggedValueDefinition.setEnumerationValues(new String[] {"value1", "value2", "value3"});

And for ModelElement tagged value, you can assign the model element only when creating the actual tagged value. Once the tagged value is created from definition, you can assign the model element using the setValue() method.

Sample Plugins

This sample plugin demonstrate how to create stereotype and definitions on classes. After deploy the plugin to VP applications, you can click on the plugin button in application toolbar to trigger it.

Trigger sample plugin

Trigger sample plugin

Download Sample Plugin

You can download the sample plugins at here.

Related Articles

1055 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply