01: package org.romaframework.aspect.reporting.jr.ds;
02:
03: import java.util.Collection;
04: import java.util.Iterator;
05: import java.util.LinkedList;
06: import java.util.List;
07: import java.util.Map;
08: import java.util.NoSuchElementException;
09:
10: import net.sf.jasperreports.engine.JRException;
11: import net.sf.jasperreports.engine.JRField;
12: import net.sf.jasperreports.engine.JRRewindableDataSource;
13:
14: public class RomaHashMapListDataSource implements
15: JRRewindableDataSource {
16: public final static String FIELD_NAME = "source";
17:
18: List<Object> list = new LinkedList<Object>();
19:
20: Iterator<Object> iterator;
21:
22: Object current;
23:
24: public RomaHashMapListDataSource(
25: Collection<Map<String, Object>> iList) {
26: super ();
27: list.addAll(iList);
28: iterator = list.iterator();
29: }
30:
31: public void moveFirst() throws JRException {
32: iterator = list.iterator();
33: }
34:
35: public Object getFieldValue(JRField arg0) throws JRException {
36: if (arg0.getName().equals(FIELD_NAME)) {
37: if (current != null) {
38: return current;
39: } else {
40: return "";
41: }
42: } else {
43: throw new JRException("Field " + arg0.getName()
44: + " not defined in dataSource");
45: }
46: }
47:
48: public boolean next() throws JRException {
49: try {
50: current = iterator.next();
51: return true;
52: } catch (final NoSuchElementException e) {
53: return false;
54: }
55: }
56: }
|