Hello,<br />
<br />
i programmed a ODA Driver and want integrate it in a Java program.<br />
<br />
There is a great example to use the JDBC-Oda Driver in a Java class:<br />
<a class='bbc_url' href='
http://wiki.eclipse.org/Java_-_Build_Dynamic_Table_(BIRT)'>Java - Build Dynamic Table (BIRT) - Eclipsepedia</a><br />
<br />
For my training, i would like to integrate the google_oda_driver:<br />
(in order to know how to do it with my oda driver)<br />
<br />
Here you can download the google oda driver:<br />
<a class='bbc_url' href='
http://individual.utoronto.ca/kuong/...-oda_1.0.0.zip'>http://individual.utoronto.ca/kuong/...-oda_1.0.0.zip</a><br />
<br />
The both jar files (runtime and ui) i copied to the eclipseplugins folder.<br />
<br />
And changed the methods buildDataSource() and buildDataSets() class DECreateDynamicTable following:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
package Demo;
import java.io.IOException;
import java.util.ArrayList;
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.model.api.CellHandle;
import org.eclipse.birt.report.model.api.DataItemHandle;
import org.eclipse.birt.report.model.api.DesignConfig;
import org.eclipse.birt.report.model.api.ElementFactory;
import org.eclipse.birt.report.model.api.IDesignEngine;
import org.eclipse.birt.report.model.api.IDesignEngineFactory;
import org.eclipse.birt.report.model.api.LabelHandle;
import org.eclipse.birt.report.model.api.OdaDataSetHandle;
import org.eclipse.birt.report.model.api.OdaDataSourceHandle;
import org.eclipse.birt.report.model.api.PropertyHandle;
import org.eclipse.birt.report.model.api.ReportDesignHandle;
import org.eclipse.birt.report.model.api.RowHandle;
import org.eclipse.birt.report.model.api.SessionHandle;
import org.eclipse.birt.report.model.api.StructureFactory;
import org.eclipse.birt.report.model.api.TableHandle;
import org.eclipse.birt.report.model.api.activity.SemanticException;
import org.eclipse.birt.report.model.api.elements.structures.ComputedColumn;
import com.ibm.icu.util.ULocale;
/**
* Dynamic Table BIRT Design Engine API (DEAPI) demo.
*/
public class CopyOfDECreateDynamicTable
{
ReportDesignHandle designHandle = null;
ElementFactory designFactory = null;
StructureFactory structFactory = null;
public static void main( String[] args )
{
try
{
CopyOfDECreateDynamicTable de = new CopyOfDECreateDynamicTable();
ArrayList al = new ArrayList();
al.add("Nr1");
al.add("Nr2");
al.add("Nr3");
al.add("Nr4");
al.add("Nr5");
al.add("Nr6");
al.add("Nr7");
de.buildReport(al );
}
catch ( IOException e )
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch ( SemanticException e )
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
void buildDataSource( ) throws SemanticException
{
OdaDataSourceHandle dsHandle = designFactory.newOdaDataSource(
"Data Source", "org.eclipse.datatools.connectivity.oda.google" );
dsHandle.setProperty( "username", "info@innoventsolutions.com" );;
dsHandle.setProperty( "password", "innovent2007" );
designHandle.getDataSources( ).add( dsHandle );
}
void buildDataSet( ) throws SemanticException
{
OdaDataSetHandle dsHandle = designFactory.newOdaDataSet( "ds",
"org.eclipse.datatools.connectivity.oda.google.dataSet" );
dsHandle.setDataSource( "Data Source" );
String qry = "http://spreadsheets.google.com/feeds/list/o05323973627365490072.7329113802600165656/od7/private/full";
dsHandle.setQueryText( qry );
designHandle.getDataSets( ).add( dsHandle );
}
void buildReport(ArrayList cols ) throws IOException, SemanticException
{
//Configure the Engine and start the Platform
DesignConfig config = new DesignConfig( );
config.setProperty("BIRT_HOME", "C:/java/birt-runtime-2_5_0/ReportEngine");
IDesignEngine engine = null;
try{
Platform.startup( config );
IDesignEngineFactory factory = (IDesignEngineFactory) Platform
.createFactoryObject( IDesignEngineFactory.EXTENSION_DESIGN_ENGINE_FACTORY );
engine = factory.createDesignEngine( config );
}catch( Exception ex){
ex.printStackTrace();
}
SessionHandle session = engine.newSessionHandle( ULocale.ENGLISH ) ;
try{
//open a design or a template
designHandle = session.createDesign();
designFactory = designHandle.getElementFactory( );
buildDataSource();
buildDataSet( );
TableHandle table = designFactory.newTableItem( "table", cols.size() );
table.setWidth( "100%" );
table.setDataSet( designHandle.findDataSet( "ds" ) );
PropertyHandle computedSet = table.getColumnBindings( );
ComputedColumn cs1 = null;
for( int i=0; i < cols.size(); i++){
cs1 = StructureFactory.createComputedColumn();
cs1.setName((String)cols.get(i));
cs1.setExpression("dataSetRow["" + (String)cols.get(i) + ""]");
computedSet.addItem(cs1);
}
// table header
RowHandle tableheader = (RowHandle) table.getHeader( ).get( 0 );
for( int i=0; i < cols.size(); i++){
LabelHandle label1 = designFactory.newLabel( (String)cols.get(i) );
label1.setText((String)cols.get(i));
CellHandle cell = (CellHandle) tableheader.getCells( ).get( i );
cell.getContent( ).add( label1 );
}
// table detail
RowHandle tabledetail = (RowHandle) table.getDetail( ).get( 0 );
for( int i=0; i < cols.size(); i++){
CellHandle cell = (CellHandle) tabledetail.getCells( ).get( i );
DataItemHandle data = designFactory.newDataItem( "data_"+(String)cols.get(i) );
data.setResultSetColumn( (String)cols.get(i));
cell.getContent( ).add( data );
}
designHandle.getBody( ).add( table );
// Save the design and close it.
designHandle.saveAs( "c:/tmp/VielleichtGehts.rptdesign" ); //$NON-NLS-1$
designHandle.close( );
System.out.println("Finished");
}catch (Exception e){
e.printStackTrace();
}
}
}
</pre>
<br />
Now, when i run the program, i get a java.lang.NullPointerException:<br />
<br />
java.lang.NullPointerException<br />
at Demo.CopyOfDECreateDynamicTable.buildDataSource(CopyOfDECreateDynamicTable.java:70)<br />
at Demo.CopyOfDECreateDynamicTable.buildReport(CopyOfDECreateDynamicTable.java:124)<br />
at Demo.CopyOfDECreateDynamicTable.main(CopyOfDECreateDynamicTable.java:51)<br />
<br />
I would be pleased to get help.<br />
<br />
Thank you.<br />
<br />
Best regards<br />
Jenny