KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > bsf > remoteIterator > common > RemoteIteratorResultTable


1 /* ******************************************************************************** *
2  * Copyright (c) 2002 - 2004 Bright Side Factory. All rights reserved. *
3  * *
4  * Redistribution and use in source and binary forms, with or without modification, *
5  * are permitted provided that the following conditions are met: *
6  * *
7  * 1. Redistributions of source code must retain the above copyright notice, this *
8  * list of conditions and the following disclaimer. *
9  * *
10  * 2. Redistributions in binary form must reproduce the above copyright notice, *
11  * this list of conditions and the following disclaimer in the documentation and/or *
12  * other materials provided with the distribution. *
13  * *
14  * 3. The end-user documentation included with the redistribution, if any, must *
15  * include the following acknowledgment: "This product includes software developed *
16  * by the Bright Side Factory (http://www.bs-factory.org/)." Alternately, this *
17  * acknowledgment may appear in the software itself, if and wherever such *
18  * third-party acknowledgments normally appear. *
19  * *
20  * 4. The names "Bright Side", "BS Framework" and "Bright Side Factory" must not be *
21  * used to endorse or promote products derived from this software without prior *
22  * written permission. For written permission, please contact info@bs-factory.org. *
23  * *
24  * 5. Products derived from this software may not be called "Bright Side", nor may *
25  * "Bright Side" appear in their name, without prior written permission of the *
26  * Bright Side Factory. *
27  * *
28  * THIS SOFTWARE IS PROVIDED ''AS IS'' BY THE COPYRIGHT OWNER AND ANY EXPRESSED OR *
29  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF *
30  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT *
31  * SHALL THE COPYRIGHT OWNER OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, *
32  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, *
33  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, *
34  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
35  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE *
36  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS OFTWARE, EVEN IF ADVISED *
37  * OF THE POSSIBILITY OF SUCH DAMAGE. *
38  * *
39  * ================================================================================ *
40  * *
41  * This software consists of voluntary contributions made by many individuals on *
42  * behalf of the Bright Side Factory. For more information on the Bright Side *
43  * Factory, please see http://www.bs-factory.org. *
44  * *
45  * ******************************************************************************** */

46 package org.bsf.remoteIterator.common;
47
48 import java.io.Serializable JavaDoc;
49 import java.util.ArrayList JavaDoc;
50 import java.util.List JavaDoc;
51
52 /**
53  * This class defines the RemoteIterator's result format expected by the client.
54  *
55  * @see org.bsf.remoteIterator.server.RemoteIteratorBean
56  */

57 public class RemoteIteratorResultTable implements Serializable JavaDoc {
58     public static final int RESULT_TABLE_DEFAULT_INITIAL_SIZE = 100;
59
60     // Flags to inform about the state of the ResultTable
61
private boolean _isLast;
62     private boolean _isFirst;
63     private boolean _isBeforeFirst;
64     private boolean _isAlreadyLast;
65
66     // Store the rows' values
67
private List JavaDoc _rows;
68
69     // Store the rows' indexes
70
private List JavaDoc _rowIndexes;
71
72     // *************************************************************************
73
// ****************************** Constructor ******************************
74
// *************************************************************************
75

76     /**
77      * Creates a RemoteIteratorResultTable using the RESULT_TABLE_DEFAULT_INITIAL_SIZE.
78      * If you an idea of how many rows will be in this ResultTable you should
79      * probably use other constructor. By specifying the number of rows you will
80      * prevent ongoing resize of the underlying Lists used to store the rows and
81      * the indexes.
82      *
83      * @see #RemoteIteratorResultTable( int p_size );
84      * @see #RESULT_TABLE_DEFAULT_INITIAL_SIZE
85      */

86     public RemoteIteratorResultTable() {
87         _rows = new ArrayList JavaDoc( RESULT_TABLE_DEFAULT_INITIAL_SIZE );
88         _rowIndexes = new ArrayList JavaDoc( RESULT_TABLE_DEFAULT_INITIAL_SIZE );
89     }
90
91     /**
92      * Creates a RemoteIteratorResultTable using the given int as the default
93      * size for the underlying Lists. Enables to prevent ongoing resize of the
94      * Lists. Should be used if you have an idea of how many rows will be in
95      * the Lists.
96      *
97      * @param p_initialSize The initial size of the underlying Lists.
98      *
99      * @see #RemoteIteratorResultTable()
100      */

101     public RemoteIteratorResultTable( int p_initialSize ) {
102         _rows = new ArrayList JavaDoc( p_initialSize );
103         _rowIndexes = new ArrayList JavaDoc( p_initialSize );
104     }
105
106     // *************************************************************************
107
// ******************************** Accessors ******************************
108
// *************************************************************************
109

110     /**
111      * @return the actual number of rows in this RemoteIteratorResultTable. Could
112      * be less than the final number if called before all the rows are added to
113      * it.
114      *
115      * @see #addRow
116      * @see org.bsf.remoteIterator.server.RemoteIteratorBean
117      */

118     public int getSize() {
119         return _rows.size();
120     }
121
122     public boolean isFirst() {
123         return _isFirst;
124     }
125
126     public void setFirst( boolean p_first ) {
127         _isFirst = p_first;
128     }
129
130     public boolean isLast() {
131         return _isLast;
132     }
133
134     public void setLast( boolean p_last ) {
135         _isLast = p_last;
136     }
137
138     public boolean isAlreadyLast() {
139         return _isAlreadyLast;
140     }
141
142     public void setAlreadyLast( boolean p_alreadyLast ) {
143         _isAlreadyLast = p_alreadyLast;
144     }
145
146     public boolean isBeforeFirst() {
147         return _isBeforeFirst;
148     }
149
150     public void setBeforeFirst( boolean p_beforeFirst ) {
151         _isBeforeFirst = p_beforeFirst;
152     }
153
154     public List JavaDoc getRows() {
155         return _rows;
156     }
157
158     public List JavaDoc getRowIndexes() {
159         return _rowIndexes;
160     }
161
162     /**
163      * adds the row (an arrayList) in the list of result.
164      * Used by the RI.
165      * @param p_rows
166      */

167     public void addRow( List JavaDoc p_rows, Integer JavaDoc p_rowsPosition ) {
168         _rows.add( p_rows );
169         _rowIndexes.add( p_rowsPosition );
170     }
171
172 }
173
Popular Tags