1 28 package net.sf.jasperreports.engine.data; 29 30 import java.util.Collection ; 31 import java.util.Iterator ; 32 import java.util.Map ; 33 34 import net.sf.jasperreports.engine.JRField; 35 import net.sf.jasperreports.engine.JRRewindableDataSource; 36 37 41 public class JRMapCollectionDataSource implements JRRewindableDataSource 42 { 43 44 47 private Collection records = null; 48 private Iterator iterator = null; 49 private Map currentRecord = null; 50 51 52 55 public JRMapCollectionDataSource(Collection col) 56 { 57 records = col; 58 59 if (records != null) 60 { 61 iterator = records.iterator(); 62 } 63 } 64 65 66 69 public boolean next() 70 { 71 boolean hasNext = false; 72 73 if (iterator != null) 74 { 75 hasNext = iterator.hasNext(); 76 77 if (hasNext) 78 { 79 currentRecord = (Map )iterator.next(); 80 } 81 } 82 83 return hasNext; 84 } 85 86 87 90 public Object getFieldValue(JRField field) 91 { 92 Object value = null; 93 94 if (currentRecord != null) 95 { 96 value = currentRecord.get(field.getName()); 97 } 98 99 return value; 100 } 101 102 103 106 public void moveFirst() 107 { 108 if (records != null) 109 { 110 iterator = records.iterator(); 111 } 112 } 113 114 115 } 116 | Popular Tags |