1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sf.jameleon.event;
20
21 import java.util.*;
22
23 public class TestRunEventHandler{
24
25 private static TestRunEventHandler eventHandler;
26
27 private final List testRunListeners = Collections.synchronizedList(new LinkedList());
28
29 private TestRunEventHandler(){}
30
31 public static TestRunEventHandler getInstance(){
32 if (eventHandler == null) {
33 eventHandler = new TestRunEventHandler();
34 }
35 return eventHandler;
36 }
37
38 public void clearInstance(){
39 eventHandler = null;
40 }
41
42 public void addTestRunListener(TestRunListener trl){
43 if (trl != null && !testRunListeners.contains(trl)){
44 testRunListeners.add(trl);
45 }
46 }
47
48 public List getTestRunListeners(){
49 return testRunListeners;
50 }
51
52 public void removeTestRunListener(TestRunListener trl){
53 testRunListeners.remove(trl);
54 }
55
56 public void beginTestRun(Calendar startTime){
57 TestRunEvent tre = new TestRunEvent(startTime);
58 synchronized(testRunListeners){
59 Iterator it = testRunListeners.iterator();
60 TestRunListener trl;
61 while (it.hasNext()) {
62 trl = (TestRunListener)it.next();
63 trl.beginTestRun(tre);
64 }
65 }
66 }
67
68 public void endTestRun(Calendar endTime){
69 TestRunEvent tre = new TestRunEvent(endTime);
70 synchronized(testRunListeners){
71 Iterator it = testRunListeners.iterator();
72 TestRunListener trl;
73 while (it.hasNext()) {
74 trl = (TestRunListener)it.next();
75 trl.endTestRun(tre);
76 }
77 }
78 }
79
80 }