Changeset 1146 for trunk/autoquest-test-utils/src/main/java/de/ugoe
- Timestamp:
- 04/04/13 16:06:07 (12 years ago)
- 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 17 17 import static org.junit.Assert.*; 18 18 19 import java.io.FileNotFoundException;20 import java.io.FileOutputStream;21 import java.io.PrintWriter;22 19 import java.util.ArrayList; 23 20 import java.util.HashMap; … … 33 30 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection; 34 31 import 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; 32 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 33 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; 34 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList; 35 import de.ugoe.cs.autoquest.tasktrees.treeifc.IUserSession; 38 36 39 37 /** … … 56 54 57 55 /** 58 * TODO: comment 59 * 56 * 60 57 */ 61 58 public TaskTreeChecker() { … … 64 61 65 62 /** 66 * TODO: comment 67 * 63 * 68 64 */ 69 65 public TaskTreeChecker(boolean doTrace) { … … 74 70 * 75 71 */ 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) { 88 73 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>(); 95 82 96 83 while (taskMatcher.find()) { 97 84 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 { 117 98 if (expected == null) { 118 99 assertNull("null", checked); … … 123 104 assertEquals(expected.toString() + ": types do not match", 124 105 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(); 130 158 131 159 if ((expectedChildren != null) && (expectedChildren.size() > 0)) { … … 136 164 if (expected instanceof ISequence) { 137 165 for (int i = 0; i < expectedChildren.size(); i++) { 138 assertTask NodesEqual(expectedChildren.get(i), checkedChildren.get(i));166 assertTaskInstancesEqual(expectedChildren.get(i), checkedChildren.get(i)); 139 167 } 140 168 } … … 144 172 for (int j = 0; j < checkedChildren.size(); j++) { 145 173 try { 146 assertTask NodesEqual174 assertTaskInstancesEqual 147 175 (expectedChildren.get(i), checkedChildren.get(j)); 148 176 found = true; … … 166 194 167 195 /** 168 * TODO: comment169 196 * 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) { 310 199 if ("}".equals(taskMatcher.group(1))) { 311 200 throw new IllegalArgumentException("invalid task specification"); … … 338 227 List<TaskSpec> children = new ArrayList<TaskSpec>(); 339 228 while (taskMatcher.find() && !"}".equals(taskMatcher.group(0))) { 340 children.add(parseTask (taskMatcher));229 children.add(parseTaskInstance(taskMatcher)); 341 230 } 342 231 … … 352 241 * @param taskMapCopy 353 242 */ 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) 356 246 { 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 { 383 277 if (doTrace) { 384 278 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 388 284 if (("Event".equals(taskSpec.type) && (!(task instanceof IEventTask))) || 389 285 ("TextInputEvent".equals(taskSpec.type) && … … 396 292 if (doTrace) { 397 293 System.err.println("task types do not match: " + taskSpec.type + " != " + 398 task.getClass().getSimpleName() + "\n");294 task.getClass().getSimpleName() + "\n"); 399 295 } 400 296 return false; … … 440 336 } 441 337 } 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()))) 445 363 { 446 364 if (doTrace) { … … 448 366 ("numbers of children do not match: " + 449 367 (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"); 451 370 } 452 371 return false; 453 372 } 454 373 455 Iterator<ITask TreeNode> children = task.getChildren().iterator();374 Iterator<ITaskInstance> children = taskInstance.getChildren().iterator(); 456 375 if (taskSpec.children != null) { 457 376 for (TaskSpec child : taskSpec.children) { 458 if (!taskSpecEqualsTask (child, children.next())) {377 if (!taskSpecEqualsTaskInstance(child, children.next(), tasks)) { 459 378 if (doTrace) { 460 379 System.err.println("one of the children does not match\n"); … … 478 397 } 479 398 } 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 }516 399 517 400 /** 518 * TODO comment 519 * 520 * @version $Revision: $ $Date: $ 521 * @author 2011, last modified by $Author: $ 401 * 522 402 */ 523 403 private class TaskSpec { -
trunk/autoquest-test-utils/src/main/java/de/ugoe/cs/autoquest/tasktrees/TaskTreeDecoder.java
r1123 r1146 26 26 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection; 27 27 import 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; 28 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 29 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskBuilder; 30 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskFactory; 31 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; 32 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList; 33 import de.ugoe.cs.autoquest.tasktrees.treeifc.IUserSession; 31 34 import de.ugoe.cs.autoquest.test.DummyGUIElement; 32 35 … … 37 40 * @author 2012, last modified by $Author: patrick$ 38 41 */ 39 public class TaskTree Instantiator {40 41 /** */ 42 private static Pattern task Pattern = Pattern.compile("([^{}]+)\\{|\\}");43 44 /** */ 45 private static Pattern task DetailsPattern =42 public class TaskTreeDecoder { 43 44 /** */ 45 private static Pattern taskInstancePattern = Pattern.compile("([^{}]+)\\{|\\}"); 46 47 /** */ 48 private static Pattern taskInstanceDetailsPattern = 46 49 Pattern.compile("\\s*(\\w*)\\s*([\\w\\(\\)\"]*)\\s*((\\w*)|(\".*\"))?"); 47 50 48 51 /** */ 49 private ITask TreeNodeFactory taskTreeNodeFactory;50 51 /** */ 52 private ITask TreeBuilder taskTreeBuilder;52 private ITaskFactory taskFactory; 53 54 /** */ 55 private ITaskBuilder taskBuilder; 53 56 54 57 /** */ 55 58 Map<String, IEventTarget> targets = new HashMap<String, IEventTarget>(); 56 59 60 /** */ 61 Map<String, ITask> tasks = new HashMap<String, ITask>(); 62 57 63 /** 58 64 * 59 65 */ 60 public TaskTreeInstantiator(ITaskTreeNodeFactory taskTreeNodeFactory, 61 ITaskTreeBuilder taskTreeBuilder) 62 { 66 public TaskTreeDecoder(ITaskFactory taskFactory, ITaskBuilder taskBuilder) { 63 67 super(); 64 this.task TreeNodeFactory = taskTreeNodeFactory;65 this.task TreeBuilder = taskTreeBuilder;68 this.taskFactory = taskFactory; 69 this.taskBuilder = taskBuilder; 66 70 } 67 71 … … 69 73 * 70 74 */ 71 public ITask TreeNode instantiateTaskTree(String taskTreeSpec) {72 ITask TreeNode task= null;73 74 Matcher taskMatcher = task Pattern.matcher(taskTreeSpec);75 public ITaskInstanceList decode(String taskTreeSpec) { 76 ITaskInstanceList taskInstanceList = null; 77 78 Matcher taskMatcher = taskInstancePattern.matcher(taskTreeSpec); 75 79 76 80 if (taskMatcher.find()) { 77 task = parseTask(taskMatcher);81 taskInstanceList = parseTaskInstanceList(taskMatcher); 78 82 } 79 83 … … 82 86 } 83 87 84 return task ;88 return taskInstanceList; 85 89 } 86 90 … … 88 92 * 89 93 */ 90 private ITask TreeNode parseTask(Matcher taskMatcher) {94 private ITaskInstanceList parseTaskInstanceList(Matcher taskMatcher) { 91 95 if ("}".equals(taskMatcher.group(1))) { 92 throw new IllegalArgumentException("invalid task specification");96 throw new IllegalArgumentException("invalid task instance list specification"); 93 97 } 94 98 95 99 String taskDetails = taskMatcher.group(1); 96 100 97 Matcher matcher = task DetailsPattern.matcher(taskDetails);101 Matcher matcher = taskInstanceDetailsPattern.matcher(taskDetails); 98 102 99 103 if (!matcher.find()) { … … 101 105 } 102 106 103 ITaskTreeNode task;104 105 107 String type = matcher.group(1); 106 108 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()); 130 116 } 131 117 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); 133 181 } 134 182 135 183 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 139 189 while (taskMatcher.find() && !"}".equals(taskMatcher.group(0))) { 190 ITaskInstance childInstance = parseTaskInstance(taskMatcher); 191 140 192 if (task instanceof ISequence) { 141 task TreeBuilder.addChild((ISequence) task, parseTask(taskMatcher));193 taskBuilder.addChild((ISequence) task, childInstance.getTask()); 142 194 } 143 195 else if (task instanceof ISelection) { 144 task TreeBuilder.addChild((ISelection) task, parseTask(taskMatcher));196 taskBuilder.addChild((ISelection) task, childInstance.getTask()); 145 197 } 146 198 else if (task instanceof IIteration) { 147 if (( task.getChildren() == null) || (task.getChildren().size() == 0)) {148 task TreeBuilder.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())) { 151 203 throw new IllegalArgumentException 152 204 ("can not add more than one child to an iteration"); … … 154 206 } 155 207 else if (task instanceof IOptional) { 156 if (( task.getChildren() == null) || (task.getChildren().size() == 0)) {157 task TreeBuilder.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())) { 160 212 throw new IllegalArgumentException 161 213 ("can not add more than one child to an optional"); … … 164 216 else { 165 217 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; 171 225 } 172 226
Note: See TracChangeset
for help on using the changeset viewer.