refined use of generics
This commit is contained in:
parent
fba8bcc7dc
commit
8c8eca7e05
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2006 the original author or authors.
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -19,6 +19,7 @@ package org.springframework.web.servlet.view.jasperreports;
|
|||
import net.sf.jasperreports.engine.JRExporter;
|
||||
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Configurable JasperReports View, allowing to specify the JasperReports exporter
|
||||
|
|
@ -33,7 +34,7 @@ import org.springframework.beans.BeanUtils;
|
|||
*/
|
||||
public class ConfigurableJasperReportsView extends AbstractJasperReportsSingleFormatView {
|
||||
|
||||
private Class exporterClass;
|
||||
private Class<? extends JRExporter> exporterClass;
|
||||
|
||||
private boolean useWriter = true;
|
||||
|
||||
|
|
@ -43,11 +44,8 @@ public class ConfigurableJasperReportsView extends AbstractJasperReportsSingleFo
|
|||
* {@link IllegalArgumentException} if the <code>Class</code> doesn't implement
|
||||
* {@link JRExporter}. Required setting, as it does not have a default.
|
||||
*/
|
||||
public void setExporterClass(Class exporterClass) {
|
||||
if (!(JRExporter.class.isAssignableFrom(exporterClass))) {
|
||||
throw new IllegalArgumentException(
|
||||
"Exporter class [" + exporterClass.getName() + "] does not implement JRExporter");
|
||||
}
|
||||
public void setExporterClass(Class<? extends JRExporter> exporterClass) {
|
||||
Assert.isAssignable(JRExporter.class, exporterClass);
|
||||
this.exporterClass = exporterClass;
|
||||
}
|
||||
|
||||
|
|
@ -78,7 +76,7 @@ public class ConfigurableJasperReportsView extends AbstractJasperReportsSingleFo
|
|||
*/
|
||||
@Override
|
||||
protected JRExporter createExporter() {
|
||||
return (JRExporter) BeanUtils.instantiateClass(this.exporterClass);
|
||||
return BeanUtils.instantiateClass(this.exporterClass);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -82,7 +82,7 @@ public class JasperReportsMultiFormatView extends AbstractJasperReportsView {
|
|||
* Stores the format mappings, with the format discriminator
|
||||
* as key and the corresponding view class as value.
|
||||
*/
|
||||
private Map<String, Class> formatMappings;
|
||||
private Map<String, Class<? extends AbstractJasperReportsView>> formatMappings;
|
||||
|
||||
/**
|
||||
* Stores the mappings of mapping keys to Content-Disposition header values.
|
||||
|
|
@ -95,7 +95,7 @@ public class JasperReportsMultiFormatView extends AbstractJasperReportsView {
|
|||
* with a default set of mappings.
|
||||
*/
|
||||
public JasperReportsMultiFormatView() {
|
||||
this.formatMappings = new HashMap<String, Class>(4);
|
||||
this.formatMappings = new HashMap<String, Class<? extends AbstractJasperReportsView>>(4);
|
||||
this.formatMappings.put("csv", JasperReportsCsvView.class);
|
||||
this.formatMappings.put("html", JasperReportsHtmlView.class);
|
||||
this.formatMappings.put("pdf", JasperReportsPdfView.class);
|
||||
|
|
@ -120,7 +120,7 @@ public class JasperReportsMultiFormatView extends AbstractJasperReportsView {
|
|||
* <li><code>xls</code> - <code>JasperReportsXlsView</code></li>
|
||||
* </ul>
|
||||
*/
|
||||
public void setFormatMappings(Map<String, Class> formatMappings) {
|
||||
public void setFormatMappings(Map<String, Class<? extends AbstractJasperReportsView>> formatMappings) {
|
||||
if (CollectionUtils.isEmpty(formatMappings)) {
|
||||
throw new IllegalArgumentException("'formatMappings' must not be empty");
|
||||
}
|
||||
|
|
@ -173,7 +173,7 @@ public class JasperReportsMultiFormatView extends AbstractJasperReportsView {
|
|||
logger.debug("Rendering report using format mapping key [" + format + "]");
|
||||
}
|
||||
|
||||
Class viewClass = this.formatMappings.get(format);
|
||||
Class<? extends AbstractJasperReportsView> viewClass = this.formatMappings.get(format);
|
||||
if (viewClass == null) {
|
||||
throw new IllegalArgumentException("Format discriminator [" + format + "] is not a configured mapping");
|
||||
}
|
||||
|
|
@ -182,7 +182,7 @@ public class JasperReportsMultiFormatView extends AbstractJasperReportsView {
|
|||
logger.debug("Rendering report using view class [" + viewClass.getName() + "]");
|
||||
}
|
||||
|
||||
AbstractJasperReportsView view = (AbstractJasperReportsView) BeanUtils.instantiateClass(viewClass);
|
||||
AbstractJasperReportsView view = BeanUtils.instantiateClass(viewClass);
|
||||
// Can skip most initialization since all relevant URL processing
|
||||
// has been done - just need to convert parameters on the sub view.
|
||||
view.setExporterParameters(getExporterParameters());
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -21,8 +21,6 @@ import java.util.Map;
|
|||
import java.util.Properties;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import net.sf.jasperreports.engine.design.JRCompiler;
|
||||
|
||||
import org.springframework.web.servlet.view.AbstractUrlBasedView;
|
||||
import org.springframework.web.servlet.view.UrlBasedViewResolver;
|
||||
|
||||
|
|
@ -48,8 +46,6 @@ public class JasperReportsViewResolver extends UrlBasedViewResolver {
|
|||
|
||||
private DataSource jdbcDataSource;
|
||||
|
||||
private JRCompiler reportCompiler;
|
||||
|
||||
|
||||
/**
|
||||
* Requires the view class to be a subclass of {@link AbstractJasperReportsView}.
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -23,16 +23,6 @@ import org.springframework.context.support.StaticApplicationContext;
|
|||
*/
|
||||
public abstract class AbstractConfigurableJasperReportsViewTests extends AbstractJasperReportsViewTests {
|
||||
|
||||
public void testSetInvalidExporterClass() throws Exception {
|
||||
try {
|
||||
new ConfigurableJasperReportsView().setExporterClass(String.class);
|
||||
fail("Should not be able to set invalid view class.");
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
// success
|
||||
}
|
||||
}
|
||||
|
||||
public void testNoConfiguredExporter() throws Exception {
|
||||
ConfigurableJasperReportsView view = new ConfigurableJasperReportsView();
|
||||
view.setUrl(COMPILED_REPORT);
|
||||
|
|
@ -44,4 +34,5 @@ public abstract class AbstractConfigurableJasperReportsViewTests extends Abstrac
|
|||
// success
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -78,7 +78,8 @@ public class JasperReportsMultiFormatViewTests extends AbstractJasperReportsView
|
|||
|
||||
JasperReportsMultiFormatView view = (JasperReportsMultiFormatView) getView(UNCOMPILED_REPORT);
|
||||
|
||||
Map<String, Class> mappings = new HashMap<String, Class>();
|
||||
Map<String, Class<? extends AbstractJasperReportsView>> mappings =
|
||||
new HashMap<String, Class<? extends AbstractJasperReportsView>>();
|
||||
mappings.put("test", ExporterParameterTestView.class);
|
||||
|
||||
Map<String, String> exporterParameters = new HashMap<String, String>();
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -28,7 +28,8 @@ public class JasperReportsMultiFormatViewWithCustomMappingsTests extends JasperR
|
|||
protected AbstractJasperReportsView getViewImplementation() {
|
||||
JasperReportsMultiFormatView view = new JasperReportsMultiFormatView();
|
||||
view.setFormatKey("fmt");
|
||||
Map<String, Class> mappings = new HashMap<String, Class>();
|
||||
Map<String, Class<? extends AbstractJasperReportsView>> mappings =
|
||||
new HashMap<String, Class<? extends AbstractJasperReportsView>>();
|
||||
mappings.put("csv", JasperReportsCsvView.class);
|
||||
mappings.put("comma-separated", JasperReportsCsvView.class);
|
||||
mappings.put("html", JasperReportsHtmlView.class);
|
||||
|
|
|
|||
Loading…
Reference in New Issue