KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > web > servlet > view > jasperreports > ConfigurableJasperReportsView


1 /*
2  * Copyright 2002-2006 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.web.servlet.view.jasperreports;
18
19 import net.sf.jasperreports.engine.JRExporter;
20
21 import org.springframework.beans.BeanUtils;
22
23 /**
24  * Configurable JasperReports View, allowing to specify the JasperReports exporter
25  * to be specified through bean properties rather than through the view class name.
26  *
27  * @author Rob Harrop
28  * @since 2.0
29  * @see JasperReportsCsvView
30  * @see JasperReportsHtmlView
31  * @see JasperReportsPdfView
32  * @see JasperReportsXlsView
33  */

34 public class ConfigurableJasperReportsView extends AbstractJasperReportsSingleFormatView {
35
36     private Class JavaDoc exporterClass;
37
38     private boolean useWriter = true;
39
40
41     /**
42      * Set the {@link JRExporter} implementation <code>Class</code> to use. Throws
43      * {@link IllegalArgumentException} if the <code>Class</code> doesn't implement
44      * {@link JRExporter}. Required setting, as it does not have a default.
45      */

46     public void setExporterClass(Class JavaDoc exporterClass) {
47         if (!(JRExporter.class.isAssignableFrom(exporterClass))) {
48             throw new IllegalArgumentException JavaDoc(
49                     "Exporter class [" + exporterClass.getName() + "] does not implement JRExporter");
50         }
51         this.exporterClass = exporterClass;
52     }
53
54     /**
55      * Specifies whether or not the {@link JRExporter} writes to the {@link java.io.PrintWriter}
56      * of the associated with the request (<code>true</code>) or whether it writes directly to the
57      * {@link java.io.InputStream} of the request (<code>false</code>). Default is <code>true</code>.
58      */

59     public void setUseWriter(boolean useWriter) {
60         this.useWriter = useWriter;
61     }
62
63     /**
64      * Checks that the {@link #setExporterClass(Class) exporterClass} property is specified.
65      */

66     protected void onInit() {
67         if (this.exporterClass == null) {
68             throw new IllegalArgumentException JavaDoc("exporterClass is required");
69         }
70     }
71
72
73     /**
74      * Returns a new instance of the specified {@link JRExporter} class.
75      * @see #setExporterClass(Class)
76      * @see BeanUtils#instantiateClass(Class)
77      */

78     protected JRExporter createExporter() {
79         return (JRExporter) BeanUtils.instantiateClass(this.exporterClass);
80     }
81
82     /**
83      * Indicates how the {@link JRExporter} should render its data.
84      * @see #setUseWriter(boolean)
85      */

86     protected boolean useWriter() {
87         return this.useWriter;
88     }
89
90 }
91
Popular Tags