måndag, mars 27, 2006

Callout from within Oracle Business Rules

Within Oracle Business Rules you sometimes need to make callouts to an external Object within the action part of your rule. This is very easy to achieve. Suppose that you have a class with an external method similar to:

package myPackage;
public class CallOut {
public CallOut() { }

public void test(String myVariable) {
System.out.println("Callout from Rules with argument: " + myVariable);
}
}

and you would like to call upon this method from within the action part of a rule. The first thing you need to do is also to import this class into your dictionary. Once done, you need to define a new RLFunction. This function needs to have 2 variables defined, one for the class itself, and one for the argument. The argument should have the argument type String, while the class needs to have the Type CallOut, or whatever your class is named. Within the function body you then define the actual function like:

TestCallOut.test(message);

Now you have a Rules function that you cal call upon from the action part of any rule within your ruleset(s), like:

Call callOut( Passenger.name, new CallOut () )

The RL code that is generated for such a task will look like:

function callOut(String message, myPackage.CallOut TestCallOut)
{
//RL literal statement
TestCallOut.test(message);
}// DM.callOut

for the function, this will be defined in the DM ruleset. The call will look like:

rule myRule
{
priority = 0;
if
(
(
fact myPackage.SomeFactObject v0_SomeFactObject && (
(v0_SomeFactObject.anAttribute <>
)
{
DM.callOut(v0_SomeFactObject.someArgument, new myPackage.CallOut());
}
} //end rule myRule;

I hope this will have shown you how-to make a callout from Oracle Business Rules to a method within an Object.

Inga kommentarer:

Skicka en kommentar