When I prepared for the “Oracle Enterprise Architect Master Certification” I was introduced to Sparx Enterprise Architect. It was recommended as the best tool to model and design the practical tasks I had to solve during the certification process by the coach I met at the Oracle certification center.

Enterprise Architect (EA) is always up-to-date when supporting the latest UML specifications and you can be sure that it is 100% compliant to the specification (very important for certification tasks). It does also offer a lot more features that you can use in a software development process like requirements engineering or creating and managing test and maintenance models. As EA is a language neutral UML modelling architecture tool, it supports a lot of programming languages like Java, C, C# or PHP. I am going to explain, how to optimize EA for modelling Java projects on this blog in this and future posts.

When creating class models I would like to use all classes and interfaces of the java standard (JEE and JSE) as well as the classes of 3rd party libraries I want to use in my project. To use the complete Java enterprise standard you need to download the JEE 7 API jar file that can be found on public maven repositories like http://central.maven.org/maven2/javax/javaee-api/7.0/javaee-api-7.0.jar

The downloaded file contains all implementations and classes (with empty implementations) of the JEE 7 standard for server-side Java development. The file you need to import for all Java classes of the standard edition is the rt.jar file that is placed in your local JRE in the lib subdirectory. This file is about 50 – 60 MB large and it contains much more files than you need for modelling projects in EA.

what?
contents of rt.jar

From all those packages you can delete the private packages from Oracle and Sun (we should never need them as they should only be used by internal JSE classes). If you want to develop a web application, you can also delete all swing and awt packages from the file, so that you get an optimized file of about 10 MB file size.

To separate all imported classes from my project classes I usually create an import package in my EA project. I do also create sub packages for java (jse and jee) and other 3rd party imports, so that the package structure looks like this:

project structure
project structure for all imported java libraries

Now it’s time to import the java standard into EA. Select the package where you would like to import the classes (jee or jse) and open the context menu (right mouse click) and select “Code Engineering” – “Import binary module”.

import a binary module (a jar file)
import a binary module (a jar file)

In the next dialog select “Java jar Archive” from the list of import types and select the jar file you want to import. In the next dialog select “Overwrite existing classes” and “Do not import private members” (we cannot use them anyway) and click the Import button. It will take about one minute for the Enterprise Edition and 5 to 10 minutes for the Standard Edition to be imported (on my workstation).

import options for binary modules
import options for binary modules

The imported structure for the Enterprise Edition should look like that:

structure after import of JEE 7 classes
structure after import of JEE 7 classes

We need another important step to make EA handle those imports in the way we would like to get: select the jee and the jse packages and select “Code Engineering” – “Set as Namespace Root” from the context menu. With this configuration we make sure that EA is able to generate valid Java code with correct import and package statements.

Now it’s time to test Java modelling with a class model we create in EA. I created a class model structure with a package and one class (IndexController) for a web project. I want to create a new method in this class that finds the current user session (the http session object), so I added the method findCurrentSession() that returns a HttpSession object. As return type you can select a class from the available classes or search for an object type (faster). As you can see EA is able to locate the HttpSession class in the javax.servlet.http package. That looks promising, now let’s try and generate Java code for developers to code the method body. Select the class model package and click Code EngineeringCreate source code.

EA now generates a Java project structure with packages and the IndexController.java file in your selected directory. The generated java file looks like this:

package de.mekaso.webproject.controller;

import javax.servlet.http.HttpSession;

/**
 * @author Meik
 * @version 1.0
 * @created 31-Jul-2016 15:34:18
 */
public class IndexController {

  public IndexController() {
  }

  public void finalize() throws Throwable {
  }

  public HttpSession findCurrentSession(){
    return null;
  }

}

As you can see EA managed to create a valid package declaration and a valid import statement for the used HttpSession class. It generated a type comment for the IndexController class with information about the author and the creation date by using the information that is entered in the notes section of the EA class element for the comment.

EA generates an empty default constructor and a finalize method for a generated class. This behavior can be customized in the options dialog. Just unselect the checkboxes in the “Souce Code Engineering” – “Object Lifetimes” section for Generate Constructor / Destructor and your Java class will only contain the attributes and methods that you just modelled.

constructor / destructor options in EA
constructor / destructor options in EA
package de.mekaso.webproject.controller;

import javax.servlet.http.HttpSession;

/**
 * @author Meik
 * @version 1.0
 * @created 31-Jul-2016 15:34:18
 */
public class IndexController {

  public HttpSession findCurrentSession(){
    return null;
  }

}

By Meik Kaufmann

I am a certified oracle enterprise architect and like to share my knowledge and experience that I gain in the projects I am working on.

3 thoughts on “Teaching Enterprise Architect standard Java”
    1. EA treats annotations and exceptions as “tagged values”. I will write another blog post with a detailed guide to model these java specific things in EA pretty soon. Stay tuned…

Leave a Reply

Your email address will not be published. Required fields are marked *