com.ibm.websphere.brb.implementor
Class ImplementorHelper

java.lang.Object
  |
  +--com.ibm.websphere.brb.implementor.ImplementorHelper

public abstract class ImplementorHelper
extends java.lang.Object

A helper class for RuleImplementor implementations.


Field Summary
static int EQUALS
           
static int GREATER_THAN
           
static int GREATER_THAN_EQUALS
           
static int LESS_THAN
           
static int LESS_THAN_EQUALS
           
static int RANGE_INCLUSIVE
           
static int RANGE_NONINCLUSIVE
           
 
Constructor Summary
ImplementorHelper()
           
 
Method Summary
static void assertParamLength(java.lang.Object[] params, int correctParamLength, java.lang.String name)
          Ensure that the parameter list which is passed has the given number of parameters, and that each parameter is non-null.
static void assertParamLengthAllowNulls(java.lang.Object[] params, int correctParamLength, java.lang.String name)
          Ensure that the parameter list which is passed has the given number of parameters.
static ConstraintReturn compare(java.lang.Object val1, java.lang.Object val2, java.lang.Object val3, int operator, java.lang.String name)
          Compare the values using the given operator and return the result.
static java.lang.String getMessage(java.lang.String resourceKey, java.lang.Object[] formatArgs)
          Retrieve a translated message from the Business Rule Beans default resource bundle.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EQUALS

public static final int EQUALS

LESS_THAN

public static final int LESS_THAN

LESS_THAN_EQUALS

public static final int LESS_THAN_EQUALS

GREATER_THAN

public static final int GREATER_THAN

GREATER_THAN_EQUALS

public static final int GREATER_THAN_EQUALS

RANGE_INCLUSIVE

public static final int RANGE_INCLUSIVE

RANGE_NONINCLUSIVE

public static final int RANGE_NONINCLUSIVE
Constructor Detail

ImplementorHelper

public ImplementorHelper()
Method Detail

assertParamLength

public static void assertParamLength(java.lang.Object[] params,
                                     int correctParamLength,
                                     java.lang.String name)
                              throws BRBeansIllegalArgumentException
Ensure that the parameter list which is passed has the given number of parameters, and that each parameter is non-null. If the wrong number of parameters is given, or any of the parameters are null, an exception is thrown which contains, as a replacement value, the given method name. An exception is also thrown if params is null.

Parameters:
params - the parameter list to check
correctParamLength - the proper length of the parameter list
name - the class and method name of the calling method to fill in as replacement text.
Throws:
BRBeansIllegalArgumentException - if the parameter list is the wrong length, or any of the parameters are null

assertParamLengthAllowNulls

public static void assertParamLengthAllowNulls(java.lang.Object[] params,
                                               int correctParamLength,
                                               java.lang.String name)
                                        throws BRBeansIllegalArgumentException
Ensure that the parameter list which is passed has the given number of parameters. Individual parameters are allowed to be null. If the wrong number of parameters is given, an exception is thrown which contains, as a replacement value, the given method name. An exception is also thrown if params is null.

Parameters:
params - the parameter list to check
correctParamLength - the proper length of the parameter list
name - the class and method name of the calling method to fill in as replacement text.
Throws:
BRBeansIllegalArgumentException - if the parameter list is the wrong length

compare

public static ConstraintReturn compare(java.lang.Object val1,
                                       java.lang.Object val2,
                                       java.lang.Object val3,
                                       int operator,
                                       java.lang.String name)
                                throws BRBeansIllegalArgumentException
Compare the values using the given operator and return the result. All numeric types are converted to Double before performing the comparison. If a String can be converted to a number (using Double.valueOf()), it will be treated as a Double for comparison. If a String cannot be converted to a number, it will be compared as a String. In the end the values must either be all numeric, all non-numeric Strings, or all Dates in order to perform the comparison. Otherwise an exception is thrown.

If the operator specified is RANGE_INCLUSIVE or RANGE_NONINCLUSIVE, then all three values must be specified (none can be null). In this case val1 is the lower bound of the range, val2 is the value to be checked, and val3 is the upper bound. If any of the three values is null, an exception is thrown. For other operators only val1 and val2 are used. val3 is ignored. val1 is the left-hand operand and val2 is the right-hand operand.

Parameters:
val1 - the left-hand operand
val2 - the right-hand operand, or middle operand if val3 is non-null
val3 - the right-hand operand for a three-operand operator, or null
operator - the operator to use
name - the rule implementor calling this general function
Returns:
the results of the comparison

getMessage

public static java.lang.String getMessage(java.lang.String resourceKey,
                                          java.lang.Object[] formatArgs)
Retrieve a translated message from the Business Rule Beans default resource bundle.
Parameters:
resourceKey - The key in the resource bundle that will be used to select the specific message that is retrieved for getMessage().
formatArguments - The arguments to be passed to the MessageFormat class to act as replacement variables in the message that is retrieved from the resource bundle. Valid types are those supported by MessageFormat.