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.TestSuiteTag;
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 TestSuiteEventHandler{
29
30 private static TestSuiteEventHandler eventHandler;
31 private final List testSuiteListeners = Collections.synchronizedList(new LinkedList());;
32
33 private TestSuiteEventHandler(){}
34
35 public static TestSuiteEventHandler getInstance(){
36 if (eventHandler == null) {
37 eventHandler = new TestSuiteEventHandler();
38 }
39 return eventHandler;
40 }
41
42 public void clearInstance(){
43 eventHandler = null;
44 }
45
46 public void addTestSuiteListener(TestSuiteListener tsl){
47 if (tsl != null && !testSuiteListeners.contains(tsl)){
48 testSuiteListeners.add(tsl);
49 }
50 }
51
52 public List getTestSuiteListeners(){
53 return testSuiteListeners;
54 }
55
56 public void removeTestSuiteListener(TestSuiteListener tsl){
57 testSuiteListeners.remove(tsl);
58 }
59
60 public void beginTestSuite(TestSuiteTag tst){
61 TestSuiteEvent tse = new TestSuiteEvent(tst);
62 synchronized(testSuiteListeners){
63 Iterator it = testSuiteListeners.iterator();
64 TestSuiteListener tsl;
65 while (it.hasNext()) {
66 tsl = (TestSuiteListener)it.next();
67 tsl.beginTestSuite(tse);
68 }
69 }
70 }
71
72 public void endTestSuite(TestSuiteTag tst){
73 TestSuiteEvent tse = new TestSuiteEvent(tst);
74 synchronized(testSuiteListeners){
75 Iterator it = testSuiteListeners.iterator();
76 TestSuiteListener tsl;
77 while (it.hasNext()) {
78 tsl = (TestSuiteListener)it.next();
79 tsl.endTestSuite(tse);
80 }
81 }
82 }
83
84 }