001: /*
002: * Copyright (c) 2004-2005, Hewlett-Packard Company and Massachusetts
003: * Institute of Technology. All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions are
007: * met:
008: *
009: * - Redistributions of source code must retain the above copyright
010: * notice, this list of conditions and the following disclaimer.
011: *
012: * - Redistributions in binary form must reproduce the above copyright
013: * notice, this list of conditions and the following disclaimer in the
014: * documentation and/or other materials provided with the distribution.
015: *
016: * - Neither the name of the Hewlett-Packard Company nor the name of the
017: * Massachusetts Institute of Technology nor the names of their
018: * contributors may be used to endorse or promote products derived from
019: * this software without specific prior written permission.
020: *
021: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
022: * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
023: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
024: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
025: * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
026: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
027: * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
028: * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
029: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
030: * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
031: * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
032: * DAMAGE.
033: */
034: package org.dspace.checker;
035:
036: import java.sql.SQLException;
037:
038: import org.dspace.core.PluginManager;
039:
040: /**
041: * Decorator that dispatches a specified number of bitstreams from a delegate
042: * dispatcher.
043: *
044: * @author Jim Downing
045: * @author Grace Carpenter
046: * @author Nathan Sarr
047: *
048: */
049: public class LimitedCountDispatcher implements BitstreamDispatcher {
050: /** The remaining number of bitstreams to iterate through. */
051: private int remaining = 1;
052:
053: /** The dispatcher to delegate to for retrieving bitstreams. */
054: private BitstreamDispatcher delegate = null;
055:
056: /**
057: * Default constructor uses PluginManager
058: */
059: public LimitedCountDispatcher() {
060: this ((BitstreamDispatcher) PluginManager
061: .getSinglePlugin(BitstreamDispatcher.class));
062: }
063:
064: /**
065: * Constructor.
066: *
067: * @param del
068: * The bitstream distpatcher to delegate to.
069: * @param count
070: * the number of bitstreams to check.
071: */
072: public LimitedCountDispatcher(BitstreamDispatcher del, int count) {
073: this (del);
074: remaining = count;
075: }
076:
077: /**
078: * Constructor.
079: *
080: * @param del
081: * The bitstream distpatcher to delegate to.
082: */
083: public LimitedCountDispatcher(BitstreamDispatcher del) {
084: delegate = del;
085: }
086:
087: /**
088: * Retreives the next bitstream to be checked.
089: *
090: * @return the bitstream id
091: * @throws SQLException
092: * if database error occurs.
093: */
094: public int next() {
095: if (remaining > 0) {
096: remaining--;
097:
098: return delegate.next();
099: } else {
100: return BitstreamDispatcher.SENTINEL;
101: }
102: }
103: }
|