[jboss-svn-commits] JBL Code SVN: r20480 - in labs/jbossrules/trunk/drools-docs/drools-docs-expert/en/Chapter-Examples: StateExampleExample and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Sat Jun 14 09:15:44 EDT 2008


Author: mark.proctor at jboss.com
Date: 2008-06-14 09:15:44 -0400 (Sat, 14 Jun 2008)
New Revision: 20480

Added:
   labs/jbossrules/trunk/drools-docs/drools-docs-expert/en/Chapter-Examples/HonestPoliticianExample/
   labs/jbossrules/trunk/drools-docs/drools-docs-expert/en/Chapter-Examples/MannersExample/
   labs/jbossrules/trunk/drools-docs/drools-docs-expert/en/Chapter-Examples/NumberGuessExample/
   labs/jbossrules/trunk/drools-docs/drools-docs-expert/en/Chapter-Examples/Section-HonestPoliticianExample.xml
   labs/jbossrules/trunk/drools-docs/drools-docs-expert/en/Chapter-Examples/Section-NumberGuessExample.xml
   labs/jbossrules/trunk/drools-docs/drools-docs-expert/en/Chapter-Examples/Section-SodukiExample.xml
   labs/jbossrules/trunk/drools-docs/drools-docs-expert/en/Chapter-Examples/SodukiExample/
   labs/jbossrules/trunk/drools-docs/drools-docs-expert/en/Chapter-Examples/StateExampleExample/
   labs/jbossrules/trunk/drools-docs/drools-docs-expert/en/Chapter-Examples/StateExampleExample/state_example_agenda1.png
   labs/jbossrules/trunk/drools-docs/drools-docs-expert/en/Chapter-Examples/StateExampleExample/state_example_audit1.png
   labs/jbossrules/trunk/drools-docs/drools-docs-expert/en/Chapter-Examples/TroubleTicketExample/
Removed:
   labs/jbossrules/trunk/drools-docs/drools-docs-expert/en/Chapter-Examples/HonestPolitician/
   labs/jbossrules/trunk/drools-docs/drools-docs-expert/en/Chapter-Examples/Manners/
   labs/jbossrules/trunk/drools-docs/drools-docs-expert/en/Chapter-Examples/NumberGuess/
   labs/jbossrules/trunk/drools-docs/drools-docs-expert/en/Chapter-Examples/Section-HonestPolitician.xml
   labs/jbossrules/trunk/drools-docs/drools-docs-expert/en/Chapter-Examples/Soduki/
   labs/jbossrules/trunk/drools-docs/drools-docs-expert/en/Chapter-Examples/StateExample/
   labs/jbossrules/trunk/drools-docs/drools-docs-expert/en/Chapter-Examples/StateExampleExample/state_example_agenda1.png
   labs/jbossrules/trunk/drools-docs/drools-docs-expert/en/Chapter-Examples/StateExampleExample/state_example_audit1.png
   labs/jbossrules/trunk/drools-docs/drools-docs-expert/en/Chapter-Examples/TroubleTicket/
Modified:
   labs/jbossrules/trunk/drools-docs/drools-docs-expert/en/Chapter-Examples/Section-Examples.xml
   labs/jbossrules/trunk/drools-docs/drools-docs-expert/en/Chapter-Examples/Section-TroubleTicketExample.xml
Log:
JBRULES-1643
-trying to move example images to section folders for better grouping

Copied: labs/jbossrules/trunk/drools-docs/drools-docs-expert/en/Chapter-Examples/HonestPoliticianExample (from rev 20479, labs/jbossrules/trunk/drools-docs/drools-docs-expert/en/Chapter-Examples/HonestPolitician)

Copied: labs/jbossrules/trunk/drools-docs/drools-docs-expert/en/Chapter-Examples/MannersExample (from rev 20479, labs/jbossrules/trunk/drools-docs/drools-docs-expert/en/Chapter-Examples/Manners)

Copied: labs/jbossrules/trunk/drools-docs/drools-docs-expert/en/Chapter-Examples/NumberGuessExample (from rev 20479, labs/jbossrules/trunk/drools-docs/drools-docs-expert/en/Chapter-Examples/NumberGuess)

Modified: labs/jbossrules/trunk/drools-docs/drools-docs-expert/en/Chapter-Examples/Section-Examples.xml
===================================================================
--- labs/jbossrules/trunk/drools-docs/drools-docs-expert/en/Chapter-Examples/Section-Examples.xml	2008-06-14 13:00:09 UTC (rev 20479)
+++ labs/jbossrules/trunk/drools-docs/drools-docs-expert/en/Chapter-Examples/Section-Examples.xml	2008-06-14 13:15:44 UTC (rev 20480)
@@ -715,840 +715,13 @@
 			<!---<para>Todo : Add Audit and Agenda Views for this sample.</para>-->
 		</section>
 
-    <xi:include href="Section-HonestPolitician.xml" />
+    <xi:include href="Section-HonestPoliticianExample.xml" />
+    
+    <xi:include href="Section-SodukiExample.xml" />
+    
+    <xi:include href="Section-NumberGuessExample.xml" />
 
-  <section>
-    <title>Sudoku Example</title>
 
-    <programlisting><emphasis role="bold">Name:</emphasis> Sudoku
-<emphasis role="bold">Main class:</emphasis> org.drools.examples.sudoku.Main
-<emphasis role="bold">Type:</emphasis> java application
-<emphasis role="bold">Rules file:</emphasis> sudokuSolver.drl, sudokuValidator.drl
-<emphasis role="bold">Objective:</emphasis> Demonstrates the solving of logic problems, and complex pattern matching.e
-</programlisting>
-
-    <para>This example demonstrates how Drools can be used to find a solution
-    in a large potential solution space based on a number of constraints. We
-    use the popular puzzle of Sudoku. This example also shows how Drools can
-    be integrated into a graphical interface and how callbacks can be used to
-    interact with a running Drools rules engine in order to update the
-    graphical interface based on changes in the working memory at
-    runtime.</para>
-
-    <section>
-      <title>Sudoku Overview</title>
-
-      <para>Sudoku is a logic-based number placement puzzle. The objective is
-      to fill a 9x9 grid so that each column, each row, and each of the nine
-      3x3 zones contains the digits from 1 to 9 once and only once.</para>
-
-      <para>The puzzle setter provides a partially completed grid and the
-      puzzle solver's task is to complete the grid with these
-      constraints.</para>
-
-      <para>The general strategy to solve the problem is to ensure that when
-      you insert a new number it should be unique in that particular
-      region(blocks) and also in that particular row and column.</para>
-
-      <para>See <programlisting>URL: http://en.wikipedia.org/wiki/Sudoku</programlisting>
-      for a more detailed description.</para>
-    </section>
-
-    <section>
-      <title>Running the Example</title>
-
-      <para>Download and install drools-examples as described above and then
-      execute java org.drools.examples.sudoku.Main (this example requires Java
-      5).</para>
-
-      <para>A window will be displayed with a relatively simple partially
-      filled grid. <screenshot>
-          <screeninfo>New remote site</screeninfo>
-
-          <mediaobject>
-            <imageobject>
-              <imagedata fileref="sudoku1.png" />
-            </imageobject>
-          </mediaobject>
-        </screenshot></para>
-
-      <para>Click on the Solve button and the Drools-based engine will fill
-      out the remaining values. The console will display detailed information
-      of the rules which are executing to solve the puzzle in a human readable
-      form.</para>
-
-      <para><computeroutput>Rule #3 determined the value at (4,1) could not be
-      4 as this value already exists in the same column at (8,1) Rule #3
-      determined the value at (5,5) could not be 2 as this value already
-      exists in the same row at (5,6) Rule #7 determined (3,5) is 2 as this is
-      the only possible cell in the column that can have this value Rule #1
-      cleared the other PossibleCellValues for (3,5) as a ResolvedCellValue of
-      2 exists for this cell. Rule #1 cleared the other PossibleCellValues for
-      (3,5) as a ResolvedCellValue of 2 exists for this cell. ... Rule #3
-      determined the value at (1,1) could not be 1 as this value already
-      exists in the same zone at (2,1) Rule #6 determined (1,7) is 1 as this
-      is the only possible cell in the row that can have this value Rule #1
-      cleared the other PossibleCellValues for (1,7) as a ResolvedCellValue of
-      1 exists for this cell. Rule #6 determined (1,1) is 8 as this is the
-      only possible cell in the row that can have this value
-      </computeroutput></para>
-
-      <para>Once all of the activated rules for the solving logic have
-      executed, the engine executes a second rule base to check that the
-      solution is complete and valid. In this case it is, and the "Solve"
-      button is disabled and displays the text "Solved (1052ms)". <screenshot>
-          <screeninfo>New remote site</screeninfo>
-
-          <mediaobject>
-            <imageobject>
-              <imagedata fileref="sudoku2.png" />
-            </imageobject>
-          </mediaobject>
-        </screenshot></para>
-
-      <para>The example comes with a number of grids which can be loaded and
-      solved. Click on File-&gt;Samples-&gt;Medium to load a more challenging
-      grid. Note that the solve button is enabled when the new grid is loaded.
-      <screenshot>
-          <screeninfo>New remote site</screeninfo>
-
-          <mediaobject>
-            <imageobject>
-              <imagedata fileref="sudoku3.png" />
-            </imageobject>
-          </mediaobject>
-        </screenshot></para>
-
-      <para>Click on the "Solve" button again to solve this new grid.
-      <screenshot>
-          <screeninfo>New remote site</screeninfo>
-
-          <mediaobject>
-            <imageobject>
-              <imagedata fileref="sudoku4.png" />
-            </imageobject>
-          </mediaobject>
-        </screenshot></para>
-
-      <para>Now, let us load a Sudoku grid that is deliberately invalid. Click
-      on File-&gt;Samples-&gt;!DELIBERATELY BROKEN!. Note that this grid
-      starts with some issues, for example the value 5 appears twice in the
-      first row. <screenshot>
-          <screeninfo>New remote site</screeninfo>
-
-          <mediaobject>
-            <imageobject>
-              <imagedata fileref="sudoku5.png" />
-            </imageobject>
-          </mediaobject>
-        </screenshot></para>
-
-      <para>Nevertheless, click on the "Solve" button to apply the solving
-      rules to this invalid Grid. Note that the "Solve" button is relabelled
-      to indicate that the resulting solution is invalid. <screenshot>
-          <screeninfo>New remote site</screeninfo>
-
-          <mediaobject>
-            <imageobject>
-              <imagedata fileref="sudoku6.png" />
-            </imageobject>
-          </mediaobject>
-        </screenshot></para>
-
-      <para>In addition, the validation rule set outputs all of the issues
-      which are discovered to the console. <programlisting>
-There are two cells on the same column with the same value at (6,0) and (4,0)
-There are two cells on the same column with the same value at (4,0) and (6,0)
-There are two cells on the same row with the same value at (2,4) and (2,2)
-There are two cells on the same row with the same value at (2,2) and (2,4)
-There are two cells on the same row with the same value at (6,3) and (6,8)
-There are two cells on the same row with the same value at (6,8) and (6,3)
-There are two cells on the same column with the same value at (7,4) and (0,4)
-There are two cells on the same column with the same value at (0,4) and (7,4)
-There are two cells on the same row with the same value at (0,8) and (0,0)
-There are two cells on the same row with the same value at (0,0) and (0,8)
-There are two cells on the same column with the same value at (1,2) and (3,2)
-There are two cells on the same column with the same value at (3,2) and (1,2)
-There are two cells in the same zone with the same value at (6,3) and (7,3)
-There are two cells in the same zone with the same value at (7,3) and (6,3)
-There are two cells on the same column with the same value at (7,3) and (6,3)
-There are two cells on the same column with the same value at (6,3) and (7,3)   
-      </programlisting></para>
-
-      <para>We will look at the solving rule set later in this section, but
-      for the moment we should note that some theoretically solvable solutions
-      can not be solved by the engine as it stands. Click on
-      File-&gt;Samples-&gt;Hard 3 to load a sparsely populated Grid.
-      <screenshot>
-          <screeninfo>New remote site</screeninfo>
-
-          <mediaobject>
-            <imageobject>
-              <imagedata fileref="sudoku7.png" />
-            </imageobject>
-          </mediaobject>
-        </screenshot></para>
-
-      <para>Now click on the "Solve" button and note that the current rules
-      are unable to complete the grid, even though (if you are a Sudoku
-      afficiando) you may be able to see a way forward with the solution.
-      <screenshot>
-          <screeninfo>New remote site</screeninfo>
-
-          <mediaobject>
-            <imageobject>
-              <imagedata fileref="sudoku8.png" />
-            </imageobject>
-          </mediaobject>
-        </screenshot></para>
-
-      <para>At the present time, the solving functionality has been achieved
-      by the use of ten rules. This rule set could be extended to enable the
-      engine to tackle more complex logic for filling grids such as
-      this.</para>
-    </section>
-
-    <section>
-      <title>Java Source and Rules Overview</title>
-
-      <para>The Java source code can be found in the
-      /src/main/java/org/drools/examples/sudoku directory, with the two DRL
-      files defining the rules located in the
-      /src/main/rules/org/drools/examples/sudoku directory.</para>
-
-      <para>org.drools.examples.sudoku.swing contains a set of classes which
-      implement a framework for Sudoku puzzles. Note that this package does
-      not have any dependencies on the Drools libraries. SudokuGridModel
-      defines an interface which can be implemented to store a Sudoku puzzle
-      as a 9x9 grid of Integer values, some of which may be null, indicating
-      that the value for the cell has not yet been resolved. SudokuGridView is
-      a Swing component which can visualise any implementation of
-      SudokuGridModel. SudokuGridEvent and SudokuGridListener are used to
-      communicate state changes between the model and the view, events are
-      fired when a cell's value is resolved or changed. If you are familiar
-      with the model-view-controller patterns in other Swing components such
-      as JTable then this pattern should be familiar. SudokuGridSamples
-      provides a number of partially filled Sudoku puzzles for demo
-      purposes.</para>
-
-      <para>org.drools.examples.sudoku.rules contains an implementation of
-      SudokuGridModel which is based on Drools. Two POJOs are used, both of
-      which extend AbstractCellValue and represent a value for a specific cell
-      in the grid, including the row and column location of the cell, an index
-      of the 3x3 zone the cell is contained in and the value of the cell.
-      PossibleCellValue indicates that we do not currently know for sure what
-      the value in a cell is. There can be 2-9 PossibleCellValues for a given
-      cell. ResolvedCellValue indicates that we have determined what the value
-      for a cell must be. There can only be 1 ResolvedCellValue for a given
-      cell. DroolsSudokuGridModel implements SudokuGridModel and is
-      responsible for converting an initial two dimensional array of partially
-      specified cells into a set of CellValue POJOs, creating a working memory
-      based on solverSudoku.drl and inserting the CellValue POJOs into the
-      working memory. When the solve() method is called it calls
-      fireAllRules() on this working memory to try to solve the puzzle.
-      DroolsSudokuGridModel attaches a WorkingMemoryListener to the working
-      memory, which allows it to be called back on insert() and retract()
-      events as the puzzle is solved. When a new ResolvedCellValue is inserted
-      into the working memory, this call back allows the implementation to
-      fire a SudokuGridEvent to its SudokuGridListeners which can then update
-      themselves in realtime. Once all the rules fired by the solver working
-      memory have executed, DroolsSudokuGridModel runs a second set of rules,
-      based on validatorSudoku.drl which works with the same set of POJOs to
-      determine if the resulting grid is a valid and full solution.</para>
-
-      <para>org.drools.examples.sudoku.Main implements a Java application
-      which hooks the components desribed above together.</para>
-
-      <para>org.drools.examples.sudoku contains two DRL files.
-      solverSudoku.drl defines the rules which attempt to solve a Sudoku
-      puzzle and validator.drl defines the rules which determin whether the
-      current state of the working memory represents a valid solution. Both
-      use PossibleCellValue and ResolvedCellValue POJOs as their facts and
-      both output information to the console as their rules fire. In a
-      real-world situation we would insert() logging information and use the
-      WorkingMemoryListener to display this information to a user rather than
-      use the console in this fashion.</para>
-    </section>
-
-    <section>
-      <title>Sudoku Validator Rules (validatorSudoku.drl)</title>
-
-      <para>We start with the validator rules as this rule set is shorter and
-      simpler than the solver rule set.</para>
-
-      <para>The first rule simply checks that no PossibleCellValue objects
-      remain in the working memory. Once the puzzle is solved, only
-      ResolvedCellValue objects should be present, one for each cell.</para>
-
-      <para>The other three rules each match all of the ResolvedCellValue
-      objects and store them in thenew_remote_sitetes instance variable
-      $resolved. They then look respectively for ResolvedCellValues that
-      contain the same value and are located, respectively, in the same row,
-      column or 3x3 zone. If these rules are fired they add a message to a
-      global List of Strings describing the reason the solution is invalid.
-      DroolsSudokoGridModel injects this List before it runs the rule set and
-      checks whether it is empty or not having called fireAllRules(). If it is
-      not empty then it prints all the Strings in the list and sets a flag to
-      indicate that the Grid is not solved.</para>
-    </section>
-
-    <section>
-      <title>Sudoku Solving Rules (solverSudoku.drl)</title>
-
-      <para>Now let us look at the more complex rule set used to solve Sudoku
-      puzzles.</para>
-
-      <para>Rule #1 is basically a "book-keeping" rule. Several of the other
-      rules insert() ResolvedCellValues into the working memory at specific
-      rows and columns once they have determined that a given cell must have a
-      certain value. At this point, it is important to clear the working
-      memory of any inserted PossibleCellValues at the same row and column
-      with invalid values. This rule is therefore given a higher salience than
-      the remaining rules to ensure that as soon as the LHS is true,
-      activations for the rule move to the top of the agenda and are fired. In
-      turn this prevents the spurious firing of other rules due to the
-      combination of a ResolvedCellValue and one or more PossibleCellValues
-      being present in the same cell. This rule also calls update() on the
-      ResolvedCellValue, even though its value has not in fact been modified
-      to ensure that Drools fires an event to any WorkingMemoryListeners
-      attached to the working memory so that they can update themselves - in
-      this case so that the GUI can display the new state of the grid.</para>
-
-      <para>Rule #2 identifies cells in the grid which have only one possible
-      value. The first line of the when caluse matches all of the
-      PossibleCellValue objects in the working memory. The second line
-      demonstrates a use of the not keyword. This rule will only fire if no
-      other PossibleCellValue objects exist in the working memory at the same
-      row and column but with a different value. When the rule fires, the
-      single PossibleCellValue at the row and column is retracted from the
-      working memory and is replaced by a new ResolvedCellValue at the same
-      row and column with the same value.</para>
-
-      <para>Rule #3 removes PossibleCellValues with a given value from a row
-      when they have the same value as a ResolvedCellValue. In other words,
-      when a cell is filled out with a resolved value, we need to remove the
-      possibility of any other cell on the same row having this value. The
-      first line of the when clause matches all ResolvedCellValue objects in
-      the working memory. The second line matches PossibleCellValues which
-      have both the same row and the same value as these ResolvedCellValue
-      objects. If any are found, the rule activates and, when fired retracts
-      the PossibleCellValue which can no longer be a solution for that
-      cell.</para>
-
-      <para>Rules #4 and #5 act in the same way as Rule #3 but check for
-      redundant PossibleCellValues in a given column and a given zone of the
-      grid as a ResolvedCellValue respectively.</para>
-
-      <para>Rule #6 checks for the scenario where a possible cell value only
-      appears once in a given row. The first line of the LHS matches against
-      all PossibleCellValues in the working memory, storing the result in a
-      number of local variables. The second line checks that no other
-      PossibleCellValues with the same value exist on this row. The third to
-      fifth lines check that there is not a ResolvedCellValue with the same
-      value in the same zone, row or column so that this rule does not fire
-      prematurely. Interestingly we could remove lines 3-5 and give rules
-      #3,#4 and #5 a higher salience to make sure they always fired before
-      rules #6,#7 and #8. When the rule fires, we know that $possible must
-      represent the value for the cell so, as in Rule #2 we retract $possible
-      and replace it with the equivalent, new ResolvedCellValue.</para>
-
-      <para>Rules #7 and #8 act in the same way as Rule #2 but check for
-      single PossibleCellValues in a given column and a given zone of the grid
-      respectively.</para>
-
-      <para>Rule #9 represents the most complex currently implemented rule.
-      This rule implements the logic that, if we know that a pair of given
-      values can only occur in two cells on a specific row, (for example we
-      have determined the values of 4 and 6 can only appear in the first row
-      in cells 0,3 and 0,5) and this pair of cells can not hold other values
-      then, although we do not know which of the pair contains a four and
-      which contains a six we know that the 4 and the 6 must be in these two
-      cells and hence can remove the possibility of them occuring anywhere
-      else in the same row (phew!). TODO: more detail here and I think the
-      rule can be cleaned up in the DRL file before fully documenting
-      it.</para>
-
-      <para>Rules #10 and #11 act in the same way as Rule #9 but check for the
-      existance of only two possible values in a given column and zone
-      respectively.</para>
-
-      <para>To solve harder grids, the rule set would need to be extended
-      further with more complex rules that encapsulated more complex
-      reasoning.</para>
-    </section>
-
-    <section>
-      <title>Suggestions for Future Developments</title>
-
-      <para>There are a number of ways in which this example could be
-      developed. The reader is encouraged to consider these as
-      excercises.</para>
-
-      <itemizedlist>
-        <listitem>
-          <para>Agenda-group: agenda groups are a great declarative tool for
-          phased execution. In this example, it is easy to see we have 2
-          phases: "resolution" and "validation". Right now, they are executed
-          by creating two separate rule bases, each for one "job". I think it
-          would be better for us to define agenda-groups for all the rules,
-          spliting them in "resolution" rules and "validation" rules, all
-          loaded in a single rule base. The engine executes resolution and
-          right after that, executes validation.</para>
-        </listitem>
-
-        <listitem>
-          <para>Auto-focus: auto focus is a great way of handling exceptions
-          to the regular rules execution. In our case, if we detect an
-          inconsistency, either in the input data or in the resolution rules,
-          why should we spend time continuing the execution if it will be
-          invalid anyway? I think it is better to simply (and immediatly)
-          report the inconsistency as soon as it is found. To do that, since
-          we now have a single rulebase with all rules, we simply need to
-          define auto-focus attribute for all rules validating puzzle
-          consistency.</para>
-        </listitem>
-
-        <listitem>
-          <para>Logical insert: an inconsistency only exists while wrong data
-          is in the working memory. As so, we could state that the the
-          validation rules logically insert inconsistencies and as soon as the
-          offending data is retracted, the inconsistency no longer
-          exists.</para>
-        </listitem>
-
-        <listitem>
-          <para>session.iterateObjects(): although a valid use case having a
-          global list to add the found problems, I think it would be more
-          interesting to ask the stateful session by the desired list of
-          problems, using session.iterateObjects( new ClassObjectFilter(
-          Inconsistency.class ) ); Having the inconsistency class can also
-          allow us to paint in RED the offending cells in the GUI.</para>
-        </listitem>
-
-        <listitem>
-          <para>drools.halt(): even reporting the error as soon as it is
-          found, we need a way to tell the engine to stop evaluating rules. We
-          can do that creating a rule that in the presence of Inconsistencies,
-          calls drools.halt() to stop evaluation.</para>
-        </listitem>
-
-        <listitem>
-          <para>queries: looking at the method getPossibleCellValues(int row,
-          int col) in DroolsSudokuGridModel, we see it iterating over all
-          CellValues and looking for the few it wants. That, IMO, is a great
-          opportunity to teach drools queries. We just define a query to
-          return the objects we want and iterate over it. Clean and nice.
-          Other queries may be defined as needed.</para>
-        </listitem>
-
-        <listitem>
-          <para>session.iterateObjects(): although a valid use case having a
-          global list to add the found problems, I think it would be more
-          interesting to ask the stateful session by the desired list of
-          problems, using session.iterateObjects( new ClassObjectFilter(
-          Inconsistency.class ) ); Having the inconsistency class can also
-          allow us to paint in RED the offending cells in the GUI.</para>
-        </listitem>
-
-        <listitem>
-          <para>Globals as services: the main objective of this change is to
-          attend the next change I will propose, but it is nice by its own I
-          guess. :) In order to teach the use of "globals" as services, it
-          would be nice to setup a call back, so that each rule that finds the
-          ResolvedCellValue for a given cell can call, to notify and update
-          the corresponding cell in the GUI, providing immediate feedback for
-          the user. Also, the last found cell could have its number painted in
-          a different color to facilitate the identification of the rules
-          conclusions.</para>
-        </listitem>
-
-        <listitem>
-          <para>Step by step execution: now that we have immediate user
-          feedback, we can make use of the restricted run feature in drools.
-          I.e., we could add a button in the GUI, so that the user clicks and
-          causes the execution of a single rule, by calling fireAllRules( 1 ).
-          This way, the user can see, step by step, what the engine is
-          doing.</para>
-        </listitem>
-      </itemizedlist>
-    </section>
-  </section>
-
-
-    <section>
-      <title>Number Guess</title>
-
-      <programlisting><emphasis role="bold">Name:</emphasis> Number Guess 
-<emphasis role="bold">Main class:</emphasis> org.drools.examples.NumberGuessExample
-<emphasis role="bold">Type:</emphasis> java application
-<emphasis role="bold">Rules file:</emphasis> NumberGuess.drl
-<emphasis role="bold">Objective:</emphasis> Demonstrate use of Rule Flow to organise Rules
-</programlisting>
-
-      <para>The "Number Guess" example shows the use of RuleFlow, a way of
-      controlling the order in which rules are fired. It uses widely
-      understood workflow diagrams to make clear the order that groups of
-      rules will be executed.</para>
-
-      <example>
-        <title>Creating the Number Guess RuleBase - extract 1 from
-        NumberGuessExample.java main() method</title>
-
-        <programlisting>final PackageBuilder builder = new PackageBuilder();
-
-builder.addPackageFromDrl( new InputStreamReader( 
-         ShoppingExample.class.getResourceAsStream( "NumberGuess.drl" ) ) );
-builder.addRuleFlow( new InputStreamReader( 
-         ShoppingExample.class.getResourceAsStream( "NumberGuess.rfm" ) ) );
-
-final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
-ruleBase.addPackage( builder.getPackage() );
-
-</programlisting>
-      </example>
-
-      <para>The creation of the package, and the loading of the rules (using
-      the addPackageFromDrl() method ) is the same as the previous examples.
-      There is a additional line to add the RuleFlow (NumberGuess.rfm) as you
-      have the option of specifying different ruleflows for the same RuleBase.
-      Otherwise the RuleBase is created in the same manner as before.</para>
-
-      <example>
-        <title>Starting the RuleFlow - extract 2 from NumberGuessExample.java
-        main() method</title>
-
-        <programlisting>final StatefulSession session = ruleBase.newStatefulSession();
-
-session.insert( new GameRules( 100,  5 ) );
-session.insert( new RandomNumber() );
-session.insert( new Game() );
-
-session.startProcess( "Number Guess" );
-session.fireAllRules();
-
-session.dispose();
-
-</programlisting>
-      </example>
-
-      <para>Once we have a RuleBase we can use it to obtain a stateful
-      session. Into our session we insert our facts (standard Java Objects).
-      For simplicity in this sample, these classes are all contained within
-      our NumberGuessExample.java file. The GameRules class provides the
-      maximum range and the number of guesses allowed. The RandomNumber class
-      automatically generates a number between 0 and 100 and makes it
-      available to our rules after insertion (via the getValue() method). The
-      Game class keeps track of the guesses we have made before, and the
-      number of guesses we have made.</para>
-
-      <para>Note that before we call the standard fireAllRules() method, we
-      also start the process that we loaded earlier (via the startProcess()
-      method). We explain where to obtain the parameter we pass ("Number
-      Guess" - the id of the ruleflow) when we talk about the RuleFlow file
-      and the graphical RuleFlow editor below.</para>
-
-      <para>Before we finish we our Java code , we note that In 'real life' we
-      would examine the final state of the objects (e.g. how many guesses it
-      took, so that we could add it to a high score table). For this example
-      we are content to ensure the working memory session is cleared by
-      calling the dispose() method.</para>
-
-      <figure>
-        <title>RuleFlow for the NumberGuess Example</title>
-
-        <mediaobject>
-          <imageobject>
-            <imagedata fileref="numberguess-ruleflow.png" />
-          </imageobject>
-        </mediaobject>
-      </figure>
-
-      <para>If you open the NumberGuess.rf file open in the Drools IDE (and
-      have the JBoss Rules extensions installed correctly in Eclipse) you
-      should see the above diagram, similar to a standard flowchart. Its icons
-      are similar (but not exactly the same) as the JBoss jBPM workflow
-      product. Should you wish to edit the diagram, a menu of available
-      components should be available to the left of the diagram in the IDE,
-      which is call the pallete. This diagram is saved in a (almost human)
-      readable xml format, using xstream.</para>
-
-      <para>If it is not already open, ensure the properties view is visible
-      in the IDE. It can opened by selecting Window -&gt; Show View -&gt;
-      Other and then select the Properties view. If you do this <emphasis
-      role="bold">before</emphasis> you select any item on the RuleFlow (or
-      click on blank space in the RuleFlow) you should be presented with the
-      following set of properties.</para>
-
-      <figure>
-        <title>Properties for the Number Guess RuleFlow</title>
-
-        <mediaobject>
-          <imageobject>
-            <imagedata fileref="numberguess-ruleflow-properties.png" />
-          </imageobject>
-        </mediaobject>
-      </figure>
-
-      <para>Keep an eye on the properties view as we progress through the
-      example RuleFlow as it gives valuable information. In this case it
-      provides us with the ID of the RuleFlow process that we used in our
-      earlier code example when we called session.startprocess().</para>
-
-      <para>To give an overview of each of the node types (boxes) in the
-      NumberGuess RuleFlow.</para>
-
-      <para>
-        <itemizedlist>
-          <listitem>
-            <para>The Start and End nodes (green arrow and red box) are where
-            the RuleFlow starts and ends.</para>
-          </listitem>
-
-          <listitem>
-            <para>RuleFlowGroup (simple yellow box). These map to the
-            RuleFlowGroups in our rules (DRL) file that we will look at later.
-            For example when the flow reaches the 'Too High' RuleFlowGroup,
-            only those rules marked with an attribute of <emphasis
-            role="bold">ruleflow-group "Too High" </emphasis> can potentially
-            fire.</para>
-          </listitem>
-
-          <listitem>
-            <para>Action Nodes (yellow box with cog like icon). These can
-            perform standard Java method calls. Most action nodes in this
-            example call System.out.println to give an indication to the user
-            of what is going on.</para>
-          </listitem>
-
-          <listitem>
-            <para>Split and Join Nodes (Blue Ovals) such as "Guess Correct"
-            and "More Guesses Join" where the flow of control can split
-            (according to various conditions) and / or rejoin.</para>
-          </listitem>
-
-          <listitem>
-            <para>Arrows that indicate the flow between the various
-            nodes.</para>
-          </listitem>
-        </itemizedlist>
-      </para>
-
-      <para>These various nodes work together with the Rules to make the
-      Number Guess game work. For example, the "Guess" RuleFlowGroup allows
-      only the rule "Get user Guess" to fire (details below) as only that Rule
-      has a matching attribute of <emphasis role="bold">ruleflow-group
-      "Guess"</emphasis></para>
-
-      <example>
-        <title>A Rule that will fire only a specific point in the RuleFlow -
-        extract from NumberGuess.drl</title>
-
-        <programlisting>rule "Get user Guess"
- ruleflow-group "Guess"
- no-loop
- when    
-     $r : RandomNumber()
-     rules : GameRules( allowed : allowedGuesses )
-     game : Game( guessCount &lt; allowed )
-     not ( Guess() )
- then
-     System.out.println( "You have " + ( rules.allowedGuesses - game.guessCount ) 
-     + " out of " + rules.allowedGuesses + " guesses left.\nPlease enter your guess 
-     from 0 to " + rules.maxRange );
-        br = new BufferedReader( new InputStreamReader( System.in ) );
-        modify ( game ) { guessCount = game.guessCount + 1 }
-        i = br.readLine();        
-    insert( new Guess( i ) );
-end</programlisting>
-      </example>
-
-      <para>The rest of this rule is fairly standard : The <emphasis
-      role="bold">LHS (when)</emphasis> section of the rule states that it
-      will be activated for each <emphasis>RandomNumber</emphasis> object
-      inserted into the working memory where <emphasis>guessCount</emphasis>
-      is less than the <emphasis>allowedGuesses</emphasis> ( read from the
-      GameRules Class) and where the user has not guessed the correct
-      number.</para>
-
-      <para>The <emphasis role="bold">RHS (consequence, then)</emphasis>
-      prints a message to the user, then awaits user input from
-      <emphasis>System.in. </emphasis> After getting this input (as System.in
-      blocks until the &lt;return&gt; key is pressed) it updates/modifes the
-      guess count, the actual guess and makes both available in the working
-      memory.</para>
-
-      <para>The rest of the Rules file is fairly standard ; the package
-      declares the dialect is set to MVEL, various Java classes are imported.
-      In total, there are five rules in this file:</para>
-
-      <orderedlist>
-          <listitem>
-            <para>Get User Guess, the Rule we examined above.</para>
-          </listitem>
-
-          <listitem>
-            <para>A Rule to record the highest guess.</para>
-          </listitem>
-
-          <listitem>
-            <para>A Rule to record the lowest guess.</para>
-          </listitem>
-
-          <listitem>
-            <para>A Rule to inspect the guess and retract it from memory if
-            incorrect.</para>
-          </listitem>
-
-          <listitem>
-            <para>A Rule that notifies the user that all guesses have been
-            used up.</para>
-          </listitem>
-        </orderedlist>
-	
-	<para>One point of integration between the standard Rules and
-      the RuleFlow is via the 'ruleflow-group' attribute on the rules (as
-      dicussed above). A <emphasis role="bold">second point of integration
-      between the Rules File (drl) and the Rules Flow .rf files </emphasis>is
-      that the Split Nodes (the blue ovals) can use values in working memory
-      (as updated by the Rules) to decide which flow of action to take. To see
-      how this works click on the "Guess Correct Node" ; then within the
-      properties view, open the constraints editor (the button at the right
-      that appears once you click on the 'Constraints' property line). You
-      should see something similar to the Diagram below.</para>
-
-      <figure>
-        <title>Edit Constraints for the GuessCorrect Node</title>
-
-        <mediaobject>
-          <imageobject>
-            <imagedata fileref="numberguess-editconstraints.png" />
-          </imageobject>
-        </mediaobject>
-      </figure>
-
-      <para>Click on 'Edit' beside 'To node Too High' and you see a dialog
-      like the one below. The values in the 'Textual Editor' follow the
-      standard Rule Format (LHS) and can refer to objects in working memory.
-      The consequence (RHS) is that the flow of control follows this node
-      (i.e. To node Too high') if the LHS expression evaluates to true.</para>
-
-      <figure>
-        <title>Constraints Editor for the GuessCorrect Node / value too
-        high</title>
-
-        <mediaobject>
-          <imageobject>
-            <imagedata fileref="numberguess-constraint-toohigh.png" />
-          </imageobject>
-        </mediaobject>
-      </figure>
-
-      <para>Since the NumberGuess.java example contains a main() method, it
-      can be run as a standard Java application (either from the command line
-      or via the IDE). A typical game might result in the interaction below
-      (the numbers in bold are typed in by the user).</para>
-
-      <example>
-        <title>Example Console output where the Number Guess Example beat the
-        human!</title>
-
-        <programlisting>You have 5 out of 5 guesses left.
-Please enter your guess from 0 to 100
-<emphasis role="bold">50</emphasis>
-Your guess was too high
-You have 4 out of 5 guesses left.
-Please enter your guess from 0 to 100
-<emphasis role="bold">25</emphasis>
-Your guess was too low
-You have 3 out of 5 guesses left.
-Please enter your guess from 0 to 100
-<emphasis role="bold">37</emphasis>
-Your guess was too low
-You have 2 out of 5 guesses left.
-Please enter your guess from 0 to 100
-<emphasis role="bold">44</emphasis>
-Your guess was too low
-You have 1 out of 5 guesses left.
-Please enter your guess from 0 to 100
-<emphasis role="bold">47</emphasis>
-Your guess was too low
-You have no more guesses
-The correct guess was 48 
-
-</programlisting>
-      </example>
-
-      <para>A summary of what is happening in this sample is:</para>
-
-
-        <orderedlist>
-          <listitem>
-            <para>Main() method of NumberGuessExample.java loads RuleBase,
-            gets a StatefulSession and inserts Game, GameRules and
-            RandomNumber (containing the target number) objects into it. This
-            method sets the process flow we are going to use, and fires all
-            rules. Control passes to the RuleFlow.</para>
-          </listitem>
-
-          <listitem>
-            <para>The NumberGuess.rf RuleFlow begins at the Start node.</para>
-          </listitem>
-
-          <listitem>
-            <para>Control passes (via the "more guesses" join node) to the
-            Guess Node..</para>
-          </listitem>
-
-          <listitem>
-            <para>At the Guess node, the appropriate RuleFlowGroup ("Get user
-            Guess") is enabled. In this case the Rule "Guess" (in the
-            NumberGuess.drl file) is triggered. This rule displays a message
-            to the user, takes the response, and puts it into memory. Flow
-            passes to the next Rule Flow Node.</para>
-          </listitem>
-
-          <listitem>
-            <para>At the next node , "Guess Correct", constraints inspect the
-            current session and decide which path we take next.</para>
-
-            <para>If the guess in step 4 was too high / too low flow procees
-            along a path which has (i) An action node with normal Java code
-            prints a too high / too low statement and (ii) a RuleFlowGroup
-            causes a highest guess / lowest guess Rule to be triggered in the
-            Rules file. Flow passes from these nodes to step 6.</para>
-
-            <para>If the guess in step 4 just right we proceed along the path
-            towards the end of the Rule Flow. Before we get there, an action
-            node with normal Java code prints a statement "you guessed
-            correctly". There is a join node here (just before the Rule Flow
-            End) so that our no-more-guesses path (step 7) can also terminate
-            the RuleFlow.</para>
-          </listitem>
-
-          <listitem>
-            <para>Control passes as per the RuleFlow via a join node, a guess
-            incorrect RuleFlowGroup (triggers a rule to retract a guess from
-            working memory) onto the "more guesses" decision node.</para>
-          </listitem>
-
-          <listitem>
-            <para>The "more guesses" decision node (right hand side of
-            ruleflow) uses constraints (again looking at values that the Rules
-            have put into the working memory) to decide if we have more
-            guesses and if so, goto step 3. If not we proceed to the end of
-            the workflow, via a RuleFlowGroup that triggers a rule stating
-            "you have no more guesses".</para>
-          </listitem>
-
-          <listitem>
-            <para>The Loop 3-7 continues until the number is guessed
-            correctly, or we run out of guesses.</para>
-          </listitem>
-        </orderedlist>
-
-    </section>
-
-
   <section>
     <title>Miss Manners and Benchmarking</title>
 

Deleted: labs/jbossrules/trunk/drools-docs/drools-docs-expert/en/Chapter-Examples/Section-HonestPolitician.xml
===================================================================
--- labs/jbossrules/trunk/drools-docs/drools-docs-expert/en/Chapter-Examples/Section-HonestPolitician.xml	2008-06-14 13:00:09 UTC (rev 20479)
+++ labs/jbossrules/trunk/drools-docs/drools-docs-expert/en/Chapter-Examples/Section-HonestPolitician.xml	2008-06-14 13:15:44 UTC (rev 20480)
@@ -1,152 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-	<section xml:base="../">
-		<title>Honest Politician Example</title>
-
-		<para>The honest politician example demonstrates truth maintenance with logical assertions, the basic premise is that an object can only exist while a statement is true. A rule's consequence can logical insert an object with the insertLogical method, this means the object will only remain in the working memory as long as the rule that logically inserted it remains true, when the rule is no longer true the object is automatically retracted.</para>
-
-    <para>In this example there is Politician class with a name and a boolean
-    value for honest state, four politicians with honest state set to true are
-    inserted.</para>
-
-    <para><example>
-        <title>Politician Class</title>
-
-        <programlisting>public class Politician {
-    private String name;
-    private boolean honest;
-    ...
-}</programlisting>
-      </example><example>
-        <title>Honest Politician Example Execution</title>
-
-        <programlisting>Politician blair  = new Politician("blair", true);
-Politician bush  = new Politician("bush", true);
-Politician chirac  = new Politician("chirac", true);
-Politician schroder   = new Politician("schroder", true);
-        
-session.insert( blair );
-session.insert( bush );
-session.insert( chirac );
-session.insert( schroder );
-
-session.fireAllRules();</programlisting>
-      </example>The console out shows that while there is atleast one honest
-    polician democracy lives, however as each politician is in turn corrupted
-    by an evil corporation, when all politicians are dishonest democracy is
-    dead.<example>
-        <title>Honest Politician Example Console Output</title>
-
-        <programlisting>Hurrah!!! Democracy Lives
-I'm an evil corporation and I have corrupted schroder
-I'm an evil corporation and I have corrupted chirac
-I'm an evil corporation and I have corrupted bush
-I'm an evil corporation and I have corrupted blair
-We are all Doomed!!! Democracy is Dead
-</programlisting>
-      </example>As soon as there is one more more honest politcians in the
-    working memory a new Hope object is logically asserted, this object will
-    only exist while there is at least one or more honest politicians, the
-    moment all politicians are dishonest then the Hope object will be
-    automatically retracted. This rule is given a salience of 10 to make sure
-    it fires before any other rules, as at this stage the "Hope is Dead" rule
-    is actually true.</para>
-
-    <example>
-      <title>Honest Politician Example : Rule "We have an honest
-      politician"</title>
-
-      <programlisting>rule "We have an honest Politician"
-    salience 10
-    when
-        exists( Politician( honest == true ) )
-    then
-        insertLogical( new Hope() );
-end</programlisting>
-    </example>
-
-    <para>As soon as a Hope object exists the "Hope Lives" rule matches, and
-    fires, it has a salience of 10 so that it takes priority over "Corrupt the
-    Honest".</para>
-
-    <example>
-      <title>Honest Politician Example : Rule "Hope Lives"</title>
-
-      <programlisting>rule "Hope Lives"
-    salience 10
-    when
-        exists( Hope() )
-    then
-        System.out.println("Hurrah!!! Democracy Lives");
-end</programlisting>
-    </example>
-
-    <para>Now that hope exists and we have, at the start, four honest
-    politicians we have 4 activations for this rule all in conflict. This rule
-    iterates over those rules firing each one in turn, corrupting each
-    politician so that they are no longer honest. When all four politicians
-    have been corrupted we have no politicians with the property "honest ==
-    true" thus the rule "We hvae an honest Politician" is no longer true and
-    the object it logical inserts "new Hope()" is automatically
-    retracted.</para>
-
-    <example>
-      <title>Honest Politician Example : Rule "Corrupt the Honest"</title>
-
-      <programlisting>rule "Corrupt the Honest"
-    when
-        politician : Politician( honest == true )   
-        exists( Hope() )
-    then
-        System.out.println( "I'm an evil corporation and I have corrupted " + politician.getName() );
-        modify ( politician ) { honest = false };
-end</programlisting>
-    </example>
-
-    <para>With Hope being automatically retracted, via the truth maintenance
-    system, then Hope no longer exists in the system and this rule will match
-    and fire.</para>
-
-    <example>
-      <title>Honest Politician Example : Rule "Hope is Dead"</title>
-
-      <programlisting>rule "Hope is Dead"
-    when
-        not( Hope() )
-    then
-        System.out.println( "We are all Doomed!!! Democracy is Dead" );
-end</programlisting>
-    </example>
-
-    <para>lets take a look the audit trail for this application:</para>
-
-    <figure>
-      <title>Honest Politician Example Audit View</title>
-
-      <mediaobject>
-        <imageobject>
-          <imagedata fileref="honest_politician_audit.png" />
-        </imageobject>
-      </mediaobject>
-    </figure>
-
-    <para>The moment we insert the first politician we have two activations,
-    the "We have an honest Politician" is activated only once for the first
-    inserted politician because it uses an existential 'exists' conditional
-    element which only matches. the rule "Hope is Dead" is also activated at
-    this stage, because as of yet we have not inserted the Hope object. "We
-    have an honest Politician" fires first, as it has a higher salience over
-    "Hope is Dead" which inserts the Hope object, that action is highlighted
-    green above. The insertion of the Hope object activates "Hope Lives" and
-    de-activates "Hope is Dead", it also actives "Corrupt the Honest" for each
-    inserted honested politician. "Rule Hope Lives" executes printing
-    "Hurrah!!! Democracy Lives". Then for each politician the rule "Corrupt
-    the Honest" fires printing "I'm an evil corporation and I have corrupted
-    X", where X is the name of the politician, and modifies the politicians
-    honest value to false. When the last honest polician is corrupted Hope is
-    automatically retracted, by the truth maintenance system, as shown by the
-    blue highlighted area. The green highlighted area shows the origin of the
-    currently selected blue highlighted area. Once Hope is retracted "Hope is
-    dead" activates and fires printing "We are all Doomed!!! Democracy is
-    Dead".</para>
-
-  </section>

Copied: labs/jbossrules/trunk/drools-docs/drools-docs-expert/en/Chapter-Examples/Section-HonestPoliticianExample.xml (from rev 20479, labs/jbossrules/trunk/drools-docs/drools-docs-expert/en/Chapter-Examples/Section-HonestPolitician.xml)
===================================================================
--- labs/jbossrules/trunk/drools-docs/drools-docs-expert/en/Chapter-Examples/Section-HonestPoliticianExample.xml	                        (rev 0)
+++ labs/jbossrules/trunk/drools-docs/drools-docs-expert/en/Chapter-Examples/Section-HonestPoliticianExample.xml	2008-06-14 13:15:44 UTC (rev 20480)
@@ -0,0 +1,152 @@
+<?xml version="1.0" encoding="UTF-8"?>
+	<section xml:base="../">
+		<title>Honest Politician Example</title>
+
+		<para>The honest politician example demonstrates truth maintenance with logical assertions, the basic premise is that an object can only exist while a statement is true. A rule's consequence can logical insert an object with the insertLogical method, this means the object will only remain in the working memory as long as the rule that logically inserted it remains true, when the rule is no longer true the object is automatically retracted.</para>
+
+    <para>In this example there is Politician class with a name and a boolean
+    value for honest state, four politicians with honest state set to true are
+    inserted.</para>
+
+    <para><example>
+        <title>Politician Class</title>
+
+        <programlisting>public class Politician {
+    private String name;
+    private boolean honest;
+    ...
+}</programlisting>
+      </example><example>
+        <title>Honest Politician Example Execution</title>
+
+        <programlisting>Politician blair  = new Politician("blair", true);
+Politician bush  = new Politician("bush", true);
+Politician chirac  = new Politician("chirac", true);
+Politician schroder   = new Politician("schroder", true);
+        
+session.insert( blair );
+session.insert( bush );
+session.insert( chirac );
+session.insert( schroder );
+
+session.fireAllRules();</programlisting>
+      </example>The console out shows that while there is atleast one honest
+    polician democracy lives, however as each politician is in turn corrupted
+    by an evil corporation, when all politicians are dishonest democracy is
+    dead.<example>
+        <title>Honest Politician Example Console Output</title>
+
+        <programlisting>Hurrah!!! Democracy Lives
+I'm an evil corporation and I have corrupted schroder
+I'm an evil corporation and I have corrupted chirac
+I'm an evil corporation and I have corrupted bush
+I'm an evil corporation and I have corrupted blair
+We are all Doomed!!! Democracy is Dead
+</programlisting>
+      </example>As soon as there is one more more honest politcians in the
+    working memory a new Hope object is logically asserted, this object will
+    only exist while there is at least one or more honest politicians, the
+    moment all politicians are dishonest then the Hope object will be
+    automatically retracted. This rule is given a salience of 10 to make sure
+    it fires before any other rules, as at this stage the "Hope is Dead" rule
+    is actually true.</para>
+
+    <example>
+      <title>Honest Politician Example : Rule "We have an honest
+      politician"</title>
+
+      <programlisting>rule "We have an honest Politician"
+    salience 10
+    when
+        exists( Politician( honest == true ) )
+    then
+        insertLogical( new Hope() );
+end</programlisting>
+    </example>
+
+    <para>As soon as a Hope object exists the "Hope Lives" rule matches, and
+    fires, it has a salience of 10 so that it takes priority over "Corrupt the
+    Honest".</para>
+
+    <example>
+      <title>Honest Politician Example : Rule "Hope Lives"</title>
+
+      <programlisting>rule "Hope Lives"
+    salience 10
+    when
+        exists( Hope() )
+    then
+        System.out.println("Hurrah!!! Democracy Lives");
+end</programlisting>
+    </example>
+
+    <para>Now that hope exists and we have, at the start, four honest
+    politicians we have 4 activations for this rule all in conflict. This rule
+    iterates over those rules firing each one in turn, corrupting each
+    politician so that they are no longer honest. When all four politicians
+    have been corrupted we have no politicians with the property "honest ==
+    true" thus the rule "We hvae an honest Politician" is no longer true and
+    the object it logical inserts "new Hope()" is automatically
+    retracted.</para>
+
+    <example>
+      <title>Honest Politician Example : Rule "Corrupt the Honest"</title>
+
+      <programlisting>rule "Corrupt the Honest"
+    when
+        politician : Politician( honest == true )   
+        exists( Hope() )
+    then
+        System.out.println( "I'm an evil corporation and I have corrupted " + politician.getName() );
+        modify ( politician ) { honest = false };
+end</programlisting>
+    </example>
+
+    <para>With Hope being automatically retracted, via the truth maintenance
+    system, then Hope no longer exists in the system and this rule will match
+    and fire.</para>
+
+    <example>
+      <title>Honest Politician Example : Rule "Hope is Dead"</title>
+
+      <programlisting>rule "Hope is Dead"
+    when
+        not( Hope() )
+    then
+        System.out.println( "We are all Doomed!!! Democracy is Dead" );
+end</programlisting>
+    </example>
+
+    <para>lets take a look the audit trail for this application:</para>
+
+    <figure>
+      <title>Honest Politician Example Audit View</title>
+
+      <mediaobject>
+        <imageobject>
+          <imagedata fileref="HonestPoliticianExample/honest_politician_audit.png" />
+        </imageobject>
+      </mediaobject>
+    </figure>
+
+    <para>The moment we insert the first politician we have two activations,
+    the "We have an honest Politician" is activated only once for the first
+    inserted politician because it uses an existential 'exists' conditional
+    element which only matches. the rule "Hope is Dead" is also activated at
+    this stage, because as of yet we have not inserted the Hope object. "We
+    have an honest Politician" fires first, as it has a higher salience over
+    "Hope is Dead" which inserts the Hope object, that action is highlighted
+    green above. The insertion of the Hope object activates "Hope Lives" and
+    de-activates "Hope is Dead", it also actives "Corrupt the Honest" for each
+    inserted honested politician. "Rule Hope Lives" executes printing
+    "Hurrah!!! Democracy Lives". Then for each politician the rule "Corrupt
+    the Honest" fires printing "I'm an evil corporation and I have corrupted
+    X", where X is the name of the politician, and modifies the politicians
+    honest value to false. When the last honest polician is corrupted Hope is
+    automatically retracted, by the truth maintenance system, as shown by the
+    blue highlighted area. The green highlighted area shows the origin of the
+    currently selected blue highlighted area. Once Hope is retracted "Hope is
+    dead" activates and fires printing "We are all Doomed!!! Democracy is
+    Dead".</para>
+
+  </section>

Added: labs/jbossrules/trunk/drools-docs/drools-docs-expert/en/Chapter-Examples/Section-NumberGuessExample.xml
===================================================================
--- labs/jbossrules/trunk/drools-docs/drools-docs-expert/en/Chapter-Examples/Section-NumberGuessExample.xml	                        (rev 0)
+++ labs/jbossrules/trunk/drools-docs/drools-docs-expert/en/Chapter-Examples/Section-NumberGuessExample.xml	2008-06-14 13:15:44 UTC (rev 20480)
@@ -0,0 +1,373 @@
+<?xml version="1.0" encoding="UTF-8"?>
+    <section xml:base="../">
+      <title>Number Guess</title>
+
+      <programlisting><emphasis role="bold">Name:</emphasis> Number Guess 
+<emphasis role="bold">Main class:</emphasis> org.drools.examples.NumberGuessExample
+<emphasis role="bold">Type:</emphasis> java application
+<emphasis role="bold">Rules file:</emphasis> NumberGuess.drl
+<emphasis role="bold">Objective:</emphasis> Demonstrate use of Rule Flow to organise Rules
+</programlisting>
+
+      <para>The "Number Guess" example shows the use of RuleFlow, a way of
+      controlling the order in which rules are fired. It uses widely
+      understood workflow diagrams to make clear the order that groups of
+      rules will be executed.</para>
+
+      <example>
+        <title>Creating the Number Guess RuleBase - extract 1 from
+        NumberGuessExample.java main() method</title>
+
+        <programlisting>final PackageBuilder builder = new PackageBuilder();
+
+builder.addPackageFromDrl( new InputStreamReader( 
+         ShoppingExample.class.getResourceAsStream( "NumberGuess.drl" ) ) );
+builder.addRuleFlow( new InputStreamReader( 
+         ShoppingExample.class.getResourceAsStream( "NumberGuess.rfm" ) ) );
+
+final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
+ruleBase.addPackage( builder.getPackage() );
+
+</programlisting>
+      </example>
+
+      <para>The creation of the package, and the loading of the rules (using
+      the addPackageFromDrl() method ) is the same as the previous examples.
+      There is a additional line to add the RuleFlow (NumberGuess.rfm) as you
+      have the option of specifying different ruleflows for the same RuleBase.
+      Otherwise the RuleBase is created in the same manner as before.</para>
+
+      <example>
+        <title>Starting the RuleFlow - extract 2 from NumberGuessExample.java
+        main() method</title>
+
+        <programlisting>final StatefulSession session = ruleBase.newStatefulSession();
+
+session.insert( new GameRules( 100,  5 ) );
+session.insert( new RandomNumber() );
+session.insert( new Game() );
+
+session.startProcess( "Number Guess" );
+session.fireAllRules();
+
+session.dispose();
+
+</programlisting>
+      </example>
+
+      <para>Once we have a RuleBase we can use it to obtain a stateful
+      session. Into our session we insert our facts (standard Java Objects).
+      For simplicity in this sample, these classes are all contained within
+      our NumberGuessExample.java file. The GameRules class provides the
+      maximum range and the number of guesses allowed. The RandomNumber class
+      automatically generates a number between 0 and 100 and makes it
+      available to our rules after insertion (via the getValue() method). The
+      Game class keeps track of the guesses we have made before, and the
+      number of guesses we have made.</para>
+
+      <para>Note that before we call the standard fireAllRules() method, we
+      also start the process that we loaded earlier (via the startProcess()
+      method). We explain where to obtain the parameter we pass ("Number
+      Guess" - the id of the ruleflow) when we talk about the RuleFlow file
+      and the graphical RuleFlow editor below.</para>
+
+      <para>Before we finish we our Java code , we note that In 'real life' we
+      would examine the final state of the objects (e.g. how many guesses it
+      took, so that we could add it to a high score table). For this example
+      we are content to ensure the working memory session is cleared by
+      calling the dispose() method.</para>
+
+      <figure>
+        <title>RuleFlow for the NumberGuess Example</title>
+
+        <mediaobject>
+          <imageobject>
+            <imagedata fileref="NumberGuessExample/numberguess-ruleflow.png" />
+          </imageobject>
+        </mediaobject>
+      </figure>
+
+      <para>If you open the NumberGuess.rf file open in the Drools IDE (and
+      have the JBoss Rules extensions installed correctly in Eclipse) you
+      should see the above diagram, similar to a standard flowchart. Its icons
+      are similar (but not exactly the same) as the JBoss jBPM workflow
+      product. Should you wish to edit the diagram, a menu of available
+      components should be available to the left of the diagram in the IDE,
+      which is call the pallete. This diagram is saved in a (almost human)
+      readable xml format, using xstream.</para>
+
+      <para>If it is not already open, ensure the properties view is visible
+      in the IDE. It can opened by selecting Window -&gt; Show View -&gt;
+      Other and then select the Properties view. If you do this <emphasis
+      role="bold">before</emphasis> you select any item on the RuleFlow (or
+      click on blank space in the RuleFlow) you should be presented with the
+      following set of properties.</para>
+
+      <figure>
+        <title>Properties for the Number Guess RuleFlow</title>
+
+        <mediaobject>
+          <imageobject>
+            <imagedata fileref="NumberGuessExample/numberguess-ruleflow-properties.png" />
+          </imageobject>
+        </mediaobject>
+      </figure>
+
+      <para>Keep an eye on the properties view as we progress through the
+      example RuleFlow as it gives valuable information. In this case it
+      provides us with the ID of the RuleFlow process that we used in our
+      earlier code example when we called session.startprocess().</para>
+
+      <para>To give an overview of each of the node types (boxes) in the
+      NumberGuess RuleFlow.</para>
+
+      <para>
+        <itemizedlist>
+          <listitem>
+            <para>The Start and End nodes (green arrow and red box) are where
+            the RuleFlow starts and ends.</para>
+          </listitem>
+
+          <listitem>
+            <para>RuleFlowGroup (simple yellow box). These map to the
+            RuleFlowGroups in our rules (DRL) file that we will look at later.
+            For example when the flow reaches the 'Too High' RuleFlowGroup,
+            only those rules marked with an attribute of <emphasis
+            role="bold">ruleflow-group "Too High" </emphasis> can potentially
+            fire.</para>
+          </listitem>
+
+          <listitem>
+            <para>Action Nodes (yellow box with cog like icon). These can
+            perform standard Java method calls. Most action nodes in this
+            example call System.out.println to give an indication to the user
+            of what is going on.</para>
+          </listitem>
+
+          <listitem>
+            <para>Split and Join Nodes (Blue Ovals) such as "Guess Correct"
+            and "More Guesses Join" where the flow of control can split
+            (according to various conditions) and / or rejoin.</para>
+          </listitem>
+
+          <listitem>
+            <para>Arrows that indicate the flow between the various
+            nodes.</para>
+          </listitem>
+        </itemizedlist>
+      </para>
+
+      <para>These various nodes work together with the Rules to make the
+      Number Guess game work. For example, the "Guess" RuleFlowGroup allows
+      only the rule "Get user Guess" to fire (details below) as only that Rule
+      has a matching attribute of <emphasis role="bold">ruleflow-group
+      "Guess"</emphasis></para>
+
+      <example>
+        <title>A Rule that will fire only a specific point in the RuleFlow -
+        extract from NumberGuess.drl</title>
+
+        <programlisting>rule "Get user Guess"
+ ruleflow-group "Guess"
+ no-loop
+ when    
+     $r : RandomNumber()
+     rules : GameRules( allowed : allowedGuesses )
+     game : Game( guessCount &lt; allowed )
+     not ( Guess() )
+ then
+     System.out.println( "You have " + ( rules.allowedGuesses - game.guessCount ) 
+     + " out of " + rules.allowedGuesses + " guesses left.\nPlease enter your guess 
+     from 0 to " + rules.maxRange );
+        br = new BufferedReader( new InputStreamReader( System.in ) );
+        modify ( game ) { guessCount = game.guessCount + 1 }
+        i = br.readLine();        
+    insert( new Guess( i ) );
+end</programlisting>
+      </example>
+
+      <para>The rest of this rule is fairly standard : The <emphasis
+      role="bold">LHS (when)</emphasis> section of the rule states that it
+      will be activated for each <emphasis>RandomNumber</emphasis> object
+      inserted into the working memory where <emphasis>guessCount</emphasis>
+      is less than the <emphasis>allowedGuesses</emphasis> ( read from the
+      GameRules Class) and where the user has not guessed the correct
+      number.</para>
+
+      <para>The <emphasis role="bold">RHS (consequence, then)</emphasis>
+      prints a message to the user, then awaits user input from
+      <emphasis>System.in. </emphasis> After getting this input (as System.in
+      blocks until the &lt;return&gt; key is pressed) it updates/modifes the
+      guess count, the actual guess and makes both available in the working
+      memory.</para>
+
+      <para>The rest of the Rules file is fairly standard ; the package
+      declares the dialect is set to MVEL, various Java classes are imported.
+      In total, there are five rules in this file:</para>
+
+      <orderedlist>
+          <listitem>
+            <para>Get User Guess, the Rule we examined above.</para>
+          </listitem>
+
+          <listitem>
+            <para>A Rule to record the highest guess.</para>
+          </listitem>
+
+          <listitem>
+            <para>A Rule to record the lowest guess.</para>
+          </listitem>
+
+          <listitem>
+            <para>A Rule to inspect the guess and retract it from memory if
+            incorrect.</para>
+          </listitem>
+
+          <listitem>
+            <para>A Rule that notifies the user that all guesses have been
+            used up.</para>
+          </listitem>
+        </orderedlist>
+	
+	<para>One point of integration between the standard Rules and
+      the RuleFlow is via the 'ruleflow-group' attribute on the rules (as
+      dicussed above). A <emphasis role="bold">second point of integration
+      between the Rules File (drl) and the Rules Flow .rf files </emphasis>is
+      that the Split Nodes (the blue ovals) can use values in working memory
+      (as updated by the Rules) to decide which flow of action to take. To see
+      how this works click on the "Guess Correct Node" ; then within the
+      properties view, open the constraints editor (the button at the right
+      that appears once you click on the 'Constraints' property line). You
+      should see something similar to the Diagram below.</para>
+
+      <figure>
+        <title>Edit Constraints for the GuessCorrect Node</title>
+
+        <mediaobject>
+          <imageobject>
+            <imagedata fileref="NumberGuessExample/numberguess-editconstraints.png" />
+          </imageobject>
+        </mediaobject>
+      </figure>
+
+      <para>Click on 'Edit' beside 'To node Too High' and you see a dialog
+      like the one below. The values in the 'Textual Editor' follow the
+      standard Rule Format (LHS) and can refer to objects in working memory.
+      The consequence (RHS) is that the flow of control follows this node
+      (i.e. To node Too high') if the LHS expression evaluates to true.</para>
+
+      <figure>
+        <title>Constraints Editor for the GuessCorrect Node / value too
+        high</title>
+
+        <mediaobject>
+          <imageobject>
+            <imagedata fileref="NumberGuessExample/numberguess-constraint-toohigh.png" />
+          </imageobject>
+        </mediaobject>
+      </figure>
+
+      <para>Since the NumberGuess.java example contains a main() method, it
+      can be run as a standard Java application (either from the command line
+      or via the IDE). A typical game might result in the interaction below
+      (the numbers in bold are typed in by the user).</para>
+
+      <example>
+        <title>Example Console output where the Number Guess Example beat the
+        human!</title>
+
+        <programlisting>You have 5 out of 5 guesses left.
+Please enter your guess from 0 to 100
+<emphasis role="bold">50</emphasis>
+Your guess was too high
+You have 4 out of 5 guesses left.
+Please enter your guess from 0 to 100
+<emphasis role="bold">25</emphasis>
+Your guess was too low
+You have 3 out of 5 guesses left.
+Please enter your guess from 0 to 100
+<emphasis role="bold">37</emphasis>
+Your guess was too low
+You have 2 out of 5 guesses left.
+Please enter your guess from 0 to 100
+<emphasis role="bold">44</emphasis>
+Your guess was too low
+You have 1 out of 5 guesses left.
+Please enter your guess from 0 to 100
+<emphasis role="bold">47</emphasis>
+Your guess was too low
+You have no more guesses
+The correct guess was 48 
+
+</programlisting>
+      </example>
+
+      <para>A summary of what is happening in this sample is:</para>
+
+
+        <orderedlist>
+          <listitem>
+            <para>Main() method of NumberGuessExample.java loads RuleBase,
+            gets a StatefulSession and inserts Game, GameRules and
+            RandomNumber (containing the target number) objects into it. This
+            method sets the process flow we are going to use, and fires all
+            rules. Control passes to the RuleFlow.</para>
+          </listitem>
+
+          <listitem>
+            <para>The NumberGuess.rf RuleFlow begins at the Start node.</para>
+          </listitem>
+
+          <listitem>
+            <para>Control passes (via the "more guesses" join node) to the
+            Guess Node..</para>
+          </listitem>
+
+          <listitem>
+            <para>At the Guess node, the appropriate RuleFlowGroup ("Get user
+            Guess") is enabled. In this case the Rule "Guess" (in the
+            NumberGuess.drl file) is triggered. This rule displays a message
+            to the user, takes the response, and puts it into memory. Flow
+            passes to the next Rule Flow Node.</para>
+          </listitem>
+
+          <listitem>
+            <para>At the next node , "Guess Correct", constraints inspect the
+            current session and decide which path we take next.</para>
+
+            <para>If the guess in step 4 was too high / too low flow procees
+            along a path which has (i) An action node with normal Java code
+            prints a too high / too low statement and (ii) a RuleFlowGroup
+            causes a highest guess / lowest guess Rule to be triggered in the
+            Rules file. Flow passes from these nodes to step 6.</para>
+
+            <para>If the guess in step 4 just right we proceed along the path
+            towards the end of the Rule Flow. Before we get there, an action
+            node with normal Java code prints a statement "you guessed
+            correctly". There is a join node here (just before the Rule Flow
+            End) so that our no-more-guesses path (step 7) can also terminate
+            the RuleFlow.</para>
+          </listitem>
+
+          <listitem>
+            <para>Control passes as per the RuleFlow via a join node, a guess
+            incorrect RuleFlowGroup (triggers a rule to retract a guess from
+            working memory) onto the "more guesses" decision node.</para>
+          </listitem>
+
+          <listitem>
+            <para>The "more guesses" decision node (right hand side of
+            ruleflow) uses constraints (again looking at values that the Rules
+            have put into the working memory) to decide if we have more
+            guesses and if so, goto step 3. If not we proceed to the end of
+            the workflow, via a RuleFlowGroup that triggers a rule stating
+            "you have no more guesses".</para>
+          </listitem>
+
+          <listitem>
+            <para>The Loop 3-7 continues until the number is guessed
+            correctly, or we run out of guesses.</para>
+          </listitem>
+        </orderedlist>
+
+    </section>
\ No newline at end of file

Added: labs/jbossrules/trunk/drools-docs/drools-docs-expert/en/Chapter-Examples/Section-SodukiExample.xml
===================================================================
--- labs/jbossrules/trunk/drools-docs/drools-docs-expert/en/Chapter-Examples/Section-SodukiExample.xml	                        (rev 0)
+++ labs/jbossrules/trunk/drools-docs/drools-docs-expert/en/Chapter-Examples/Section-SodukiExample.xml	2008-06-14 13:15:44 UTC (rev 20480)
@@ -0,0 +1,457 @@
+<?xml version="1.0" encoding="UTF-8"?>
+  <section xml:base="../">
+    <title>Sudoku Example</title>
+
+    <programlisting><emphasis role="bold">Name:</emphasis> Sudoku
+<emphasis role="bold">Main class:</emphasis> org.drools.examples.sudoku.Main
+<emphasis role="bold">Type:</emphasis> java application
+<emphasis role="bold">Rules file:</emphasis> sudokuSolver.drl, sudokuValidator.drl
+<emphasis role="bold">Objective:</emphasis> Demonstrates the solving of logic problems, and complex pattern matching.e
+</programlisting>
+
+    <para>This example demonstrates how Drools can be used to find a solution
+    in a large potential solution space based on a number of constraints. We
+    use the popular puzzle of Sudoku. This example also shows how Drools can
+    be integrated into a graphical interface and how callbacks can be used to
+    interact with a running Drools rules engine in order to update the
+    graphical interface based on changes in the working memory at
+    runtime.</para>
+
+    <section>
+      <title>Sudoku Overview</title>
+
+      <para>Sudoku is a logic-based number placement puzzle. The objective is
+      to fill a 9x9 grid so that each column, each row, and each of the nine
+      3x3 zones contains the digits from 1 to 9 once and only once.</para>
+
+      <para>The puzzle setter provides a partially completed grid and the
+      puzzle solver's task is to complete the grid with these
+      constraints.</para>
+
+      <para>The general strategy to solve the problem is to ensure that when
+      you insert a new number it should be unique in that particular
+      region(blocks) and also in that particular row and column.</para>
+
+      <para>See <programlisting>URL: http://en.wikipedia.org/wiki/Sudoku</programlisting>
+      for a more detailed description.</para>
+    </section>
+
+    <section>
+      <title>Running the Example</title>
+
+      <para>Download and install drools-examples as described above and then
+      execute java org.drools.examples.sudoku.Main (this example requires Java
+      5).</para>
+
+      <para>A window will be displayed with a relatively simple partially
+      filled grid. <screenshot>
+          <screeninfo>New remote site</screeninfo>
+
+          <mediaobject>
+            <imageobject>
+              <imagedata fileref="SodukiExample/sudoku1.png" />
+            </imageobject>
+          </mediaobject>
+        </screenshot></para>
+
+      <para>Click on the Solve button and the Drools-based engine will fill
+      out the remaining values. The console will display detailed information
+      of the rules which are executing to solve the puzzle in a human readable
+      form.</para>
+
+      <para><computeroutput>Rule #3 determined the value at (4,1) could not be
+      4 as this value already exists in the same column at (8,1) Rule #3
+      determined the value at (5,5) could not be 2 as this value already
+      exists in the same row at (5,6) Rule #7 determined (3,5) is 2 as this is
+      the only possible cell in the column that can have this value Rule #1
+      cleared the other PossibleCellValues for (3,5) as a ResolvedCellValue of
+      2 exists for this cell. Rule #1 cleared the other PossibleCellValues for
+      (3,5) as a ResolvedCellValue of 2 exists for this cell. ... Rule #3
+      determined the value at (1,1) could not be 1 as this value already
+      exists in the same zone at (2,1) Rule #6 determined (1,7) is 1 as this
+      is the only possible cell in the row that can have this value Rule #1
+      cleared the other PossibleCellValues for (1,7) as a ResolvedCellValue of
+      1 exists for this cell. Rule #6 determined (1,1) is 8 as this is the
+      only possible cell in the row that can have this value
+      </computeroutput></para>
+
+      <para>Once all of the activated rules for the solving logic have
+      executed, the engine executes a second rule base to check that the
+      solution is complete and valid. In this case it is, and the "Solve"
+      button is disabled and displays the text "Solved (1052ms)". <screenshot>
+          <screeninfo>New remote site</screeninfo>
+
+          <mediaobject>
+            <imageobject>
+              <imagedata fileref="SodukiExample/sudoku2.png" />
+            </imageobject>
+          </mediaobject>
+        </screenshot></para>
+
+      <para>The example comes with a number of grids which can be loaded and
+      solved. Click on File-&gt;Samples-&gt;Medium to load a more challenging
+      grid. Note that the solve button is enabled when the new grid is loaded.
+      <screenshot>
+          <screeninfo>New remote site</screeninfo>
+
+          <mediaobject>
+            <imageobject>
+              <imagedata fileref="SodukiExample/sudoku3.png" />
+            </imageobject>
+          </mediaobject>
+        </screenshot></para>
+
+      <para>Click on the "Solve" button again to solve this new grid.
+      <screenshot>
+          <screeninfo>New remote site</screeninfo>
+
+          <mediaobject>
+            <imageobject>
+              <imagedata fileref="SodukiExample/sudoku4.png" />
+            </imageobject>
+          </mediaobject>
+        </screenshot></para>
+
+      <para>Now, let us load a Sudoku grid that is deliberately invalid. Click
+      on File-&gt;Samples-&gt;!DELIBERATELY BROKEN!. Note that this grid
+      starts with some issues, for example the value 5 appears twice in the
+      first row. <screenshot>
+          <screeninfo>New remote site</screeninfo>
+
+          <mediaobject>
+            <imageobject>
+              <imagedata fileref="SodukiExample/sudoku5.png" />
+            </imageobject>
+          </mediaobject>
+        </screenshot></para>
+
+      <para>Nevertheless, click on the "Solve" button to apply the solving
+      rules to this invalid Grid. Note that the "Solve" button is relabelled
+      to indicate that the resulting solution is invalid. <screenshot>
+          <screeninfo>New remote site</screeninfo>
+
+          <mediaobject>
+            <imageobject>
+              <imagedata fileref="SodukiExample/sudoku6.png" />
+            </imageobject>
+          </mediaobject>
+        </screenshot></para>
+
+      <para>In addition, the validation rule set outputs all of the issues
+      which are discovered to the console. <programlisting>
+There are two cells on the same column with the same value at (6,0) and (4,0)
+There are two cells on the same column with the same value at (4,0) and (6,0)
+There are two cells on the same row with the same value at (2,4) and (2,2)
+There are two cells on the same row with the same value at (2,2) and (2,4)
+There are two cells on the same row with the same value at (6,3) and (6,8)
+There are two cells on the same row with the same value at (6,8) and (6,3)
+There are two cells on the same column with the same value at (7,4) and (0,4)
+There are two cells on the same column with the same value at (0,4) and (7,4)
+There are two cells on the same row with the same value at (0,8) and (0,0)
+There are two cells on the same row with the same value at (0,0) and (0,8)
+There are two cells on the same column with the same value at (1,2) and (3,2)
+There are two cells on the same column with the same value at (3,2) and (1,2)
+There are two cells in the same zone with the same value at (6,3) and (7,3)
+There are two cells in the same zone with the same value at (7,3) and (6,3)
+There are two cells on the same column with the same value at (7,3) and (6,3)
+There are two cells on the same column with the same value at (6,3) and (7,3)   
+      </programlisting></para>
+
+      <para>We will look at the solving rule set later in this section, but
+      for the moment we should note that some theoretically solvable solutions
+      can not be solved by the engine as it stands. Click on
+      File-&gt;Samples-&gt;Hard 3 to load a sparsely populated Grid.
+      <screenshot>
+          <screeninfo>New remote site</screeninfo>
+
+          <mediaobject>
+            <imageobject>
+              <imagedata fileref="SodukiExample/sudoku7.png" />
+            </imageobject>
+          </mediaobject>
+        </screenshot></para>
+
+      <para>Now click on the "Solve" button and note that the current rules
+      are unable to complete the grid, even though (if you are a Sudoku
+      afficiando) you may be able to see a way forward with the solution.
+      <screenshot>
+          <screeninfo>New remote site</screeninfo>
+
+          <mediaobject>
+            <imageobject>
+              <imagedata fileref="SodukiExample/sudoku8.png" />
+            </imageobject>
+          </mediaobject>
+        </screenshot></para>
+
+      <para>At the present time, the solving functionality has been achieved
+      by the use of ten rules. This rule set could be extended to enable the
+      engine to tackle more complex logic for filling grids such as
+      this.</para>
+    </section>
+
+    <section>
+      <title>Java Source and Rules Overview</title>
+
+      <para>The Java source code can be found in the
+      /src/main/java/org/drools/examples/sudoku directory, with the two DRL
+      files defining the rules located in the
+      /src/main/rules/org/drools/examples/sudoku directory.</para>
+
+      <para>org.drools.examples.sudoku.swing contains a set of classes which
+      implement a framework for Sudoku puzzles. Note that this package does
+      not have any dependencies on the Drools libraries. SudokuGridModel
+      defines an interface which can be implemented to store a Sudoku puzzle
+      as a 9x9 grid of Integer values, some of which may be null, indicating
+      that the value for the cell has not yet been resolved. SudokuGridView is
+      a Swing component which can visualise any implementation of
+      SudokuGridModel. SudokuGridEvent and SudokuGridListener are used to
+      communicate state changes between the model and the view, events are
+      fired when a cell's value is resolved or changed. If you are familiar
+      with the model-view-controller patterns in other Swing components such
+      as JTable then this pattern should be familiar. SudokuGridSamples
+      provides a number of partially filled Sudoku puzzles for demo
+      purposes.</para>
+
+      <para>org.drools.examples.sudoku.rules contains an implementation of
+      SudokuGridModel which is based on Drools. Two POJOs are used, both of
+      which extend AbstractCellValue and represent a value for a specific cell
+      in the grid, including the row and column location of the cell, an index
+      of the 3x3 zone the cell is contained in and the value of the cell.
+      PossibleCellValue indicates that we do not currently know for sure what
+      the value in a cell is. There can be 2-9 PossibleCellValues for a given
+      cell. ResolvedCellValue indicates that we have determined what the value
+      for a cell must be. There can only be 1 ResolvedCellValue for a given
+      cell. DroolsSudokuGridModel implements SudokuGridModel and is
+      responsible for converting an initial two dimensional array of partially
+      specified cells into a set of CellValue POJOs, creating a working memory
+      based on solverSudoku.drl and inserting the CellValue POJOs into the
+      working memory. When the solve() method is called it calls
+      fireAllRules() on this working memory to try to solve the puzzle.
+      DroolsSudokuGridModel attaches a WorkingMemoryListener to the working
+      memory, which allows it to be called back on insert() and retract()
+      events as the puzzle is solved. When a new ResolvedCellValue is inserted
+      into the working memory, this call back allows the implementation to
+      fire a SudokuGridEvent to its SudokuGridListeners which can then update
+      themselves in realtime. Once all the rules fired by the solver working
+      memory have executed, DroolsSudokuGridModel runs a second set of rules,
+      based on validatorSudoku.drl which works with the same set of POJOs to
+      determine if the resulting grid is a valid and full solution.</para>
+
+      <para>org.drools.examples.sudoku.Main implements a Java application
+      which hooks the components desribed above together.</para>
+
+      <para>org.drools.examples.sudoku contains two DRL files.
+      solverSudoku.drl defines the rules which attempt to solve a Sudoku
+      puzzle and validator.drl defines the rules which determin whether the
+      current state of the working memory represents a valid solution. Both
+      use PossibleCellValue and ResolvedCellValue POJOs as their facts and
+      both output information to the console as their rules fire. In a
+      real-world situation we would insert() logging information and use the
+      WorkingMemoryListener to display this information to a user rather than
+      use the console in this fashion.</para>
+    </section>
+
+    <section>
+      <title>Sudoku Validator Rules (validatorSudoku.drl)</title>
+
+      <para>We start with the validator rules as this rule set is shorter and
+      simpler than the solver rule set.</para>
+
+      <para>The first rule simply checks that no PossibleCellValue objects
+      remain in the working memory. Once the puzzle is solved, only
+      ResolvedCellValue objects should be present, one for each cell.</para>
+
+      <para>The other three rules each match all of the ResolvedCellValue
+      objects and store them in thenew_remote_sitetes instance variable
+      $resolved. They then look respectively for ResolvedCellValues that
+      contain the same value and are located, respectively, in the same row,
+      column or 3x3 zone. If these rules are fired they add a message to a
+      global List of Strings describing the reason the solution is invalid.
+      DroolsSudokoGridModel injects this List before it runs the rule set and
+      checks whether it is empty or not having called fireAllRules(). If it is
+      not empty then it prints all the Strings in the list and sets a flag to
+      indicate that the Grid is not solved.</para>
+    </section>
+
+    <section>
+      <title>Sudoku Solving Rules (solverSudoku.drl)</title>
+
+      <para>Now let us look at the more complex rule set used to solve Sudoku
+      puzzles.</para>
+
+      <para>Rule #1 is basically a "book-keeping" rule. Several of the other
+      rules insert() ResolvedCellValues into the working memory at specific
+      rows and columns once they have determined that a given cell must have a
+      certain value. At this point, it is important to clear the working
+      memory of any inserted PossibleCellValues at the same row and column
+      with invalid values. This rule is therefore given a higher salience than
+      the remaining rules to ensure that as soon as the LHS is true,
+      activations for the rule move to the top of the agenda and are fired. In
+      turn this prevents the spurious firing of other rules due to the
+      combination of a ResolvedCellValue and one or more PossibleCellValues
+      being present in the same cell. This rule also calls update() on the
+      ResolvedCellValue, even though its value has not in fact been modified
+      to ensure that Drools fires an event to any WorkingMemoryListeners
+      attached to the working memory so that they can update themselves - in
+      this case so that the GUI can display the new state of the grid.</para>
+
+      <para>Rule #2 identifies cells in the grid which have only one possible
+      value. The first line of the when caluse matches all of the
+      PossibleCellValue objects in the working memory. The second line
+      demonstrates a use of the not keyword. This rule will only fire if no
+      other PossibleCellValue objects exist in the working memory at the same
+      row and column but with a different value. When the rule fires, the
+      single PossibleCellValue at the row and column is retracted from the
+      working memory and is replaced by a new ResolvedCellValue at the same
+      row and column with the same value.</para>
+
+      <para>Rule #3 removes PossibleCellValues with a given value from a row
+      when they have the same value as a ResolvedCellValue. In other words,
+      when a cell is filled out with a resolved value, we need to remove the
+      possibility of any other cell on the same row having this value. The
+      first line of the when clause matches all ResolvedCellValue objects in
+      the working memory. The second line matches PossibleCellValues which
+      have both the same row and the same value as these ResolvedCellValue
+      objects. If any are found, the rule activates and, when fired retracts
+      the PossibleCellValue which can no longer be a solution for that
+      cell.</para>
+
+      <para>Rules #4 and #5 act in the same way as Rule #3 but check for
+      redundant PossibleCellValues in a given column and a given zone of the
+      grid as a ResolvedCellValue respectively.</para>
+
+      <para>Rule #6 checks for the scenario where a possible cell value only
+      appears once in a given row. The first line of the LHS matches against
+      all PossibleCellValues in the working memory, storing the result in a
+      number of local variables. The second line checks that no other
+      PossibleCellValues with the same value exist on this row. The third to
+      fifth lines check that there is not a ResolvedCellValue with the same
+      value in the same zone, row or column so that this rule does not fire
+      prematurely. Interestingly we could remove lines 3-5 and give rules
+      #3,#4 and #5 a higher salience to make sure they always fired before
+      rules #6,#7 and #8. When the rule fires, we know that $possible must
+      represent the value for the cell so, as in Rule #2 we retract $possible
+      and replace it with the equivalent, new ResolvedCellValue.</para>
+
+      <para>Rules #7 and #8 act in the same way as Rule #2 but check for
+      single PossibleCellValues in a given column and a given zone of the grid
+      respectively.</para>
+
+      <para>Rule #9 represents the most complex currently implemented rule.
+      This rule implements the logic that, if we know that a pair of given
+      values can only occur in two cells on a specific row, (for example we
+      have determined the values of 4 and 6 can only appear in the first row
+      in cells 0,3 and 0,5) and this pair of cells can not hold other values
+      then, although we do not know which of the pair contains a four and
+      which contains a six we know that the 4 and the 6 must be in these two
+      cells and hence can remove the possibility of them occuring anywhere
+      else in the same row (phew!). TODO: more detail here and I think the
+      rule can be cleaned up in the DRL file before fully documenting
+      it.</para>
+
+      <para>Rules #10 and #11 act in the same way as Rule #9 but check for the
+      existance of only two possible values in a given column and zone
+      respectively.</para>
+
+      <para>To solve harder grids, the rule set would need to be extended
+      further with more complex rules that encapsulated more complex
+      reasoning.</para>
+    </section>
+
+    <section>
+      <title>Suggestions for Future Developments</title>
+
+      <para>There are a number of ways in which this example could be
+      developed. The reader is encouraged to consider these as
+      excercises.</para>
+
+      <itemizedlist>
+        <listitem>
+          <para>Agenda-group: agenda groups are a great declarative tool for
+          phased execution. In this example, it is easy to see we have 2
+          phases: "resolution" and "validation". Right now, they are executed
+          by creating two separate rule bases, each for one "job". I think it
+          would be better for us to define agenda-groups for all the rules,
+          spliting them in "resolution" rules and "validation" rules, all
+          loaded in a single rule base. The engine executes resolution and
+          right after that, executes validation.</para>
+        </listitem>
+
+        <listitem>
+          <para>Auto-focus: auto focus is a great way of handling exceptions
+          to the regular rules execution. In our case, if we detect an
+          inconsistency, either in the input data or in the resolution rules,
+          why should we spend time continuing the execution if it will be
+          invalid anyway? I think it is better to simply (and immediatly)
+          report the inconsistency as soon as it is found. To do that, since
+          we now have a single rulebase with all rules, we simply need to
+          define auto-focus attribute for all rules validating puzzle
+          consistency.</para>
+        </listitem>
+
+        <listitem>
+          <para>Logical insert: an inconsistency only exists while wrong data
+          is in the working memory. As so, we could state that the the
+          validation rules logically insert inconsistencies and as soon as the
+          offending data is retracted, the inconsistency no longer
+          exists.</para>
+        </listitem>
+
+        <listitem>
+          <para>session.iterateObjects(): although a valid use case having a
+          global list to add the found problems, I think it would be more
+          interesting to ask the stateful session by the desired list of
+          problems, using session.iterateObjects( new ClassObjectFilter(
+          Inconsistency.class ) ); Having the inconsistency class can also
+          allow us to paint in RED the offending cells in the GUI.</para>
+        </listitem>
+
+        <listitem>
+          <para>drools.halt(): even reporting the error as soon as it is
+          found, we need a way to tell the engine to stop evaluating rules. We
+          can do that creating a rule that in the presence of Inconsistencies,
+          calls drools.halt() to stop evaluation.</para>
+        </listitem>
+
+        <listitem>
+          <para>queries: looking at the method getPossibleCellValues(int row,
+          int col) in DroolsSudokuGridModel, we see it iterating over all
+          CellValues and looking for the few it wants. That, IMO, is a great
+          opportunity to teach drools queries. We just define a query to
+          return the objects we want and iterate over it. Clean and nice.
+          Other queries may be defined as needed.</para>
+        </listitem>
+
+        <listitem>
+          <para>session.iterateObjects(): although a valid use case having a
+          global list to add the found problems, I think it would be more
+          interesting to ask the stateful session by the desired list of
+          problems, using session.iterateObjects( new ClassObjectFilter(
+          Inconsistency.class ) ); Having the inconsistency class can also
+          allow us to paint in RED the offending cells in the GUI.</para>
+        </listitem>
+
+        <listitem>
+          <para>Globals as services: the main objective of this change is to
+          attend the next change I will propose, but it is nice by its own I
+          guess. :) In order to teach the use of "globals" as services, it
+          would be nice to setup a call back, so that each rule that finds the
+          ResolvedCellValue for a given cell can call, to notify and update
+          the corresponding cell in the GUI, providing immediate feedback for
+          the user. Also, the last found cell could have its number painted in
+          a different color to facilitate the identification of the rules
+          conclusions.</para>
+        </listitem>
+
+        <listitem>
+          <para>Step by step execution: now that we have immediate user
+          feedback, we can make use of the restricted run feature in drools.
+          I.e., we could add a button in the GUI, so that the user clicks and
+          causes the execution of a single rule, by calling fireAllRules( 1 ).
+          This way, the user can see, step by step, what the engine is
+          doing.</para>
+        </listitem>
+      </itemizedlist>
+    </section>
+  </section>
\ No newline at end of file

Modified: labs/jbossrules/trunk/drools-docs/drools-docs-expert/en/Chapter-Examples/Section-TroubleTicketExample.xml
===================================================================
--- labs/jbossrules/trunk/drools-docs/drools-docs-expert/en/Chapter-Examples/Section-TroubleTicketExample.xml	2008-06-14 13:00:09 UTC (rev 20479)
+++ labs/jbossrules/trunk/drools-docs/drools-docs-expert/en/Chapter-Examples/Section-TroubleTicketExample.xml	2008-06-14 13:15:44 UTC (rev 20480)
@@ -1,81 +1,191 @@
 <?xml version="1.0" encoding="UTF-8"?>
+
+  <!-- Trouble Ticket example -->
 	<section xml:base="../">
-  <!-- Trouble Ticket example -->
-		<title>Pricing Rule Decision Table Example</title>
+			<title>Executing the Example</title>
 
-		<para>The Pricing Rule decision table demonstrates the use of a decision table in a spreadsheet (XLS format) in calculating the retail cost of an insurance policy. The purpose of the set of rules provided is to calculate a base price, and an additional discount for a car driver applying for a specific policy. The drivers age, history and the policy type all contribute to what the basic premium is, and an additional chunk of rules deals with refining this with a subtractive percentage discount.</para>
+			<para>The example creates 4 customers, with their name and subscription class, it then creates 4 tickets for each of the customers, note that the ticket takes the customer in the constructor (that sets up the object relationship. The tickets and the customers are then inserted. Notice that we keep a fact handle - which we will use to notify the engine that that specific ticket changed later on. The last line has the all important fireAllRules(), which tells the engine to take action on the data it has.</para>
 
-		<programlisting><emphasis role="bold">Name:</emphasis> Example Policy Pricing
-<emphasis role="bold">Main class:</emphasis> org.drools.examples.PricingRuleDTExample
-<emphasis role="bold">Type:</emphasis> java application
-<emphasis role="bold">Rules file:</emphasis> ExamplePolicyPricing.xls
-<emphasis role="bold">Objective:</emphasis> demonstrate spreadsheet based decision tables.    </programlisting>
+			<example>
+				<title>Trouble Ticket Example : Creating and Inserting Facts</title>
 
-		<section>
-			<title>Executing the example</title>
+				<programlisting>Customer a = new Customer( "A",
+                           "Gold" );
+Customer b = new Customer( "B",
+                           "Platinum" );
+Customer c = new Customer( "C",
+                           "Silver" );
+Customer d = new Customer( "D",
+                           "Silver" );
 
-			<para>Open the PricingRuleDTExample.java and execute it as a Java application. It should produce the following console output:</para>
+Ticket t1 = new Ticket( a );
+Ticket t2 = new Ticket( b );
+Ticket t3 = new Ticket( c );
+Ticket t4 = new Ticket( d );
 
-			<programlisting>Cheapest possible
-BASE PRICE IS: 120
-DISCOUNT IS: 20     </programlisting>
+session.insert( a );
+session.insert( b );
+session.insert( c );
+session.insert( d );
 
-			<para>The code to the execute the example is very similar to the other examples. The rules are loaded, the facts inserted and a stateless session is used. What is different is how the rules are obtained:</para>
+session.insert( t1 );
+session.insert( t2 );
+FactHandle ft3 = session.insert( t3 );
+session.insert( t4 );
 
-			<programlisting>SpreadsheetCompiler compiler = new SpreadsheetCompiler();
-String drl = compiler.compile(getSpreadsheetStream(), InputType.XLS);
-</programlisting>
+session.fireAllRules();</programlisting>
+			</example>
 
-			<para>Note the use of the SpreadsheetCompiler class. It is what takes the XLS (as a binary InputStream to the XLS file), and outputs ordinary DRL (which is then dealt with in the usual way). You can (if you like) also print out the DRL. If you use the BRMS, all this is of course taken care of for you.</para>
+			<para>We have the "New Ticket" rule which has the highest priority (salience of 10 - the default is zero), The purpose of this is simply to log the fact that a new ticket has arrived in the system:</para>
 
-			<para>There are 2 facts used in this example, Driver, and Policy. Both are used with their default values. The Driver is 30 years old, has had no prior claims and currently has a risk profile of LOW. The Policy being applied for is COMPREHENSIVE, and the policy has not yet been approved.</para>
-		</section>
-		
-		<section>
-			<title>The decision table</title>
+			<programlisting>rule "New Ticket"
+ salience 10
+ when
+  customer : Customer( )
+  ticket : Ticket( customer == customer, status == "New" )
+  then
+ System.out.println( "New : " + ticket );
+end    </programlisting>
 
-			<para>In this decision table, each row is a rule, and each column is a condition or an action.</para>
+			<para>Note that we are "joining" the ticket fact with the customer fact. It's not really needed in this case, as we don't do anything (yet) with the customer fact. If you look in the TroubleTicketExample.java, you will also see that the facts are being inserted into the engine - note that we assert BOTH Customer and Ticket object (even though the ticket belongs to a customer - this allows the engine to join the objects together how it wants - this is what is meant by "relational" programming - we let the rule engine define what the relationships are. For instance, although the code is structured so that a ticket belongs to a customer, we may be interested in looking at tickets from different customers of the same type in the future).</para>
 
+			<para>If we run the rules, we should expect that the "New Ticket" rule will be activated for all tickets, so looking at the audit log view (by opening the file which was saved automatically when the rules were run):</para>
+
 			<figure>
-				<title>Decision table configuration</title>
+				<title>Audit view</title>
 
 				<mediaobject>
 					<imageobject>
-						<imagedata fileref="TroubleTicket/DT_Config.png" />
+						<imagedata fileref="TroubleTicketExample/tt_audit_view.png" />
 					</imageobject>
 				</mediaobject>
 			</figure>
 
-			<para>Referring to the above, we have the RuleSet declaration, which provides the package name. There are also other optional items you can have here, such as Variables for global variables, and Imports for importing classes. In this case, the namespace of the rules is the same as the fact classes we are using, so we can omit it.</para>
+			<para>Referring to the above audit log, we can see each customer asserted, but nothing happens. As soon as the first ticket gets asserted, it joins it with the customer, and creates some activations: one is the "new ticket" rule, the other is for the appropriate priority (which we will show below). Note that items in the above view do not mean the rule fired at that point.</para>
 
-			<para>Moving further down, we can see the RuleTable declaration. The name after this (Pricing bracket) is used as the prefix for all the generated rules. Below that, we have CONDITION or ACTION - this indicates the purpose of the column (ie does it form part of the condition, or an action of a rule that will be generated).</para>
+			<para>Also, don't forget to use "fireAllRules()" - a common mistake ! (In this case we are using a statefull session, so this is necessary).</para>
 
-			<para>You can see there is a Driver which is spanned across 3 cells, this means the template expressions below it apply to that fact. So we look at the drivers age range (which uses $1 and $2 with comma separated values), locationRiskProfile, and priorClaims in the respective columns. In the action columns, we are setting the policy base price, and then logging a message.</para>
+			<para>If we run the rules, we should expect that the "New Ticket" rule will be activated for all tickets, so looking at the audit log view (by opening the file which was saved automatically when the rules were run):</para>
 
 			<figure>
-				<title>Base price calculation</title>
+				<title>Audit view</title>
 
 				<mediaobject>
 					<imageobject>
-						<imagedata fileref="TroubleTicket/DT_Table1.png" />
+						<imagedata fileref="TroubleTicketExample/tt_audit_view.png" />
 					</imageobject>
 				</mediaobject>
 			</figure>
 
-			<para>Referring to the above, we can see there are broad category brackets (indicated by the comment in the left most column). As we know the details of our driver and their policy, we can tell (with a bit of thought) that they should match row number 18, as they have no prior accidents, and are 30 years old. This gives us a base price of 120.</para>
+			<para>Referring to the above audit log, we can see each customer asserted, but nothing happens. As soon as the first ticket gets asserted, it joins it with the customer, and creates some activations: one is the "new ticket" rule, the other is for the appropriate priority (which we will show below). Note that items in the above view do not mean the rule fired at that point.</para>
+			
+		</section>
+		
+		<section>
+			<title>Platinum gets the best service</title>
 
+			<para>All the wonderful platinum customers have to get great service, so first thing to note is that as soon as a ticket arrives, we escalate if it is for a platinum customer:</para>
+
+			<programlisting>rule "Platinum Priority"
+ when
+  customer : Customer( subscription == "Platinum" )
+  ticket : Ticket( customer == customer, status == "New" )
+ then;
+  ticket.setStatus( "Escalate" );
+  update( ticket );
+end      </programlisting>
+
+			<para>Here we are joining Ticket to customer again (customer == customer), but we are also checking that the customer is "Platinum". When this is the case, we set the ticket status to "Escalate" and call update (which tells the engine that the ticket has changed).</para>
+			
+		</section>
+		
+		<section>
+			<title>Silver and Gold</title>
+
+			<para>For silver and gold class, its a similar story to platinum:</para>
+
+			<programlisting>rule "Silver Priority"
+ duration 3000
+ when
+  customer : Customer( subscription == "Silver" )
+  ticket : Ticket( customer == customer, status == "New" )
+ then
+  ticket.setStatus( "Escalate" );
+  update( ticket );
+end
+
+rule "Gold Priority"
+ duration 1000
+ when
+  customer : Customer( subscription == "Gold" )
+  ticket : Ticket( customer == customer, status == "New" )
+ then
+  ticket.setStatus( "Escalate" );
+  update( ticket );
+end   </programlisting>
+
+			<para>In this case, note the use of "duration XXX" - XXX is the number of milliseconds to wait to check that this rule holds true. Should it do so, after XXX milliseconds, then the action takes effect. So in the above case, after 3 seconds the "Silver" priority kicks in, but after 1 second "Gold" does. In both cases the tickets are escalated (just like with platinum. This is what we mean by temporal rules (rules that take effect over time).</para>
+
+		</section>
+		
+		<section>
+			<title>Escalating</title>
+
+			<para>The actual escalation of a ticket happens in a rule:</para>
+
+			<programlisting>rule "Escalate"
+ when
+  customer : Customer( )
+  ticket : Ticket( customer == customer, status == "Escalate" )
+ then
+  sendEscalationEmail( customer, ticket );
+end     </programlisting>
+
+			<para>In this case, the action is to call a function which sends an email (the function is defined down the bottom of the drl file). This rule reacts to the rules which update the ticket and set its status to escalate.</para>
+
+			<para>In the code that launches the example, we have a "sleep" to make sure all this happens (and print out the results). Note also that after the rules are fired, we modify the status of the Customer "C" to "Done" - and then tell the engine. This causes it to evaluate and fire the rule that looks for "tickets" that are "Done" (in which is just logs a message).</para>
+	
+		</section>
+		
+		<section>
+			<title>Running it</title>
+
+			<para>Running the example (by launching the TroubleTicket.java class as an application) should yield the output:</para>
+
+			<programlisting>New : [Ticket [Customer D : Silver] : New]
+New : [Ticket [Customer C : Silver] : New]
+New : [Ticket [Customer B : Platinum] : New]
+New : [Ticket [Customer A : Gold] : New]
+Email : [Ticket [Customer B : Platinum] : Escalate]
+[[ Sleeping 5 seconds ]]
+Email : [Ticket [Customer A : Gold] : Escalate]
+Done : [Ticket [Customer C : Silver] : Done]
+Email : [Ticket [Customer D : Silver] : Escalate]
+[[ awake ]]    </programlisting>
+
 			<figure>
-				<title>Discount calculation</title>
+				<title>Audit log</title>
 
 				<mediaobject>
 					<imageobject>
-						<imagedata fileref="TroubleTicket/DT_Table2.png" />
+						<imagedata fileref="TroubleTicketExample/tt_audit_firing.png" />
 					</imageobject>
 				</mediaobject>
 			</figure>
 
-			<para>Referring to the above, we are seeing if there is any discount we can give our driver. Based on the Age bracket, number of priot claims, and the policy type, a discount is provided. In our case, the drive is 3, with no priors, and they are applying for COMPREHENSIVE, this means we can give a discount of 20%. Note that this is actually a separate table, but in the same worksheet. This different templates apply.</para>
+			<para>Referring to the above audit log, we can see the events as they happen. Once the rules start firing, the first items are the "Activation Executed" for the new tickets, as expected (they do nothing, just log the fact). Note the "Activation executed" item for the platinum ticket - that is the next one to go (remember it has the default salience, so it happens after the "New ticket" rule, but otherwise it is immediate - there is no "duration" delay for it). The platinum activation results in a Object modification (which is the escalation) - this in turn creates an activation record for the "escalate ticket" rule - which is what we wanted. Straight after that it executes the action to escalate the ticket.</para>
 
-			<para>It is important to note that decision tables generate rules, this means they aren't simply top down logic, but more a means to capture data that generate rules (this is a subtle difference that confuses some people). The evaluation of the rules is not "top down" necessarily, all the normal indexing and mechanics of the rule engine still apply.</para>
+			<para>The next event to occur is due to the:</para>
+			<programlisting>t3.setStatus( "Done" );
+
+session.update( ft3,
+                t3 );
+</programlisting> 
+			<para>in the code (outside of rules) - this simulates a customer service officer maarking a ticket as done (and of course, uses the fact handle we kept from before). This results in a cancelled activation (as we no longer have a New Silvert customer ticket - it is done) and a new activation to log the fact it was done.</para>
+
+			<para>In all the excitement, in parallel the engine has been watching the time pass, and it happens that the Gold tickets start to escalate, and then silver (as expected).</para>
+			
 		</section>
-	</section>	
\ No newline at end of file
+
+	</section>  
+  

Copied: labs/jbossrules/trunk/drools-docs/drools-docs-expert/en/Chapter-Examples/SodukiExample (from rev 20479, labs/jbossrules/trunk/drools-docs/drools-docs-expert/en/Chapter-Examples/Soduki)

Copied: labs/jbossrules/trunk/drools-docs/drools-docs-expert/en/Chapter-Examples/StateExampleExample (from rev 20479, labs/jbossrules/trunk/drools-docs/drools-docs-expert/en/Chapter-Examples/StateExample)

Deleted: labs/jbossrules/trunk/drools-docs/drools-docs-expert/en/Chapter-Examples/StateExampleExample/state_example_agenda1.png
===================================================================
(Binary files differ)

Copied: labs/jbossrules/trunk/drools-docs/drools-docs-expert/en/Chapter-Examples/StateExampleExample/state_example_agenda1.png (from rev 20478, labs/jbossrules/trunk/drools-docs/drools-docs-expert/en/Chapter-Examples/StateExample/state_example_agenda1.png)
===================================================================
(Binary files differ)

Deleted: labs/jbossrules/trunk/drools-docs/drools-docs-expert/en/Chapter-Examples/StateExampleExample/state_example_audit1.png
===================================================================
(Binary files differ)

Copied: labs/jbossrules/trunk/drools-docs/drools-docs-expert/en/Chapter-Examples/StateExampleExample/state_example_audit1.png (from rev 20478, labs/jbossrules/trunk/drools-docs/drools-docs-expert/en/Chapter-Examples/StateExample/state_example_audit1.png)
===================================================================
(Binary files differ)

Copied: labs/jbossrules/trunk/drools-docs/drools-docs-expert/en/Chapter-Examples/TroubleTicketExample (from rev 20479, labs/jbossrules/trunk/drools-docs/drools-docs-expert/en/Chapter-Examples/TroubleTicket)




More information about the jboss-svn-commits mailing list