JavaCall

You use this function to call the method MethodName in the Java object TargetObject with parameters, or, to call the static method MethodName in the Java class ClassName with parameters.

Adding Java archive (JAR) files to the shared library directory

Before you can use this policy function, you must make the Java classes available to Netcool/Impact during run time. To make the Java classes available, complete the following steps:
  1. Copy the Java classes to the $IMPACT_HOME/dsalib directory.
  2. Restart the Impact Server to load the JAR files.
You must repeat this procedure for each Impact Server. This is necessary because the Java class files in the $IMPACT_HOME/dsalib directory are not replicated between servers.

Syntax

JavaCall( ClassName, TargetObject, MethodName, Parameters )

Parameters

Table 1. JavaCall function parameters

Parameter

Description

ClassName

Name of the Java class. When you are using a non-static method call, this parameter is set to null.

TargetObject

Name of the instantiated Java object. When you are using a static method, this parameter is set to null.

MethodName

Name of the Java method in the Java class you are calling.

Parameters

An array of parameter values the method requires.

Returns

Value that the method returns, if any.

Examples

Get a system property named app. Call the java.lang.System.getProperty( String key ) method with the following line:

IPL example:

propValue = JavaCall("java.lang.System", null, "getProperty", { "app" } );

The same example in JavaScript:

propValue = JavaCall("java.lang.System", null, "getProperty", [ "app" ] );

In this example, use this function to check JVM properties by calling methods on class java.lang.System from your policy. This IPL example, prints the value of a JRE system property named app:

propvalue = JavaCall("java.lang.System", null, "getProperty",
{ "app" } );
log("Property \"app\" is " + propvalue);

The same example in JavaScript:

propvalue = JavaCall("java.lang.System", null, "getProperty",
[ "app" ] );
Log("Property \"app\" is " + propvalue);

In the following IPL example, create a Java object of class Vector and call its methods:

// Create an new instance of Java class java.util.Vector
vector = NewJavaObject("java.util.Vector", null);
//Add "111111" to vector.
JavaCall(null, vector, "add", { "111111" });
// Retrieve element at position 0.
log("The first element is " + JavaCall(null, vector, "get", { 0 }) );
// Add element "22222" to position 0
JavaCall(null, vector, "add", { 0, "22222" });
// Print out the element at position 0.
// It should now be "22222", not "111111".
log("The first element is " + JavaCall(null, vector, "get", { 0 }) );
// Add element "33333" to vector.
JavaCall(null, vector, "add", { "33333" });
// Print out the current size of vector. The value should be 3.
log("Vector size is " + JavaCall(null, vector, "size", {}));

If you are using JavaScript, for a JavaCall that needs an integer argument you must use the Integer.parseInt JavaCall to create an actual integer.

// Create an new instance of Java class java.util.Vector
vector = NewJavaObject("java.util.Vector", null);
 index = JavaCall("java.lang.Integer", null, "parseInt", ["0"]);
//Add "111111" to vector.
JavaCall(null, vector, "add", ["111111"]);
// Retrieve element at position 0.
Log("The first element is " + JavaCall(null, vector, "get", [index]) );
// Add element "22222" to position 0
JavaCall(null, vector, "add", [index, "22222"]);
Log("The first element is " + JavaCall(null, vector, "get", [index]) );