You can read tagged values from your model at runtime in an OCL expression, so a model-driven application can use model metadata without writing code.
A tagged value is metadata stored on a model element. In a runtime expression, the taggedValue and taggedValueOnFeature OCL operators return the tagged-value value as a string.
Read a tagged value from a class
Use oclType to get the runtime object's class, then call taggedValue with the tagged-value name.
G.allinstances->first.oclType.taggedValue('Eco.PresentationUnit')
In this example:
G.allinstances->firstselects one runtime instance ofG.oclTypegets that instance's model class.taggedValue('Eco.PresentationUnit')reads theEco.PresentationUnittagged value defined on the class.
Use this pattern when the tagged value is set on the class itself. For the operator definition and a shorter example, see Documentation:OCLOperators taggedValue.
Read a tagged value from an attribute or association end
A class-level lookup does not read tagged values set on a feature. A feature is an attribute or an association end on a class. To read metadata from a feature, call taggedValueOnFeature on the class type.
G.allinstances->first.oclType.taggedValueOnFeature('SomeAttribute', 'Eco.PresentationUnit')
The arguments are:
| Position | Value | Example |
|---|---|---|
| First | The feature name: an attribute or association end on the class. | 'SomeAttribute'
|
| Second | The tagged-value name to read from that feature. | 'Eco.PresentationUnit'
|
For example, if the SomeAttribute attribute of G has a tagged value named Eco.PresentationUnit, the expression returns that value as a string.
See Documentation:OCLOperators taggedValueOnFeature for the operator reference.
Use the expressions in your model
- In MDriven Designer, select the expression field where you need the metadata value, such as an expression used by your ViewModel or rule.
- Identify where the tagged value is defined: on the class, or on a named attribute or association end.
- Use
oclType.taggedValue('TagName')for a class-level tagged value. - Use
oclType.taggedValueOnFeature('FeatureName', 'TagName')for a feature-level tagged value. - Replace the example names with the exact tagged-value and feature names from your model.
Keep the tagged value on the model element that owns the information. For example, a presentation-unit setting for a specific attribute belongs on that attribute and is read with taggedValueOnFeature, while metadata that applies to every instance of a class belongs on the class and is read with taggedValue.
Manage tagged values in MDriven Designer
You can add and inspect tagged values in the tagged-value editor in MDriven Designer. The editor is available where tagged values are accessed. Select Refresh From Wiki to update the available help and type-sensitive tagged-value information. See Documentation:Tagged values in the Designer.
For tagged values that affect client rendering, consult Documentation:Important TaggedValues for MDriven Turnkey Web-UI is found Here or Documentation:Important TaggedValues for MDriven WPF Fat client rather than duplicating those settings in expressions.
