1 24 25 package org.ofbiz.content.report; 26 27 import java.util.Collection ; 28 import java.util.Iterator ; 29 import java.util.Map ; 30 31 import net.sf.jasperreports.engine.JRDataSource; 32 import net.sf.jasperreports.engine.JRException; 33 import net.sf.jasperreports.engine.JRField; 34 35 41 public class JRMapCollectionDataSource implements JRDataSource { 42 43 private Collection data = null; 44 private Iterator iterator = null; 45 private Map currentMap = null; 46 47 public JRMapCollectionDataSource(Collection mapCollection) { 48 this.data = mapCollection; 49 50 if (data != null) { 51 this.iterator = data.iterator(); 52 } 53 } 54 55 public boolean next() throws JRException { 56 boolean hasNext = false; 57 58 if (this.iterator != null) { 59 hasNext = this.iterator.hasNext(); 60 61 if (hasNext) { 62 try { 63 this.currentMap = (Map ) this.iterator.next(); 64 } catch (Exception e) { 65 throw new JRException("Current collection object does not seem to be a Map.", e); 66 } 67 } 68 } 69 70 return hasNext; 71 } 72 73 public Object getFieldValue(JRField jrField) throws JRException { 74 Object value = null; 75 76 if (currentMap != null) { 77 value = currentMap.get(jrField.getName()); 78 } 79 80 return value; 81 } 82 83 } 84 | Popular Tags |