In order to use the Java adapter in your UML model, you need respect some prerequisites.

Java Runtime Environment

To be able to use the Java adapter in your UML model, you need to setup the Java Runtime environment on the Bridge.

On the Preferences tab of the Bridge, you can define, which version of the Java runtime you want to use for all deployed composite services. Select preference Java Adapter to display the JAVA_HOME path that is actually used.

During Bridge installation, JAVA_HOME is set to the recommended path (JRE delivered with the Bridge). We strongly recommend not to use a Java runtime that is older than the one that has been installed with Bridge. Otherwise, deployed xUML services may not run properly.

Refer to Preferences of the xUML Services for more information on how to set the Java preferences.

Requirements for Importing Java Classes

In order to import the Java classes, you need the JAR files containing all necessary classes and all its referenced classes. All classes need to follow the JavaBeans™ specification.

Especially the following conditions must apply:

ElementCondition
ClassesAll classes that will be referenced by the Java adapter need to be declared public and have a public default constructor (zero-argument constructor).
MethodsMethods that will be called by the Java adapter need to be declared public and must be static.
Data Types

For all method parameter and return types, the following conditions need to be fulfilled:

  • All types can be mapped to a Bridge base type.

  • They hold a public default constructor (zero-argument constructor). The class attributes have corresponding getter and setter methods. All class attributes are subject to the same conditions that apply to parameter and return types.

The following table shows all possible mappings of Java data types to Bridge base types. The mappings will be prompted during the import of the Java classes, if the xUML Importer cannot identify them automatically.

Java Data TypeBridge Base Type
boolean, java.lang.BooleanBoolean
byte, java.lang.ByteInteger
short, java.lang.ShortInteger
int, java.lang.IntegerInteger
long, java.lang.LongInteger
float, java.lang.FloatFloat
double, java.lang.DoubleFloat
char, java.lang.CharacterString
java.lang.StringString
java.util.Date and subclassesDateTime
java.util.GregorianCalendar and subclassesDateTime
java.io.InputStream and subclassesBlob
byte[], java.lang.Byte[]Blob
java.util.Collection and implementationsArray
Arrays except byte[] and java.lang.Byte[]Array
java.util.Map and implementations Array of a specialized class with stereotype <<MapEntry>> having two attributes of Bridge base type

The java.io.File class cannot be mapped, as it is not known, if it will be used as input or output.

If you cannot import a Java class because it does not apply to the requirements listed above, you can write your own Java wrapper class instead without modifying the original class. If the wrapper class applies to the import preconditions, you can import it instead.

Arrays of InputStream are not supported.

Java Class Development Hints

TopicHint
Checked exceptions in the default constructorThe Bridge Java wrapper cannot handle checked exceptions in the default constructor of a Java class. If you need this nevertheless, you need to wrap the checked exception with an unchecked one.
Data manipulation on the Java objectIf you want to manipulate data of a Java object, there is no need to transfer it to xUML and back (if not necessary). Leave the object management to Java and store the created objects in a thread-save concurrent hashmap. Then, simply transfer only an object id between the xUML model and the Java implementation.
Catching exceptions after adapter call

If you want to catch exceptions that occurred during the adapter call in your xUML model, you need to throw these exceptions in your Java code using one of the following:

throw new BridgeException("your error message", "your error code", "your error domain");
throw new BridgeException("your error message", "your error code");
throw new BridgeException("your error message");

In order to use BridgeException, you need to import class ch.e2e.bridge.server.BridgeException from addon.jar to your Java implementation. You can find this JAR in your Magic Draw installation folder at /plugins/ch.e2e.builder.plugin.magicdraw/lib/system/addon.jar.

  • No labels