Java and Enterprise Architect from Sparx Systems – Getting Started


This is the first in a series of blogs relating to the use of Java with Enterprise Architect (EA) from Sparx Systems. The purpose of the blogs is to provide a starting point for Java programmers in their use of the language with EA.

The official post from Sparx Systems is to use Java as a scripting language within EA. While this is useful, I have a preference to create Java applications outside of EA. The diagram below describes how a Java application can be created which interfaces into the Sparx Object Model.
The connection between the Java application and EA is a COM object (SSJavaCOM.dll) provided by EA. This page from EA provides information on how to install the COM object within your windows environment.
The Java application’s “view” of the Object Model is via a JAR file ( eaapi) which provides the linkage between the COM object and the Java software.


I use Netbeans for Java Development and once you have installed a 32 bit JDK it is relatively easy to create the Java application that will interface into the EA Object Model. The Java application needs the eaapi.jar file as a local library. I have used ANT for building the application.


The starting point for the API is the Repository object. It represents the repository for an individual model.  From a Java perspective, this is the first object to open. The repository can be hosted on a cloud server or on a local file system. The code example below demonstrates opening a repository that is hosted on a local file system. As described in the manual, if the repository is located on a server then a connection string should be passed as a parameter.
try{
      Repository rep = new Repository();
      rep.OpenFile(<file location>);
}
catch ( Exception e) {
     System.out.println(rep.GetLastError());   // error helper method for error messages
}
It is also recommended to close the file ( or connection ) before exiting the application.
rep.CloseFile();
The next blog entry will examine extracting elements from a repository and how the API handles the structure of an EA model. 

Comments

Popular posts from this blog

Creating Items in Sparx EA via Java

Module Management - Part 1 - getModule() Pattern

Traversing a EA Model via Java