Index: trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/TaskBuilder.java
===================================================================
--- trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/TaskBuilder.java	(revision 1362)
+++ trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/TaskBuilder.java	(revision 1422)
@@ -19,4 +19,5 @@
 import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration;
 import de.ugoe.cs.autoquest.tasktrees.treeifc.IIterationInstance;
+import de.ugoe.cs.autoquest.tasktrees.treeifc.IMarkingTemporalRelationship;
 import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptional;
 import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptionalInstance;
@@ -25,4 +26,5 @@
 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence;
 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequenceInstance;
+import de.ugoe.cs.autoquest.tasktrees.treeifc.IStructuringTemporalRelationship;
 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask;
 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskBuilder;
@@ -60,7 +62,143 @@
         }
         
-        /*IStructuringTemporalRelationship parentTask =
-            (IStructuringTemporalRelationship) parent.getTask();
-        
+        SequenceInstance seqInstance = (SequenceInstance) instance;
+        
+        // check if new child instance matches the model, if this can be checked
+        IStructuringTemporalRelationship parentTask =
+            (IStructuringTemporalRelationship) instance.getTask();
+        
+        if (((parentTask.getChildren() != null) && (parentTask.getChildren().size() > 0)) &&
+            ((parentTask.getChildren().size() <= seqInstance.size()) ||
+             (!parentTask.getChildren().get(seqInstance.size()).equals(child.getTask()))))
+        {
+            throw new IllegalArgumentException
+                ("the task of the child instance to be added does not belong to the children " +
+                 "of the task of the parent instance");
+        }
+
+        seqInstance.addChild(child);
+    }
+
+    /* (non-Javadoc)
+     * @see ITaskBuilder#addChild(ISequenceInstance, int, ITaskInstance)
+     */
+    public void addChild(ISequenceInstance instance, int index, ITaskInstance child)
+        throws IllegalArgumentException
+    {
+        if (!(instance instanceof SequenceInstance)) {
+            throw new IllegalArgumentException
+                ("illegal type of sequence instance provided: " + instance.getClass());
+        }
+
+        if (!(child instanceof TaskInstance)) {
+            throw new IllegalArgumentException
+                ("illegal type of task instance provided: " + child.getClass());
+        }
+        
+        SequenceInstance seqInstance = (SequenceInstance) instance;
+        
+        // check if new child instance matches the model, if this can be checked
+        IStructuringTemporalRelationship parentTask =
+            (IStructuringTemporalRelationship) instance.getTask();
+        
+        if (((parentTask.getChildren() != null) && (parentTask.getChildren().size() > 0)) &&
+            ((parentTask.getChildren().size() <= index) ||
+             (!parentTask.getChildren().get(index).equals(child.getTask()))))
+        {
+            throw new IllegalArgumentException
+                ("the task of the child instance to be added does not belong to the children " +
+                 "of the task of the parent instance");
+        }
+        
+        seqInstance.addChild(index, child);
+    }
+
+    /* (non-Javadoc)
+     * @see ITaskBuilder#addChild(IIterationInstance, ITaskInstance)
+     */
+    @Override
+    public void addChild(IIterationInstance instance, ITaskInstance child)
+        throws IllegalArgumentException
+    {
+        if (!(instance instanceof IterationInstance)) {
+            throw new IllegalArgumentException
+                ("illegal type of iteration instance provided: " + instance.getClass());
+        }
+
+        if (!(child instanceof TaskInstance)) {
+            throw new IllegalArgumentException
+                ("illegal type of task instance provided: " + child.getClass());
+        }
+        
+        // check if new child instance matches the model, if this can be checked
+        IMarkingTemporalRelationship parentTask =
+            (IMarkingTemporalRelationship) instance.getTask();
+                
+        boolean foundChildTask = parentTask.getMarkedTask() != null ?
+            parentTask.getMarkedTask().equals(child.getTask()) : true;
+                
+        if (!foundChildTask) {
+            throw new IllegalArgumentException
+                ("the task of the child instance does not match the model of the task of the " +
+                 "iteration instance: " + parentTask.getMarkedTask() + " <> " + child.getTask());
+        }
+
+        ((IterationInstance) instance).addChild(child);
+    }
+
+    /* (non-Javadoc)
+     * @see ITaskBuilder#addChild(IIterationInstance, int, ITaskInstance)
+     */
+    public void addChild(IIterationInstance instance, int index, ITaskInstance child)
+        throws IllegalArgumentException
+    {
+        if (!(instance instanceof IterationInstance)) {
+            throw new IllegalArgumentException
+                ("illegal type of iteration instance provided: " + instance.getClass());
+        }
+
+        if (!(child instanceof TaskInstance)) {
+            throw new IllegalArgumentException
+                ("illegal type of task instance provided: " + child.getClass());
+        }
+        
+        // check if new child instance matches the model, if this can be checked
+        IMarkingTemporalRelationship parentTask =
+            (IMarkingTemporalRelationship) instance.getTask();
+                
+        boolean foundChildTask = parentTask.getMarkedTask() != null ?
+            parentTask.getMarkedTask().equals(child.getTask()) : true;
+                
+        if (!foundChildTask) {
+            throw new IllegalArgumentException
+                ("the task of the child instance does not match the model of the task of the " +
+                 "iteration instance: " + parentTask.getMarkedTask() + " <> " + child.getTask());
+        }
+
+        ((IterationInstance) instance).addChild(index, child);
+    }
+
+    /* (non-Javadoc)
+     * @see ITaskBuilder#setChild(ISelectionInstance, ITaskInstance)
+     */
+    @Override
+    public void setChild(ISelectionInstance instance, ITaskInstance child)
+        throws IllegalArgumentException
+    {
+        if (!(instance instanceof SelectionInstance)) {
+            throw new IllegalArgumentException
+                ("illegal type of selection instance provided: " + instance.getClass());
+        }
+
+        if (!(child instanceof TaskInstance)) {
+            throw new IllegalArgumentException("illegal type of task instance provided: " +
+                                               (child == null ? null : child.getClass()));
+        }
+        
+        // check if new child instance matches the model, if this can be checked
+        IStructuringTemporalRelationship parentTask =
+            (IStructuringTemporalRelationship) instance.getTask();
+        
+        boolean foundChildTask = false;
         for (ITask parentTaskChild : parentTask.getChildren()) {
             if (parentTaskChild.equals(child.getTask())) {
@@ -73,19 +211,20 @@
             throw new IllegalArgumentException
                 ("the task of the child instance to be added does not belong to the children " +
-                 "of the task of the parent instance");
-        }*/
-
-        ((SequenceInstance) instance).addChild(child);
-    }
-
-    /* (non-Javadoc)
-     * @see ITaskBuilder#addChild(ISequenceInstance, int, ITaskInstance)
-     */
-    public void addChild(ISequenceInstance instance, int index, ITaskInstance child)
+                 "of the selection task model of the parent instance");
+        }
+
+        ((SelectionInstance) instance).setChild(child);
+    }
+
+    /* (non-Javadoc)
+     * @see ITaskBuilder#setChild(IOptionalInstance, ITaskInstance)
+     */
+    @Override
+    public void setChild(IOptionalInstance instance, ITaskInstance child)
         throws IllegalArgumentException
     {
-        if (!(instance instanceof SequenceInstance)) {
-            throw new IllegalArgumentException
-                ("illegal type of sequence instance provided: " + instance.getClass());
+        if (!(instance instanceof OptionalInstance)) {
+            throw new IllegalArgumentException
+                ("illegal type of optional instance provided: " + instance.getClass());
         }
 
@@ -95,159 +234,16 @@
         }
         
-        /*IStructuringTemporalRelationship parentTask =
-            (IStructuringTemporalRelationship) parent.getTask();
-        
-        for (ITask parentTaskChild : parentTask.getChildren()) {
-            if (parentTaskChild.equals(child.getTask())) {
-                foundChildTask = true;
-                break;
-            }
-        }
+        // check if new child instance matches the model, if this can be checked
+        IMarkingTemporalRelationship parentTask =
+            (IMarkingTemporalRelationship) instance.getTask();
+            
+        boolean foundChildTask = parentTask.getMarkedTask() != null ?
+            parentTask.getMarkedTask().equals(child.getTask()) : true;
             
         if (!foundChildTask) {
             throw new IllegalArgumentException
-                ("the task of the child instance to be added does not belong to the children " +
-                 "of the task of the parent instance");
-        }*/
-
-        ((SequenceInstance) instance).addChild(index, child);
-    }
-
-    /* (non-Javadoc)
-     * @see ITaskBuilder#addChild(IIterationInstance, ITaskInstance)
-     */
-    @Override
-    public void addChild(IIterationInstance instance, ITaskInstance child)
-        throws IllegalArgumentException
-    {
-        if (!(instance instanceof IterationInstance)) {
-            throw new IllegalArgumentException
-                ("illegal type of iteration instance provided: " + instance.getClass());
-        }
-
-        if (!(child instanceof TaskInstance)) {
-            throw new IllegalArgumentException
-                ("illegal type of task instance provided: " + child.getClass());
-        }
-        
-        /*IStructuringTemporalRelationship parentTask =
-            (IStructuringTemporalRelationship) parent.getTask();
-        
-        IMarkingTemporalRelationship parentTask =
-            (IMarkingTemporalRelationship) parent.getTask();
-            
-        foundChildTask = parentTask.getMarkedTask() != null ?
-            parentTask.getMarkedTask().equals(child.getTask()) : false;
-            
-        if (!foundChildTask) {
-            throw new IllegalArgumentException
-                ("the task of the child instance to be added does not belong to the children " +
-                 "of the task of the parent instance");
-        }*/
-
-        ((IterationInstance) instance).addChild(child);
-    }
-
-    /* (non-Javadoc)
-     * @see ITaskBuilder#addChild(IIterationInstance, int, ITaskInstance)
-     */
-    public void addChild(IIterationInstance instance, int index, ITaskInstance child)
-        throws IllegalArgumentException
-    {
-        if (!(instance instanceof IterationInstance)) {
-            throw new IllegalArgumentException
-                ("illegal type of iteration instance provided: " + instance.getClass());
-        }
-
-        if (!(child instanceof TaskInstance)) {
-            throw new IllegalArgumentException
-                ("illegal type of task instance provided: " + child.getClass());
-        }
-        
-        /*IStructuringTemporalRelationship parentTask =
-            (IStructuringTemporalRelationship) parent.getTask();
-        
-        IMarkingTemporalRelationship parentTask =
-            (IMarkingTemporalRelationship) parent.getTask();
-            
-        foundChildTask = parentTask.getMarkedTask() != null ?
-            parentTask.getMarkedTask().equals(child.getTask()) : false;
-            
-        if (!foundChildTask) {
-            throw new IllegalArgumentException
-                ("the task of the child instance to be added does not belong to the children " +
-                 "of the task of the parent instance");
-        }*/
-
-        ((IterationInstance) instance).addChild(index, child);
-    }
-
-    /* (non-Javadoc)
-     * @see ITaskBuilder#setChild(ISelectionInstance, ITaskInstance)
-     */
-    @Override
-    public void setChild(ISelectionInstance instance, ITaskInstance child)
-        throws IllegalArgumentException
-    {
-        if (!(instance instanceof SelectionInstance)) {
-            throw new IllegalArgumentException
-                ("illegal type of selection instance provided: " + instance.getClass());
-        }
-
-        if (!(child instanceof TaskInstance)) {
-            throw new IllegalArgumentException("illegal type of task instance provided: " +
-                                               (child == null ? null : child.getClass()));
-        }
-        
-        /*IStructuringTemporalRelationship parentTask =
-            (IStructuringTemporalRelationship) parent.getTask();
-        
-        for (ITask parentTaskChild : parentTask.getChildren()) {
-            if (parentTaskChild.equals(child.getTask())) {
-                foundChildTask = true;
-                break;
-            }
-        }
-            
-        if (!foundChildTask) {
-            throw new IllegalArgumentException
-                ("the task of the child instance to be added does not belong to the children " +
-                 "of the task of the parent instance");
-        }*/
-
-        ((SelectionInstance) instance).setChild(child);
-    }
-
-    /* (non-Javadoc)
-     * @see ITaskBuilder#setChild(IOptionalInstance, ITaskInstance)
-     */
-    @Override
-    public void setChild(IOptionalInstance instance, ITaskInstance child)
-        throws IllegalArgumentException
-    {
-        if (!(instance instanceof OptionalInstance)) {
-            throw new IllegalArgumentException
-                ("illegal type of optional instance provided: " + instance.getClass());
-        }
-
-        if (!(child instanceof TaskInstance)) {
-            throw new IllegalArgumentException
-                ("illegal type of task instance provided: " + child.getClass());
-        }
-        
-        /*IStructuringTemporalRelationship parentTask =
-            (IStructuringTemporalRelationship) parent.getTask();
-        
-        IMarkingTemporalRelationship parentTask =
-            (IMarkingTemporalRelationship) parent.getTask();
-            
-        foundChildTask = parentTask.getMarkedTask() != null ?
-            parentTask.getMarkedTask().equals(child.getTask()) : false;
-            
-        if (!foundChildTask) {
-            throw new IllegalArgumentException
-                ("the task of the child instance to be added does not belong to the children " +
-                 "of the task of the parent instance");
-        }*/
+                ("the task of the child instance does not match the model of the task of the " +
+                 "optional instance: " + parentTask.getMarkedTask() + " <> " + child.getTask());
+        }
 
         ((OptionalInstance) instance).setChild(child);
