Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Java Event Handle Not Found
liaojinmei
I am trying to dynamically create a design and have it use a scripted data set. Here is my code, but I am getting "myPackage.MockEventHandle" not found" error. The MockEventHandle is in the same jar file as the BirtEngineService. I thought since I set the task's appContext classLoader to be the loader that loads my BirtEngineService, it should be able to find the MockEventHandle class too. Am I missing something?
My BirtEngineService class:
public class BirtEngineService
{
private static Logger log = Logger.getLogger(BirtEngineService.class);
private ServletContext context = null;
private IReportEngine reportEngine = null;
private IDesignEngine designEngine = null;
private IDatabase db = null;
private void createAndRunTable(HttpServletResponse resp) throws Exception{
SessionHandle session = designEngine.newSessionHandle( ULocale.ENGLISH ) ;
// Create a new report design.
ReportDesignHandle design = session.createDesign( );
// The element factory creates instances of the various BIRT elements.
ElementFactory efactory = design.getElementFactory( );
DesignElementHandle element = efactory.newSimpleMasterPage( "Page Master" );
design.getMasterPages( ).add( element );
// add the datasource and dataset
ScriptDataSourceHandle dataSourceHandle = efactory.newScriptDataSource("Data Source");
design.getDataSources().add(dataSourceHandle);
ScriptDataSetHandle dataSetHandle = efactory.newScriptDataSet("Data Set");
dataSetHandle.setDataSource("Data Source");
dataSetHandle.setEventHandlerClass("myPackage.MockEventHandle");
design.getDataSets().add(dataSetHandle);
// add the table
TableHandle table = efactory.newTableItem("table", 2);
table.setWidth("80%");
table.setDataSet(dataSetHandle);
design.getBody().add(table);
IReportRunnable report = reportEngine.openReportDesign(design);
IRunAndRenderTask task = reportEngine.createRunAndRenderTask( report );
Map appContext = task.getAppContext();
ClassLoader loader = BirtEngineService.class.getClassLoader();
appContext.put(EngineConstants.APPCONTEXT_CLASSLOADER_KEY, loader);
Connection con = db.getConnection();
appContext.put("OdaJDBCDriverPassInConnection", con);
//set output options
HTMLRenderOption options = new HTMLRenderOption();
//set the image handler to a HTMLServerImageHandler if you plan on using the base image url.
options.setImageHandler(new HTMLServerImageHandler());
options.setOutputFormat(HTMLRenderOption.OUTPUT_FORMAT_HTML);
options.setOutputStream(resp.getOutputStream());
options.setBaseImageURL("images");
options.setImageDirectory(context.getRealPath("/images"));
task.setRenderOption(options);
//run report
task.run();
task.close();
}
}
My MockEventHandle class:
public class MockEventHandle extends ScriptedDataSetEventAdapter
{
private int index = 0;
private int size;
public void open( IDataSetInstance dataSet )
{
size = 5;
}
public boolean fetch( IDataSetInstance dataSet, IUpdatableDataSetRow row )
{
if(index>=size) return false;
try
{
row.setColumnValue("name", "name"+index);
row.setColumnValue("age", index);
}
catch (ScriptException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
index ++;
return true;
}
public void close( IDataSetInstance dataSet )
{
}
public boolean describe( IDataSetInstance dataSet,
IScriptedDataSetMetaData metaData )
{
metaData.addColumn("name", String.class);
metaData.addColumn("age", Integer.class);
return true;
}
}
Find more posts tagged with
Comments
JasonW
Any chance you could put it in its own jar and try
something like:
config.getAppContext().put(EngineConstants.WEBAPP_CLASSPATH_KEY, "c:/jars/mjo.jar");
Jason
liaojinmei
That would work. Thanks.