You can use taggedvalue() in an OCL expression to read metadata stored as a tagged value on an object's class at runtime.
Read a class tagged value
A tagged value (also called a TV) is metadata attached to a model element. The taggedvalue() operator reads the value of a named tagged value from the class of the object on the left side of the expression.
Thing.taggedvalue('mytaggedvalue')
In this expression:
| Part | Meaning |
|---|---|
Thing
|
An object in the current OCL context. |
taggedvalue()
|
The OCL operator that reads class metadata. |
'mytaggedvalue'
|
The name of the tagged value to read. |
The operator returns the tagged-value value as a string.
Example
If the class of Thing has a tagged value named mytaggedvalue with the value Enabled, this expression evaluates to:
'Enabled'
You can use the returned string in an OCL expression where you need to make decisions based on metadata configured on the class.
When to use it
Use taggedvalue() when behavior depends on information modeled as metadata rather than on an attribute of each object. For example, you can place a common configuration value on a class as a tagged value and read that value at runtime for any instance of that class.
Tagged values are available on model elements and are used both by MDriven and by application models to add information that UML does not define directly. For guidance on creating and managing tagged values, see Documentation:TaggedValues.
