KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > efs > openreports > providers > BirtProvider


1 /*
2  * Copyright (C) 2006 by Open Source Software Solutions, LLC and Contributors
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the Free
6  * Software Foundation; either version 2 of the License, or (at your option)
7  * any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
16  * Place - Suite 330, Boston, MA 02111-1307, USA.
17  *
18  * Original Author : Roberto Nibali - rnibali@pyx.ch
19  * Contributor(s) : Erik Swenson - erik@oreports.com
20  *
21  */

22
23 package org.efs.openreports.providers;
24
25 import java.util.logging.Level JavaDoc;
26
27 import org.apache.log4j.Logger;
28 import org.eclipse.birt.core.exception.BirtException;
29 import org.eclipse.birt.core.framework.IPlatformContext;
30 import org.eclipse.birt.core.framework.Platform;
31 import org.eclipse.birt.core.framework.PlatformConfig;
32 import org.eclipse.birt.core.framework.PlatformFileContext;
33 import org.eclipse.birt.report.engine.api.EngineConfig;
34 import org.eclipse.birt.report.engine.api.HTMLActionHandler;
35 import org.eclipse.birt.report.engine.api.HTMLEmitterConfig;
36 import org.eclipse.birt.report.engine.api.HTMLServerImageHandler;
37 import org.eclipse.birt.report.engine.api.IReportEngine;
38 import org.eclipse.birt.report.engine.api.IReportEngineFactory;
39 import org.springframework.beans.factory.DisposableBean;
40
41 /**
42  * Provides the init and startup of the birt engine and config.
43  *
44  * @author Roberto Nibali
45  *
46  */

47 public class BirtProvider implements DisposableBean
48 {
49     protected static Logger log = Logger.getLogger(BirtProvider.class);
50     
51     private static IReportEngine birtEngine = null;
52
53     public static synchronized IReportEngine getBirtEngine(String JavaDoc birtHome)
54     {
55         if (birtEngine == null)
56         {
57             log.info("Starting BIRT Engine and OSGI Platform");
58                         
59             PlatformConfig platformConfig = new PlatformConfig();
60             platformConfig.getBIRTHome(birtHome);
61             
62             IPlatformContext context = new PlatformFileContext(platformConfig);
63             
64             HTMLServerImageHandler imageHandler = new HTMLServerImageHandler();
65             
66             HTMLEmitterConfig emitterConfig = new HTMLEmitterConfig();
67             emitterConfig.setActionHandler(new HTMLActionHandler());
68             emitterConfig.setImageHandler(imageHandler);
69
70             EngineConfig config = new EngineConfig();
71             config.setEngineHome("");
72             config.setPlatformContext(context);
73             config.setLogConfig(null, Level.ALL);
74             config.getEmitterConfigs().put("html", emitterConfig);
75
76             try
77             {
78                 Platform.startup(config);
79             }
80             catch (BirtException e)
81             {
82                 log.error("BirtException", e);
83             }
84
85             IReportEngineFactory factory = (IReportEngineFactory) Platform
86                     .createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);
87             
88             birtEngine = factory.createReportEngine(config);
89             
90             log.info("BIRT Engine Started");
91         }
92                 
93         birtEngine.changeLogLevel(Level.SEVERE);
94         
95         return birtEngine;
96     }
97
98     public void destroy()
99     {
100         if (birtEngine == null) return;
101         
102         birtEngine.destroy();
103         birtEngine.shutdown();
104         Platform.shutdown();
105         birtEngine = null;
106         
107         log.info("BIRT Engine and OSGI Platform Shutdown");
108     }
109 }
110
Popular Tags