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 net.sf.jameleon.TestCaseTag;
22
23 import java.util.Collections;
24 import java.util.Iterator;
25 import java.util.LinkedList;
26 import java.util.List;
27
28 public class TestCaseEventHandler{
29
30 private static TestCaseEventHandler eventHandler;
31 private final List testCaseListeners = Collections.synchronizedList(new LinkedList());
32
33 private TestCaseEventHandler(){}
34
35 public static TestCaseEventHandler getInstance(){
36 if (eventHandler == null) {
37 eventHandler = new TestCaseEventHandler();
38 }
39 return eventHandler;
40 }
41
42 public void clearInstance(){
43 eventHandler = null;
44 }
45
46 public void addTestCaseListener(TestCaseListener tcl){
47 if (tcl != null && !testCaseListeners.contains(tcl)){
48 testCaseListeners.add(tcl);
49 }
50 }
51
52 public List getTestCaseListeners(){
53 return testCaseListeners;
54 }
55
56 public void removeTestCaseListener(TestCaseListener tcl){
57 testCaseListeners.remove(tcl);
58 }
59
60 public void beginTestCase(TestCaseTag tct){
61 TestCaseEvent tce = new TestCaseEvent(tct);
62 synchronized(testCaseListeners){
63 Iterator it = testCaseListeners.iterator();
64 TestCaseListener tcl;
65 while (it.hasNext()) {
66 tcl = (TestCaseListener)it.next();
67 tcl.beginTestCase(tce);
68 }
69 }
70 }
71
72 public void endTestCase(TestCaseTag tct){
73 TestCaseEvent tce = new TestCaseEvent(tct);
74 synchronized(testCaseListeners){
75 Iterator it = testCaseListeners.iterator();
76 TestCaseListener tcl;
77 while (it.hasNext()) {
78 tcl = (TestCaseListener)it.next();
79 tcl.endTestCase(tce);
80 }
81 }
82 }
83
84 }