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.

Languages Supported

An Executable StateMachine supports code generation for these platform languages:

Language Platform

Example of Framework Path

Microsoft Native (C/C++)

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

Microsoft .NET (C#)

C:\Windows\Microsoft.NET\Framework\v3.5

Scripting (JavaScript)

N/A

Oracle Java (Java)

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

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)

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)

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)

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