@SuppressWarnings( "unused" )
private PentahoTableDataFactory getJarDataFactory() throws Exception {
PentahoTableDataFactory factory = null;
if ( isDefinedResource( AbstractJFreeReportComponent.DATACOMPONENT_JARINPUT ) ) {
final IActionSequenceResource resource = getResource( AbstractJFreeReportComponent.DATACOMPONENT_JARINPUT );
final InputStream in;
try {
in = resource.getInputStream( RepositoryFilePermission.READ, LocaleHelper.getLocale() );
try {
// not being able to read a single char is definitly a big boo ..
if ( in.read() == -1 ) {
throw new Exception( Messages.getInstance().getErrorString( "JFreeReport.ERROR_0009_REPORT_JAR_UNREADABLE" ) ); //$NON-NLS-1$
} else {
final ClassLoader loader = ReportUtils.createJarLoader( getSession(), resource );
if ( loader == null ) {
throw new Exception( Messages.getInstance().getString(
"JFreeReportDataComponent.ERROR_0035_COULD_NOT_CREATE_CLASSLOADER" ) ); //$NON-NLS-1$
} else if ( !isDefinedInput( AbstractJFreeReportComponent.DATACOMPONENT_CLASSLOCINPUT ) ) {
throw new Exception( Messages.getInstance().getErrorString(
"JFreeReport.ERROR_0012_CLASS_LOCATION_MISSING" ) ); //$NON-NLS-1$
} else {
final String classLocation =
getInputStringValue( AbstractJFreeReportComponent.DATACOMPONENT_CLASSLOCINPUT );
// Get input parameters, and set them as properties in the report
// object.
final ReportParameterValues reportProperties = new ReportParameterValues();
final Set paramNames = getInputNames();
final Iterator it = paramNames.iterator();
while ( it.hasNext() ) {
final String paramName = (String) it.next();
final Object paramValue = getInputValue( paramName );
if ( paramValue instanceof Object[] ) {
final Object[] values = (Object[]) paramValue;
final StringBuffer valuesBuffer = new StringBuffer();
// TODO support non-string items
for ( int i = 0; i < values.length; i++ ) {
if ( i == 0 ) {
valuesBuffer.append( values[i].toString() );
} else {
valuesBuffer.append( ',' ).append( values[i].toString() );
}
}
reportProperties.put( paramName, valuesBuffer.toString() );
} else {
reportProperties.put( paramName, paramValue );
}
}
final DataFactory dataFactory = new PentahoDataFactory( loader );
final TableModel model = dataFactory.queryData( classLocation, new ParameterDataRow( reportProperties ) );
factory = new PentahoTableDataFactory( AbstractJFreeReportComponent.DATACOMPONENT_DEFAULTINPUT, model );
}
}
} catch ( Exception e ) {
throw new Exception( Messages.getInstance().getErrorString( "JFreeReport.ERROR_0009_REPORT_JAR_UNREADABLE" ) ); //$NON-NLS-1$
}
} catch ( FileNotFoundException e1 ) {
throw new Exception( Messages.getInstance().getErrorString(
"JFreeReport.ERROR_0010_REPORT_JAR_MISSING", resource.getAddress() ) ); //$NON-NLS-1$
}
}
return factory;
}