001: /*BEGIN_COPYRIGHT_BLOCK
002: *
003: * Copyright (c) 2001-2007, JavaPLT group at Rice University (javaplt@rice.edu)
004: * All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions are met:
008: * * Redistributions of source code must retain the above copyright
009: * notice, this list of conditions and the following disclaimer.
010: * * Redistributions in binary form must reproduce the above copyright
011: * notice, this list of conditions and the following disclaimer in the
012: * documentation and/or other materials provided with the distribution.
013: * * Neither the names of DrJava, the JavaPLT group, Rice University, nor the
014: * names of its contributors may be used to endorse or promote products
015: * derived from this software without specific prior written permission.
016: *
017: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
018: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
019: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
020: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
021: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
022: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
023: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
024: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
025: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
026: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
027: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
028: *
029: * This software is Open Source Initiative approved Open Source Software.
030: * Open Source Initative Approved is a trademark of the Open Source Initiative.
031: *
032: * This file is part of DrJava. Download the current version of this project
033: * from http://www.drjava.org/ or http://sourceforge.net/projects/drjava/
034: *
035: * END_COPYRIGHT_BLOCK*/
036:
037: package edu.rice.cs.drjava.model.javadoc;
038:
039: import java.io.File;
040: import edu.rice.cs.drjava.model.EventNotifier;
041:
042: /**
043: * Keeps track of all listeners to a JavadocModel, and has the ability
044: * to notify them of some event.
045: * <p>
046: *
047: * This class has a specific role of managing JavadocListeners. Other
048: * classes with similar names use similar code to perform the same function for
049: * other interfaces, e.g. InteractionsEventNotifier and GlobalEventNotifier.
050: * These classes implement the appropriate interface definition so that they
051: * can be used transparently as composite packaging for a particular listener
052: * interface.
053: * <p>
054: *
055: * Components which might otherwise manage their own list of listeners use
056: * EventNotifiers instead to simplify their internal implementation. Notifiers
057: * should therefore be considered a private implementation detail of the
058: * components, and should not be used directly outside of the "host" component.
059: * <p>
060: *
061: * All methods in this class must use the synchronization methods
062: * provided by ReaderWriterLock. This ensures that multiple notifications
063: * (reads) can occur simultaneously, but only one thread can be adding
064: * or removing listeners (writing) at a time, and no reads can occur
065: * during a write.
066: * <p>
067: *
068: * <i>No</i> methods on this class should be synchronized using traditional
069: * Java synchronization!
070: * <p>
071: *
072: * @version $Id: JavadocEventNotifier.java 4255 2007-08-28 19:17:37Z mgricken $
073: */
074: class JavadocEventNotifier extends EventNotifier<JavadocListener>
075: implements JavadocListener {
076:
077: /** Called after Javadoc is started by the GlobalModel. */
078: public void javadocStarted() {
079: _lock.startRead();
080: try {
081: for (JavadocListener jl : _listeners) {
082: jl.javadocStarted();
083: }
084: } finally {
085: _lock.endRead();
086: }
087: }
088:
089: /** Called after Javadoc is finished.
090: * @param success whether the Javadoc operation generated proper output
091: * @param destDir if (success == true) the location where the output was
092: * generated, otherwise undefined (possibly null)
093: * @param allDocs Whether Javadoc was run for all open documents
094: */
095: public void javadocEnded(boolean success, File destDir,
096: boolean allDocs) {
097: _lock.startRead();
098: try {
099: for (JavadocListener jl : _listeners) {
100: jl.javadocEnded(success, destDir, allDocs);
101: }
102: } finally {
103: _lock.endRead();
104: }
105: }
106:
107: /** Called before attempting Javadoc, to give users a chance to save.
108: * Do not continue with Javadoc if the user doesn't save!
109: */
110: public void saveBeforeJavadoc() {
111: _lock.startRead();
112: try {
113: for (JavadocListener jl : _listeners) {
114: jl.saveBeforeJavadoc();
115: }
116: } finally {
117: _lock.endRead();
118: }
119: }
120: }
|