KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > myfaces > component > html > ext > _SerializableListDataModel


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.myfaces.component.html.ext;
17
18 import javax.faces.component.StateHolder;
19 import java.io.Serializable JavaDoc;
20 import java.util.ArrayList JavaDoc;
21 import java.util.List JavaDoc;
22
23 /**
24  * @author Manfred Geiler (latest modification by $Author: matze $)
25  * @version $Revision: 1.7 $ $Date: 2004/10/13 11:50:57 $
26  * %Log$
27  */

28 class _SerializableListDataModel
29         extends _SerializableDataModel
30 {
31     //private static final Log log = LogFactory.getLog(_SerializableDataModel.class);
32

33     public _SerializableListDataModel(int first, int rows, List JavaDoc list)
34     {
35         _first = first;
36         _rows = rows;
37         _rowCount = list.size();
38         if (_rows <= 0)
39         {
40             _rows = _rowCount - first;
41         }
42
43         if (_rows == _rowCount)
44         {
45             //whole list must be saved
46
if (list instanceof Serializable JavaDoc || list instanceof StateHolder)
47             {
48                 _list = list;
49             }
50             else
51             {
52                 //copy list
53
_list = new ArrayList JavaDoc(list);
54             }
55         }
56         else
57         {
58             int size = _rows > 0 && _rows < _rowCount ? _rows : _rowCount;
59             _list = new ArrayList JavaDoc(size);
60             if (size > _rowCount - _first)
61             {
62                 size = _rowCount - _first;
63             }
64             for (int i = 0; i < size; i++)
65             {
66                 _list.add(list.get(_first + i));
67             }
68         }
69     }
70 }
71
Popular Tags