Generating data object elements for BIRT report designs
To generate data object data sources, data sets, and cubes for a BIRT report design, first configure BIRT_HOME to access the Actuate commercial model API Java archive (JAR) files from Actuate iHub. To accomplish this task, generate a DesignConfig object with a custom BIRT_HOME path, as shown in the following code:
// Create an DesignConfig object.
DesignConfig config = new DesignConfig( );
// Set up the path to your BIRT Home Directory.
config.setBIRTHome("C:\Actuate3\BIRTiHubVisualization\modules\BIRTiHub\iHub\Jar\BIRT\platform");
Use the path to the iHub installation specific to your system.
Using this design configuration object, create and configure a Design Engine object, open a new session, and generate or open a report design object, as shown in the following code:
// Create the engine.
DesignEngine engine = new DesignEngine( config );
SessionHandle sessionHandle = engine.newSessionHandle( ULocale.ENGLISH );
ReportDesignHandle designHandle = sessionHandle.createDesign( );
These objects are contained in the model API package org.eclipse.birt.report.model.api.
The ElementFactory class supports access to all the elements in a report. The following code generates an Element Factory object:
ElementFactory factory = designHandle.getElementFactory( );
To generate data sources, data sets, and cubes, use the datamart methods of an ElementFactory object: newDataMartCube( ) for a new cube, newDataMartDataSet( ) for a data set, and newDataMartSource( ) for a new data source. For example, to instantiate a new data source, use the following code:
DataMartDataSourceHandle dataSource =
factory.newDataMartDataSource("Data Object Data Source");
Associate a handle for a data object data source with an actual data source from the contents of a data or data design file. For example, to associate a data source handle with a data source from test.datadesign, use the following code:
dataSource.setDataMartURL( "test" );
dataSource.setAccessType( DesignChoiceConstants.ACCESS_TYPE_TRANSIENT );
Finally, add the data element to the report design, as shown in the following code:
designHandle.getDataSources( ).add( dataSource );
To complete the data source assignment, output the report design into a file and close the design handle object, using code similar to the following:
FileOutputStream fos = new FileOutputStream( "output.rptdesign" );
designHandle.serialize( fos );
// Close the document.
fos.close( );
designHandle.close( );
The resulting output file, output.rptdesign, contains the new data source, retrieved from test.datadesign. This data source appears in Data Sources in Data Explorer and establishes a link to the .datadesign file, test.datadesign. The XML source for output.rptdesign includes markup similar to the following lines:
<datamart-node location="file:/MyProject/test.datadesign">
...
<data-sources>
<data-mart-data-source name="Data Object Data Source" id="7">
<property name="datamartURL">test</property>
<property name="accessType">transient</property>
</data-mart-data-source>
</data-sources>
When exporting this report design to a volume, also export test.datadesign to maintain the reference to the data source.
Creating data object data sets for BIRT report designs
To create a data object data set, use the newDataMartDataSet( ) method from ElementFactory. For example, to instantiate a new data set, use the following code:
DataMartDataSetHandle dataSet =
factory.newDataMartDataSet("Data Set");
Associate the data object data cube with a DataMartDataSourceHandle object and then add the name of a data set from the data or data design file. For example, to access a data set called "SetName", use the following code:
dataSet.setDataSource( dataSource.getName( ) );
dataSet.setDataObject( "SetName" );
DataMartDataSetHandle inherits the setDataSource( ) method from DataSetHandle.
Finally, add the data element to the report design, as shown in the following code:
designHandle.getDataSets( ).add( dataSet );
Creating data object data cubes for BIRT report designs
To create a data object data cube, use the newDataMartDataCube( ) method from ElementFactory. For example, to instantiate a new data cube, use the following code:
DataMartDataCubeHandle dataCube =
factory.newDataMartDataCube("Data Cube");
Associate the data object data cube with a DataMartDataSourceHandle object and assign a data cube from the data or data design file. For example, to access a data cube called "CubeName", use the following code:
dataCube.setDataSource( dataSource.getName( ) );
dataCube.setDataObject("CubeName");
Finally, add the data element to the report design, as shown in the following code:
designHandle.getDataCubes( ).add( dataCube );