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

Prev Next

Code Generation for Executable StateMachines

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

Language Supported

An Executable StateMachine supports code generation for these platform languages:

  • Microsoft Native C/C++
  • Microsoft .NET (C#)
  • Scripting (JavaScript)
  • Oracle Java (Java)

From Enterprise Architect Release 14.1, code generation is supported without dependency on the simulation environment (compilers). For example, if you don't have Visual Studio installed, you can still generate code from the model and use it in your own project. The compilers are still needed if you want to simulate models in Enterprise Architect.

Simulation Environment (Compiler Settings)

If you want to simulate the Executable StateMachine model in Enterprise Architect, these platforms or compilers are required for the languages:

Language Platform

Example of Framework Path

Microsoft Native (C/C++)

C:\Program Files (x86)\Microsoft Visual Studio 12.0

C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional (or other editions)

Microsoft .NET (C#)

C:\Windows\Microsoft.NET\Framework\v3.5 (or higher)

Scripting (JavaScript)

N/A

Oracle Java (Java)

C:\Program Files (x86)\Java\jdk1.7.0_17 (or higher)

Access

Ribbon

Simulate > Executable > Statemachines > Generate, Build and Run      or

Simulate > Executable > Statemachines > Generate

Generating Code

The 'Simulate > Executable > Statemachines' ribbon options provide commands for generating code for the StateMachine.  Select the Executable Statemachine Artifact first, then use the ribbon option to generate the code. The 'Executable Statemachine Code Generation' dialog displayed depends on the code language.

Generating Code (Java on WIndows)

The code generation dialog for an executable state machine

Project output directory

Displays the directory in which the generated code files will be stored.  If necessary, click on the  button at the right of the field to browse for and select a different directory. The names of the generated classes and their source file paths are displayed after this.

Executable Statemachine Target Machine

Select the 'Local' option.

Java JDK

Enter the installation directory of the Java JDK to be used.

Generating Code (Java on Linux)

Targeting Linux during executable statemachine code generation

Project output directory:

Displays the directory in which the generated code files will be stored.  If necessary, click on the  button at the right of the field to browse for and select a different directory. The names of the generated classes and their source file paths are displayed when the path is changed

Executable Statemachine Target Machine

Select the 'Remote' option.

Operating System

Select Linux.

Port

This is the debugger port to be used. You will find references to this port number in the 'Debug' and 'DebugRun' sections of the Analyzer Script generated.

Generating Code (Other Languages)

Targeting .NET in Executable Statemachine Code Generation

At the same time the System Output window opens at the 'Executable StateMachine Output' page, on which progress messages, warnings or errors are displayed during code generation.

On the 'Executable StateMachine Code Generation' dialog, the 'Artifact' field and 'Language' field display the element name and coding language as defined in the element's 'Properties' dialog.

Field/Option

Description

See also

Project output directory

Displays the directory in which the generated code files will be stored.  If necessary, click on the  button at the right of the field to browse for and select a different directory.

Project build environment

The fields and information in this panel vary depending on the language defined in the Artifact element and in the script. However, each supported language provides an option to define the path to the target frameworks that are required to build and run the generated code; examples are shown in the Languages Supported section of this topic.

This path, and its Local Paths ID, are defined in the 'Local Paths' dialog and shown here on the 'Executable StateMachine Code Generation' dialog.

Local Paths Dialog

Generate

Click on this button to generate the StateMachine code. The code generation will overwrite any existing files in the project output directory. The set of files will include all required files including those for each Class referenced by the StateMachine.

Each Executable StateMachine that is generated will also generate an Execution Analyzer script, which is the configuration script for building, running and debugging the Executable StateMachine.

Building Code

The code generated by an Executable StateMachine can be built 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 build directly using the Execution Analyzer script, including using the built-in shortcut Ctrl+Shift+F12.

Ribbon Build Command

The 'Simulate > Executable > Statemachines' drop-down menu provides a 'Build' command, which you can use to compile the code that already exists in the target directory. This can be used directly after generating the code or if you have modified the generated code in any way.

Ribbon Generate, Build and Run Command

The 'Simulate > Executable > Statemachines' drop-down menu provides a shortcut to allow changes made to a StateMachine to be quickly tested. This command updates the code before building it, and then starts the simulation.

Build Output

When building, all output  is shown on the 'Build' page of the System Output window. You can double-click on any compiler errors to open a source editor at 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.

Learn more