KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dspace > checker > LimitedCountDispatcher


1 /*
2  * Copyright (c) 2004-2005, Hewlett-Packard Company and Massachusetts
3  * Institute of Technology. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  * - Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * - Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * - Neither the name of the Hewlett-Packard Company nor the name of the
17  * Massachusetts Institute of Technology nor the names of their
18  * contributors may be used to endorse or promote products derived from
19  * this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
30  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
31  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
32  * DAMAGE.
33  */

34 package org.dspace.checker;
35
36 import java.sql.SQLException JavaDoc;
37
38 import org.dspace.core.PluginManager;
39
40 /**
41  * Decorator that dispatches a specified number of bitstreams from a delegate
42  * dispatcher.
43  *
44  * @author Jim Downing
45  * @author Grace Carpenter
46  * @author Nathan Sarr
47  *
48  */

49 public class LimitedCountDispatcher implements BitstreamDispatcher
50 {
51     /** The remaining number of bitstreams to iterate through. */
52     private int remaining = 1;
53
54     /** The dispatcher to delegate to for retrieving bitstreams. */
55     private BitstreamDispatcher delegate = null;
56
57     /**
58      * Default constructor uses PluginManager
59      */

60     public LimitedCountDispatcher()
61     {
62         this((BitstreamDispatcher) PluginManager
63                 .getSinglePlugin(BitstreamDispatcher.class));
64     }
65
66     /**
67      * Constructor.
68      *
69      * @param del
70      * The bitstream distpatcher to delegate to.
71      * @param count
72      * the number of bitstreams to check.
73      */

74     public LimitedCountDispatcher(BitstreamDispatcher del, int count)
75     {
76         this(del);
77         remaining = count;
78     }
79
80     /**
81      * Constructor.
82      *
83      * @param del
84      * The bitstream distpatcher to delegate to.
85      */

86     public LimitedCountDispatcher(BitstreamDispatcher del)
87     {
88         delegate = del;
89     }
90
91     /**
92      * Retreives the next bitstream to be checked.
93      *
94      * @return the bitstream id
95      * @throws SQLException
96      * if database error occurs.
97      */

98     public int next()
99     {
100         if (remaining > 0)
101         {
102             remaining--;
103
104             return delegate.next();
105         }
106         else
107         {
108             return BitstreamDispatcher.SENTINEL;
109         }
110     }
111 }
112
Popular Tags