亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊(cè) 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫(kù)
最近訪問板塊 發(fā)新帖
查看: 2803 | 回復(fù): 0
打印 上一主題 下一主題

BIRT Design API 學(xué)習(xí) [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2008-07-29 14:06 |只看該作者 |倒序?yàn)g覽
以下這個(gè)例子來自birt 的官方教材,我沒有改動(dòng)任何的信息.
這個(gè)例子演示了從建立DataSource ,然后建立DataSet , 動(dòng)態(tài)的根據(jù)輸入數(shù)據(jù)輸出report template .
關(guān)于Birt 的 API , 在 eclipse 的 help content 里面有,3.3 支持新的基于topic 的search ,可以幫我們簡(jiǎn)化搜索的topic , 其中有五個(gè)API (一共是5個(gè)) : Report Object Model API , Report Engine API , Birt Report Scripting API , Open Data Access API , Data Engine API .另外也提供詳細(xì)的講解每一個(gè)report 的元素的意思.非常好的一份資料 .

DECreateDynamicTable.java  例子code :

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 DECreateDynamicTable
{
    ReportDesignHandle designHandle = null;
    ElementFactory designFactory = null;
    StructureFactory structFactory = null;   

    public static void main( String[] args )
    {
        try
        {
            DECreateDynamicTable de = new DECreateDynamicTable();
            ArrayList al = new ArrayList();
            al.add("OFFICECODE");
            al.add("CITY");
            al.add("COUNTRY");
            
            de.buildReport(al, "From Offices" );
        }
        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.birt.report.data.oda.jdbc" );
        dsHandle.setProperty( "odaDriverClass",
                "org.eclipse.birt.report.data.oda.sampledb.Driver" );
        dsHandle.setProperty( "odaURL", "jdbc:classicmodels:sampledb" );
        dsHandle.setProperty( "odaUser", "ClassicModels" );
        dsHandle.setProperty( "odaPassword", "" );

        designHandle.getDataSources( ).add( dsHandle );

    }

    void buildDataSet(ArrayList cols, String fromClause ) throws SemanticException
    {

        OdaDataSetHandle dsHandle = designFactory.newOdaDataSet( "ds",
                "org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet" );
        dsHandle.setDataSource( "Data Source" );
        String qry = "Select ";
        for( int i=0; i < cols.size(); i++){
            qry += " " + cols.get(i);
            if( i != (cols.size() -1) ){
                qry += ",";
            }
            
        }
        qry += " " + fromClause;
        
        dsHandle.setQueryText( qry );

        designHandle.getDataSets( ).add( dsHandle );
        
         
        
    }
    void buildReport(ArrayList cols, String fromClause ) throws IOException, SemanticException
    {


        //Configure the Engine and start the Platform
        DesignConfig config = new DesignConfig( );

        config.setProperty("BIRT_HOME", "C:/birt-runtime-2_1_1/birt-runtime-2_1_1/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.openDesign("c:/tmp/testdeapi.rptdesign");

            designFactory = designHandle.getElementFactory( );

            buildDataSource();
             buildDataSet(cols, fromClause);

            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:/temp/sample.rptdesign" ); //$NON-NLS-1$
            designHandle.close( );
             System.out.println("Finished");
        }catch (Exception e){
            e.printStackTrace();
        }        

    }
}


這個(gè)例子一共有四個(gè)函數(shù) :
1 . Main 函數(shù):  這個(gè)例子簡(jiǎn)單之處在與它可以直接的運(yùn)行,只要你修改了
     config.setProperty("BIRT_HOME", "C:/birt-runtime-2_1_1/birt-runtime-2_1_1/ReportEngine");    指向你自己的Birt Runtime 解壓后的ReportEngine 目錄.
     designHandle = session.openDesign("c:/tmp/testdeapi.rptdesign");                             你可以從Birt 里面建立一個(gè)新的Report template.然后指向這個(gè)report 就可以了
     designHandle.saveAs( "c:/temp/sample.rptdesign" ); //$NON-NLS-1$                             指定一個(gè)你想保存的位置,c:/temp  目錄存在你才能夠保存到c:/temp 目錄下.
2 . buildDataSource   函數(shù)把一個(gè)ReportDesignHandle 的 Data Source 初始化, setProperties 左邊的String 是不能變的,Data Source 的名字可以隨便取,取DataSet 的時(shí)候要根據(jù)這個(gè)名字來取.
3 . buildDataSet      通過拼sql 的方式 ,來build DataSet, 注意sql 別拼錯(cuò)了.
4 . buildReport       注意element 的初始化順序.在所有的DataItem 外面都是一層Cell,Cell 外面才是row .這個(gè)例子使用的row 來拼成table 的,也可以用column 來拼,相對(duì)應(yīng)的數(shù)據(jù)處理也是一個(gè)column 一個(gè) column 的處理的了.
您需要登錄后才可以回帖 登錄 | 注冊(cè)

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號(hào)-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號(hào):11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國(guó)互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請(qǐng)注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP