Extending the functionality of IBM Workplace Forms with the Function Call Interface

Return to article

Sample FunctionCall class
package com.ibm.wpforms.samples;

import java.io.File;
import java.util.Date;

import com.PureEdge.IFSSingleton;
import com.PureEdge.IFSUserDataHolder;
import com.PureEdge.ShortHolder;
import com.PureEdge.ShortListHolder;
import com.PureEdge.StringHolder;
import com.PureEdge.StringListHolder;
import com.PureEdge.error.UWIException;
import com.PureEdge.ifx.IFX;
import com.PureEdge.xfdl.FormNodeP;
import com.PureEdge.xfdl.FunctionCall;
import com.PureEdge.xfdl.FunctionCallImplBase;
import com.PureEdge.xfdl.FunctionCallManager;

public class FciFunctionCall extends FunctionCallImplBase implements FunctionCall {

//Define a unique ID to the every custom function
public static final int READ_FILE = 1;

public FciFunctionCall(IFX IFXMan) throws UWIException {
FunctionCallManager theFCM;

//Retrieve the Function Call Manager
if ((theFCM = IFSSingleton.getFunctionCallManager()) == null)
throw new UWIException("Needed Function Call Manager");

//Register this extension to IFXMan
IFXMan.registerInterface(this,FunctionCall.FUNCTIONCALL_INTERFACE_NAME,
FunctionCall.FUNCTIONCALL_CURRENT_VERSION,
 FunctionCall.FUNCTIONCALL_MIN_VERSION_SUPPORTED, 0x01000300,0, null,
  theFCM.getDefaultListener());

//Register custom function to the Function Call Manager
theFCM.registerFunctionCall(this, "sample_package", "readFile",
 FciFunctionCall.READ_FILE, FunctionCall.FCI_FOLLOWS_STRICT_CALLING_PARAMETERS, "S",
  0x01000300, "");
}

public void help(String thePackageName, String theFunctionName, int
 theFunctionID,IFSUserDataHolder theFunctionData, StringHolder theQuickDesc,
 StringHolder theFunctionDesc, StringHolder theSampleCode, StringListHolder
  theArgsNameList,
 StringListHolder theArgsDescList, ShortListHolder theArgsFlagList, StringHolder
  theRetValDesc,
 ShortHolder theRetValFlag) throws UWIException
{
            ; // leave this empty
}
}

public void evaluate(String thePackageName, String theFunctionName, int theFunctionID,
 int theFunctionInstance, short theCommand, FormNodeP theForm, FormNodeP theComputeNode,
  IFSUserDataHolder theFunctionData, IFSUserDataHolder theFunctionInstanceData,
 FormNodeP[] theArgList, FormNodeP theResult) throws UWIException {
if (theCommand == FunctionCall.FCICOMMAND_RUN) {
if (theFunctionID == FciFunctionCall.READ_FILE) {
String theFileLocation = null;
//Get the first parameter which is the only parameter
theFileLocation = theArgList[0].getLiteralEx(null);
File theFile = new File(theFileLocation);

//Use Form API to set the file information to form
theForm.setLiteralByRefEx(null, "PAGE1.name.value", 0, null, null, theFile.getName());
theForm.setLiteralByRefEx(null, "PAGE1.size.value", 0, null, null, "" + theFile.length()
 + " bytes");
theForm.setLiteralByRefEx(null, "PAGE1.lastModify.value", 0, null, null, new
 Date(theFile.lastModified()).toString());
theForm.setLiteralByRefEx(null, "PAGE1.canRead.value", 0, null, null, theFile.canRead()
 == true ? "true" : "false");
theForm.setLiteralByRefEx(null, "PAGE1.canWrite.value", 0, null, null, theFile.canWrite()
 == true ? "true" : "false");

//Return ‘1’ if everything works well
theResult.setLiteralEx(null, "1");
}
}
}
}

Return to article