KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > nava > informa > utils > poller > CompositeObserver


1 //
2
// Informa -- RSS Library for Java
3
// Copyright (c) 2002 by Niko Schmuck
4
//
5
// Niko Schmuck
6
// http://sourceforge.net/projects/informa
7
// mailto:niko_schmuck@users.sourceforge.net
8
//
9
// This library is free software.
10
//
11
// You may redistribute it and/or modify it under the terms of the GNU
12
// Lesser General Public License as published by the Free Software Foundation.
13
//
14
// Version 2.1 of the license should be included with this distribution in
15
// the file LICENSE. If the license is not included with this distribution,
16
// you may find a copy at the FSF web site at 'www.gnu.org' or 'www.fsf.org',
17
// or you may write to the Free Software Foundation, 675 Mass Ave, Cambridge,
18
// MA 02139 USA.
19
//
20
// This library is distributed in the hope that it will be useful,
21
// but WITHOUT ANY WARRANTY; without even the implied waranty of
22
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23
// Lesser General Public License for more details.
24
//
25
// $Id: CompositeObserver.java,v 1.2 2004/08/24 17:45:56 spyromus Exp $
26
//
27

28 package de.nava.informa.utils.poller;
29
30 import de.nava.informa.core.ChannelIF;
31 import de.nava.informa.core.ItemIF;
32
33 import java.util.List JavaDoc;
34 import java.util.Vector JavaDoc;
35
36 /**
37  * Composite observer delivers all received events to sub observers.
38  *
39  * @author Aleksey Gureev (spyromus@noizeramp.com)
40  */

41 class CompositeObserver implements PollerObserverIF {
42   private List JavaDoc observers = new Vector JavaDoc();
43
44   /**
45    * Invoked by Poller when new item is approved for addition. Item is transient
46    * and should be added to specified channel.
47    *
48    * @param item item added.
49    * @param channel destination channel.
50    */

51   public final void itemFound(ItemIF item, ChannelIF channel) {
52     final int size = observers.size();
53     for (int i = 0; i < size; i++) {
54       final PollerObserverIF observer = (PollerObserverIF) observers.get(i);
55       try {
56         observer.itemFound(item, channel);
57       } catch (RuntimeException JavaDoc e) {
58         // Do not care about exceptions from sub-observers.
59
}
60     }
61   }
62
63   /**
64    * Invoked by Poller when poller of the channel failed.
65    *
66    * @param channel channel.
67    * @param e original cause of failure.
68    */

69   public final void channelErrored(ChannelIF channel, Exception JavaDoc e) {
70     final int size = observers.size();
71     for (int i = 0; i < size; i++) {
72       final PollerObserverIF observer = (PollerObserverIF) observers.get(i);
73       try {
74         observer.channelErrored(channel, e);
75       } catch (RuntimeException JavaDoc e1) {
76         // Do not care about exceptions from sub-observers.
77
}
78     }
79   }
80
81   /**
82    * Invoked when Poller detected changes in channel information (title and etc).
83    *
84    * @param channel channel.
85    */

86   public final void channelChanged(ChannelIF channel) {
87     final int size = observers.size();
88     for (int i = 0; i < size; i++) {
89       final PollerObserverIF observer = (PollerObserverIF) observers.get(i);
90       try {
91         observer.channelChanged(channel);
92       } catch (RuntimeException JavaDoc e1) {
93         // Do not care about exceptions from sub-observers.
94
}
95     }
96   }
97
98   /**
99    * Invoked by Poller when checking of the channel started.
100    *
101    * @param channel channel.
102    */

103   public final void pollStarted(ChannelIF channel) {
104     final int size = observers.size();
105     for (int i = 0; i < size; i++) {
106       final PollerObserverIF observer = (PollerObserverIF) observers.get(i);
107       try {
108         observer.pollStarted(channel);
109       } catch (RuntimeException JavaDoc e1) {
110         // Do not care about exceptions from sub-observers.
111
}
112     }
113   }
114
115   /**
116    * Invoked by Poller when checking of the channel finished.
117    *
118    * @param channel channel.
119    */

120   public final void pollFinished(ChannelIF channel) {
121     final int size = observers.size();
122     for (int i = 0; i < size; i++) {
123       final PollerObserverIF observer = (PollerObserverIF) observers.get(i);
124       try {
125         observer.pollFinished(channel);
126       } catch (RuntimeException JavaDoc e1) {
127         // Do not care about exceptions from sub-observers.
128
}
129     }
130   }
131
132   /**
133    * Adds new observer to the list.
134    *
135    * @param observer new observer.
136    */

137   public final void add(PollerObserverIF observer) {
138     if (!observers.contains(observer)) {
139       observers.add(observer);
140     }
141   }
142
143   /**
144    * Removes observer from the list.
145    *
146    * @param observer registered observer.
147    */

148   public final void remove(PollerObserverIF observer) {
149     observers.remove(observer);
150   }
151 }
152
Popular Tags