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

    Fields
    Modifier and Type
    Field
    Description
    static final short
    the BOOLEAN data type
    static final short
    the DATE data type
    static final short
    the NUMERIC data type
    static final short
    the STRING data type
    static final short
    the TIME data type
    static final short
    the TIMESTAMP data type
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the names of all functions.
    int[]
    getParamTypes(String functionName)
    Gets the parameter types of the specified function.
    int
    getReturnType(String functionName)
    Gets the return type of the specified function.
    getValue(String functionName, Object[] args)
    This is where you implement your function.
  • Field Details

  • Method Details

    • getAllFunctionNames

      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(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(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

      Object getValue(String functionName, Object[] args) throws 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") invalid input: '&'invalid input: '&' (args[0] instanceof int) invalid input: '&'invalid input: '&' (args[1] instanceof int) )
          return java.lang.Math.max((int) args[0], (int) args[1]);

        else if (functionName.equals("MIN") invalid input: '&'invalid input: '&' (args[0] instanceof int) invalid input: '&'invalid input: '&' (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:
      Exception