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
- Copy the Java classes to the $IMPACT_HOME/dsalib directory.
- Restart the Impact Server to load the JAR files.
Syntax
JavaCall( ClassName, TargetObject,
MethodName, Parameters )Parameters
Parameter |
Description |
|---|---|
|
Name of the Java class. When you are using a non-static method call, this parameter is set to null. |
|
Name of the instantiated Java object. When you are using a static method, this parameter is set to null. |
|
Name of the Java method in the Java class you are calling. |
|
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]) );