When using the Invoke Java operator, use the following guidelines for implementing Java code:
For more information about BeanShell syntax and commands, see the following site: http://www.beanshell.org/
The BeanShell interpreter only implements "final" (and ignores the others).
Only "synchronized’ is currently implemented. The BeanShell interpreter ignores the others.
// Import the classes that you want to use
import ca.tech.pam.MyAccount;
// Note: no need to import StringBuffer and Date because they are part of the
// automatically imported packages
// import java.lang.StringBuffer;
// import java.util.Date;
// Note: the jar that contains the ca.tech.pam.MyAccount class
// must be in the list of External Jars of the operator or the module;
// but java lang and java util are in rt.jar, which is automatically put in the classpath
MyAccount acct = new MyAccount(newDate(),100);
// Use the public methods of the MyAccount object
acct.addFunds(34);
acct.subFunds(10);
// Define your own method
String getStatement(MyAccount acc) {
StringBuffer strBuff = new StringBuffer("Account Balance: " + acc.getBalance());
Date dt = new Date(System.currentTimeMillis());
strBuff.append(" on date: " + dt);
return strBuff.toString();
}
// Use the method you defined
// also print the statement using the 'logger' object that you
// setup in the 'Logger' page of the operator
logger.info(getStatement(acct));
Note: To execute this statement, set the logger to true and provide the log file name. Otherwise an error occurs during execution.
At the end of execution, the log message contains:
Account Balance: 124. on date: Wed Jul 13 12:53:37 EDT 2011
(The message includes the correct date and time of execution.)
|
Copyright © 2014 CA.
All rights reserved.
|
|