KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jasperreports > engine > JasperFillManager


1 /*
2  * ============================================================================
3  * GNU Lesser General Public License
4  * ============================================================================
5  *
6  * JasperReports - Free Java report-generating library.
7  * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * JasperSoft Corporation
24  * 303 Second Street, Suite 450 North
25  * San Francisco, CA 94107
26  * http://www.jaspersoft.com
27  */

28 package net.sf.jasperreports.engine;
29
30 import java.io.File JavaDoc;
31 import java.io.InputStream JavaDoc;
32 import java.io.OutputStream JavaDoc;
33 import java.sql.Connection JavaDoc;
34 import java.util.Map JavaDoc;
35
36 import net.sf.jasperreports.engine.fill.JRFiller;
37 import net.sf.jasperreports.engine.util.JRLoader;
38 import net.sf.jasperreports.engine.util.JRSaver;
39
40
41 /**
42  * Fašade class for filling compiled report designs with data from report data sources,
43  * in order to produce page-oriented documents, ready-to-print.
44  * <p>
45  * All methods receive a Map object that should contain the values for the report parameters.
46  * These value are retrieved by the engine using the corresponding report parameter name as the key.
47  * <p>
48  * There are two types of method signatures with regards to the data source
49  * provided for filling the report:
50  * <ul>
51  * <li>Methods that receive an instance of the {@link net.sf.jasperreports.engine.JRDataSource} interface
52  * and use it directly for retrieving report data;
53  * <li>Methods that receive an instance of the {@link java.sql.Connection} interface and retrieve
54  * the report data by executing the report internal SQL query through this JDBC connection and wrapping
55  * the returned {@link java.sql.ResultSet} object inside a {@link net.sf.jasperreports.engine.JRResultSetDataSource}
56  * instance.
57  * </ul>
58  *
59  * @see net.sf.jasperreports.engine.JasperReport
60  * @see net.sf.jasperreports.engine.JRDataSource
61  * @see net.sf.jasperreports.engine.fill.JRFiller
62  * @see net.sf.jasperreports.engine.JasperPrint
63  * @author Teodor Danciu (teodord@users.sourceforge.net)
64  * @version $Id: JasperFillManager.java 1229 2006-04-19 13:27:35 +0300 (Wed, 19 Apr 2006) teodord $
65  */

66 public class JasperFillManager
67 {
68
69
70     /**
71      * Fills the compiled report design loaded from the specified file.
72      * The result of this operation is another file that will contain the serialized
73      * {@link JasperPrint} object representing the generated document,
74      * having the same name as the report design as declared in the source file,
75      * plus the <code>*.jrprint</code> extension, located in the same directory as the source file.
76      *
77      * @param sourceFileName source file containing the compile report design
78      * @param parameters report parameters map
79      * @param connection JDBC connection object to use for executing the report internal SQL query
80      */

81     public static String JavaDoc fillReportToFile(
82         String JavaDoc sourceFileName,
83         Map JavaDoc parameters,
84         Connection JavaDoc connection
85         ) throws JRException
86     {
87         File JavaDoc sourceFile = new File JavaDoc(sourceFileName);
88
89         JasperReport jasperReport = (JasperReport)JRLoader.loadObject(sourceFile);
90
91         File JavaDoc destFile = new File JavaDoc(sourceFile.getParent(), jasperReport.getName() + ".jrprint");
92         String JavaDoc destFileName = destFile.toString();
93
94         fillReportToFile(jasperReport, destFileName, parameters, connection);
95         
96         return destFileName;
97     }
98
99
100     /**
101      * Fills the compiled report design loaded from the specified file.
102      * The result of this operation is another file that will contain the serialized
103      * {@link JasperPrint} object representing the generated document,
104      * having the same name as the report design as declared in the source file,
105      * plus the <code>*.jrprint</code> extension, located in the same directory as the source file.
106      *
107      * @param sourceFileName source file containing the compile report design
108      * @param parameters report parameters map
109      * @see JRFiller#fillReport(JasperReport, Map)
110      */

111     public static String JavaDoc fillReportToFile(
112         String JavaDoc sourceFileName,
113         Map JavaDoc parameters
114         ) throws JRException
115     {
116         File JavaDoc sourceFile = new File JavaDoc(sourceFileName);
117
118         JasperReport jasperReport = (JasperReport)JRLoader.loadObject(sourceFile);
119
120         File JavaDoc destFile = new File JavaDoc(sourceFile.getParent(), jasperReport.getName() + ".jrprint");
121         String JavaDoc destFileName = destFile.toString();
122
123         fillReportToFile(jasperReport, destFileName, parameters);
124         
125         return destFileName;
126     }
127
128     
129     /**
130      * Fills the compiled report design loaded from the file received as the first parameter
131      * and places the result in the file specified by the second parameter.
132      *
133      * @param sourceFileName source file containing the compile report design
134      * @param destFileName file name to place the generated report into
135      * @param parameters report parameters map
136      * @param connection JDBC connection object to use for executing the report internal SQL query
137      */

138     public static void fillReportToFile(
139         String JavaDoc sourceFileName,
140         String JavaDoc destFileName,
141         Map JavaDoc parameters,
142         Connection JavaDoc connection
143         ) throws JRException
144     {
145         JasperReport jasperReport = (JasperReport)JRLoader.loadObject(sourceFileName);
146
147         fillReportToFile(jasperReport, destFileName, parameters, connection);
148     }
149
150     
151     /**
152      * Fills the compiled report design loaded from the file received as the first parameter
153      * and places the result in the file specified by the second parameter.
154      *
155      * @param sourceFileName source file containing the compile report design
156      * @param destFileName file name to place the generated report into
157      * @param parameters report parameters map
158      * @see JRFiller#fillReport(JasperReport, Map)
159      */

160     public static void fillReportToFile(
161         String JavaDoc sourceFileName,
162         String JavaDoc destFileName,
163         Map JavaDoc parameters
164         ) throws JRException
165     {
166         JasperReport jasperReport = (JasperReport)JRLoader.loadObject(sourceFileName);
167
168         fillReportToFile(jasperReport, destFileName, parameters);
169     }
170
171     
172     /**
173      * Fills the compiled report design received as the first parameter
174      * and places the result in the file specified by the second parameter.
175      *
176      * @param jasperReport compiled report design object to use for filling
177      * @param destFileName file name to place the generated report into
178      * @param parameters report parameters map
179      * @param connection JDBC connection object to use for executing the report internal SQL query
180      */

181     public static void fillReportToFile(
182         JasperReport jasperReport,
183         String JavaDoc destFileName,
184         Map JavaDoc parameters,
185         Connection JavaDoc connection
186         ) throws JRException
187     {
188         JasperPrint jasperPrint = fillReport(jasperReport, parameters, connection);
189
190         JRSaver.saveObject(jasperPrint, destFileName);
191     }
192
193     
194     /**
195      * Fills the compiled report design received as the first parameter
196      * and places the result in the file specified by the second parameter.
197      *
198      * @param jasperReport compiled report design object to use for filling
199      * @param destFileName file name to place the generated report into
200      * @param parameters report parameters map
201      * @see JRFiller#fillReport(JasperReport, Map)
202      */

203     public static void fillReportToFile(
204         JasperReport jasperReport,
205         String JavaDoc destFileName,
206         Map JavaDoc parameters
207         ) throws JRException
208     {
209         JasperPrint jasperPrint = fillReport(jasperReport, parameters);
210
211         JRSaver.saveObject(jasperPrint, destFileName);
212     }
213
214     
215     /**
216      * Fills the compiled report design loaded from the specified file and returns
217      * the generated report object.
218      *
219      * @param sourceFileName source file containing the compile report design
220      * @param parameters report parameters map
221      * @param connection JDBC connection object to use for executing the report internal SQL query
222      * @return generated report object
223      */

224     public static JasperPrint fillReport(
225         String JavaDoc sourceFileName,
226         Map JavaDoc parameters,
227         Connection JavaDoc connection
228         ) throws JRException
229     {
230         File JavaDoc sourceFile = new File JavaDoc(sourceFileName);
231
232         JasperReport jasperReport = (JasperReport)JRLoader.loadObject(sourceFile);
233
234         return fillReport(jasperReport, parameters, connection);
235     }
236
237     
238     /**
239      * Fills the compiled report design loaded from the specified file and returns
240      * the generated report object.
241      *
242      * @param sourceFileName source file containing the compile report design
243      * @param parameters report parameters map
244      * @return generated report object
245      * @see JRFiller#fillReport(JasperReport, Map)
246      */

247     public static JasperPrint fillReport(
248         String JavaDoc sourceFileName,
249         Map JavaDoc parameters
250         ) throws JRException
251     {
252         File JavaDoc sourceFile = new File JavaDoc(sourceFileName);
253
254         JasperReport jasperReport = (JasperReport)JRLoader.loadObject(sourceFile);
255
256         return fillReport(jasperReport, parameters);
257     }
258
259     
260     /**
261      * Fills the compiled report design loaded from the supplied input stream and writes
262      * the generated report object to the output stream specified by the second parameter.
263      *
264      * @param inputStream input stream to read the compiled report design object from
265      * @param outputStream output stream to write the generated report object to
266      * @param parameters report parameters map
267      * @param connection JDBC connection object to use for executing the report internal SQL query
268      */

269     public static void fillReportToStream(
270         InputStream JavaDoc inputStream,
271         OutputStream JavaDoc outputStream,
272         Map JavaDoc parameters,
273         Connection JavaDoc connection
274         ) throws JRException
275     {
276         JasperReport jasperReport = (JasperReport)JRLoader.loadObject(inputStream);
277
278         fillReportToStream(jasperReport, outputStream, parameters, connection);
279     }
280
281     
282     /**
283      * Fills the compiled report design loaded from the supplied input stream and writes
284      * the generated report object to the output stream specified by the second parameter.
285      *
286      * @param inputStream input stream to read the compiled report design object from
287      * @param outputStream output stream to write the generated report object to
288      * @param parameters report parameters map
289      * @see JRFiller#fillReport(JasperReport, Map)
290      */

291     public static void fillReportToStream(
292         InputStream JavaDoc inputStream,
293         OutputStream JavaDoc outputStream,
294         Map JavaDoc parameters
295         ) throws JRException
296     {
297         JasperReport jasperReport = (JasperReport)JRLoader.loadObject(inputStream);
298
299         fillReportToStream(jasperReport, outputStream, parameters);
300     }
301
302     
303     /**
304      * Fills the compiled report design supplied as the first parameter and writes
305      * the generated report object to the output stream specified by the second parameter.
306      *
307      * @param jasperReport compiled report design object to use for filling
308      * @param outputStream output stream to write the generated report object to
309      * @param parameters report parameters map
310      * @param connection JDBC connection object to use for executing the report internal SQL query
311      */

312     public static void fillReportToStream(
313         JasperReport jasperReport,
314         OutputStream JavaDoc outputStream,
315         Map JavaDoc parameters,
316         Connection JavaDoc connection
317         ) throws JRException
318     {
319         JasperPrint jasperPrint = fillReport(jasperReport, parameters, connection);
320
321         JRSaver.saveObject(jasperPrint, outputStream);
322     }
323
324     
325     /**
326      * Fills the compiled report design supplied as the first parameter and writes
327      * the generated report object to the output stream specified by the second parameter.
328      *
329      * @param jasperReport compiled report design object to use for filling
330      * @param outputStream output stream to write the generated report object to
331      * @param parameters report parameters map
332      * @see JRFiller#fillReport(JasperReport, Map)
333      */

334     public static void fillReportToStream(
335         JasperReport jasperReport,
336         OutputStream JavaDoc outputStream,
337         Map JavaDoc parameters
338         ) throws JRException
339     {
340         JasperPrint jasperPrint = fillReport(jasperReport, parameters);
341
342         JRSaver.saveObject(jasperPrint, outputStream);
343     }
344
345     
346     /**
347      * Fills the compiled report design loaded from the supplied input stream and returns
348      * the generated report object.
349      *
350      * @param inputStream input stream to read the compiled report design object from
351      * @param parameters report parameters map
352      * @param connection JDBC connection object to use for executing the report internal SQL query
353      * @return generated report object
354      */

355     public static JasperPrint fillReport(
356         InputStream JavaDoc inputStream,
357         Map JavaDoc parameters,
358         Connection JavaDoc connection
359         ) throws JRException
360     {
361         JasperReport jasperReport = (JasperReport)JRLoader.loadObject(inputStream);
362
363         return fillReport(jasperReport, parameters, connection);
364     }
365
366     
367     /**
368      * Fills the compiled report design loaded from the supplied input stream and returns
369      * the generated report object.
370      *
371      * @param inputStream input stream to read the compiled report design object from
372      * @param parameters report parameters map
373      * @return generated report object
374      * @see JRFiller#fillReport(JasperReport, Map)
375      */

376     public static JasperPrint fillReport(
377         InputStream JavaDoc inputStream,
378         Map JavaDoc parameters
379         ) throws JRException
380     {
381         JasperReport jasperReport = (JasperReport)JRLoader.loadObject(inputStream);
382
383         return fillReport(jasperReport, parameters);
384     }
385
386     
387     /**
388      * Fills the compiled report design supplied as the first parameter and returns
389      * the generated report object.
390      *
391      * @param jasperReport compiled report design object to use for filling
392      * @param parameters report parameters map
393      * @param connection JDBC connection object to use for executing the report internal SQL query
394      * @return generated report object
395      */

396     public static JasperPrint fillReport(
397         JasperReport jasperReport,
398         Map JavaDoc parameters,
399         Connection JavaDoc connection
400         ) throws JRException
401     {
402         return JRFiller.fillReport(jasperReport, parameters, connection);
403     }
404
405     
406     /**
407      * Fills the compiled report design supplied as the first parameter and returns
408      * the generated report object.
409      *
410      * @param jasperReport compiled report design object to use for filling
411      * @param parameters report parameters map
412      * @return generated report object
413      * @see JRFiller#fillReport(JasperReport, Map)
414      */

415     public static JasperPrint fillReport(
416         JasperReport jasperReport,
417         Map JavaDoc parameters
418         ) throws JRException
419     {
420         return JRFiller.fillReport(jasperReport, parameters);
421     }
422
423     
424     /**
425      * Fills the compiled report design loaded from the specified file.
426      * The result of this operation is another file that will contain the serialized
427      * {@link JasperPrint} object representing the generated document,
428      * having the same name as the report design as declared in the source file,
429      * plus the <code>*.jrprint</code> extension, located in the same directory as the source file.
430      *
431      * @param sourceFileName source file containing the compile report design
432      * @param parameters report parameters map
433      * @param dataSource data source object
434      */

435     public static String JavaDoc fillReportToFile(
436         String JavaDoc sourceFileName,
437         Map JavaDoc parameters,
438         JRDataSource dataSource
439         ) throws JRException
440     {
441         File JavaDoc sourceFile = new File JavaDoc(sourceFileName);
442
443         JasperReport jasperReport = (JasperReport)JRLoader.loadObject(sourceFile);
444
445         File JavaDoc destFile = new File JavaDoc(sourceFile.getParent(), jasperReport.getName() + ".jrprint");
446         String JavaDoc destFileName = destFile.toString();
447
448         fillReportToFile(jasperReport, destFileName, parameters, dataSource);
449         
450         return destFileName;
451     }
452
453     
454     /**
455      * Fills the compiled report design loaded from the file received as the first parameter
456      * and places the result in the file specified by the second parameter.
457      *
458      * @param sourceFileName source file containing the compile report design
459      * @param destFileName file name to place the generated report into
460      * @param parameters report parameters map
461      * @param dataSource data source object
462      */

463     public static void fillReportToFile(
464         String JavaDoc sourceFileName,
465         String JavaDoc destFileName,
466         Map JavaDoc parameters,
467         JRDataSource dataSource
468         ) throws JRException
469     {
470         JasperReport jasperReport = (JasperReport)JRLoader.loadObject(sourceFileName);
471
472         fillReportToFile(jasperReport, destFileName, parameters, dataSource);
473     }
474
475     
476     /**
477      * Fills the compiled report design received as the first parameter
478      * and places the result in the file specified by the second parameter.
479      *
480      * @param jasperReport compiled report design object to use for filling
481      * @param destFileName file name to place the generated report into
482      * @param parameters report parameters map
483      * @param dataSource data source object
484      */

485     public static void fillReportToFile(
486         JasperReport jasperReport,
487         String JavaDoc destFileName,
488         Map JavaDoc parameters,
489         JRDataSource dataSource
490         ) throws JRException
491     {
492         JasperPrint jasperPrint = fillReport(jasperReport, parameters, dataSource);
493
494         JRSaver.saveObject(jasperPrint, destFileName);
495     }
496
497     
498     /**
499      * Fills the compiled report design loaded from the specified file and returns
500      * the generated report object.
501      *
502      * @param sourceFileName source file containing the compile report design
503      * @param parameters report parameters map
504      * @param dataSource data source object
505      * @return generated report object
506      */

507     public static JasperPrint fillReport(
508         String JavaDoc sourceFileName,
509         Map JavaDoc parameters,
510         JRDataSource dataSource
511         ) throws JRException
512     {
513         File JavaDoc sourceFile = new File JavaDoc(sourceFileName);
514
515         JasperReport jasperReport = (JasperReport)JRLoader.loadObject(sourceFile);
516
517         return fillReport(jasperReport, parameters, dataSource);
518     }
519
520     
521     /**
522      * Fills the compiled report design loaded from the supplied input stream and writes
523      * the generated report object to the output stream specified by the second parameter.
524      *
525      * @param inputStream input stream to read the compiled report design object from
526      * @param outputStream output stream to write the generated report object to
527      * @param parameters report parameters map
528      * @param dataSource data source object
529      */

530     public static void fillReportToStream(
531         InputStream JavaDoc inputStream,
532         OutputStream JavaDoc outputStream,
533         Map JavaDoc parameters,
534         JRDataSource dataSource
535         ) throws JRException
536     {
537         JasperReport jasperReport = (JasperReport)JRLoader.loadObject(inputStream);
538
539         fillReportToStream(jasperReport, outputStream, parameters, dataSource);
540     }
541
542     
543     /**
544      * Fills the compiled report design supplied as the first parameter and writes
545      * the generated report object to the output stream specified by the second parameter.
546      *
547      * @param jasperReport compiled report design object to use for filling
548      * @param outputStream output stream to write the generated report object to
549      * @param parameters report parameters map
550      * @param dataSource data source object
551      */

552     public static void fillReportToStream(
553         JasperReport jasperReport,
554         OutputStream JavaDoc outputStream,
555         Map JavaDoc parameters,
556         JRDataSource dataSource
557         ) throws JRException
558     {
559         JasperPrint jasperPrint = fillReport(jasperReport, parameters, dataSource);
560
561         JRSaver.saveObject(jasperPrint, outputStream);
562     }
563
564     
565     /**
566      * Fills the compiled report design loaded from the supplied input stream and returns
567      * the generated report object.
568      *
569      * @param inputStream input stream to read the compiled report design object from
570      * @param parameters report parameters map
571      * @param dataSource data source object
572      * @return generated report object
573      */

574     public static JasperPrint fillReport(
575         InputStream JavaDoc inputStream,
576         Map JavaDoc parameters,
577         JRDataSource dataSource
578         ) throws JRException
579     {
580         JasperReport jasperReport = (JasperReport)JRLoader.loadObject(inputStream);
581
582         return fillReport(jasperReport, parameters, dataSource);
583     }
584
585     
586     /**
587      * Fills the compiled report design supplied as the first parameter and returns
588      * the generated report object.
589      *
590      * @param jasperReport compiled report design object to use for filling
591      * @param parameters report parameters map
592      * @param dataSource data source object
593      * @return generated report object
594      */

595     public static JasperPrint fillReport(
596         JasperReport jasperReport,
597         Map JavaDoc parameters,
598         JRDataSource dataSource
599         ) throws JRException
600     {
601         return JRFiller.fillReport(jasperReport, parameters, dataSource);
602     }
603
604
605 }
606
Popular Tags