24.11. Pet Store Example: Running PetStore.java

To use PetStore.java, the following conditions must be met:
  1. The main() method has run and loaded the Rule Base but not yet fired the rules. So far, this is the only code in connection with rules that has been run.
  2. A new PetStoreUI object has been created and given a handle to the Rule Base, for later use.
  3. Swing components are deployed and the console waits for user input.
  • The file PetStore.java contains a main() method, so that it can be run as a standard Java application, either from the command line or via the IDE. This assumes you have your classpath set correctly.
  • The first screen that appears is the Pet Store Demo. It has a list of available products, an empty list of selected products, checkout and reset buttons, and an empty system messages area.
Pressing the "Checkout" button fires the business rules:
  1. Method CheckOutCallBack.checkout() is called by the Swing class waiting for the click on the "Checkout" button. This inserts the data from the TableModel object and inserts it into the Session's Working Memory. It then fires the rules.
  2. The first rule to fire will be the one with auto-focus set to true. It loops through all the products in the cart, ensures that the products are in the Working Memory, and then gives the Show Items and Evaluation agenda groups a chance to fire. The rules in these groups add the contents of the cart to the text area (at the bottom of the window), decide whether or not to give the user free fish food, and to ask us whether they want to buy a fish tank.