001: /*
002: * Copyright (C) 2005 - 2008 JasperSoft Corporation. All rights reserved.
003: * http://www.jaspersoft.com.
004: *
005: * Unless you have purchased a commercial license agreement from JasperSoft,
006: * the following license terms apply:
007: *
008: * This program is free software; you can redistribute it and/or modify
009: * it under the terms of the GNU General Public License version 2 as published by
010: * the Free Software Foundation.
011: *
012: * This program is distributed WITHOUT ANY WARRANTY; and without the
013: * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
014: * See the GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
018: * or write to:
019: *
020: * Free Software Foundation, Inc.,
021: * 59 Temple Place - Suite 330,
022: * Boston, MA USA 02111-1307
023: *
024: *
025: *
026: *
027: * SampleJRDataSourceFactory.java
028: *
029: * Created on 22 giugno 2003, 23.57
030: *
031: */
032:
033: package it.businesslogic.ireport.connection;
034:
035: import java.util.Vector;
036: import net.sf.jasperreports.engine.*;
037: import net.sf.jasperreports.engine.data.*;
038:
039: /**
040: *
041: * @author Administrator
042: */
043: public class SampleJRDataSourceFactory {
044:
045: // This is the method to call to get the datasource.
046: // The method must be static.....
047: public JRDataSource createDatasource() {
048: javax.swing.table.DefaultTableModel tm = new javax.swing.table.DefaultTableModel(
049: 4, 2);
050:
051: SampleBean person = new SampleBean();
052: person.setFirstName("Giulio");
053: person.setLastName("Toffoli");
054: person.setEmail("gt@businesslogic.it");
055: tm.setValueAt(person, 0, 0);
056: tm.setValueAt("Test value row 1 col 1", 0, 1);
057:
058: person = new SampleBean();
059: person.setFirstName("Teodor");
060: person.setLastName("Danciu");
061: person.setEmail("teodor@hotmail.com");
062: tm.setValueAt(person, 1, 0);
063: tm.setValueAt("Test value row 2 col 1", 1, 1);
064:
065: person = new SampleBean();
066: person.setFirstName("Mario");
067: person.setLastName("Rossi");
068: person.setEmail("mario@rossi.org");
069: tm.setValueAt(person, 2, 0);
070: tm.setValueAt("Test value row 3 col 1", 2, 1);
071:
072: person = new SampleBean();
073: person.setFirstName("Jennifer");
074: person.setLastName("Lopez");
075: person.setEmail("lopez@jennifer.com");
076: tm.setValueAt(person, 3, 0);
077: tm.setValueAt("Test value row 4 col 1", 3, 1);
078:
079: return new JRTableModelDataSource(tm);
080: }
081:
082: public JRDataSource createBeanCollectionDatasource() {
083:
084: return new JRBeanCollectionDataSource(createBeanCollection());
085: }
086:
087: public static Vector createBeanCollection() {
088: java.util.Vector coll = new java.util.Vector();
089:
090: SampleBean person = new SampleBean();
091: person.setFirstName("Giulio");
092: person.setLastName("Toffoli");
093: person.setEmail("gt@businesslogic.it");
094: coll.add(person);
095:
096: person = new SampleBean();
097: person.setFirstName("Teodor");
098: person.setLastName("Danciu");
099: person.setEmail("teodor@hotmail.com");
100: coll.add(person);
101:
102: person = new SampleBean();
103: person.setFirstName("Mario");
104: person.setLastName("Rossi");
105: person.setEmail("mario@rossi.org");
106: coll.add(person);
107:
108: person = new SampleBean();
109: person.setFirstName("Jennifer");
110: person.setLastName("Lopez");
111: person.setEmail("lopez@jennifer.com");
112: coll.add(person);
113:
114: return coll;
115: }
116: }
|