public Object execute(String function, Object callData) throws XException
{
// for result
Document response = null;
Configuration config = Configuration.getInstance();
AS400Connection as400Connection = AS400Connection.getInstance(config
.getValue(Constants.CHAPTER_SYSTEM, mDestination.getName(),
"AS400Name"));
int timeout = config.getValueAsIntOptional(Constants.CHAPTER_SYSTEM,
mDestination.getName(), "ProgramTimeout") * 1000;
if (timeout == 0)
{
timeout = Integer.MAX_VALUE;
}
/*
* If there is no real AS400 available, then testdata will be used.
*/
if (as400Connection.isTestSystem())
{
return XMLHelper.parseXML(getTestData(function), null, null);
}
// Conect to the iSeries
AS400 as400 = as400Connection.getSystem();
// Character converter
try
{
mConverter = new CharConverter(as400.getCcsid());
}
catch (UnsupportedEncodingException e)
{
throw new XException(Constants.LOCATION_EXTERN,
Constants.LAYER_TECHNICAL,
Constants.PACKAGE_TECHNICAL_AS400, "0", e);
}
// Determine how to operate
String callType = config.getValue("AS400Program", function, "CallType");
if (!CALLTYPE_SINGLE.equals(callType)
&& !CALLTYPE_MULTI.equals(callType))
{
List params = new Vector();
params.add(callType);
throw new XException(Constants.LOCATION_EXTERN,
Constants.LAYER_TECHNICAL,
Constants.PACKAGE_TECHNICAL_AS400, "39", params);
} // if (!CALLTYPE_SINGLE.equals(callType) &&
// !CALLTYPE_MULTI.equals(callType))
if (CALLTYPE_SINGLE.equals(callType))
{ // Only one calling step, only one record wil be returned as result
// Read the name of the programm from the configuration
String programName = config.getValue("AS400Program", function,
"Program");
// Structure for input an (still empty) output parameters
ProgramParameter[] parameters = getParametersFromDocument(
(Document) callData, callType, function, 1, 1);
// the program call itself
callAS400Program(as400, programName, parameters, timeout);
// Get the output values.
List outputList = makeOutputFields(as400, parameters, 1);
// Place output values in specified XML structure.
response = getResponseDocument(function, outputList);
} // then (CALLTYPE_SINGLE.equals(callType))
else if (CALLTYPE_MULTI.equals(callType))
{ // Call multiple times to get entire list of output data
// First call will determine amount of returned records.
// Next phase is to call (another program) to get each time one
// record.
// Read the name of the output count determining program from the
// configuration
String programNameAmount = config.getValue("AS400Program",
function, "ProgramAmount");
// Read the e
String programNameData = config.getValue("AS400Program", function,
"ProgramData");
/*
* First call of the AS400 program to get the amount of rows to be
* retrieved.