KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > rice > cs > drjava > model > junit > JUnitEventNotifier


1  /*BEGIN_COPYRIGHT_BLOCK
2  *
3  * This file is part of DrJava. Download the current version of this project from http://www.drjava.org/
4  * or http://sourceforge.net/projects/drjava/
5  *
6  * DrJava Open Source License
7  *
8  * Copyright (C) 2001-2005 JavaPLT group at Rice University (javaplt@rice.edu). All rights reserved.
9  *
10  * Developed by: Java Programming Languages Team, Rice University, http://www.cs.rice.edu/~javaplt/
11  *
12  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
13  * documentation files (the "Software"), to deal with the Software without restriction, including without limitation
14  * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
15  * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
16  *
17  * - Redistributions of source code must retain the above copyright notice, this list of conditions and the
18  * following disclaimers.
19  * - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
20  * following disclaimers in the documentation and/or other materials provided with the distribution.
21  * - Neither the names of DrJava, the JavaPLT, Rice University, nor the names of its contributors may be used to
22  * endorse or promote products derived from this Software without specific prior written permission.
23  * - Products derived from this software may not be called "DrJava" nor use the term "DrJava" as part of their
24  * names without prior written permission from the JavaPLT group. For permission, write to javaplt@rice.edu.
25  *
26  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
27  * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28  * CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
29  * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
30  * WITH THE SOFTWARE.
31  *
32  *END_COPYRIGHT_BLOCK*/

33
34 package edu.rice.cs.drjava.model.junit;
35
36 import java.util.List JavaDoc;
37 import edu.rice.cs.drjava.model.EventNotifier;
38 import edu.rice.cs.drjava.model.OpenDefinitionsDocument;
39 import edu.rice.cs.drjava.model.compiler.CompilerListener;
40 import edu.rice.cs.util.classloader.ClassFileError;
41 import edu.rice.cs.util.swing.Utilities;
42
43 /**
44  * Keeps track of all listeners to a JUnitModel, and has the ability
45  * to notify them of some event.
46  * <p>
47  *
48  * This class has a specific role of managing JUnitListeners. Other
49  * classes with similar names use similar code to perform the same function for
50  * other interfaces, e.g. InteractionsEventNotifier and GlobalEventNotifier.
51  * These classes implement the appropriate interface definition so that they
52  * can be used transparently as composite packaging for a particular listener
53  * interface.
54  * <p>
55  *
56  * Components which might otherwise manage their own list of listeners use
57  * EventNotifiers instead to simplify their internal implementation. Notifiers
58  * should therefore be considered a private implementation detail of the
59  * components, and should not be used directly outside of the "host" component.
60  * <p>
61  *
62  * All methods in this class must use the synchronization methods
63  * provided by ReaderWriterLock. This ensures that multiple notifications
64  * (reads) can occur simultaneously, but only one thread can be adding
65  * or removing listeners (writing) at a time, and no reads can occur
66  * during a write.
67  * <p>
68  *
69  * <i>No</i> methods on this class should be synchronized using traditional
70  * Java synchronization!
71  * <p>
72  *
73  * @version $Id: JUnitEventNotifier.java 3839 2006-05-14 20:28:51Z rcartwright $
74  */

75 class JUnitEventNotifier extends EventNotifier<JUnitListener> implements JUnitListener {
76   
77   public void addListener(JUnitListener jul) {
78     super.addListener(jul);
79 // Utilities.show("Adding listener " + jul + " to listener list in " + this);
80
}
81
82   /** Called when trying to test a non-TestCase class.
83    * @param isTestAll whether or not it was a use of the test all button
84    */

85   public void nonTestCase(boolean isTestAll) {
86     _lock.startRead();
87     try { for (JUnitListener jul : _listeners) { jul.nonTestCase(isTestAll); } }
88     finally { _lock.endRead(); }
89   }
90
91   public void classFileError(ClassFileError e) {
92     _lock.startRead();
93     try { for (JUnitListener jul : _listeners) { jul.classFileError(e); } }
94     finally { _lock.endRead(); }
95   }
96   
97  /** Called before JUnit is started by the DefaultJUnitModel. */
98   public void compileBeforeJUnit(final CompilerListener cl) {
99     _lock.startRead();
100     try { for (JUnitListener jul : _listeners) { jul.compileBeforeJUnit(cl); } }
101     finally { _lock.endRead(); }
102   }
103   
104   /** Called after junit/junitAll is started by the GlobalModel. */
105   public void junitStarted() {
106     _lock.startRead();
107     try { for (JUnitListener jul : _listeners) { jul.junitStarted(); } }
108     finally { _lock.endRead(); }
109   }
110
111   /** Called after junitClasses is started by the GlobalModel. */
112   public void junitClassesStarted() {
113     _lock.startRead();
114     try { for (JUnitListener jul : _listeners) { jul.junitClassesStarted(); } }
115     finally { _lock.endRead(); }
116   }
117
118   /** Called to indicate that a suite of tests has started running.
119    * @param numTests The number of tests in the suite to be run.
120    */

121   public void junitSuiteStarted(int numTests) {
122     _lock.startRead();
123     try { for (JUnitListener jul : _listeners) { jul.junitSuiteStarted(numTests); } }
124     finally { _lock.endRead(); }
125   }
126
127   /** Called when a particular test is started.
128    * @param name The name of the test being started.
129    */

130   public void junitTestStarted(String JavaDoc name) {
131     _lock.startRead();
132     try { for (JUnitListener jul : _listeners) { jul.junitTestStarted(name); } }
133     finally { _lock.endRead(); }
134   }
135
136   /** Called when a particular test has ended.
137    * @param name The name of the test that has ended.
138    * @param wasSuccessful Whether the test passed or not.
139    * @param causedError If not successful, whether the test caused an error or simply failed.
140    */

141   public void junitTestEnded(String JavaDoc name, boolean wasSuccessful, boolean causedError) {
142     _lock.startRead();
143     try { for (JUnitListener jul : _listeners) { jul.junitTestEnded(name, wasSuccessful, causedError); } }
144     finally { _lock.endRead(); }
145   }
146
147   /** Called after JUnit is finished running tests. */
148   public void junitEnded() {
149 // new ScrollableDialog(null, "Ready to grab acquireReadLock for junitListener queue in junitEnded" + _listeners, "", "").show();
150
_lock.startRead();
151 // new ScrollableDialog(null, "Grabbed acquireReadLock for junitListener queue in junitEnded" + _listeners, "", "").show();
152
try { for(JUnitListener jul : _listeners) { jul.junitEnded(); } }
153     finally { _lock.endRead(); }
154   }
155 }
156
157
Popular Tags