Book a Demo
Prev Next

Java Example

This sample program demonstrates how easy it is to navigate, query and report on the current model using a high-level language such as Java.

When run, it will print the names of every Package in the currently-loaded model.

Create the Project

In the Browser window, select the Package in which to create the template, then use the 'Develop > Source Code > Create from Pattern' ribbon option to display the Patterns window; click on the 'Application Patterns' option.

From the 'Application Patterns' page, select the Java > RepositoryInterface template. Specify the destination folder on the file system in which the project template will be created, and click on the OK button.

Open the Project

A Package structure similar to this will be created for you.

Expand the structure until you locate the 'Repository Interface' diagram and open it.

A Class diagram as an interface to a process in Sparx Systems Enterprise Architect.

Build the Script

The commands on the diagram will operate on the active build configuration. Before executing them, double-click on the Analyzer Scripts link and select the checkbox next to the 'Repository Interface' build configuration.

Run the Script

Double-click on the Run link; a Console will open. The Console will pause after completion so you can read the output. The output from the program will also be output to the 'Script' tab of the System Output window. You can alter this by changing the code.

Debug the Script

Select the 'Program' Class from the Browser window and press Ctrl+E to open the source code.

Place a breakpoint in one of the functions and then double-click on the DebugRun link. When the breakpoint is encountered the line of code will become highlighted in the editor, as shown.