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
File:
1 moved

Legend:

Unmodified
Added
Removed
  • 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.