Please note : This help page is not for the latest version of Enterprise Architect. The latest help can be found here.

Code Generation for Executable State Machines

The code generated for an Executable State Machine is based on its language property. This might be Java, C, C++, C# or Javascript. Regardless, Enterprise Architect generates the appropriate code, which is immediately ready to compile and run. There are no manual interventions necessary before you run it. In fact after the initial generation, any Executable State Machine can be generated, built and executed at the click of a button.

Generating Code

The context menu of an Executable State Machine provides special code generation commands for generating the State Machine. The first option is to generate the code, which will display this dialog.

Feature

Description

Set Generation Path

The generation dialog allows you to enter a target directory to which all source files will be generated.

Set Framework Path

Each supported language provides an option to define the path to the target frameworks that are required to compile and run the generated code. For more information, see the Languages Supported section.

Files Created

Regardless of the selected language, the code generation of an execution analyzer will create a similar set of files as shown here for C#.

In addition, there are also files generated for each Class used by the Executable State Machine.

Execution Analyzer Scripts

Each Executable State Machine that is generated will also generate an Execution Analyzer script. This allows the generated code to be compiled either from the Execution Analyzer window or using the Executable State Machine context menu.

Generation Output

Where generating progress messages, warnings or errors are displayed in the 'Executable State Machine Output' page of the System Output window.

Compiling Code

The code generated by an Executable Statemachine can be compiled by Enterprise Architect in one of three ways.

Method

Description

Execution Analyzer Script

The generated execution analyzer script includes a command to build the source code. This means that when it is active you can compile directly using the execution analyzer script, including using the built-in shortcut key Ctrl+Shift+F12.

Compile Context Menu Command

The 'Code Generation' context menu of an Executable State Machine provides a 'Compile' command, allowing you to compile the code that already exists in the target directory. This can be used directly after calling 'Generate', or if you have modified the generated code in any way.

Generate, Build and Run Command

The 'Code Generation' context menu of an Executable State Machine provides a shortcut to allow changes made to a State Machine to be quickly tested. This command updates the code before compiling it, and then starts the simulation as discussed in detail in a later topic.

Compiler Output

When compiling, all output from the compiler is shown on the Build page of the System Output window. This also allows you to double-click on any compiler errors to open a source editor to the appropriate line.

Leveraging existing code

Executable Statemachines generated and executed by Enterprise Architect can leverage existing code for which no Class model exists. To do this you would create an abstract Class element naming only the operations to call in the external codebase. You would then create a generalization between this interface and the Statemachine Class, adding the required linkages manually in the Analyzer Script. For Java you might add .jar files to the Class path. For native code you might add a .dll to the linkage.

Languages Supported

An Executable Statemachine supports code generation for these platform languages:

Language Platform

Languages

Microsoft Native

  • C
  • C++

Microsoft .NET

  • C#

Scripting

  • JavaScript

Oracle Java

  • Java

Learn more