Tutorial 1: Creating a data element using the Design Engine API
This tutorial provides step-by-step instructions for creating a Java class that generates a BIRT report design with a BIRT data source generated from a BIRT data design file. You perform the following tasks:
To compile a Design Engine API application, the design engine Java archive (JAR) files from Actuate iHub must be in your classpath. You can find the design engine JAR files in the <Actuate home>/modules/BIRTiHub/iHub/Jar/BIRT/lib directory folder. The main JAR files that contain the design engine classes are coreapi.jar and modelapi.jar files. In addition, you need a data design file from which to generate the data objects. For this tutorial, the data design file is include.datadesign.
1 In Java perspective, select File➛New➛Project. New Project appears, as shown in Figure 8‑1.
Figure 8‑1 Creating a new project
2 Expand Java, select Java Project, and choose Next. New Java Project appears, as shown in Figure 8‑2.
Figure 8‑2 Creating the DataObjectExample project
3 In Project Name type:
DataObjectExample
4 In Project layout, select:
Use project folder as root for sources and class files
5 Choose Next. Java Settings appears.
6 Set the project build path.
1 Select the Libraries tab.
2 Choose Add External JARs.
3 In JAR Selection, navigate to the iHub\Jar\BIRT\lib directory. For the default installation of BIRT on Windows, this directory is:
4 Choose Finish. GenerateDataObject.java opens in the Java editor.
5 Add a BIRT_HOME static variable to the class. For the default installation of iHub on a Windows system, use the following line in the body of the GenerateDataObject class body:
FileOutputStream fos = new FileOutputStream("test.rptdesign");
designHandle.serialize( fos );
fos.close( );
designHandle.close( );
System.out.println("Done");
Read the code explanations:
To access a data source and its contents, the application must first generate and configure a design engine object.
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 Add the import statements shown in Listing 8‑2 to the beginning of the file.
5 Create a Run configuration for GenerateDataObject.java class.
1 In Package Explorer, select:
GenerateDataObject.java
2 From the main menu, choose Run➛Run 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: