🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
OCLOperators oclIsInState
This page was created by Hans.karlsen on 2017-09-14. Last edited by Wikiadmin on 2026-07-29.

You can use oclIsInState in OCL expressions to test whether an object is currently in a named state in one of its defined state machines.

Syntax

object.oclIsInState(#StateName)

The operator returns a Boolean value:

Result Meaning
true The object has a defined state machine that is currently in the specified state.
false No state machine defined for the object is currently in the specified state.

#StateName is a state literal. Replace StateName with the state you want to test.

Example: select objects in a state

The following expression returns all Article objects that are currently in the Manufacturing state:

Article.allinstances->select(a | a.oclIsInState(#Manufacturing))

The expression works in two parts:

  1. Article.allinstances obtains the existing Article instances. See allInstances.
  2. select keeps each article for which a.oclIsInState(#Manufacturing) evaluates to true.

For example, if three articles exist and only two have a state machine currently in Manufacturing, the result contains those two articles.

Test one object

Use the operator directly when the expression already has an object as its context. For an Article, this expression tests whether that article is in Manufacturing:

self.oclIsInState(#Manufacturing)

You can use the Boolean result in a larger condition. For example, the following condition is true only when the article is in Manufacturing and its name is not empty:

self.oclIsInState(#Manufacturing) and self.Name.notEmpty

See OCL Boolean Operators for combining Boolean conditions.

Multiple state machines

An object can have one or more state machines defined. oclIsInState tests whether one of those state machines is currently in the specified state. It returns true when a matching current state is found.

For example, if an Article has multiple state machines and one is currently in Manufacturing, this expression evaluates to true:

article.oclIsInState(#Manufacturing)

Use the exact state name

The state literal must identify the state you intend to test. In the examples, #Manufacturing tests the state named Manufacturing; it does not test an attribute value or a text value that happens to contain that word.

Related operators

oclIsInState tests an object's current state. It does not test the object's runtime class. To test an object's type or subtype, use oclIsKindOf.

See also