List of usage examples for org.springframework.util CollectionUtils findValueOfType
@Nullable public static Object findValueOfType(Collection<?> collection, Class<?>[] types)
From source file:ua.com.manometer.jasperreports.AbstractJasperReportsView.java
/** * Create a populated <code>JasperPrint</code> instance from the configured * <code>JasperReport</code> instance. * <p>By default, this method will use any <code>JRDataSource</code> instance * (or wrappable <code>Object</code>) that can be located using {@link #setReportDataKey}, * a lookup for type <code>JRDataSource</code> in the model Map, or a special value * retrieved via {@link #getReportData}. * <p>If no <code>JRDataSource</code> can be found, this method will use a JDBC * <code>Connection</code> obtained from the configured <code>javax.sql.DataSource</code> * (or a DataSource attribute in the model). If no JDBC DataSource can be found * either, the JasperReports engine will be invoked with plain model Map, * assuming that the model contains parameters that identify the source * for report data (e.g. Hibernate or JPA queries). * @param model the model for this request * @throws IllegalArgumentException if no <code>JRDataSource</code> can be found * and no <code>javax.sql.DataSource</code> is supplied * @throws SQLException if there is an error when populating the report using * the <code>javax.sql.DataSource</code> * @throws JRException if there is an error when populating the report using * a <code>JRDataSource</code> * @return the populated <code>JasperPrint</code> instance * @see #getReportData/*from w ww. j a v a2 s.c o m*/ * @see #setJdbcDataSource */ protected JasperPrint fillReport(Map<String, Object> model) throws Exception { // Determine main report. JasperReport report = getReport(); if (report == null) { throw new IllegalStateException("No main report defined for 'fillReport' - " + "specify a 'url' on this view or override 'getReport()' or 'fillReport(Map)'"); } JRDataSource jrDataSource = null; DataSource jdbcDataSourceToUse = null; // Try model attribute with specified name. if (this.reportDataKey != null) { Object reportDataValue = model.get(this.reportDataKey); if (reportDataValue instanceof DataSource) { jdbcDataSourceToUse = (DataSource) reportDataValue; } else { jrDataSource = convertReportData(reportDataValue); } } else { Collection values = model.values(); jrDataSource = CollectionUtils.findValueOfType(values, JRDataSource.class); if (jrDataSource == null) { JRDataSourceProvider provider = CollectionUtils.findValueOfType(values, JRDataSourceProvider.class); if (provider != null) { jrDataSource = createReport(provider); } else { jdbcDataSourceToUse = CollectionUtils.findValueOfType(values, DataSource.class); if (jdbcDataSourceToUse == null) { jdbcDataSourceToUse = this.jdbcDataSource; } } } } if (jdbcDataSourceToUse != null) { return doFillReport(report, model, jdbcDataSourceToUse); } else { // Determine JRDataSource for main report. if (jrDataSource == null) { jrDataSource = getReportData(model); } if (jrDataSource != null) { // Use the JasperReports JRDataSource. if (logger.isDebugEnabled()) { logger.debug("Filling report with JRDataSource [" + jrDataSource + "]"); } return JasperFillManager.fillReport(report, model, jrDataSource); } else { // Assume that the model contains parameters that identify // the source for report data (e.g. Hibernate or JPA queries). logger.debug("Filling report with plain model"); return JasperFillManager.fillReport(report, model); } } }
From source file:ua.com.manometer.jasperreports.AbstractJasperReportsView.java
/** * Create an appropriate <code>JRDataSource</code> for passed-in report data. * Called by {@link #fillReport} when its own lookup steps were not successful. * <p>The default implementation looks for a value of type <code>java.util.Collection</code> * or object array (in that order). Can be overridden in subclasses. * @param model the model map, as passed in for view rendering * @return the <code>JRDataSource</code> or <code>null</code> if the data source is not found * @see #getReportDataTypes/* www . j a v a 2s. c o m*/ * @see #convertReportData */ protected JRDataSource getReportData(Map<String, Object> model) { // Try to find matching attribute, of given prioritized types. Object value = CollectionUtils.findValueOfType(model.values(), getReportDataTypes()); return (value != null ? convertReportData(value) : null); }
From source file:org.springframework.amqp.rabbit.connection.RabbitResourceHolder.java
public Connection getConnection(Class<? extends Connection> connectionType) { return CollectionUtils.findValueOfType(this.connections, connectionType); }
From source file:org.springframework.jms.connection.JmsResourceHolder.java
@Nullable public Connection getConnection(Class<? extends Connection> connectionType) { return CollectionUtils.findValueOfType(this.connections, connectionType); }
From source file:org.springframework.jms.connection.JmsResourceHolder.java
@Nullable public Session getSession(Class<? extends Session> sessionType, @Nullable Connection connection) { List<Session> sessions = (connection != null ? this.sessionsPerConnection.get(connection) : this.sessions); return CollectionUtils.findValueOfType(sessions, sessionType); }