[Enterprise Extensions only]

Simple Trigger Point - an example

A simple trigger point is used to trigger a rule or rules specified by name. This type of trigger point is used by invoking the trigger method on an instance of the TriggerPoint class. All rules with the specified name will be triggered and the results combined using the combining strategy specified on the TriggerPoint object. This type of trigger point only finds rules that are marked as not being classifiers.

The following shows an example of using a simple trigger point to trigger a rule named isSeniorCitizen (in the com/acme/ageRules folder) that determines whether a person is classified as a senior citizen based on the passed in age.

 ...
// create an instance of TriggerPoint for triggering the rule and specify that the 
// ReturnFirstCombiningStrategy is to be used to return only the first result if
// multiple rules are found.
TriggerPoint tp = new TriggerPoint();
tp.setCombiningStrategy(CombiningStrategy.RETURN_FIRST, TriggerPoint.ALL_RULES);

// define paramdter list that's passed to the rule
Object [ ] plist = new Object[1];

// define age of person to be tested
Integer age = new Integer(64);

// define name of rule to be fired
String ruleName = "com/acme/ageRules/isSeniorCitizen";

// define result of rule firing
Object result = null;

// initialize parameter list
plist[0] = age;

try {

	// fire "com/acme/ageRules/isSeniorCitizen" rule passing paramdter list containing age.  
	// Note: in this case the target object is not used and could be null.
	result = tp.trigger(this, plist, ruleName);

	// put result into usable format.  A single result is returned since we specified to use
	// the ReturnFirstCombiningStrategy.  By default an array of results would be returned.
	boolean seniorCitizen = ((Boolean)result).booleanValue();

	// make use of result
	if( seniorCitizen ) {
		...
	}

}
catch(BusinessRuleBeansException e ) {

	// handle exception
	...

}