Ignore:
Timestamp:
04/04/13 16:06:07 (11 years ago)
Author:
pharms
Message:
  • complete refactoring of task tree model with a separation of task models and task instances
  • appropriate adaptation of task tree generation process
  • appropriate adaptation of commands and task tree visualization
Location:
trunk/autoquest-test-utils/src/main/java/de/ugoe/cs/autoquest/tasktrees
Files:
2 added
1 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/autoquest-test-utils/src/main/java/de/ugoe/cs/autoquest/tasktrees/TaskTreeChecker.java

    r1123 r1146  
    1717import static org.junit.Assert.*; 
    1818 
    19 import java.io.FileNotFoundException; 
    20 import java.io.FileOutputStream; 
    21 import java.io.PrintWriter; 
    2219import java.util.ArrayList; 
    2320import java.util.HashMap; 
     
    3330import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection; 
    3431import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence; 
    35 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTree; 
    36 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode; 
    37 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNodeInfo; 
     32import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 
     33import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; 
     34import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList; 
     35import de.ugoe.cs.autoquest.tasktrees.treeifc.IUserSession; 
    3836 
    3937/** 
     
    5654 
    5755    /** 
    58      * TODO: comment 
    59      *  
     56     * 
    6057     */ 
    6158    public TaskTreeChecker() { 
     
    6461 
    6562    /** 
    66      * TODO: comment 
    67      *  
     63     * 
    6864     */ 
    6965    public TaskTreeChecker(boolean doTrace) { 
     
    7470     * 
    7571     */ 
    76     public void assertTaskTree(String taskTreeSpec, ITaskTree taskTree) { 
    77         Map<ITaskTreeNode, Integer> taskMapCopy = new HashMap<ITaskTreeNode, Integer>(); 
    78  
    79         for (Map.Entry<ITaskTreeNode, ITaskTreeNodeInfo> entry : taskTree.getTaskMap().entrySet()) { 
    80             if (entry.getValue().getNoOfOccurencesInTree() > 0) { 
    81                 taskMapCopy.put(entry.getKey(), entry.getValue().getNoOfOccurencesInTree()); 
    82             } 
    83             else { 
    84                 taskMapCopy.put(entry.getKey(), 1); 
    85             } 
    86         } 
    87  
     72    public void assertTaskInstanceList(String userSessionSpec, ITaskInstanceList taskInstances) { 
    8873        if (doTrace) { 
    89             dumpTaskMap(taskMapCopy); 
    90         } 
    91  
    92         TaskSpec task = null; 
    93  
    94         Matcher taskMatcher = taskPattern.matcher(taskTreeSpec); 
     74            new TaskTreeEncoder().encode(taskInstances, System.err); 
     75        } 
     76 
     77        TaskSpec taskInstanceSpec = null; 
     78 
     79        Matcher taskMatcher = taskPattern.matcher(userSessionSpec); 
     80         
     81        Map<String, ITask> tasks = new HashMap<String, ITask>(); 
    9582 
    9683        while (taskMatcher.find()) { 
    9784 
    98             task = parseTask(taskMatcher); 
    99              
    100             if (task != null) { 
    101                 assertTaskAndChildrenInMapAndRemove(task, taskMapCopy); 
    102             } 
    103         } 
    104  
    105         assertTrue("more tasks in map, than expected", taskMapCopy.isEmpty()); 
    106     } 
    107  
    108     /** 
    109      * <p> 
    110      * TODO: comment 
    111      * </p> 
    112      * 
    113      * @param oracle 
    114      * @param result 
    115      */ 
    116     public void assertTaskNodesEqual(ITaskTreeNode expected, ITaskTreeNode checked) { 
     85            taskInstanceSpec = parseTaskInstance(taskMatcher); 
     86             
     87            if (taskInstanceSpec != null) { 
     88                assertTaskInstanceList(taskInstanceSpec, taskInstances, tasks); 
     89            } 
     90        } 
     91    } 
     92 
     93    /** 
     94     * 
     95     */ 
     96    public void assertTaskInstanceListsEqual(ITaskInstanceList expected, ITaskInstanceList checked) 
     97    { 
    11798        if (expected == null) { 
    11899            assertNull("null", checked); 
     
    123104            assertEquals(expected.toString() + ": types do not match", 
    124105                         expected.getClass(), checked.getClass()); 
    125             assertEquals(expected.toString() + ": names do not match", 
    126                          expected.getName(), checked.getName()); 
    127              
    128             List<ITaskTreeNode> expectedChildren = expected.getChildren(); 
    129             List<ITaskTreeNode> checkedChildren = checked.getChildren(); 
     106             
     107            if ((expected != null) && (expected.size() > 0)) { 
     108                assertNotNull(expected.toString() + ": children not there", checked); 
     109                assertEquals(expected.toString() + ": different number of children", 
     110                             expected.size(), checked.size()); 
     111                 
     112                Map<ITask, ITask> equalTasksMap = new HashMap<ITask, ITask>(); 
     113                for (int i = 0; i < expected.size(); i++) { 
     114                    assertTaskInstancesEqual(expected.get(i), checked.get(i), equalTasksMap); 
     115                } 
     116            } 
     117            else { 
     118                assertTrue(expected.toString() + ": unexpected children", 
     119                           (checked == null) || (checked.size() == 0)); 
     120            } 
     121        } 
     122    } 
     123 
     124    /** 
     125     * 
     126     */ 
     127    public void assertTaskInstancesEqual(ITaskInstance expected, ITaskInstance checked) { 
     128        Map<ITask, ITask> equalTasksMap = new HashMap<ITask, ITask>(); 
     129        assertTaskInstancesEqual(expected, checked, equalTasksMap); 
     130    } 
     131 
     132    /** 
     133     * 
     134     */ 
     135    private void assertTaskInstancesEqual(ITaskInstance     expected, 
     136                                          ITaskInstance     checked, 
     137                                          Map<ITask, ITask> equalTasksMap) 
     138    { 
     139        if (expected == null) { 
     140            assertNull("null", checked); 
     141        } 
     142        else { 
     143            assertNotNull(expected.toString(), checked); 
     144             
     145            assertEquals(expected.toString() + ": types do not match", 
     146                         expected.getClass(), checked.getClass()); 
     147             
     148            if (equalTasksMap.containsKey(expected.getTask())) { 
     149                assertEquals(expected.toString() + ": tasks do not match", 
     150                             checked.getTask(), equalTasksMap.get(expected.getTask())); 
     151            } 
     152            else { 
     153                equalTasksMap.put(expected.getTask(), checked.getTask()); 
     154            } 
     155             
     156            List<ITaskInstance> expectedChildren = expected.getChildren(); 
     157            List<ITaskInstance> checkedChildren = checked.getChildren(); 
    130158             
    131159            if ((expectedChildren != null) && (expectedChildren.size() > 0)) { 
     
    136164                if (expected instanceof ISequence) { 
    137165                    for (int i = 0; i < expectedChildren.size(); i++) { 
    138                         assertTaskNodesEqual(expectedChildren.get(i), checkedChildren.get(i)); 
     166                        assertTaskInstancesEqual(expectedChildren.get(i), checkedChildren.get(i)); 
    139167                    } 
    140168                } 
     
    144172                        for (int j = 0; j < checkedChildren.size(); j++) { 
    145173                            try { 
    146                                 assertTaskNodesEqual 
     174                                assertTaskInstancesEqual 
    147175                                    (expectedChildren.get(i), checkedChildren.get(j)); 
    148176                                found = true; 
     
    166194 
    167195    /** 
    168      * TODO: comment 
    169196     *  
    170      * @param taskTree 
    171      */ 
    172     public void dumpAsCheckString(ITaskTree taskTree) { 
    173         dumpNodeAsCheckString(taskTree.getRoot(), new int[4], ""); 
    174     } 
    175  
    176     /** 
    177      * TODO: comment 
    178      *  
    179      * @param root 
    180      * @param string 
    181      */ 
    182     private void dumpNodeAsCheckString(ITaskTreeNode node, int[] typeCounters, String indent) { 
    183         System.out.print("       \""); 
    184         System.out.print(indent); 
    185  
    186         if (node instanceof ISequence) { 
    187             System.out.print("Sequence sequence"); 
    188             System.out.print(typeCounters[0]++); 
    189             System.out.println(" {\" +"); 
    190         } 
    191         else if (node instanceof IIteration) { 
    192             System.out.print("Iteration iteration"); 
    193             System.out.print(typeCounters[1]++); 
    194             System.out.println(" {\" +"); 
    195         } 
    196         else if (node instanceof ISelection) { 
    197             System.out.print("Selection selection"); 
    198             System.out.print(typeCounters[2]++); 
    199             System.out.println(" {\" +"); 
    200         } 
    201         else if (node instanceof IEventTask) { 
    202             if (((IEventTask) node).getEventType() instanceof TextInput) { 
    203                 System.out.print("TextInputEvent textInput"); 
    204                 System.out.print(typeCounters[3]++); 
    205                 System.out.print(" \""); 
    206                 System.out.print(((TextInput) ((IEventTask) node).getEventType()).getEnteredText()); 
    207                 System.out.print("\""); 
    208             } 
    209             else { 
    210                 System.out.print("Event "); 
    211                 System.out.print(((IEventTask) node).getEventType().getName()); 
    212             } 
    213             System.out.print(" {}\" +"); 
    214         } 
    215         else { 
    216             fail("unknown type of node in task tree " + node); 
    217         } 
    218  
    219         for (ITaskTreeNode child : node.getChildren()) { 
    220             dumpNodeAsCheckString(child, typeCounters, indent + "  "); 
    221         } 
    222  
    223         if (!(node instanceof IEventTask)) { 
    224             System.out.print("       \""); 
    225             System.out.print(indent); 
    226             System.out.print("}\" +"); 
    227         } 
    228  
    229         System.out.println(); 
    230     } 
    231  
    232     /** 
    233      * TODO: comment 
    234      *  
    235      * @param taskTree 
    236      */ 
    237     public void dumpFullTaskTree(ITaskTree taskTree) throws FileNotFoundException { 
    238         PrintWriter out = null; 
    239         try { 
    240             out = new PrintWriter(new FileOutputStream("taskTree.txt")); 
    241             dumpFullNode(taskTree.getRoot(), out, "", 0); 
    242         } 
    243         finally { 
    244             if (out != null) { 
    245                 out.close(); 
    246             } 
    247         } 
    248  
    249     } 
    250  
    251     /** 
    252      * 
    253      */ 
    254     private void dumpFullNode(ITaskTreeNode node, PrintWriter out, String indent, int index) { 
    255         if (node instanceof ISequence) { 
    256             if (index > 0) { 
    257                 out.println(); 
    258             } 
    259             out.print(indent); 
    260             out.print(node.toString()); 
    261             out.println(" {"); 
    262         } 
    263         else if (node instanceof IIteration) { 
    264             if (index > 0) { 
    265                 out.println(); 
    266             } 
    267             out.print(indent); 
    268             out.print(node.toString()); 
    269             out.println(" {"); 
    270         } 
    271         else if (node instanceof ISelection) { 
    272             if (index > 0) { 
    273                 out.println(); 
    274             } 
    275             out.print(indent); 
    276             out.print(node.toString()); 
    277             out.println(" {"); 
    278         } 
    279         else if (node instanceof IEventTask) { 
    280             out.print(indent); 
    281             out.print(((IEventTask) node).getEventType()); 
    282             out.print(" "); 
    283             out.print(((IEventTask) node).getEventTarget().getStringIdentifier()); 
    284 //            if (((IEventTask) node).getEventTarget() instanceof IGUIElement) { 
    285 //              out.print(" "); 
    286 //              out.print(((IGUIElement) ((IEventTask) node).getEventTarget()).getSpecification()); 
    287 //            } 
    288         } 
    289         else { 
    290             fail("unknown type of node in task tree " + node); 
    291         } 
    292  
    293         int i = 0; 
    294         for (ITaskTreeNode child : node.getChildren()) { 
    295             dumpFullNode(child, out, indent + "  ", i++); 
    296         } 
    297  
    298         if (!(node instanceof IEventTask)) { 
    299             out.print(indent); 
    300             out.print("}"); 
    301         } 
    302  
    303         out.println(); 
    304     } 
    305  
    306     /** 
    307      *  
    308      */ 
    309     private TaskSpec parseTask(Matcher taskMatcher) { 
     197     */ 
     198    private TaskSpec parseTaskInstance(Matcher taskMatcher) { 
    310199        if ("}".equals(taskMatcher.group(1))) { 
    311200            throw new IllegalArgumentException("invalid task specification"); 
     
    338227        List<TaskSpec> children = new ArrayList<TaskSpec>(); 
    339228        while (taskMatcher.find() && !"}".equals(taskMatcher.group(0))) { 
    340             children.add(parseTask(taskMatcher)); 
     229            children.add(parseTaskInstance(taskMatcher)); 
    341230        } 
    342231 
     
    352241     * @param taskMapCopy 
    353242     */ 
    354     private void assertTaskAndChildrenInMapAndRemove(TaskSpec                    task, 
    355                                                      Map<ITaskTreeNode, Integer> taskMap) 
     243    private void assertTaskInstanceList(TaskSpec           taskSpec, 
     244                                        ITaskInstanceList  taskInstances, 
     245                                        Map<String, ITask> tasks) 
    356246    { 
    357         for (Map.Entry<ITaskTreeNode, Integer> entry : taskMap.entrySet()) { 
    358             if (taskSpecEqualsTask(task, entry.getKey())) { 
    359                 if (task.children != null) { 
    360                     for (TaskSpec child : task.children) { 
    361                         assertTaskAndChildrenInMapAndRemove(child, taskMap); 
    362                     } 
    363                 } 
    364  
    365                 int count = taskMap.get(entry.getKey()); 
    366                 if (count == 1) { 
    367                     taskMap.remove(entry.getKey()); 
    368                 } 
    369                 else { 
    370                     taskMap.put(entry.getKey(), count - 1); 
    371                 } 
    372                 return; 
    373             } 
    374         } 
    375  
    376         fail("expected task " + task.type + " " + task.name + " not included in task map"); 
    377     } 
    378  
    379     /** 
    380      * 
    381      */ 
    382     private boolean taskSpecEqualsTask(TaskSpec taskSpec, ITaskTreeNode task) { 
     247        if (doTrace) { 
     248            System.err.println("\ncomparing " + taskSpec.type + " with " + taskInstances + "\n"); 
     249        } 
     250 
     251        if ((taskInstances instanceof IUserSession) && (!"UserSession".equals(taskSpec.type))) { 
     252            fail("can not compare a task instance with a user session"); 
     253        } 
     254        else if ((!(taskInstances instanceof IUserSession)) && 
     255                 (!"TaskInstances".equals(taskSpec.type))) 
     256        { 
     257            fail("can not compare a task instance with a task instance list"); 
     258        } 
     259         
     260        if (taskSpec.children.length != taskInstances.size()) { 
     261            fail("number of task instances in task instance list does not match"); 
     262        } 
     263         
     264        for (int i = 0; i < taskInstances.size(); i++) { 
     265            TaskSpec childSpec = taskSpec.children[i]; 
     266            assertTrue(taskSpecEqualsTaskInstance(childSpec, taskInstances.get(i), tasks)); 
     267        } 
     268    } 
     269 
     270    /** 
     271     * 
     272     */ 
     273    private boolean taskSpecEqualsTaskInstance(TaskSpec           taskSpec, 
     274                                               ITaskInstance      taskInstance, 
     275                                               Map<String, ITask> tasks) 
     276    { 
    383277        if (doTrace) { 
    384278            System.err.println("comparing " + taskSpec.name + " with"); 
    385             dumpTask(task, 0, ""); 
    386         } 
    387  
     279            new TaskTreeEncoder().encode(taskInstance, System.err); 
     280        } 
     281 
     282        ITask task = taskInstance.getTask(); 
     283         
    388284        if (("Event".equals(taskSpec.type) && (!(task instanceof IEventTask))) || 
    389285            ("TextInputEvent".equals(taskSpec.type) && 
     
    396292            if (doTrace) { 
    397293                System.err.println("task types do not match: " + taskSpec.type + " != " + 
    398                     task.getClass().getSimpleName() + "\n"); 
     294                                   task.getClass().getSimpleName() + "\n"); 
    399295            } 
    400296            return false; 
     
    440336            } 
    441337        } 
    442  
    443         if (((taskSpec.children == null) && (task.getChildren().size() > 0)) || 
    444             ((taskSpec.children != null) && (taskSpec.children.length != task.getChildren().size()))) 
     338         
     339        // check the task name against the map 
     340        if (tasks.containsKey(taskSpec.name)) { 
     341            if (!tasks.get(taskSpec.name).equals(task)) { 
     342                if (doTrace) { 
     343                    System.err.println("the task instance is not of the expected task: " + 
     344                                       taskSpec.name + " != " + task + "\n"); 
     345                } 
     346                return false; 
     347            } 
     348        } 
     349        else if (tasks.containsValue(task)) { 
     350            if (doTrace) { 
     351                System.err.println("the task of the task instance " + taskSpec.name + 
     352                                   " should be different to another one but it isn't\n"); 
     353            } 
     354            return false; 
     355        } 
     356        else { 
     357            tasks.put(taskSpec.name, task); 
     358        } 
     359 
     360        if (((taskSpec.children == null) && (taskInstance.getChildren().size() > 0)) || 
     361            ((taskSpec.children != null) && 
     362             (taskSpec.children.length != taskInstance.getChildren().size()))) 
    445363        { 
    446364            if (doTrace) { 
     
    448366                    ("numbers of children do not match: " + 
    449367                     (taskSpec.children == null ? "0" : taskSpec.children.length) + " != " + 
    450                      (task.getChildren() == null ? "0" : task.getChildren().size()) + "\n"); 
     368                     (taskInstance.getChildren() == null ? "0" : 
     369                          taskInstance.getChildren().size()) + "\n"); 
    451370            } 
    452371            return false; 
    453372        } 
    454373 
    455         Iterator<ITaskTreeNode> children = task.getChildren().iterator(); 
     374        Iterator<ITaskInstance> children = taskInstance.getChildren().iterator(); 
    456375        if (taskSpec.children != null) { 
    457376            for (TaskSpec child : taskSpec.children) { 
    458                 if (!taskSpecEqualsTask(child, children.next())) { 
     377                if (!taskSpecEqualsTaskInstance(child, children.next(), tasks)) { 
    459378                    if (doTrace) { 
    460379                        System.err.println("one of the children does not match\n"); 
     
    478397        } 
    479398    } 
    480  
    481     /** 
    482    * 
    483    */ 
    484     private void dumpTaskMap(Map<ITaskTreeNode, Integer> taskMap) { 
    485         System.err.println(); 
    486         for (Map.Entry<ITaskTreeNode, Integer> entry : taskMap.entrySet()) { 
    487             dumpTask(entry.getKey(), entry.getValue(), ""); 
    488             System.err.println(); 
    489         } 
    490     } 
    491  
    492     /** 
    493      * 
    494      */ 
    495     private void dumpTask(ITaskTreeNode task, int count, String indent) { 
    496         System.err.print(indent); 
    497         System.err.print(task); 
    498         System.err.print(" "); 
    499         System.err.print(task.getDescription()); 
    500         System.err.print(" "); 
    501  
    502         if (count > 0) { 
    503             System.err.print("("); 
    504             System.err.print(count); 
    505             System.err.print(" occurrences)"); 
    506         } 
    507  
    508         System.err.println(); 
    509  
    510         if ((task.getChildren() != null) && (task.getChildren().size() > 0)) { 
    511             for (ITaskTreeNode child : task.getChildren()) { 
    512                 dumpTask(child, 0, indent + "  "); 
    513             } 
    514         } 
    515     } 
    516399     
    517400    /** 
    518      * TODO comment 
    519      *  
    520      * @version $Revision: $ $Date: $ 
    521      * @author 2011, last modified by $Author: $ 
     401     * 
    522402     */ 
    523403    private class TaskSpec { 
  • trunk/autoquest-test-utils/src/main/java/de/ugoe/cs/autoquest/tasktrees/TaskTreeDecoder.java

    r1123 r1146  
    2626import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection; 
    2727import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence; 
    28 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeBuilder; 
    29 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode; 
    30 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNodeFactory; 
     28import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 
     29import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskBuilder; 
     30import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskFactory; 
     31import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; 
     32import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList; 
     33import de.ugoe.cs.autoquest.tasktrees.treeifc.IUserSession; 
    3134import de.ugoe.cs.autoquest.test.DummyGUIElement; 
    3235 
     
    3740 * @author 2012, last modified by $Author: patrick$ 
    3841 */ 
    39 public class TaskTreeInstantiator { 
    40      
    41     /** */ 
    42     private static Pattern taskPattern = Pattern.compile("([^{}]+)\\{|\\}"); 
    43      
    44     /** */ 
    45     private static Pattern taskDetailsPattern = 
     42public class TaskTreeDecoder { 
     43     
     44    /** */ 
     45    private static Pattern taskInstancePattern = Pattern.compile("([^{}]+)\\{|\\}"); 
     46     
     47    /** */ 
     48    private static Pattern taskInstanceDetailsPattern = 
    4649        Pattern.compile("\\s*(\\w*)\\s*([\\w\\(\\)\"]*)\\s*((\\w*)|(\".*\"))?"); 
    4750     
    4851    /** */ 
    49     private ITaskTreeNodeFactory taskTreeNodeFactory; 
    50      
    51     /** */ 
    52     private ITaskTreeBuilder taskTreeBuilder; 
     52    private ITaskFactory taskFactory; 
     53     
     54    /** */ 
     55    private ITaskBuilder taskBuilder; 
    5356     
    5457    /** */ 
    5558    Map<String, IEventTarget> targets = new HashMap<String, IEventTarget>(); 
    5659     
     60    /** */ 
     61    Map<String, ITask> tasks = new HashMap<String, ITask>(); 
     62     
    5763    /** 
    5864     * 
    5965     */ 
    60     public TaskTreeInstantiator(ITaskTreeNodeFactory taskTreeNodeFactory, 
    61                                 ITaskTreeBuilder taskTreeBuilder) 
    62     { 
     66    public TaskTreeDecoder(ITaskFactory taskFactory, ITaskBuilder taskBuilder) { 
    6367        super(); 
    64         this.taskTreeNodeFactory = taskTreeNodeFactory; 
    65         this.taskTreeBuilder = taskTreeBuilder; 
     68        this.taskFactory = taskFactory; 
     69        this.taskBuilder = taskBuilder; 
    6670    } 
    6771 
     
    6973     * 
    7074     */ 
    71     public ITaskTreeNode instantiateTaskTree(String taskTreeSpec) { 
    72         ITaskTreeNode task = null; 
    73  
    74         Matcher taskMatcher = taskPattern.matcher(taskTreeSpec); 
     75    public ITaskInstanceList decode(String taskTreeSpec) { 
     76        ITaskInstanceList taskInstanceList = null; 
     77 
     78        Matcher taskMatcher = taskInstancePattern.matcher(taskTreeSpec); 
    7579 
    7680        if (taskMatcher.find()) { 
    77             task = parseTask(taskMatcher); 
     81            taskInstanceList = parseTaskInstanceList(taskMatcher); 
    7882        } 
    7983         
     
    8286        } 
    8387         
    84         return task; 
     88        return taskInstanceList; 
    8589    } 
    8690 
     
    8892     *  
    8993     */ 
    90     private ITaskTreeNode parseTask(Matcher taskMatcher) { 
     94    private ITaskInstanceList parseTaskInstanceList(Matcher taskMatcher) { 
    9195        if ("}".equals(taskMatcher.group(1))) { 
    92             throw new IllegalArgumentException("invalid task specification"); 
     96            throw new IllegalArgumentException("invalid task instance list specification"); 
    9397        } 
    9498         
    9599        String taskDetails = taskMatcher.group(1); 
    96100         
    97         Matcher matcher = taskDetailsPattern.matcher(taskDetails); 
     101        Matcher matcher = taskInstanceDetailsPattern.matcher(taskDetails); 
    98102         
    99103        if (!matcher.find()) { 
     
    101105        } 
    102106 
    103         ITaskTreeNode task; 
    104          
    105107        String type = matcher.group(1); 
    106108         
    107         String targetId = matcher.group(2); 
    108         if ((matcher.group(4) != null) && (!"".equals(matcher.group(4).trim()))) { 
    109             targetId += matcher.group(4).trim(); 
    110         } 
    111          
    112         IEventTarget target = targets.get(targetId); 
    113          
    114         if (target == null) { 
    115             target = new DummyGUIElement(targetId); 
    116             targets.put(targetId, target); 
    117         } 
    118          
    119         if ("Sequence".equals(type)) { 
    120             task = taskTreeNodeFactory.createNewSequence(); 
    121         } 
    122         else if ("Selection".equals(type)) { 
    123             task = taskTreeNodeFactory.createNewSelection(); 
    124         } 
    125         else if ("Iteration".equals(type)) { 
    126             task = taskTreeNodeFactory.createNewIteration(); 
    127         } 
    128         else if ("Optional".equals(type)) { 
    129             task = taskTreeNodeFactory.createNewOptional(); 
     109        ITaskInstanceList list; 
     110         
     111        if ("UserSession".equals(type)) { 
     112            list = taskFactory.createUserSession(); 
     113        } 
     114        else if ("TaskInstances".equals(type)) { 
     115            list = taskFactory.createNewTaskInstance(taskFactory.createNewSequence()); 
    130116        } 
    131117        else { 
    132             task = taskTreeNodeFactory.createNewEventTask(new StringEventType(type), target); 
     118            throw new IllegalArgumentException("unknown type of task instance list: " + type); 
     119        } 
     120         
     121        while (taskMatcher.find() && !"}".equals(taskMatcher.group(0))) { 
     122            ITaskInstance childInstance = parseTaskInstance(taskMatcher); 
     123             
     124            if (!(list instanceof IUserSession)) { 
     125                taskBuilder.addChild 
     126                    ((ISequence) ((ITaskInstance) list).getTask(), childInstance.getTask()); 
     127            } 
     128 
     129            taskBuilder.addTaskInstance(list, childInstance); 
     130        } 
     131 
     132        return list; 
     133    } 
     134 
     135    /** 
     136     *  
     137     */ 
     138    private ITaskInstance parseTaskInstance(Matcher taskMatcher) { 
     139        if ("}".equals(taskMatcher.group(1))) { 
     140            throw new IllegalArgumentException("invalid task instance specification"); 
     141        } 
     142         
     143        String taskDetails = taskMatcher.group(1); 
     144         
     145        Matcher matcher = taskInstanceDetailsPattern.matcher(taskDetails); 
     146         
     147        if (!matcher.find()) { 
     148            throw new IllegalArgumentException("could not parse task details"); 
     149        } 
     150 
     151        String type = matcher.group(1); 
     152        String id = matcher.group(2); 
     153         
     154        ITask task = tasks.get(id); 
     155         
     156        if (task == null) { 
     157            if ("Sequence".equals(type)) { 
     158                task = taskFactory.createNewSequence(); 
     159            } 
     160            else if ("Selection".equals(type)) { 
     161                task = taskFactory.createNewSelection(); 
     162            } 
     163            else if ("Iteration".equals(type)) { 
     164                task = taskFactory.createNewIteration(); 
     165            } 
     166            else if ("Optional".equals(type)) { 
     167                task = taskFactory.createNewOptional(); 
     168            } 
     169            else { 
     170                IEventTarget target = targets.get(id); 
     171             
     172                if (target == null) { 
     173                    target = new DummyGUIElement(id); 
     174                    targets.put(id, target); 
     175                } 
     176             
     177                task = taskFactory.createNewEventTask(new StringEventType(type), target); 
     178            } 
     179             
     180            tasks.put(id, task); 
    133181        } 
    134182         
    135183        if ((matcher.group(5) != null) && (!"".equals(matcher.group(5).trim()))) { 
    136             taskTreeBuilder.setDescription(task, matcher.group(5).trim()); 
    137         } 
    138  
     184            taskBuilder.setDescription(task, matcher.group(5).trim()); 
     185        } 
     186 
     187        ITaskInstance instance = taskFactory.createNewTaskInstance(task); 
     188         
    139189        while (taskMatcher.find() && !"}".equals(taskMatcher.group(0))) { 
     190            ITaskInstance childInstance = parseTaskInstance(taskMatcher); 
     191             
    140192            if (task instanceof ISequence) { 
    141                 taskTreeBuilder.addChild((ISequence) task, parseTask(taskMatcher)); 
     193                taskBuilder.addChild((ISequence) task, childInstance.getTask()); 
    142194            } 
    143195            else if (task instanceof ISelection) { 
    144                 taskTreeBuilder.addChild((ISelection) task, parseTask(taskMatcher)); 
     196                taskBuilder.addChild((ISelection) task, childInstance.getTask()); 
    145197            } 
    146198            else if (task instanceof IIteration) { 
    147                 if ((task.getChildren() == null) || (task.getChildren().size() == 0)) { 
    148                     taskTreeBuilder.setChild((IIteration) task, parseTask(taskMatcher)); 
    149                 } 
    150                 else { 
     199                if (((IIteration) task).getMarkedTask() == null) { 
     200                    taskBuilder.setMarkedTask((IIteration) task, childInstance.getTask()); 
     201                } 
     202                else if (!((IIteration) task).getMarkedTask().equals(childInstance.getTask())) { 
    151203                    throw new IllegalArgumentException 
    152204                        ("can not add more than one child to an iteration"); 
     
    154206            } 
    155207            else if (task instanceof IOptional) { 
    156                 if ((task.getChildren() == null) || (task.getChildren().size() == 0)) { 
    157                     taskTreeBuilder.setChild((IOptional) task, parseTask(taskMatcher)); 
    158                 } 
    159                 else { 
     208                if (((IOptional) task).getMarkedTask() == null) { 
     209                    taskBuilder.setMarkedTask((IOptional) task, childInstance.getTask()); 
     210                } 
     211                else if (!((IOptional) task).getMarkedTask().equals(childInstance.getTask())) { 
    160212                    throw new IllegalArgumentException 
    161213                        ("can not add more than one child to an optional"); 
     
    164216            else { 
    165217                throw new IllegalArgumentException("can not add children to something that is no " + 
    166                                                    "sequence, selection, or iteration"); 
    167             } 
    168         } 
    169  
    170         return task; 
     218                                                   "sequence, selection, iteration, or optional"); 
     219            } 
     220             
     221            taskBuilder.addChild(instance, childInstance); 
     222        } 
     223 
     224        return instance; 
    171225    } 
    172226 
Note: See TracChangeset for help on using the changeset viewer.