Task 3:  
Create the main( ) method to test the code
Add a main( ) method to run the class.
1  
public static void main( String[] args ) throws Exception
{
}
An error indicating that the BirtException class is not defined appears.
2  
3  
Listing 31-1  
DesignConfig config = new DesignConfig( );
config.setBIRTHome( BIRT_HOME );
 
DesignEngine engine = new DesignEngine( config );
SessionHandle sessionHandle = engine.newSessionHandle( ULocale.ENGLISH );
ReportDesignHandle designHandle = sessionHandle.createDesign();
ElementFactory factory = designHandle.getElementFactory( );
 
DataMartDataSourceHandle dataSource = factory.newDataMartDataSource( "Data Source" );
dataSource.setDataMartURL( "include" );
dataSource.setAccessType( DesignChoiceConstants.ACCESS_TYPE_TRANSIENT );
designHandle.getDataSources( ).add( dataSource );
 
FileOutputStream fos = new FileOutputStream("test.rptdesign");
designHandle.serialize( fos );
fos.close( );
 
designHandle.close( );
System.out.println("Done");
Read the code explanations:
*
*
After creating the engine object, the code instantiates a new session. The SessionHandle object manages the state of all open data and report designs. Use SessionHandle to open, close, and create data designs, and to set global properties, such as the locale and the units of measure for data elements. Create the session handle only once. BIRT supports only a single SessionHandle.
*
Generate a new design handle using the SessionHandle object. Create a design engine element factory using the DesignHandle object.
*
Create a new instance of DataMartDataSourceHandle and set the datamart URL to the name of a datamart file, include, which corresponds to the include.datadesign file added to the project. Then, configure the access type and add the data source handle to the design handle object.
*
Finally, open a file output stream to a report design, test.rptdesign, that uses the data object. Export the data design element to the report design.
4  
Listing 31-2  
import java.io.FileOutputStream;
import org.eclipse.birt.core.exception.BirtException;
import org.eclipse.birt.report.model.api.DesignConfig;
import org.eclipse.birt.report.model.api.DesignEngine;
import org.eclipse.birt.report.model.api.ElementFactory;
import org.eclipse.birt.report.model.api.ReportDesignHandle;
import org.eclipse.birt.report.model.api.SessionHandle;
import org.eclipse.birt.report.model.api.elements.DesignChoiceConstants;
import com.actuate.birt.report.model.api.DataMartDataSourceHandle;
import com.ibm.icu.util.ULocale;

Additional Links:

Copyright Actuate Corporation 2012