Index: trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/TemporalRelationshipRuleManager.java
===================================================================
--- trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/TemporalRelationshipRuleManager.java	(revision 1131)
+++ trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/TemporalRelationshipRuleManager.java	(revision 1146)
@@ -22,23 +22,27 @@
 import de.ugoe.cs.autoquest.eventcore.guimodel.IFrame;
 import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement;
-import de.ugoe.cs.autoquest.tasktrees.nodeequality.NodeEquality;
-import de.ugoe.cs.autoquest.tasktrees.nodeequality.NodeEqualityRuleManager;
-import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeBuilder;
-import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode;
-import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNodeFactory;
+import de.ugoe.cs.autoquest.tasktrees.taskequality.TaskEquality;
+import de.ugoe.cs.autoquest.tasktrees.taskequality.TaskEqualityRuleManager;
+import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskBuilder;
+import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskFactory;
+import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance;
+import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList;
+import de.ugoe.cs.autoquest.tasktrees.treeifc.IUserSession;
 import de.ugoe.cs.util.console.Console;
 
 /**
+ * TODO update comment
+ * 
  * <p>
  * This class is responsible for applying temporal relationship rules on a task tree. Through this,
  * a flat task tree is restructured to have more depth but to include more temporal relationships
- * between task tree nodes which are not only a major sequence. I.e. through the application of
- * rule iterations and selections of task tree nodes are detected. Which kind of temporal relations
- * between task tree nodes are detected depends on the {@link TemporalRelationshipRule}s known to
+ * between tasks which are not only a major sequence. I.e. through the application of the
+ * rules iterations and selections of tasks are detected. Which kind of temporal relations
+ * between tasks are detected depends on the {@link ITaskInstanceListScopeRule}s known to
  * this class.
  * </p>
- * <p>The class holds references to the appropriate {@link TemporalRelationshipRule}s and calls
- * their {@link TemporalRelationshipRule#apply(ITaskTreeNode, ITaskTreeBuilder, ITaskTreeNodeFactory, boolean)}
- * method for each node in the task tree it is needed for. The general behavior of this class is
+ * <p>The class holds references to the appropriate {@link ITaskInstanceListScopeRule}s and calls
+ * their {@link ITaskInstanceListScopeRule#apply(ITask, ITaskBuilder, ITaskFactory, boolean)}
+ * method for each task in the task tree it is needed for. The general behavior of this class is
  * the following:
  * <ol>
@@ -48,10 +52,10 @@
  *   </li>
  *   <li>
- *     then the {@link #applyRules(ITaskTreeNode, ITaskTreeBuilder, ITaskTreeNodeFactory, boolean)}
- *     method is called for a so far unstructured task tree node
+ *     then the {@link #applyRules(ITask, ITaskBuilder, ITaskFactory, boolean)}
+ *     method is called for a so far unstructured task
  *   </li>
  *   <li>
  *     the class iterates its internal list of rules and calls their
- *     {@link TemporalRelationshipRule#apply(ITaskTreeNode, ITaskTreeBuilder, ITaskTreeNodeFactory, boolean)}
+ *     {@link ITaskInstanceListScopeRule#apply(ITask, ITaskBuilder, ITaskFactory, boolean)}
  *     method.
  *   </li>
@@ -69,6 +73,6 @@
  *       <li>
  *         if a rule returns, that it was applied, the same rule is applied again until it returns
- *         null or feasible. For each newly created parent node provided in the rule application
- *         result, the {@link #applyRules(ITaskTreeNode, ITaskTreeBuilder, ITaskTreeNodeFactory, boolean)}
+ *         null or feasible. For each newly created parent task provided in the rule application
+ *         result, the {@link #applyRules(ITask, ITaskBuilder, ITaskFactory, boolean)}
  *         method is called.
  *       </li>
@@ -76,6 +80,6 @@
  *   </li>
  * </ol>
- * Through this, all rules are tried to be applied at least once to the provided parent node and
- * all parent nodes created during the rule application.
+ * Through this, all rules are tried to be applied at least once to the provided parent task and
+ * all parent tasks created during the rule application.
  * </p>
  * 
@@ -86,22 +90,30 @@
     /**
      * <p>
-     * the node equality manager needed by the rules to compare task tree nodes with each other
-     * </p>
-     */
-    private NodeEqualityRuleManager nodeEqualityRuleManager;
-
-    /**
-     * <p>
-     * the task tree node factory to be used during rule application
-     * </p>
-     */
-    private ITaskTreeNodeFactory taskTreeNodeFactory;
-
-    /**
-     * <p>
-     * the task tree builder to be used during rule application
-     * </p>
-     */
-    private ITaskTreeBuilder taskTreeBuilder;
+     * the task equality manager needed by the rules to compare tasks with each other
+     * </p>
+     */
+    private TaskEqualityRuleManager taskEqualityRuleManager;
+
+    /**
+     * <p>
+     * the task factory to be used during rule application
+     * </p>
+     */
+    private ITaskFactory taskFactory;
+
+    /**
+     * <p>
+     * the task builder to be used during rule application
+     * </p>
+     */
+    private ITaskBuilder taskBuilder;
+
+    /**
+     * <p>
+     * the temporal relationship rules known to the manager that are executed on whole sessions.
+     * The rules are applied in the order they occur in this list.
+     * </p>
+     */
+    private ISessionScopeRule[] sessionScopeRules;
 
     /**
@@ -111,13 +123,5 @@
      * </p>
      */
-    private TemporalRelationshipRule[] treeScopeRules;
-
-    /**
-     * <p>
-     * the temporal relationship rules known to the manager that are executed on whole sub trees.
-     * The rules are applied in the order they occur in this list.
-     * </p>
-     */
-    private TemporalRelationshipRule[] nodeScopeRules;
+    private ITaskInstanceListScopeRule[] taskScopeRules;
 
     /**
@@ -126,19 +130,19 @@
      * </p>
      * 
-     * @param nodeEqualityRuleManager the node equality rule manager to be used by the known rules
-     *                                for task tree node comparison during rule application
-     * @param taskTreeNodeFactory     the node factory to be used for instantiating new task tree
-     *                                nodes during rule application
-     * @param taskTreeBuilder         the task tree builder to be used for linking task tree nodes
+     * @param taskEqualityRuleManager the task equality rule manager to be used by the known rules
+     *                                for task comparison during rule application
+     * @param taskFactory             the task factory to be used for instantiating new task tree
+     *                                tasks during rule application
+     * @param taskBuilder             the task builder to be used for linking tasks
      *                                with each other during rule application
      */
-    public TemporalRelationshipRuleManager(NodeEqualityRuleManager nodeEqualityRuleManager,
-                                           ITaskTreeNodeFactory    taskTreeNodeFactory,
-                                           ITaskTreeBuilder        taskTreeBuilder)
+    public TemporalRelationshipRuleManager(TaskEqualityRuleManager taskEqualityRuleManager,
+                                           ITaskFactory            taskFactory,
+                                           ITaskBuilder            taskBuilder)
     {
         super();
-        this.nodeEqualityRuleManager = nodeEqualityRuleManager;
-        this.taskTreeNodeFactory = taskTreeNodeFactory;
-        this.taskTreeBuilder = taskTreeBuilder;
+        this.taskEqualityRuleManager = taskEqualityRuleManager;
+        this.taskFactory = taskFactory;
+        this.taskBuilder = taskBuilder;
     }
 
@@ -146,5 +150,5 @@
      * <p>
      * initialized the temporal relationship rule manager by instantiating the known rules and
-     * providing them with a reference to the node equality manager or other information they need.
+     * providing them with a reference to the task equality manager or other information they need.
      * </p>
      */
@@ -156,36 +160,35 @@
         //frameFilter.add(ICanvas.class);
 
-        treeScopeRules = new TemporalRelationshipRule[] {
+        sessionScopeRules = new ISessionScopeRule[] {
             new SequenceForTaskDetectionRule
-                (nodeEqualityRuleManager, NodeEquality.SEMANTICALLY_EQUAL,
-                 taskTreeNodeFactory, taskTreeBuilder),
+                (taskEqualityRuleManager, TaskEquality.SEMANTICALLY_EQUAL,
+                 taskFactory, taskBuilder),
             /*new DefaultTaskSequenceDetectionRule
-                (nodeEqualityRuleManager, NodeEquality.SYNTACTICALLY_EQUAL,
-                 taskTreeNodeFactory, taskTreeBuilder),
+                (taskEqualityRuleManager, NodeEquality.SYNTACTICALLY_EQUAL,
+                 taskFactory, taskTreeBuilder),
             new DefaultTaskSequenceDetectionRule
-                (nodeEqualityRuleManager, NodeEquality.LEXICALLY_EQUAL,
-                 taskTreeNodeFactory, taskTreeBuilder),*/
+                (taskEqualityRuleManager, NodeEquality.LEXICALLY_EQUAL,
+                 taskFactory, taskTreeBuilder),*/
             /*new TreeScopeWrapperRule
                 (new DefaultIterationDetectionRule
-                    (nodeEqualityRuleManager, NodeEquality.LEXICALLY_EQUAL,
-                     taskTreeNodeFactory, taskTreeBuilder)),
+                    (taskEqualityRuleManager, NodeEquality.LEXICALLY_EQUAL,
+                     taskFactory, taskTreeBuilder)),
             new TreeScopeWrapperRule
                 (new DefaultIterationDetectionRule
-                    (nodeEqualityRuleManager, NodeEquality.SYNTACTICALLY_EQUAL,
-                     taskTreeNodeFactory, taskTreeBuilder)),
+                    (taskEqualityRuleManager, NodeEquality.SYNTACTICALLY_EQUAL,
+                     taskFactory, taskTreeBuilder)),
             new TreeScopeWrapperRule
                 (new DefaultIterationDetectionRule
-                    (nodeEqualityRuleManager, NodeEquality.SEMANTICALLY_EQUAL,
-                     taskTreeNodeFactory, taskTreeBuilder))*/
+                    (taskEqualityRuleManager, NodeEquality.SEMANTICALLY_EQUAL,
+                     taskFactory, taskTreeBuilder))*/
         };
         
         //treeScopeRules.add(new DefaultGuiElementSequenceDetectionRule(frameFilter));
 
-        nodeScopeRules = new TemporalRelationshipRule[] {
-            //new SequenceOnGuiElementDetectionRule(taskTreeNodeFactory, taskTreeBuilder),
-            //new EventSequenceOnSameTargetDetectionRule(taskTreeNodeFactory, taskTreeBuilder),
-            new TrackBarSelectionDetectionRule
-                (nodeEqualityRuleManager, taskTreeNodeFactory, taskTreeBuilder),
-            //new DefaultGuiEventSequenceDetectionRule(taskTreeNodeFactory, taskTreeBuilder),
+        taskScopeRules = new ITaskInstanceListScopeRule[] {
+            //new SequenceOnGuiElementDetectionRule(taskFactory, taskTreeBuilder),
+            //new EventSequenceOnSameTargetDetectionRule(taskFactory, taskTreeBuilder),
+            //new TrackBarSelectionDetectionRule(taskEqualityRuleManager, taskFactory, taskBuilder),
+            //new DefaultGuiEventSequenceDetectionRule(taskFactory, taskTreeBuilder),
         };
 
@@ -194,43 +197,26 @@
     /**
      * <p>
-     * applies the known rules to the provided parent node. For the creation of further nodes,
-     * the provided builder and node factory are utilized. The method expectes, that no more data
+     * applies the known rules to the provided sessions. For the creation of further tasks,
+     * the provided builder and task factory are utilized. The method expects, that no more data
      * is available and, therefore, finalizes the rule application.
      * </p>
      * 
-     * @param nodeFactory  the node factory to be used for instantiating new task tree nodes.
-     */
-    public void applyRules(ITaskTreeNode parent) {
-        applyRules(parent, true);
-    }
-
-    /**
-     * <p>
-     * applies the known rules to the provided parent node. For the creation of further nodes,
-     * the provided builder and node factory are utilized. If the finalize parameter is true, the
+     * @param taskFactory  the task factory to be used for instantiating new tasks.
+     */
+    public void applyRules(List<IUserSession> sessions) {
+        applyRules(sessionScopeRules, sessions, "");
+    }
+
+    /**
+     * <p>
+     * applies the known rules to the provided parent task. For the creation of further tasks,
+     * the provided builder and task factory are utilized. If the finalize parameter is true, the
      * rule application is finalized as far as possible without waiting for further data. If it is
      * false, the rule application is broken up at the first rule returning, that its application
-     * would be feasible. 
+     * would be feasible. The method calls itself for each parent task created through the rule
+     * application. In this case, the finalize parameter is always true.
      * </p>
      * 
-     * @param parent       the parent node to apply the rules on
-     * @param finalize     used to indicate, if the rule application shall break up if a rule would
-     *                     be feasible if further data was available, or not.
-     */
-    public void applyRules(ITaskTreeNode parent, boolean finalize) {
-        applyRules(treeScopeRules, parent, finalize, "");
-    }
-
-    /**
-     * <p>
-     * applies the known rules to the provided parent node. For the creation of further nodes,
-     * the provided builder and node factory are utilized. If the finalize parameter is true, the
-     * rule application is finalized as far as possible without waiting for further data. If it is
-     * false, the rule application is broken up at the first rule returning, that its application
-     * would be feasible. The method calls itself for each parent node created through the rule
-     * application. In this case, the finalize parameter is always true.
-     * </p>
-     * 
-     * @param parent       the parent node to apply the rules on
+     * @param parent       the parent task to apply the rules on
      * @param finalize     used to indicate, if the rule application shall break up if a rule would
      *                     be feasible if further data was available, or not.
@@ -238,31 +224,30 @@
      *                     on the recursion depth of calling this method.
      */
-    private int applyRules(TemporalRelationshipRule[] rules,
-                           ITaskTreeNode              parent,
-                           boolean                    finalize,
-                           String                     logIndent)
+    private int applyRules(ISessionScopeRule[] rules,
+                           List<IUserSession>  sessions,
+                           String              logIndent)
     {
-        Console.traceln(Level.FINER, logIndent + "applying rules for " + parent);
+        Console.traceln
+            (Level.FINER, logIndent + "applying rules for " + sessions.size() + " sessions");
 
         int noOfRuleApplications = 0;
 
-        for (TemporalRelationshipRule rule : rules) {
+        for (ISessionScopeRule rule : rules) {
             RuleApplicationResult result;
             do {
-                Console.traceln(Level.FINER, logIndent + "trying rule " + rule + " on " + parent);
-                result = rule.apply(parent, finalize);
+                Console.traceln(Level.FINER, logIndent + "trying rule " + rule);
+                result = rule.apply(sessions);
 
                 if ((result != null) &&
                     (result.getRuleApplicationStatus() == RuleApplicationStatus.FINISHED))
                 {
-                    Console.traceln
-                        (Level.FINE, logIndent + "applied rule " + rule + " on " + parent);
+                    Console.traceln(Level.FINE, logIndent + "applied rule " + rule);
                     noOfRuleApplications++;
                     
                     //dumpTask(parent, "");
 
-                    for (ITaskTreeNode newParent : result.getNewlyCreatedParentNodes()) {
+                    for (ITaskInstance newParent : result.getNewlyCreatedTaskInstances()) {
                         noOfRuleApplications +=
-                            applyRules(nodeScopeRules, newParent, true, logIndent + "  ");
+                            applyRules(taskScopeRules, newParent, logIndent + "  ");
                     }
                 }
@@ -271,11 +256,4 @@
                    (result.getRuleApplicationStatus() == RuleApplicationStatus.FINISHED));
 
-            if ((!finalize) &&
-                (result != null) &&
-                (result.getRuleApplicationStatus() == RuleApplicationStatus.FEASIBLE))
-            {
-                // in this case, don't go on applying rules, which should not be applied yet
-                break;
-            }
         }
 
@@ -289,7 +267,66 @@
 
     /**
+     * <p>
+     * applies the known rules to the provided parent task. For the creation of further tasks,
+     * the provided builder and task factory are utilized. If the finalize parameter is true, the
+     * rule application is finalized as far as possible without waiting for further data. If it is
+     * false, the rule application is broken up at the first rule returning, that its application
+     * would be feasible. The method calls itself for each parent task created through the rule
+     * application. In this case, the finalize parameter is always true.
+     * </p>
+     * 
+     * @param parent       the parent task to apply the rules on
+     * @param finalize     used to indicate, if the rule application shall break up if a rule would
+     *                     be feasible if further data was available, or not.
+     * @param logIndent    simply used for logging purposes to indent the log messages depending
+     *                     on the recursion depth of calling this method.
+     */
+    private int applyRules(ITaskInstanceListScopeRule[] rules,
+                           ITaskInstanceList            taskInstances,
+                           String                       logIndent)
+    {
+        Console.traceln(Level.FINER, logIndent + "applying rules for " + taskInstances.size() +
+                        " task instances");
+
+        int noOfRuleApplications = 0;
+
+        for (ITaskInstanceListScopeRule rule : rules) {
+            RuleApplicationResult result;
+            do {
+                Console.traceln
+                    (Level.FINER, logIndent + "trying rule " + rule + " on " + taskInstances);
+                result = rule.apply(taskInstances);
+
+                if ((result != null) &&
+                    (result.getRuleApplicationStatus() == RuleApplicationStatus.FINISHED))
+                {
+                    Console.traceln
+                        (Level.FINE, logIndent + "applied rule " + rule + " on " + taskInstances);
+                    noOfRuleApplications++;
+                    
+                    //dumpTask(parent, "");
+
+                    for (ITaskInstance newParent : result.getNewlyCreatedTaskInstances()) {
+                        noOfRuleApplications +=
+                            applyRules(taskScopeRules, newParent, logIndent + "  ");
+                    }
+                }
+            }
+            while ((result != null) &&
+                   (result.getRuleApplicationStatus() == RuleApplicationStatus.FINISHED));
+        }
+
+        if (noOfRuleApplications <= 0) {
+            Console.traceln(Level.FINE, logIndent + "no rules applied --> no temporal " +
+                            "relationship generated");
+        }
+
+        return noOfRuleApplications;
+    }
+
+    /**
      *
      */
-    /*private void dumpTask(ITaskTreeNode task, String indent) {
+    /*private void dumpTask(ITask task, String indent) {
         StringBuffer message = new StringBuffer();
         message.append(indent);
@@ -304,5 +341,5 @@
         
         if ((task.getChildren() != null) && (task.getChildren().size() > 0)) {
-            for (ITaskTreeNode child : task.getChildren()) {
+            for (ITask child : task.getChildren()) {
                 dumpTask(child, indent + "  ");
             }
