Skip to content

ProfilesAndStereoTypes

samatstarion edited this page Dec 29, 2025 · 1 revision

Profiles and Stereotypes

What is a Profile?

A Profile is a way to extend UML for a specific domain without changing UML itself. Think of UML as a general-purpose language. A profile lets you say:

“In my domain, I need extra concepts and properties.”

Examples:

  • A SysML profile adds engineering concepts like Block and Requirement
  • A tool profile adds tool-specific metadata
  • A project profile adds governance or ownership information

A Profile defines Stereotypes.

What is a Stereotype?

A Stereotype is a label with extra properties that you can apply to a UML element.

Examples:

  • A <<Block>> stereotype applied to a Class
  • A <<Requirement>> stereotype applied to a Class
  • A <<auxiliaryResource>> stereotype applied to a Package

A stereotype:

  • is always defined inside a profile
  • is always applied to an existing UML element
  • can add attributes (often called tagged values)

How stereotypes appear in UML XMI

In UML XMI files:

  • The UML model itself is stored under uml:Model
  • Stereotype applications are stored separately, as XML elements
  • Each stereotype application:
    • lives inside the xmi:XMI document
    • references the UML element it extends via a base_* attribute

Example (simplified):

<MyProfile:Requirement
    base_Class="Class_123"
    xmi:id="REQ-001"
    priority="High"/>

In this example we see that this StereoType is applied to an instance of Class with unique identifier 123. It has a property called priority with value High.

Processing Stereotypes

Stereotype applications:

  • are not UML elements
  • are not nested inside the UML element
  • are linked by ID references
  • may or may not have their own xmi:id

Because of this, tools usually extract stereotype applications into a separate data structure.

That is exactly what the StereoTypeApplication class does.

How StereoTypeApplication helps

  • The StereoTypeApplication class is a normalized, tool-friendly representation of one applied stereotype.
  • Instead of dealing with raw XMI XML, it captures just the essential information.
/// <summary>
/// The purpose of the <see cref="StereoTypeApplication"/> is to make of record of the
/// <see cref="IStereotype"/>s that have been applied to an <see cref="IElement"/>.
/// </summary>
public class StereoTypeApplication
{
    /// <summary>
    /// Gets or sets the unique identifier of the XML Element in the XMI document.
    /// </summary>
    public string XmiId { get; set; }

    /// <summary>
    /// Gets or sets the name of the MetaClass that the <see cref="IStereotype"/>
    /// has been applied to.
    /// </summary>
    public string MetaClass { get; set; }

    /// <summary>
    /// Gets or sets the unique identifier of the <see cref="IElement"/> that
    /// the <see cref="IStereotype"/> has been applied to.
    /// </summary>
    public string ElementIdentifier { get; set; }

    /// <summary>
    /// gets or sets the name of the applied <see cref="IStereotype"/>.
    /// </summary>
    public string StereoTypeName { get; set; }

    /// <summary>
    /// Gets or sets the name of the <see cref="IProfile"/> that the applied <see cref="IStereotype"/>
    /// is a member of.
    /// </summary>
    public string ProfileName { get; set; }

    /// <summary>
    /// Gets or sets the key-value pair of attributes (or properties) that
    /// the <see cref="StereoTypeApplication"/> holds.
    /// </summary>
    public Dictionary<string, string> Attributes = new();
}

When an XMI file contains a UML model wrapped in the xmi:XMI XML element, that element may contain so-called Stereotype applications. These are typically located at the bottom of the xmi:XMI, after the uml:Model XML element. When the xmi:XMI XML element is present, uml4net translates this into a xmiReaderResult.XmiRoot. The XmiRoot class contains a property called StereoTypeApplications that contains all the StereoTypeApplication objects uml4net could process from the XMI file.

var reader = XmiReaderBuilder.Create()
    .UsingSettings(x =>
    {
        x.UseStrictReading = true;
    })
    .WithLogger(this.loggerFactory)
    .Build();

var xmiReaderResult = reader.Read(<path-to-the-XMI-file>);

// get the first StereoTypeApplication from the list
var stereoTypeApplication = xmiReaderResult.XmiRoot.StereoTypeApplications[1];

Consolte.WriteLine(stereoTypeApplication.ProfileName)
Consolte.WriteLine(stereoTypeApplication.StereoTypeName)
Consolte.WriteLine(stereoTypeApplication.XmiId)
Consolte.WriteLine(stereoTypeApplication.MetaClass)
Consolte.WriteLine(stereoTypeApplication.ElementIdentifier)

stereoTypeApplication.Attributes.TryGetValue("<attribute-name-you-are-interested-in>", out var attributeValue);

Consolte.WriteLine($"<attribute-name-you-are-interested-in>:{attributeValue}")

Clone this wiki locally