There are two (2) ways of calling Java methods from Uniface using UD5:
sql
proc statement (UD5)activate
proc statement (MW1)Before you can use the activate
, you must:
See the following sections for information on these topics:
Java methods which return an numeric results are typically mapped to a "C" implementation signature in Uniface with a return type of long
returned in $status.
Here is the source for the numeric implementation of COMPUTE.ADD, and it's signature definition.
public class COMPUTE {
public static long ADD(double a, double b) {
Double Da = new Double(a);
Double Db = new Double(b);
return Da.intValue() + Db.intValue();
}
}
Define Operation: COMPUTE | |||||||
Operation Name | Communication Default | Stateless | Literal Name | Implementation | Return Value | Context | |
ADD | Synchronous | N | C | ADD | In $status | long |
Define Parameter: ADD | |||||||
Parameter Name | In | Out | Data Type | Literal Name | Interface | Length | |
a | Y | N | Basic | Floating decimal point | a | double | |
b | Y | N | Basic | Floating decimal point | b | double |
Java methods which return String results are typically mapped to a "C" implementation signature in Uniface with a return type of String
returned in the first parameter.
Here is the source for TESTDRIVE.FRED, and it's signature definition.
public class TESTDRIVE {
public static String fred (String me) {
return "hello "+me;
}
}
Define Operation: TESTDRIVE | |||||||
Operation Name | Communication Default | Stateless | Literal Name | Implementation | Return Value | Context | |
ADD | Synchronous | N | C | fred | In First Parameter |
Define Parameter: FRED | |||||||
Parameter Name | In | Out | Data Type | Literal Name | Interface | Length | |
OUTSTR | N | Y | Basic | String | outstr | char * (length 2 - 10240) | 400 |
ME | N | Y | Basic | String | me | char * (length 2 - 10240) | 400 |
Java classes should always contain a default "main" method. This method allways returns void
and takes a single parameter of type String[]
. This is mapped to a "C" implementation signature in Uniface with a return type of void
and a single String parameter. String parameters are assumed to be arrays of strings for operations main
and maintst
as well as any operations named in the "Include File Name" field of the "Define C Properties" form in the signature definition (several operations can be named separated by white space).
Here is the source for TESTDRIVE.main, and it's signature definition.
public class TESTDRIVE {
public static void main (String args[]) {
String res;
try {
res = "JDK Test Drive - iterate parameters";
for (int i = 0; i < args.length; i++) {
res = res + " " + args[i] + " " + i;
}
} catch (Exception e) {
res = "Exception=" + e;
}
return res;
}
Define Operation: TESTDRIVE | |||||||
Operation Name | Communication Default | Stateless | Literal Name | Implementation | Return Value | Context | |
MAIN | Synchronous | N | C | main | None (void) |
Define Parameter: MAIN | |||||||
Parameter Name | In | Out | Data Type | Literal Name | Interface | Length | |
ARGS | Y | N | Basic | String | args | char * (length 2 - 10240) | 1000 |
The elements of the array are passed to main
as a <GOLD> ; separated list.
By default UD5 uses the name which you define in Uniface as the signature name as the class name. However Java classes may be named differently to this, especially if they are contained in a package, e.g.:
com.sun.enterprise.appclient.Main
UD5 supports these names by using the Implementation specific properties of the signature definition in Uniface, e.g.:
$Revision: 1.9 $ $Date: 2014/11/05 02:24:16 $ | [go to top] |