System.out.println( "Bound RuleExecutionSet to URI: " + uri);
// Get a RuleRuntime and invoke the rule engine.
System.out.println( "\nRuntime API\n" );
RuleRuntime ruleRuntime = serviceProvider.getRuleRuntime();
System.out.println( "Acquired RuleRuntime: " + ruleRuntime );
// create a StatelessRuleSession
StatelessRuleSession statelessRuleSession =
(StatelessRuleSession) ruleRuntime.createRuleSession(uri,
new HashMap(), RuleRuntime.STATELESS_SESSION_TYPE);
System.out.println( "Got Stateless Rule Session: " +
statelessRuleSession );
// call executeRules with some input objects
// Create a Customer as specified by the TCK documentation.
Customer inputCustomer = new Customer();
inputCustomer.setCreditLimit(5000);
// Create an Invoice as specified by the TCK documentation.
Invoice inputInvoice = new Invoice();
inputInvoice.setAmount(2000);
// Create a input list.
List input = new ArrayList();
input.add(inputCustomer);
input.add(inputInvoice);
// Print the input.
System.out.println("Calling rule session with the following data");
System.out.println("Customer credit limit input: " +
inputCustomer.getCreditLimit());
System.out.println("Invoice:\n" +
" amount: " + inputInvoice.getAmount() +
" status: " + inputInvoice.getStatus());
// Execute the rules without a filter.
List results = statelessRuleSession.executeRules(input);
System.out.println( "Called executeRules on Stateless Rule Session: " + statelessRuleSession );
System.out.println( "Result of calling executeRules: " +
results.size() + " results." );
// Loop over the results.
Iterator itr = results.iterator();
while(itr.hasNext()) {
Object obj = itr.next();
if (obj instanceof Customer)
System.out.println("Customer credit limit result: " +
((Customer) obj).getCreditLimit());
if (obj instanceof Invoice)
System.out.println("Invoice:\n" +
" amount: " + ((Invoice) obj).getAmount() +
" status: " + ((Invoice) obj).getStatus());
}
// Release the session.
statelessRuleSession.release();
System.out.println( "Released Stateless Rule Session." );
System.out.println();
// create a StatefulRuleSession
StatefulRuleSession statefulRuleSession =
(StatefulRuleSession) ruleRuntime.createRuleSession( uri,
new HashMap(),
RuleRuntime.STATEFUL_SESSION_TYPE );
System.out.println( "Got Stateful Rule Session: " + statefulRuleSession );
// Add another Invoice.