The allStates OCL operation lets you inspect the state-machine definitions of a class and retrieve the names of every state defined for that type.
Syntax
TypeName.allStatesUse allStates on a class (type), not on an individual object instance. The operation reads model metadata: it does not return objects currently in a particular state.
Return value
allStates returns a Collection(String). Each value is the name of a state defined in any state machine for the type.
The result includes both:
- Simple states, such as
Active. - Composite states, which contain other states.
Example
Assume that Department has a lifecycle state machine with these states:
DraftActiveSuspendedClosed
Use this expression:
Department.allStatesThe result is a collection of strings containing:
'Draft', 'Active', 'Suspended', 'Closed'For example, you can use the returned state names when an expression needs to work with the set of states defined by the model rather than with a fixed, manually written list of names.
Use it in the OCL Editor
- Open the OCL Editor.
- Enter the class name, for example
Department. - Type
.allStatesto retrieve the state names defined for that class. - Use the returned string collection in the surrounding OCL expression as needed.
Notes
- The operation returns state names as strings, not state-machine objects.
allStatesexamines all state machines defined for the type.- Use
allStatesfor model introspection. To retrieve existing instances of a class, use allInstances.
