1 | // Copyright 2012 Georg-August-Universität Göttingen, Germany |
---|
2 | // |
---|
3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
---|
4 | // you may not use this file except in compliance with the License. |
---|
5 | // You may obtain a copy of the License at |
---|
6 | // |
---|
7 | // http://www.apache.org/licenses/LICENSE-2.0 |
---|
8 | // |
---|
9 | // Unless required by applicable law or agreed to in writing, software |
---|
10 | // distributed under the License is distributed on an "AS IS" BASIS, |
---|
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
12 | // See the License for the specific language governing permissions and |
---|
13 | // limitations under the License. |
---|
14 | |
---|
15 | package de.ugoe.cs.autoquest.tasktrees.treeimpl; |
---|
16 | |
---|
17 | import java.util.List; |
---|
18 | |
---|
19 | import de.ugoe.cs.autoquest.eventcore.Event; |
---|
20 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask; |
---|
21 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTaskInstance; |
---|
22 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration; |
---|
23 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IIterationInstance; |
---|
24 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptional; |
---|
25 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptionalInstance; |
---|
26 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection; |
---|
27 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelectionInstance; |
---|
28 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence; |
---|
29 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequenceInstance; |
---|
30 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel; |
---|
31 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskFactory; |
---|
32 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IUserSession; |
---|
33 | |
---|
34 | /** |
---|
35 | * <p> |
---|
36 | * this is the default implementation of the interface {@link ITaskFactory}. It |
---|
37 | * does not do anything fancy except implementing the interface. It instantiates |
---|
38 | * the other implementations of the tree ifc in this package. |
---|
39 | * </p> |
---|
40 | * |
---|
41 | * @author Patrick Harms |
---|
42 | */ |
---|
43 | public class TaskFactory implements ITaskFactory { |
---|
44 | |
---|
45 | /* |
---|
46 | * (non-Javadoc) |
---|
47 | * |
---|
48 | * @see ITaskFactory#createNewEventTask(String) |
---|
49 | */ |
---|
50 | @Override |
---|
51 | public IEventTask createNewEventTask(String description) { |
---|
52 | return new EventTask(description); |
---|
53 | } |
---|
54 | |
---|
55 | /* |
---|
56 | * (non-Javadoc) |
---|
57 | * |
---|
58 | * @see ITaskFactory#createNewIteration() |
---|
59 | */ |
---|
60 | @Override |
---|
61 | public IIteration createNewIteration() { |
---|
62 | return new Iteration(); |
---|
63 | } |
---|
64 | |
---|
65 | /* |
---|
66 | * (non-Javadoc) |
---|
67 | * |
---|
68 | * @see ITaskFactory#createNewOptional() |
---|
69 | */ |
---|
70 | @Override |
---|
71 | public IOptional createNewOptional() { |
---|
72 | return new Optional(); |
---|
73 | } |
---|
74 | |
---|
75 | /* |
---|
76 | * (non-Javadoc) |
---|
77 | * |
---|
78 | * @see ITaskFactory#createNewSelection() |
---|
79 | */ |
---|
80 | @Override |
---|
81 | public ISelection createNewSelection() { |
---|
82 | return new Selection(); |
---|
83 | } |
---|
84 | |
---|
85 | /* |
---|
86 | * (non-Javadoc) |
---|
87 | * |
---|
88 | * @see ITaskFactory#createNewSequence() |
---|
89 | */ |
---|
90 | @Override |
---|
91 | public ISequence createNewSequence() { |
---|
92 | return new Sequence(); |
---|
93 | } |
---|
94 | |
---|
95 | /* |
---|
96 | * (non-Javadoc) |
---|
97 | * |
---|
98 | * @see ITaskFactory#createNewTaskInstance(IEventTask, Event) |
---|
99 | */ |
---|
100 | @Override |
---|
101 | public IEventTaskInstance createNewTaskInstance(IEventTask task, Event event) { |
---|
102 | if (!(task instanceof EventTask)) { |
---|
103 | throw new IllegalArgumentException( |
---|
104 | "illegal type of event task provided: " + task.getClass()); |
---|
105 | } |
---|
106 | |
---|
107 | final EventTaskInstance instance = new EventTaskInstance(task, event); |
---|
108 | ((EventTask) task).addInstance(instance); |
---|
109 | |
---|
110 | return instance; |
---|
111 | } |
---|
112 | |
---|
113 | /* |
---|
114 | * (non-Javadoc) |
---|
115 | * |
---|
116 | * @see ITaskFactory#createNewTaskInstance(IIteration) |
---|
117 | */ |
---|
118 | @Override |
---|
119 | public IIterationInstance createNewTaskInstance(IIteration iteration) { |
---|
120 | if (!(iteration instanceof Iteration)) { |
---|
121 | throw new IllegalArgumentException( |
---|
122 | "illegal type of iteration provided: " |
---|
123 | + iteration.getClass()); |
---|
124 | } |
---|
125 | |
---|
126 | final IterationInstance instance = new IterationInstance(iteration); |
---|
127 | ((Iteration) iteration).addInstance(instance); |
---|
128 | |
---|
129 | return instance; |
---|
130 | } |
---|
131 | |
---|
132 | /* |
---|
133 | * (non-Javadoc) |
---|
134 | * |
---|
135 | * @see ITaskFactory#createNewTaskInstance(IOptional) |
---|
136 | */ |
---|
137 | @Override |
---|
138 | public IOptionalInstance createNewTaskInstance(IOptional optional) { |
---|
139 | if (!(optional instanceof Optional)) { |
---|
140 | throw new IllegalArgumentException( |
---|
141 | "illegal type of optional provided: " + optional.getClass()); |
---|
142 | } |
---|
143 | |
---|
144 | final OptionalInstance instance = new OptionalInstance(optional); |
---|
145 | ((Optional) optional).addInstance(instance); |
---|
146 | |
---|
147 | return instance; |
---|
148 | } |
---|
149 | |
---|
150 | /* |
---|
151 | * (non-Javadoc) |
---|
152 | * |
---|
153 | * @see ITaskFactory#createNewTaskInstance(ISelection) |
---|
154 | */ |
---|
155 | @Override |
---|
156 | public ISelectionInstance createNewTaskInstance(ISelection selection) { |
---|
157 | if (!(selection instanceof Selection)) { |
---|
158 | throw new IllegalArgumentException( |
---|
159 | "illegal type of optional provided: " |
---|
160 | + selection.getClass()); |
---|
161 | } |
---|
162 | |
---|
163 | final SelectionInstance instance = new SelectionInstance(selection); |
---|
164 | ((Selection) selection).addInstance(instance); |
---|
165 | |
---|
166 | return instance; |
---|
167 | } |
---|
168 | |
---|
169 | /* |
---|
170 | * (non-Javadoc) |
---|
171 | * |
---|
172 | * @see ITaskFactory#createNewTaskInstance(ISequence) |
---|
173 | */ |
---|
174 | @Override |
---|
175 | public ISequenceInstance createNewTaskInstance(ISequence sequence) { |
---|
176 | if (!(sequence instanceof Sequence)) { |
---|
177 | throw new IllegalArgumentException( |
---|
178 | "illegal type of sequence provided: " + sequence.getClass()); |
---|
179 | } |
---|
180 | |
---|
181 | final SequenceInstance instance = new SequenceInstance(sequence); |
---|
182 | ((Sequence) sequence).addInstance(instance); |
---|
183 | |
---|
184 | return instance; |
---|
185 | } |
---|
186 | |
---|
187 | /* |
---|
188 | * (non-Javadoc) |
---|
189 | * |
---|
190 | * @see ITaskFactory#createTaskModel(List<IUserSession>) |
---|
191 | */ |
---|
192 | @Override |
---|
193 | public ITaskModel createTaskModel(List<IUserSession> userSessions) { |
---|
194 | return new TaskModel(userSessions); |
---|
195 | } |
---|
196 | |
---|
197 | /* |
---|
198 | * (non-Javadoc) |
---|
199 | * |
---|
200 | * @see ITaskFactory#createUserSession() |
---|
201 | */ |
---|
202 | @Override |
---|
203 | public IUserSession createUserSession() { |
---|
204 | return new UserSession(); |
---|
205 | } |
---|
206 | |
---|
207 | } |
---|