001: //
002: // Informa -- RSS Library for Java
003: // Copyright (c) 2002 by Niko Schmuck
004: //
005: // Niko Schmuck
006: // http://sourceforge.net/projects/informa
007: // mailto:niko_schmuck@users.sourceforge.net
008: //
009: // This library is free software.
010: //
011: // You may redistribute it and/or modify it under the terms of the GNU
012: // Lesser General Public License as published by the Free Software Foundation.
013: //
014: // Version 2.1 of the license should be included with this distribution in
015: // the file LICENSE. If the license is not included with this distribution,
016: // you may find a copy at the FSF web site at 'www.gnu.org' or 'www.fsf.org',
017: // or you may write to the Free Software Foundation, 675 Mass Ave, Cambridge,
018: // MA 02139 USA.
019: //
020: // This library is distributed in the hope that it will be useful,
021: // but WITHOUT ANY WARRANTY; without even the implied waranty of
022: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
023: // Lesser General Public License for more details.
024: //
025: // $Id: PersistenceObserver.java,v 1.4 2004/09/02 09:13:58 spyromus Exp $
026: //
027:
028: package de.nava.informa.utils.poller;
029:
030: import de.nava.informa.core.ChannelIF;
031: import de.nava.informa.core.ItemIF;
032: import de.nava.informa.utils.manager.PersistenceManagerIF;
033: import de.nava.informa.utils.manager.PersistenceManagerException;
034:
035: /**
036: * Watches for event about new items and calls given manager to create items in channels.
037: *
038: * @author Aleksey Gureev (spyromus@noizeramp.com)
039: */
040: public class PersistenceObserver implements PollerObserverIF {
041: private PersistenceManagerIF manager;
042:
043: /**
044: * Creates observer.
045: *
046: * @param manager persistence manager to use.
047: *
048: * @throws IllegalArgumentException if manager isn't specified.
049: */
050: public PersistenceObserver(PersistenceManagerIF manager) {
051: if (manager == null) {
052: throw new IllegalArgumentException(
053: "Manager should be specified.");
054: }
055:
056: this .manager = manager;
057: }
058:
059: /**
060: * Invoked by Poller when new item is approved for addition. Item is transient
061: * and should be added to specified channel.
062: *
063: * @param item item added.
064: * @param channel destination channel.
065: */
066: public final void itemFound(ItemIF item, ChannelIF channel) {
067: try {
068: manager.createItem(channel, item);
069: } catch (PersistenceManagerException e) {
070: // We can do nothing here.
071: }
072: }
073:
074: /**
075: * Invoked by Poller when poller of the channel failed.
076: *
077: * @param channel channel.
078: * @param e original cause of failure.
079: */
080: public void channelErrored(ChannelIF channel, Exception e) {
081: }
082:
083: /**
084: * Invoked when Poller detected changes in channel information (title and etc).
085: *
086: * @param channel channel.
087: */
088: public void channelChanged(ChannelIF channel) {
089: try {
090: manager.updateChannel(channel);
091: } catch (PersistenceManagerException e) {
092: // We can do nothing here.
093: }
094: }
095:
096: /**
097: * Invoked by Poller when checking of the channel started.
098: *
099: * @param channel channel.
100: */
101: public void pollStarted(ChannelIF channel) {
102: }
103:
104: /**
105: * Invoked by Poller when checking of the channel finished.
106: *
107: * @param channel channel.
108: */
109: public void pollFinished(ChannelIF channel) {
110: }
111: }
|