User: kz Date: 2008-03-05 17:30:27+0000 Modified: dba/reportdesign/java/com/sun/star/report/pentaho/SOReportJobFactory.java
Log: INTEGRATION: CWS rptchart01_DEV300 (1.2.70); FILE MERGED 2008/02/21 09:57:23 oj 1.2.70.4: #i85225# fixes found with PMD 2008/02/20 10:52:55 oj 1.2.70.3: format changes 2008/02/19 06:42:48 oj 1.2.70.2: #i85225# ongoing work 2008/02/13 07:04:22 oj 1.2.70.1: #i85225# impl chart readhandler and oleproducer File Changes: Directory: /dba/reportdesign/java/com/sun/star/report/pentaho/ ============================================================== File [changed]: SOReportJobFactory.java Url: http://dba.openoffice.org/source/browse/dba/reportdesign/java/com/sun/star/report/pentaho/SOReportJobFactory.java?r1=1.2&r2=1.3 Delta lines: +260 -245 ----------------------- --- SOReportJobFactory.java 2007-07-09 11:56:04+0000 1.2 +++ SOReportJobFactory.java 2008-03-05 17:30:24+0000 1.3 @@ -34,8 +34,6 @@ ************************************************************************/ package com.sun.star.report.pentaho; -import java.net.URL; - import com.sun.star.beans.NamedValue; import com.sun.star.beans.XPropertySet; import com.sun.star.beans.UnknownPropertyException; @@ -43,11 +41,11 @@ import com.sun.star.beans.XPropertyChangeListener; import com.sun.star.beans.XVetoableChangeListener; import com.sun.star.embed.XStorage; +import com.sun.star.lang.IllegalArgumentException; import com.sun.star.lang.XInitialization; -import com.sun.star.lang.XMultiComponentFactory; import com.sun.star.lang.XServiceInfo; -import com.sun.star.lang.XSingleComponentFactory; import com.sun.star.lang.WrappedTargetException; +import com.sun.star.lang.XSingleComponentFactory; import com.sun.star.lib.uno.helper.Factory; import com.sun.star.lib.uno.helper.PropertySetMixin; import com.sun.star.lib.uno.helper.WeakBase; @@ -55,13 +53,19 @@ import com.sun.star.report.DataSourceFactory; import com.sun.star.report.JobProperties; import com.sun.star.report.ReportEngineParameterNames; +import com.sun.star.report.ReportExecutionException; import com.sun.star.report.ReportJob; import com.sun.star.report.ReportJobDefinition; +import com.sun.star.report.ReportJobFactory; import com.sun.star.report.SDBCReportDataFactory; import com.sun.star.report.SOImageService; import com.sun.star.report.StorageRepository; +import com.sun.star.report.XReportDefinition; +import com.sun.star.report.pentaho.SOReportJobFactory._SOReportJobFactory; +import com.sun.star.sdbc.XConnection; import com.sun.star.sdbc.XRowSet; import com.sun.star.task.XJob; +import com.sun.star.uno.Exception; import com.sun.star.uno.Type; import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.XComponentContext; @@ -74,42 +78,35 @@ */ public class SOReportJobFactory { + private SOReportJobFactory() { } - public static class _SOReportJobFactory extends WeakBase implements XInitialization, XServiceInfo, XJob, XPropertySet + public static class _SOReportJobFactory extends WeakBase implements XInitialization, XServiceInfo, XJob, XPropertySet, ReportJobFactory { + /** * The service name, that must be used to get an instance of this service. */ private static final String __serviceName = "com.sun.star.report.pentaho.SOReportJobFactory"; - private PropertySetMixin m_prophlp; - /** * The initial component contextr, that gives access to the service manager, supported singletons, ... It's * often later used */ private XComponentContext m_cmpCtx; + private XConnection activeConnection; + private XReportDefinition report; public _SOReportJobFactory(final XComponentContext xCompContext) { m_cmpCtx = xCompContext; - try - { - final XMultiComponentFactory m_xMCF = m_cmpCtx.getServiceManager(); m_prophlp = new PropertySetMixin(m_cmpCtx, this, new Type(XJob.class), null); // no optionals } - catch (Exception e) - { - Log.error ("Failed to query the service manager: ", e); - throw new RuntimeException(); - } - } /** * This method is a member of the interface for initializing an object directly after its creation. @@ -173,22 +170,42 @@ Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader()); try { + final ReportJob job = createReportJob(namedValue); + job.execute(); + } + catch (java.lang.Exception e) + { + Log.error("ReportProcessing failed", e); + throw new com.sun.star.lang.WrappedTargetException("caught a " + e.getClass().getName(), this, new com.sun.star.uno.Exception(e.getLocalizedMessage())); + } + catch (java.lang.IncompatibleClassChangeError e2) + { + Log.error("Detected an IncompatibleClassChangeError"); + e2.printStackTrace(System.err); + System.err.println(e2); + } + Thread.currentThread().setContextClassLoader(cl); + + return null; + } + + public ReportJob createReportJob(final NamedValue[] namedValue) throws IllegalArgumentException, ReportExecutionException, Exception + { XStorage input = null; XStorage output = null; XRowSet rowSet = null; String mimetype = null; + for (int i = 0; i < namedValue.length; ++i) { final NamedValue aProps = namedValue[i]; - if ("DataSource".equalsIgnoreCase(aProps.Name)) + if ("ActiveConnection".equalsIgnoreCase(aProps.Name)) { + activeConnection = (XConnection) UnoRuntime.queryInterface(XConnection.class, aProps.Value); } - else if ("RowSet".equalsIgnoreCase(aProps.Name)) - { - rowSet = (XRowSet) UnoRuntime.queryInterface(XRowSet.class, aProps.Value); - } - else if ("Parameters".equalsIgnoreCase(aProps.Name)) + else if ("ReportDefinition".equalsIgnoreCase(aProps.Name)) { + report = (XReportDefinition) UnoRuntime.queryInterface(XReportDefinition.class, aProps.Value); } else if ("InputStorage".equalsIgnoreCase(aProps.Name)) { @@ -198,56 +215,54 @@ { output = (XStorage) UnoRuntime.queryInterface(XStorage.class, aProps.Value); } + else if ("RowSet".equalsIgnoreCase(aProps.Name)) + { + rowSet = (XRowSet) UnoRuntime.queryInterface(XRowSet.class, aProps.Value); + } else if ("mimetype".equalsIgnoreCase(aProps.Name)) { mimetype = (String) aProps.Value; } } - if (rowSet == null || input == null || output == null) + if (input == null || output == null) { throw new com.sun.star.lang.IllegalArgumentException(); } + if (rowSet == null) + { + if (report == null || activeConnection == null) + { + throw new com.sun.star.lang.IllegalArgumentException(); + } + mimetype = report.getMimeType(); + } if (mimetype == null) { mimetype = "application/vnd.oasis.opendocument.text"; } - final DataSourceFactory dataFactory = new SDBCReportDataFactory(rowSet); + final DataSourceFactory dataFactory = new SDBCReportDataFactory(m_cmpCtx, activeConnection); final StorageRepository storageRepository = new StorageRepository(input, output); - final PentahoReportEngine engine = new PentahoReportEngine(); - final ReportJobDefinition definition = engine.createJobDefinition(); - final JobProperties procParms = definition.getProcessingParameters(); final String inputName = "content.xml"; final String outputName = "content.xml"; + + final PentahoReportEngine engine = new PentahoReportEngine(); + final ReportJobDefinition definition = engine.createJobDefinition(); + final JobProperties procParms = definition.getProcessingParameters(); procParms.setProperty(ReportEngineParameterNames.INPUT_REPOSITORY, storageRepository); + procParms.setProperty(ReportEngineParameterNames.OUTPUT_REPOSITORY, storageRepository); procParms.setProperty(ReportEngineParameterNames.INPUT_NAME, inputName); procParms.setProperty(ReportEngineParameterNames.OUTPUT_NAME, outputName); procParms.setProperty(ReportEngineParameterNames.CONTENT_TYPE, mimetype); procParms.setProperty(ReportEngineParameterNames.INPUT_DATASOURCE_FACTORY, dataFactory); procParms.setProperty(ReportEngineParameterNames.IMAGE_SERVICE, new SOImageService(m_cmpCtx)); + procParms.setProperty(ReportEngineParameterNames.INPUT_REPORTJOB_FACTORY, this); - final ReportJob job = engine.createJob(definition); - job.execute(); - } - catch (java.lang.Exception e) - { - Log.error("ReportProcessing failed", e); - throw new com.sun.star.lang.WrappedTargetException - ("caught a " + e.getClass().getName(), this, new com.sun.star.uno.Exception(e.getLocalizedMessage())); - } - catch (java.lang.IncompatibleClassChangeError e2) - { - Log.error("Detected an IncompatibleClassChangeError"); - e2.printStackTrace(System.err); - System.err.println(e2); - } - Thread.currentThread().setContextClassLoader(cl); - - return null; + return engine.createJob(definition); } // com.sun.star.beans.XPropertySet: --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
