EspressReport 6.6

quadbase.reportdesigner.util
Interface ICustomDefinedFunctions


public interface ICustomDefinedFunctions

An interface that can be extended to create custom functions in the Report Designer application. After creating the class that implements this interface, simply call the method QbReportDesigner.setCustomDefinedFunctions(ICustomDefinedFunctions f); to add in new custom functions in Report Designer.  Note that if an application uses a template that contains custom functions, the application must also contain the same implementation as the Designer (that created the template).

The implementing class does not have to do any parameter type checking.  Parameter type checking will be handled by the reporting engine.


Field Summary
static short BOOLEAN
          the BOOLEAN data type
static short DATE
          the DATE data type
static short NUMERIC
          the NUMERIC data type
static short STRING
          the STRING data type
static short TIME
          the TIME data type
static short TIMESTAMP
          the TIMESTAMP data type
 
Method Summary
 java.lang.String[] getAllFunctionNames()
          Returns the names of all functions.
 int[] getParamTypes(java.lang.String functionName)
          Gets the parameter types of the specified function.
 int getReturnType(java.lang.String functionName)
          Gets the return type of the specified function.
 java.lang.Object getValue(java.lang.String functionName, java.lang.Object[] args)
          This is where you implement your function.
 

Field Detail

NUMERIC

static final short NUMERIC
the NUMERIC data type

See Also:
Constant Field Values

STRING

static final short STRING
the STRING data type

See Also:
Constant Field Values

BOOLEAN

static final short BOOLEAN
the BOOLEAN data type

See Also:
Constant Field Values

DATE

static final short DATE
the DATE data type

See Also:
Constant Field Values

TIME

static final short TIME
the TIME data type

See Also:
Constant Field Values

TIMESTAMP

static final short TIMESTAMP
the TIMESTAMP data type

See Also:
Constant Field Values
Method Detail

getAllFunctionNames

java.lang.String[] getAllFunctionNames()
Returns the names of all functions.

For example, if the functions MAX and MIN are going to be defined by this class, the implementation of the getAllFunctionNames() should read:

public String[] getAllFunctionNames() {

    return new String[] {"MAX", "MIN"};
}

Returns:
a String[] of names of all functions defined in this class

getReturnType

int getReturnType(java.lang.String functionName)
Gets the return type of the specified function.

For example, if the functions MAX and MIN both return a number, the implementation of the getReturnType() function might read:

public int getReturnType(String functionName) {

    if (functionName.equals("MAX")) return NUMERIC;
    else if (functionName.equals("MIN")) return NUMERIC;
    return -1;
}

Parameters:
String - functionName: name of the custom defined function
Returns:
int: data type of the object returned by the function

getParamTypes

int[] getParamTypes(java.lang.String functionName)
Gets the parameter types of the specified function.

For example, if the functions MAX and MIN both take in two arguments of type number, the implementation of the getParamTypes() function might read:

public int[] getParamTypes(String functionName) {

    if (functionName.equals("MAX")) return new int[] {NUMERIC, NUMERIC};
    else if (functionName.equals("MIN")) return new int[] {NUMERIC, NUMERIC};
    return -1;
}

Parameters:
String - functionName: name of the custom defined function
Returns:
int[]: data type of the parameters to the function.

getValue

java.lang.Object getValue(java.lang.String functionName,
                          java.lang.Object[] args)
                          throws java.lang.Exception
This is where you implement your function. The function specified by the functionName gets passed in the correct arguments using the ARGS parameter and returns the calculated value after the function is applied. The class is responsible for type checking the incoming variables.

For example, if the functions MAX and MIN gets the maximum and minimum of the two input arguments, respectively, the implementation of the getReturnType() function might read:

public Object getValue(String functionName, Object[] args) {

    if (functionName.equals("MAX") && (args[0] instanceof int) && (args[1] instanceof int) )
      return java.lang.Math.max((int) args[0], (int) args[1]);

    else if (functionName.equals("MIN") && (args[0] instanceof int) && (args[1] instanceof int) )
      return java.lang.Math.max((int) args[0], (int) args[1]);

    return null;
}

Parameters:
String - functionName: name of the custom defined function
Object - [] args: arguments to the function
Returns:
Object: object returned by the function
Throws:
java.lang.Exception

EspressReport 6.6