KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > text > template > ListBeanDataHandler


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

5 package org.exoplatform.text.template;
6
7 import java.util.ArrayList JavaDoc;
8 import java.util.List JavaDoc;
9
10 /**
11  * @author Tuan Nguyen (tuan08@users.sourceforge.net)
12  * @since Feb 2, 2005
13  * @version $Id$
14  */

15 public class ListBeanDataHandler extends BeanDataHandler implements CollectionDataHandler {
16   protected List JavaDoc beans_;
17   protected int currentRow_;
18   
19   public ListBeanDataHandler(Class JavaDoc type) {
20     super(type) ;
21   }
22   
23   public ListBeanDataHandler setBeans(List JavaDoc beans) {
24     beans_ = beans;
25     return this;
26   }
27   
28   public ListBeanDataHandler setBeans(Object JavaDoc[] beans) {
29     beans_ = new ArrayList JavaDoc(beans.length + 3);
30     for(int i = 0 ; i < beans.length; i++) {
31       beans_.add(beans[i]);
32     }
33     return this;
34   }
35   
36   public void begin() {
37     currentRow_ = -1;
38   }
39   
40   public void end() {
41   }
42   
43   public boolean nextRow() {
44     currentRow_++;
45     if (beans_ != null) {
46       if (currentRow_ < beans_.size()) {
47         setBean(beans_.get(currentRow_));
48         return true;
49       }
50     }
51     return false;
52   }
53   
54   public int getCurrentRow() { return currentRow_; }
55   
56   public Object JavaDoc getCurrentBean() { return beans_.get(currentRow_); }
57   
58   public Object JavaDoc getBean(int index) { return beans_.get(index); }
59   
60   public List JavaDoc getBeans() { return beans_ ; }
61 }
62
Popular Tags