IDIOM Decision Suite and Business Rules Beans

Business Rule Bean Components

The Business Rule Bean framework requires that a rule component implement the interfaces defined within an IBM Rule Implementor interface (com.ibm.websphere.brb.RuleIm-plementor). This interface defines the contract that a business decision will have with the Websphere environment and the Business Rule Bean framework. This interface is illustrated below.

public Object fire (Trigger Point tp,
    Object target,
    IRuleCopy rule,
    Object[] firingParms)

public String getDescription()

public void init(Object[] initParams,
    String[] dependentRules,
    String userDefinedData,
    IRuleCopy rule)

Once implemented, a Business Rule Bean is deployed into the environment and the implementing class is associated with a name (JNDI name). The calling application will reference the Business Rule Bean by this name and interface with it via a trigger point (examples below).

An IDIOM Business Rule Bean

The following code illustrates the integration of IDIOM within a Business Rule Bean. In this example the configuration of which rules (decisions in IDIOM terminology) will be executed is externalised from both the rule and the application calling the rule, and is managed by the deployment descriptor of the rule itself. The benefit of this approach is that a single IDIOM decision can be deployed and configured as a rule many times, each deployment having a specific binding to decisions or groups of decisions within IDIOM. This behaviour can be managed by the deployment configuration with no code changes required.

//These variables are initialized in init()
public class IdiomRuler implements RuleImplementor,
                                   VehicleConstants {

public String IDIOM_SYSTEM_NAME;
public String IDIOM_SCOPE_NAME;
public String IDIOM_SLOT;
public int noDocuments;
//set to true at the end of init
boolean initialized = false;

public IdiomRuler() {
    super();
}
/**
  Executes a call to the IDIOM DecsionManager to
  execute specific Decisions/rules
*/
public Object fire(TriggerPoint tp,
    Object target,
    IRuleCopy rule,
    Object[] parms) throws BusinessRuleBeansException {

    Boolean retV = new Boolean(true);
    List list = new ArrayList();
    if (initialized) {
        // One parameter is expected - the Idiom file
        ImplementorHelper.assertParamLength(parms,
            NoDocuments, "IdiomRuler.fire");

        //Populate a list of documents from the
        //rule parameters - the number of documents
        //is defined in the initialisation
        list.clear();
        for(int I = 0; I < noDocuments; I++){
            list.add((Document) parms[I]);
        }

        try {
            //execute the decisions on documents provided
            //via the parameters and the configuration as
            //specified in the initialisation
            DecisionServer.executeSlot(new Date(),
                list,
                IDIOM_SYSTEM_NAME,
                IDIOM_SCOPE_NAME,
                IDIOM_SLOT);
        }
        catch (Exception e) {
            retV = new Boolean(false);
        }
    }
    return retV;
}

/**
  This method is called by the framework and initialises the
  Rule based on the configuration defined during deployment
*/
public void init(Object[] parms,
    String[] dependentRules,
    String userDefinedData,
    IRuleCopy rule) throws BusinessRuleBeansException {
    if (parms == null || parms.length == 0)
        return;
    // 4 parameters are expected
    ImplementorHelper.assertParamLength(parms, 4, “IdiomRuler.init”);
    // Store the initialization parameters.
    IDIOM_SYSTEM_NAME = (String) parms[0];
    IDIOM_SCOPE_NAME = (String) parms[1];
    IDIOM_SLOT = (String) parms[2];
    noDocuments = Integer.parseInt((String) params[3]);
    Initialized = true;
}

}

The Business Rule Bean configurator, as illustrated in the following image, manages the configuration of the rule and sets the values for the initialisation parameters. These parameters allow the Business Rule Bean to be configured to interface with IDIOM as illustrated in the example above.

<< Back Next >>