Changeset 1146 for trunk/autoquest-test-utils/src/main/java/de/ugoe/cs/autoquest/tasktrees/TaskTreeDecoder.java
- Timestamp:
- 04/04/13 16:06:07 (12 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
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.