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

Contents
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 compile 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.

Generating Code

The context menu of an Executable StateMachine provides special code generation commands for generating the StateMachine. The first option is to generate the code, using the 'Executable StateMachine Code Generation' dialog.

Feature

Description

Set Generation Path

Type in the 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 of this topic.

Files Created

The code generation of the Execution Analyzer will create the appropriate set of files for the selected language, as shown here for C#.

In addition, files are generated for each Class used by the Executable StateMachine.

Execution Analyzer Scripts

Each Executable StateMachine that is generated will also generate an Execution Analyzer script. You can call this to compile the generated code either from the Execution Analyzer window or using the Executable StateMachine context menu.

Generation Output

When generating, progress messages, warnings or errors are displayed in the 'Executable StateMachine 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 Ctrl+Shift+F12.

Compile Context Menu Command

The 'Code Generation' context menu of an Executable StateMachine provides a 'Compile' command, which you can use 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 StateMachine provides a shortcut to allow changes made to a StateMachine to be quickly tested. This command updates the code before compiling it, and then starts the simulation.

Compiler Output

When compiling, all output from the compiler 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.

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

Learn more