How to Create and Use Decision Point Instances

Working with Rules SDK Decision Point API 7-13 Example 7–4 Code to Await Thread Termination try { exec.awaitTermination5, TimeUnit.SECONDS; } catch InterruptedException e { e.printStackTrace; } exec.shutdown; }

7.3.4 How to Create and Use Decision Point Instances

The DriverCheckerRunnable instances call the checkDriver method. Example 7–5 shows the checkDriver method that is defined in CarRentalWithDecisionPoint . The checkDriver method handles invoking Decision Point with a Driver instance. Example 7–5 Code to Create a Decision Point Instance with getInstance public class CarRentalWithDecisionPoint extends CarRental { protected static DecisionPoint m_decisionPoint; public static void checkDriverfinal Driver driver { try { DecisionPointInstance instance = m_decisionPoint.getInstance; instance.setInputsnew ArrayListObject { { adddriver; } }; ListObject outputs = instance.invoke; if outputs.isEmpty System.err.printlnOops, no results; java.util.ListDenial denials = java.util.ListDenialoutputs.get0; if denials.isEmpty { System.out.printlnRental is allowed for + driver.getName; } else { for Denial denial : denials { System.out.printlnRental is denied for + denial.getDriver.getName + because + denial.getReason; } } } catch RLException e { e.printStackTrace; } catch SDKException e { e.printStackTrace; } } } Example 7–5 shows the following: 7-14 Oracle Fusion Middleware Users Guide for Oracle Business Rules ■ Getting a DecisionPointInstance from the static DecisionPoint defined with the DecisionPointBuilder, with the following code. DecisionPointInstance instance = m_decisionPoint.getInstance; ■ Add inputs according to the signature of the decision function associated with the Decision Point. This defines one argument of type List as the input. This List contains the Driver instances: instance.setInputsnew ArrayListObject { { adddriver; } }; ■ Invoke the Decision Point and store the return value. The return type follows the same pattern as the decision function which is being called in the Decision Point. ListObject outputs = instance.invoke; In this case the invoke returns a List of length one, containing a List of Denial instances. ■ If the return is a List of any other size than one, then this is an error: if outputs.isEmpty System.err.printlnOops, no results; ■ The first entry that is returned from the Decision Point is caste it to a List of type ListDenial : java.util.ListDenial denials = java.util.ListDenialoutputs.get0; ■ If the denials list is empty, then no Denial instances were asserted by the rules. This indicates that it is OK to rent a car to the driver. Otherwise, print the reasons why the driver rental was rejected: if denials.isEmpty { System.out.printlnRental is allowed for + driver.getName; } else { for Denial denial : denials { System.out.printlnRental is denied for + denial.getDriver.getName + because + denial.getReason; } }

7.4 Running the Car Rental Sample