Work with Java Custom Functions

In addition to C programming language and SQL, you can use Java programming language to write the body of your user-defined functions. As for implementations in C, declaring Custom Functions using Java requires a third-party tool. Specifically, you have to install a JDK (compatible with JVM 1.5) on the host where you intend to develop your Custom Functions.

Basically, the bodies of your own functions are an implementation of the Function interface that is supplied with the com.axway.xib.api.dml.Function package. When writing the body of your Java Custom Function, you create a new class that implements the interface and contains a method for the body of your function.

The following is a piece of Java code for the IsLeapYear Custom Function:

import com.axway.xib.api.dml.Function;

public class CalendarHelper implements Function
  public Object IsLeapYear(Object[] args)
    if (args[0] == null)
      return null;
    int iYear = ((Integer) args[0]).intValue();
    boolean bIsLeapYear =     (iYear % 4 == 0 && iYear % 100 != 0)
                           || (iYear % 400 == 0)
    return new Boolean(bIsLeapYear);

In such a function you receive the function parameters in the args array.

This array contains one object for each parameter. The following table shows the class of the received object in connection with the class of the real parameter:

Class of
the parameter
Class of
the received object
I java.lang.Boolean
I java.lang.Integer
R java.lang.Double
S java.lang.String
D java.lang.Date
V byte[]

Whenever one of the parameters holds a symbolic value absent or null, you receive the Java null value instead of an object. You might use this null to make the Custom Function return the symbolic value null. Returning the symbolic absent is not possible for Custom Functions written in Java.

After you’ve written your function, you use the Java compiler to compile it:

javac -classpath $CORE_ROOT/java/lib/dml-mapper-java-api-x.y.z.jar

As shown in the command above, the custom functions API is provided through a specific jar file that must be included in the class path. That file is suffixed by its revision tag in the form x.y.z.

All the compiled objects for the Custom Function, including the possible dependencies, can be placed in any location available to the integration engine server host file system.

You have, however, to build a manifest file, make its Class-Path property point to the required places, and include it in a jar in $CORE_ROOT/local/java/dmlfunctions. You are totally free in choosing the name of the jar file and to place as many files as needed in that directory.

When you define the Custom Function in Axway Mapping Services, do not forget to select Java in the Category field of the General tab. Then enter the name of the class and a name of the function for the implementation.

Defining a Custom Function in Java

Related Links