1 28 package net.sf.jasperreports.engine.data; 29 30 import java.util.Collection ; 31 import java.util.Iterator ; 32 33 import net.sf.jasperreports.engine.JRException; 34 import net.sf.jasperreports.engine.JRField; 35 36 37 41 public class JRBeanCollectionDataSource extends JRAbstractBeanDataSource 42 { 43 44 45 48 private Collection data = null; 49 private Iterator iterator = null; 50 private Object currentBean = null; 51 52 53 56 public JRBeanCollectionDataSource(Collection beanCollection) 57 { 58 this(beanCollection, true); 59 } 60 61 62 65 public JRBeanCollectionDataSource(Collection beanCollection, boolean isUseFieldDescription) 66 { 67 super(isUseFieldDescription); 68 69 this.data = beanCollection; 70 71 if (this.data != null) 72 { 73 this.iterator = this.data.iterator(); 74 } 75 } 76 77 78 81 public boolean next() 82 { 83 boolean hasNext = false; 84 85 if (this.iterator != null) 86 { 87 hasNext = this.iterator.hasNext(); 88 89 if (hasNext) 90 { 91 this.currentBean = this.iterator.next(); 92 } 93 } 94 95 return hasNext; 96 } 97 98 99 102 public Object getFieldValue(JRField field) throws JRException 103 { 104 return getFieldValue(currentBean, field); 105 } 106 107 108 111 public void moveFirst() 112 { 113 if (this.data != null) 114 { 115 this.iterator = this.data.iterator(); 116 } 117 } 118 119 120 } 121 | Popular Tags |