🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
OCLOperators allStates
This page was created by Lars.olofsson on 2017-08-13. Last edited by Wikiadmin on 2026-07-29.

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.allStates

Use 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:

  • Draft
  • Active
  • Suspended
  • Closed

Use this expression:

Department.allStates

The 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

  1. Open the OCL Editor.
  2. Enter the class name, for example Department.
  3. Type .allStates to retrieve the state names defined for that class.
  4. Use the returned string collection in the surrounding OCL expression as needed.

Notes

  • The operation returns state names as strings, not state-machine objects.
  • allStates examines all state machines defined for the type.
  • Use allStates for model introspection. To retrieve existing instances of a class, use allInstances.

See also