View Javadoc

1   // BasicReceiveNotifier.java - a HylaFAX Job representation
2   // $Id: BasicReceiveNotifier.java,v 1.2 2006/02/20 04:52:10 sjardine Exp $
3   //
4   // Copyright 2003, Innovation Software Group, LLC - http://www.innovationsw.com
5   //                Joe Phillips <joe.phillips@innovationsw.com>
6   //
7   // for information on the HylaFAX FAX server see
8   //  http://www.hylafax.org/
9   //
10  // This library is free software; you can redistribute it and/or
11  // modify it under the terms of the GNU Library General Public
12  // License as published by the Free Software Foundation; either
13  // version 2 of the License, or (at your option) any later version.
14  //
15  // This library is distributed in the hope that it will be useful,
16  // but WITHOUT ANY WARRANTY; without even the implied warranty of
17  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  // Library General Public License for more details.
19  //
20  // You should have received a copy of the GNU Library General Public
21  // License along with this library; if not, write to the Free
22  // Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23  //
24  package gnu.hylafax.job;
25  
26  import java.util.ArrayList;
27  import java.util.Iterator;
28  import java.util.List;
29  
30  /***
31   * This interface defines what a class should implement in order to notify
32   * others of job related events.
33   * 
34   * @author $Author: sjardine $
35   * @version $Id: BasicReceiveNotifier.java,v 1.2 2006/02/20 04:52:10 sjardine
36   *          Exp $
37   * @see gnu.hylafax.job.ReceiveListener
38   * @see gnu.hylafax.job.ReceiveEvent
39   */
40  public class BasicReceiveNotifier implements ReceiveNotifier {
41      private List listeners = null;
42  
43      public BasicReceiveNotifier() {
44  	listeners = new ArrayList();
45      }
46  
47      /***
48       * This method is called when Job state changes.
49       */
50      public void notifyReceiveListeners(ReceiveEvent details) {
51  	if (details == null) {
52  	    return;
53  	}
54  	synchronized (listeners) {
55  	    Iterator i = listeners.iterator();
56  	    while (i.hasNext()) {
57  		ReceiveListener l = (ReceiveListener) i.next();
58  		l.onReceiveEvent(details);
59  	    }
60  	}
61      }
62  
63      /***
64       * This method is called to register a Job Listener.
65       */
66      public void addReceiveListener(ReceiveListener l) {
67  	if (l == null) {
68  	    return;
69  	}
70  	synchronized (listeners) {
71  	    listeners.add(l);
72  	}
73      }
74  
75      /***
76       * This method is used to deregister a Job Listener.
77       */
78      public void removeReceiveListener(ReceiveListener l) {
79  	if (l == null) {
80  	    return;
81  	}
82  	synchronized (listeners) {
83  	    listeners.remove(l);
84  	}
85      }
86  
87  }
88  // BasicReceiveNotifier.java