KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > it > businesslogic > ireport > connection > SampleJRDataSourceFactory


1 /*
2  * Copyright (C) 2005 - 2006 JasperSoft Corporation. All rights reserved.
3  * http://www.jaspersoft.com.
4  *
5  * Unless you have purchased a commercial license agreement from JasperSoft,
6  * the following license terms apply:
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as published by
10  * the Free Software Foundation.
11  *
12  * This program is distributed WITHOUT ANY WARRANTY; and without the
13  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
18  * or write to:
19  *
20  * Free Software Foundation, Inc.,
21  * 59 Temple Place - Suite 330,
22  * Boston, MA USA 02111-1307
23  *
24  *
25  *
26  *
27  * SampleJRDataSourceFactory.java
28  *
29  * Created on 22 giugno 2003, 23.57
30  *
31  */

32
33 package it.businesslogic.ireport.connection;
34 import java.util.Vector JavaDoc;
35 import net.sf.jasperreports.engine.*;
36 import net.sf.jasperreports.engine.data.*;
37
38 /**
39  *
40  * @author Administrator
41  */

42 public class SampleJRDataSourceFactory {
43     
44     // This is the method to call to get the datasource.
45
// The method must be static.....
46
public JRDataSource createDatasource()
47     {
48         javax.swing.table.DefaultTableModel JavaDoc tm = new javax.swing.table.DefaultTableModel JavaDoc(4,2);
49         
50         SampleBean person = new SampleBean();
51         person.setFirstName("Giulio");
52         person.setLastName("Toffoli");
53         person.setEmail("gt@businesslogic.it");
54         tm.setValueAt(person, 0, 0);
55         tm.setValueAt("Test value row 1 col 1", 0, 1);
56         
57         person = new SampleBean();
58         person.setFirstName("Teodor");
59         person.setLastName("Danciu");
60         person.setEmail("teodor@hotmail.com");
61         tm.setValueAt(person, 1, 0);
62         tm.setValueAt("Test value row 2 col 1", 1, 1);
63         
64         person = new SampleBean();
65         person.setFirstName("Mario");
66         person.setLastName("Rossi");
67         person.setEmail("mario@rossi.org");
68         tm.setValueAt(person, 2, 0);
69         tm.setValueAt("Test value row 3 col 1", 2, 1);
70         
71         person = new SampleBean();
72         person.setFirstName("Jennifer");
73         person.setLastName("Lopez");
74         person.setEmail("lopez@jennifer.com");
75         tm.setValueAt(person, 3, 0);
76         tm.setValueAt("Test value row 4 col 1", 3, 1);
77         
78         return new JRTableModelDataSource(tm);
79     }
80     
81      public JRDataSource createBeanCollectionDatasource()
82     {
83         
84         
85         return new JRBeanCollectionDataSource(createBeanCollection());
86     }
87      
88      public static Vector JavaDoc createBeanCollection()
89      {
90             java.util.Vector JavaDoc coll = new java.util.Vector JavaDoc();
91         
92         SampleBean person = new SampleBean();
93         person.setFirstName("Giulio");
94         person.setLastName("Toffoli");
95         person.setEmail("gt@businesslogic.it");
96         coll.add(person);
97         
98         person = new SampleBean();
99         person.setFirstName("Teodor");
100         person.setLastName("Danciu");
101         person.setEmail("teodor@hotmail.com");
102         coll.add(person);
103         
104         person = new SampleBean();
105         person.setFirstName("Mario");
106         person.setLastName("Rossi");
107         person.setEmail("mario@rossi.org");
108         coll.add(person);
109         
110         person = new SampleBean();
111         person.setFirstName("Jennifer");
112         person.setLastName("Lopez");
113         person.setEmail("lopez@jennifer.com");
114         coll.add(person);
115     
116         return coll;
117      }
118 }
119
Popular Tags