Community articleImplementing your custom functions
Added by IBM contributorIBM on May 6, 2011
Rate this article 1 starsRate this article 2 starsRate this article 3 starsRate this article 4 starsRate this article 5 stars

Implement your custom functions as part of the FunctionCall method evaluate.
  • TheFunctionCall class must implement the evaluate method since it is defined as part of the FunctionCall interface.
  • evaluate is called whenever a particular function needs to be executed.
  • In the following example, the convertDate function is implemented as part of evaluate in the FunctionCall classFciFunctionCall.
  •    public class FciFunctionCall extends FunctionCallImplBase implements 
          /* Additional Code Removed */
             public void evaluate(String thePackageName, 
                String theFunctionName, int theFunctionID, 
                int theFunctionInstance, short theCommand, 
                com.PureEdge.xfdl.FormNodeP theForm, 
                com.PureEdge.xfdl.FormNodeP theComputeNode, 
                com.PureEdge.IFSUserDataHolder theFunctionData, 
                com.PureEdge.IFSUserDataHolder theFunctionInstanceData, 
                com.PureEdge.xfdl.FormNodeP  [] theArgList, 
                com.PureEdge.xfdl.FormNodeP theResult) throws UWIException
             String theDateString;
             String theLocaleString;
             String theAnswerString = null;
             Date theDate = null;
             Locale theLocale;
             DateFormat theDateFormat;
                if (theCommand == FunctionCall.FCICOMMAND_RUN) 
                /* Now we'll switch on the function ID. This makes it easy for a
                   single FunctionCall object to support multiple functions. */
                if (theFunctionID == FciFunctionCall.CONVERTDATE)
                /* First, we'll grab the string values of the two arguments. 
                   Since    we indicated that this method has two parameters and
                   that it       must have two parameters 
                   (FCI_FOLLOWS_STRICT_CALLING_PARAMETERS) when we registered 
                   it, we don't have to check to see if we actually received
                   both parameters, since this code won't even be called unless
                   the caller used the right number of parameters. */
                   theDateString = theArgList [0].getLiteralEx(null);
                   theLocaleString = theArgList [1].getLiteralEx(null);
                   /* Now we perform the conversion. */
                   if (theLocaleString.length( ) != 5) 
                      theAnswerString = "Locale must be 2 characters, " +
                         "a space and    2 characters";
                      theLocale = new Locale(theLocaleString.substring(0, 2),
                      if ((theDateFormat = DateFormat.getDateInstance(
                         DateFormat.LONG, theLocale)) == null)
                         theAnswerString = "Unrecognized locale";
                            if ((theDate = new SimpleDateFormat
                               ("yyyyMMdd").parse(theDateString)) == null)
                               theAnswerString = "Unable to parse";
                         catch (ParseException ex)
                            theAnswerString = ex.toString( );
                         if (theAnswerString == null)
                            theAnswerString = theDateFormat.format(theDate);
                   /* Lastly, we'll store the result in the result node */
                   theResult.setLiteralEx(null, theAnswerString);
             /* Additional Code Removed */

Parent topic: Setting up the FunctionCall Class

Related reference
evaluate method: API 4 Java TCreate New Article