View Javadoc

1   /*
2       Jameleon - An automation testing tool..
3       Copyright (C) 2006 Christian W. Hargraves (engrean@hotmail.com)
4   
5       This library is free software; you can redistribute it and/or
6       modify it under the terms of the GNU Lesser General Public
7       License as published by the Free Software Foundation; either
8       version 2.1 of the License, or (at your option) any later version.
9   
10      This library is distributed in the hope that it will be useful,
11      but WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13      Lesser General Public License for more details.
14  
15      You should have received a copy of the GNU Lesser General Public
16      License along with this library; if not, write to the Free Software
17      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111AssertLevel.NO_FUNCTION07 USA
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  }