xdev.reports.jasper.JRVirtualTableFormattedDataSource Maven / Gradle / Ivy
package xdev.reports.jasper;
/*-
* #%L
* XDEV BI Suite
* %%
* Copyright (C) 2011 - 2020 XDEV Software
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* .
* #L%
*/
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRField;
import xdev.lang.NotNull;
import xdev.vt.VirtualTable;
import xdev.vt.VirtualTableColumn;
import xdev.vt.VirtualTableException;
import xdev.vt.XdevClob;
/**
*
* {@link VirtualTable} data source implementation that allows to access the
* formatted data of a {@link VirtualTable}.
*
*
* {@link JRVirtualTableDataSource} uses the format settings of the underlining
* {@link VirtualTable}.
*
*
*
* If you don't want to use the format settings of the {@link VirtualTable} in
* your report see {@link JRVirtualTableFormattedDataSource}.
*
*
*
* @author XDEV Software
*
*/
public class JRVirtualTableFormattedDataSource extends AbstractVirtualTableDataSource
{
/**
* Straight forward constructor to wrap a given (non-null)
* {@link VirtualTable}.
*
* @param virtualTable
* the {@link VirtualTable} to wrap
*/
public JRVirtualTableFormattedDataSource(@NotNull final VirtualTable virtualTable)
{
super(virtualTable);
}
/**
* Retrieves the formatted value for column jrField
in the
* current row. Lookup is done by field name (column name).
*
* @param jrField
* the {@link JRField} instance defining (by name) the column of
* the {@link VirtualTableException} whose formatted value shall
* be retrieved.
* @return the formatted value in the wrapped {@link VirtualTable} instance
* from current row, column jrField
* @throws JRException
* if the column (specified by jrField.getName()
)
* could not be found or accessed
*/
@Override
public Object getFieldValue(@NotNull final JRField jrField) throws JRException
{
try
{
VirtualTableColumn> column = this.virtualTable.getColumn(jrField.getName());
switch(column.getType())
{
case BINARY:
return this.getBinaryFieldValue(jrField);
case LONGVARBINARY:
return this.getBinaryFieldValue(jrField);
case VARBINARY:
return this.getBinaryFieldValue(jrField);
case BLOB:
return this.getBinaryFieldValue(jrField);
case CLOB:
return ((XdevClob)this.virtualTable.getValueAt(this.currentRowIndex,
jrField.getName())).toJDBCClob();
default:
return this.virtualTable.getFormattedValueAt(this.currentRowIndex,
jrField.getName());
}
}
catch(Exception e)
{
throw new JRException("Unable to get value for field '" + jrField.getName(),e);
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy