Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: jac/aspects/gui/reports/JacDataSource.java


1   /*
2     Copyright (C) 2003 Laurent Martelli <laurent@aopsys.com>
3     
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU Lesser General Public License as
6     published by the Free Software Foundation; either version 2 of the
7     License, or (at your option) any later version.
8   
9     This program is distributed in the hope that it will be useful, but
10    WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    Lesser General Public License for more details.
13  
14    You should have received a copy of the GNU Lesser General Public
15    License along with this program; if not, write to the Free Software
16    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17    USA */
18  
19  package jac.aspects.gui.reports;
20  
21  import dori.jasper.engine.JRDataSource;
22  import dori.jasper.engine.JRException;
23  import dori.jasper.engine.JRField;
24  import jac.core.rtti.ClassItem;
25  import jac.core.ObjectRepository;
26  import java.util.Iterator;
27  
28  /**
29   * A data source for JasperReports.
30   */
31  public class JacDataSource implements JRDataSource {
32     ClassItem cl;
33     Iterator it;
34     Object current;
35  
36     /**
37      * Create a data source of all instances of a class.
38      */
39     public JacDataSource(ClassItem cl) {
40        this.cl = cl;
41     }
42  
43     // implementation of dori.jasper.engine.JRDataSource interface
44  
45     public boolean next() throws JRException
46     {
47        if (it==null) {
48           it = ObjectRepository.getObjects(cl).iterator();
49        }
50        boolean result = it.hasNext();
51        if (result)
52           current = it.next();
53        return result;
54     }
55  
56     public Object getFieldValue(JRField field) throws JRException
57     {
58        if (current==null) {
59           throw new JRException("No current "+cl.getName()+
60                                 " object to get field "+field.getName());
61        } else {
62           return cl.getField(field.getName()).getThroughAccessor(current);
63        }
64     }
65  
66  }