An external method is a static public Java method that is contained in a public class in a Java package that is separate from the set of built-in methods that is delivered with Connect CDC. The external method might be a member of a class in the Java JRE or in a class written by the customer or provided by a third party.
An external method can be referenced in an Connect CDC expression if the following conditions are met:
-
The method contained in the Java package must be defined as public and static. The method will be delivered or will reside in either a class file or it will be packaged with other class files in a Java jar file or zip file.
-
The class containing the method must be defined as public.
-
The datatypes of method's input parameters and its return value must be compatible with the types supported by the Expression Handler.
-
The Java package that contains the external method must be appropriately specified in the CLASSPATH for Connect CDC Listener and Connect CDC Director.
-
When the method is used in an expression, its fully qualified name, including its class and package name, must be specified when referenced in an expression.
By default, any unqualified method name, for example, “substring”, is assumed to be part of the set of built-in methods that are delivered with Connect CDC. The Expression Handler can recognize an external method and distinguish it from a built-in method if it is fully qualified and is available in the Java CLASSPATH. For example, the Java method “sqrt”, exists in the Math class of the java.lang package.
The following is an example of an expression that calculates the square root of a value contained in the column SQUARE_AREA:
java.lang.Math.sqrt(SQUARE_AREA);
The following is an example of an expression that calculates the length of the hypotenuse of a right triangle given the lengths of the other 2 sides, using the Pythagorean theorem:
java.lang.Math.sqrt(
java.lang.Math.pow(side1,2) +
java.lang.Math.pow(side2,2) );
The value for each side, side1 and side2, is first squared using the pow method and then the method sqrt is used to take the square root of the sums of the squares.
Both the external methods used, sqrt and pow, are defined in the Math class as public and static.
- To create a .zip file, use Winzip®.
- To create a .jar file, use the command:
java cvf <name of jar file to be created> <list of input class files>
- To view the classes in a jar file, use the command:
jar tf <name of the jar file>