Easily Import Most Common Java Types in your UML Project

Put some Java in your UML projects

This article is a tip: learn how to import common Java Types into your GenMyModel UML project. Part 3 explains how to create your own library of types.

Catsoo: language + terminal for advanced modeling

As you probably know, UML is not bound to a programming language, thus it cannot provide dedicated types out of the box. It only provides few simple types : Unlimited Natural, Integer, Real, String. If you want to bind your code to a framework/language and use its types, you have to define aaaaall the types you want (classes/interfaces/datatypes). For one project, it can be acceptable (but quite long and unpleasant), but when you have to do this for all your projects, it goes from unpleasant to very annoying. That’s when CatsooLang comes in to help you do that programmatically.

enter image description here

GenMyModel provides a low-level terminal based on a proprietary language called CatsooLang. FYI, Catsoo is a tiny virtual cat, insanely inspiring. The language and its terminal enable advanced users to handle model elements and diagram elements using syntax and commands. It’s much more powerful than click+drag’n’drop.

If you want to test the feature without applying changes to your model, go into safe mode by typing: #sandbox-on and perform your tests. Exit the safe mode with #sandbox-off and type again the commands you want to execute for real.

Get Java types in seconds

We provide a Java type library written in CatsooLang (source: here in github) so you get the Java types available right away.

1.First import the UML module. Just type #import 'UML':

cl> #import 'UML'
   !! Accessing 'UML'...
   !! Loading metamodel 'http://www.eclipse.org/emf/2002/Ecore' under 'ecore'
   !! _gmmf_cSegment : (src:NodeWidget x dest:NodeWidget x segtype:EClassifier x seg:Object x srcE:Object x destE:Object) -> SegmentWidget
   !! _uml_cLibrary : (name:String) -> Package
   !! _uml_cLibType : (lib:Package x tname:String x eclass:ENamedElement) -> Object
   !! _uml_cLibType : (lib:Package x tname:String) -> DataType
   !! _uml_cAssociation : (src:Type x dest:Type x aggreg:AggregationKind) -> Association
   !! _uml_cComposite : (src:Type x dest:Type) -> Association
   !! _uml_cAssociation : (src:Type x dest:Type) -> Association
   !! _uml_implements : (src:Class x dest:Interface) -> Class
   !! _uml_cPackage : (name:String x x:Integer x y:Integer) -> Package
   !! _uml_cOperation : (parent:Object x name:String) -> Object
   !! _uml_withReturnType : (parent:Operation x type:Object x lower:Integer x upper:Integer) -> Operation
   !! _uml_returnsVoid : (parent:Operation) -> Operation
   !! _uml_addParameter : (parent:Operation x name:String x type:Object x lower:Integer x upper:Integer) -> Operation
   !! _uml_withPProps : (p:Property x props:String) -> Property
   !! _uml_cAttribute : (parent:Classifier x name:String x type:Object x props:String) -> Property
   !! _uml_inherits : (src:Classifier x dest:Classifier) -> Classifier
   !! _uml_cClassifier : (parent:Object x eclass:EClass x widget:EClass x name:String x x:Integer x y:Integer) -> Class
   !! _uml_cClass : (parent:Object x name:String x x:Integer x y:Integer) -> Class
   !! _uml_cClass : (parent:Object x name:String) -> Class
   !! _uml_cInterface : (parent:Object x name:String x x:Integer x y:Integer) -> Class
   !! _uml_cInterface : (parent:Object x name:String) -> Class
   !! _uml_cPackages : (root:Package x name:String) -> Package
   !! _uml_cPackages : (root:Package x names:Collection) -> Package

2.Import the Java library

The Java library is a set a CatsooLang commands, hosted as a Gist on Github. Import it:

cl> #import 'https://gist.githubusercontent.com/aranega/865d8605321536fb2cd2/raw/javalib.catsoo'
!! Accessing 'https://gist.githubusercontent.com/aranega/865d8605321536fb2cd2/raw/javalib.catsoo'...
Java Library creation... Started
* java.lang created
* java.util created
* java.io created
Java Library creation... Done!

The Java elements are now created. List them all:

cl> tree(__libs::java);
+- Package 'java' [-]
|  +- Package 'java' [packagedElement]
|  |  +- Package 'lang' [packagedElement]
|  |  |  +- Class 'System' [packagedElement]
   ... obviously, there is more

You can also easily check if the library had been well loaded by looking at your project tree view (in the Project panel, top left). You should be able to see a new package named **gmmlibs** and if you unfold this package, you will see packages/types created by the Catsoo script.

You can use these elements in your diagram by drag/dropping them or using them as attributs parameters.

Use Java types in your online UML diagram

Create your own Java library

Is there any Java class/interface you need that is not in our library? You can add it using the terminal.

To add new Java types, we need the UML module we have already loaded:

_uml_cLibType : (lib:Package x tname:String x eclass:ENamedElement) -> Object 
_uml_cLibType : (lib:Package x tname:String) -> DataType

Documentation is available for these functions, enter doc(_uml_cLibType);.

Call _uml_cLibType with: a package, the type name and the type metaclass. Let’s create a new type MyFrameworkType which is a Class:

__libs::java _uml_cLibType('MyFrameworkType', Class);

If you want to add a new interface called Interf1 to the java.io package:

__libs::java::java::io _uml_cLibType('Interf1', Interface);

This is as simple as that. The second _uml_cLibType function behaves like the first one but creates a named DataType. So,if you want to add a new type, you can do this:

__libs::java _uml_cLibType('org.eclipse.emf.ecore.util.EcoreUtil');

Here is a little trick you can use if you want to create many Class at once

['C1', 'C2', 'C3']->_iter(__libs::java _uml_cLibType(self, Class));

Put more in your library using the editor

Now you have the java.io package created, you can drag’n drop it onto the diagramming canvas and fill it:

  1. drag and drop the java.io,

    Drag and drop package (here 'io')

  2. add your new types into it

    New type creation

Our Java library includes the well-known Java types. Do you miss your favorite one? Let us know, we’ll add it!


Tweet about this on TwitterShare on FacebookShare on Google+Share on LinkedIn

About the author

vince Team

Music, cards and beer lover...

Also PhD in Computer Science specialized in software modeling, code generation and model driven development. Interest/work in code generation, reverse engineering techniques, interpretation and compilation.