Using the BIRT data object API : Tutorial 5: Creating a data element using the Design Engine API : Task 4: Run the code
 
Task 4: Run the code
5 Create a Run configuration for GenerateDataObject.java class.
1 In Package Explorer, select:
GenerateDataObject.java
2 From the main menu, choose RunRun Configurations.
3 Double-click the Java Application link in the left frame of Run Configurations. The GenerateDataObjects configuration gets created.
4 Choose Run. Save and Launch appears. Choose OK.
6 After the execution completes, refresh the contents of the DataObjectExample project. test.rptdesign appears.
7 Open the report design and view the XML source. The XML contains a datamart element that points to include.datadesign and a data source called include, as shown in the following code:
<datamart-node location="file:/DataObjectExample/include.datadesign">
...
<data-sources>
<data-mart-data-source name="Data Source" id="4">
<property name="datamartURL">include</property>
<property name="accessType">transient</property>
</data-mart-data-source>
</data-sources>
8 In Data Explorer, expand Data Sources to view the new data source, as shown in Figure 28‑6.
Figure 28‑6 Data Source in test.rptdesign
The final code for GenerateDataObject is shown in Listing 28‑3.
Listing 28‑3 GenerateDataObject.java
package myPackage;
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.DataMartCubeHandle;
import com.actuate.birt.report.model.api.DataMartDataSourceHandle;
import com.ibm.icu.util.ULocale;
 
public class GenerateDataObject {
 
private static final String BIRT_HOME = "C:/Program Files/Actuate/iHub2/Jar/BIRT/platform";
 
public static void main( String[] args ) throws Exception
{
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");
}
}