Topic
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 Project Browser, select the Package in which to create the template, then use the ribbon or context menu to display the Model Wizard; click on the 'Application Patterns' tab.

From this tab, 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.

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 Project Browser 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.