In the following example, the convertDate function
is implemented as part of evaluate in the FunctionCall classFciFunctionCall.
public class FciFunctionCall extends FunctionCallImplBase implements
FunctionCall
{
/* Additional Code Removed */
public void evaluate(String thePackageName,
String theFunctionName, int theFunctionID,
int theFunctionInstance, short theCommand,
com.ibm.form.api.xfdl.FormNodeP theForm,
com.ibm.form.api.xfdl.FormNodeP theComputeNode,
com.ibm.form.api.IFSUserDataHolder theFunctionData,
com.ibm.form.api.IFSUserDataHolder theFunctionInstanceData,
com.ibm.form.api.xfdl.FormNodeP [] theArgList,
com.ibm.form.api.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";
else
{
theLocale = new Locale(theLocaleString.substring(0, 2),
theLocaleString.substring(3));
if ((theDateFormat = DateFormat.getDateInstance(
DateFormat.LONG, theLocale)) == null)
theAnswerString = "Unrecognized locale";
else
{
try
{
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 */
}