You can retrieve a slot value by either using a normal UML Specification structure, or by using a slot property. Using normal UML Specification to Retrieve Slot ValuesFor example, to retrieve a Name slot value type: | Code Block |
|---|
| #foreach($instance in $InstanceSpecification)
#foreach($slot in $instance.slot)
#if($slot.definingFeature.name == 'Name')
#if($slot.value.size() > 0)
#set($v = $slot.value.get(0).text)
#else
#set($v = "")
#end
Slot value is $v
#end
#end
#end |
Using Slot Property to Retrieve Slot ValuesYou can use a slot property as a shortcut to get the following information from a slot. The following code retrieves slot information from an element. In which: - $element is an element.
- slots is a property for getting slot variables.
For example, if you want to obtain a collection of slot variables of an element, type: | Code Block |
|---|
| #foreach($slot in $instanceSpecification.slots)
$slot.name
#end |
The following code retrieves slot information from an element and a classifier’s name. | Code Block |
|---|
| $element.slots.ClassifierName
or
$element.slots.get("ClassifierName") |
Where: - $element is an element.
- slots is a property for getting the slots variable.
- ClassifierName is the classifier’s name.
The code returns: - A list of slot variables whose classifier names are ClassifierName.
- If there are multiple classifiers that match the ClassifierName, the code returns the slot property of the first classifier.
- If there is no classifier that matches the ClassifierName, the code returns null.
For example, if you want to retrieve all slot values from the “Communicate” classifier, type: | Code Block |
|---|
| $instanceSpecification.slots.Communicate
$instanceSpecification.slots.get("Communicate") |
Retrieving slot value from an element, a classifier’s Name, and a defining feature name| Code Block |
|---|
| $element.slots.ClassifierName.DefiningFeatureName
or
$element.slots.ClassifierName.get("DefiningFeatureName")
or
$element.slots.get("ClassifierName").DefiningFeatureName
or
$element.slots.get("ClassifierName").get("DefiningFeatureName") |
|