reportdesign/source/core/api/ReportEngineJFree.cxx |   31 ++++++++++++---------
 reportdesign/source/core/inc/ReportEngineJFree.hxx |    4 ++
 2 files changed, 22 insertions(+), 13 deletions(-)

New commits:
commit 9a9334b6926829fb890a48047af3bd76571bf542
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Thu Jul 17 16:51:17 2025 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Fri Jul 18 07:05:36 2025 +0200

    reportdesign: Use concrete OReportDefinition in OReportEngineJFree
    
    The abstract XReportDefinition interface param allows calling
    OReportEngineJFree::setReportDefinition
    via the XReportEngine interface from dbaccess
    (s. ODocumentDefinition::onCommandOpenSomething)
    which is lower in the dependency chain than reportdesign, i.e.
    using the UNO abstraction helps to avoid a dependency cycle.
    
    However, OReportDefinition is the only implementation of that
    XReportDefinition interface actually used and can be used
    directly inside OReportEngineJFree.
    
    Therefore, cast to the specific class and use an rtl::Reference
    instead of a reference to the abstract XReportDefinition.
    
    Background is to allow extending OReportDefinition
    as needed without having to adjust the XReportDefinition
    interface in the context of the
    "Implement ReportBuilder in C++" GSoC project [1]
    in the future.
    
    [1] https://lists.freedesktop.org/archives/libreoffice/2025-May/093278.html
    
    Change-Id: Ia442dd4f64bcf2bf3ba04707ef8efcade932c2ff
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/188014
    Tested-by: Jenkins
    Reviewed-by: Adam Seskunas <adamsesku...@gmail.com>
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/reportdesign/source/core/api/ReportEngineJFree.cxx 
b/reportdesign/source/core/api/ReportEngineJFree.cxx
index ff24fa6c2ce4..b98f4a92af36 100644
--- a/reportdesign/source/core/api/ReportEngineJFree.cxx
+++ b/reportdesign/source/core/api/ReportEngineJFree.cxx
@@ -111,20 +111,27 @@ sal_Bool SAL_CALL 
OReportEngineJFree::supportsService(const OUString& ServiceNam
 uno::Reference< report::XReportDefinition > SAL_CALL 
OReportEngineJFree::getReportDefinition()
 {
     ::osl::MutexGuard aGuard(m_aMutex);
-    return m_xReport;
+    return m_pReport;
 }
 
 void SAL_CALL OReportEngineJFree::setReportDefinition( const uno::Reference< 
report::XReportDefinition >& _report )
 {
     if ( !_report.is() )
         throw lang::IllegalArgumentException();
+
+    rtl::Reference<reportdesign::OReportDefinition> pReport
+        = dynamic_cast<reportdesign::OReportDefinition*>(_report.get());
+    assert(pReport.is() && "Report is not an OReportDefinition instance");
+
     BoundListeners l;
     {
         ::osl::MutexGuard aGuard(m_aMutex);
-        if ( m_xReport != _report )
+        if (m_pReport != pReport)
         {
-            prepareSet(PROPERTY_REPORTDEFINITION, uno::Any(m_xReport), 
uno::Any(_report), &l);
-            m_xReport = _report;
+            prepareSet(PROPERTY_REPORTDEFINITION,
+                       
uno::Any(uno::Reference<report::XReportDefinition>(m_pReport)),
+                       uno::Any(_report), &l);
+            m_pReport = pReport;
         }
     }
     l.notify();
@@ -145,13 +152,13 @@ OUString OReportEngineJFree::getNewOutputName()
 {
     ::osl::MutexGuard aGuard(m_aMutex);
     ::connectivity::checkDisposed(ReportEngineBase::rBHelper.bDisposed);
-    if ( !m_xReport.is() || !m_xActiveConnection.is() )
+    if (!m_pReport.is() || !m_xActiveConnection.is())
         throw lang::IllegalArgumentException();
 
     static constexpr OUString s_sMediaType = u"MediaType"_ustr;
 
     MimeConfigurationHelper aConfighelper(m_xContext);
-    const OUString sMimeType = m_xReport->getMimeType();
+    const OUString sMimeType = m_pReport->getMimeType();
     std::shared_ptr<const SfxFilter> pFilter = SfxFilter::GetDefaultFilter( 
aConfighelper.GetDocServiceNameFromMediaType(sMimeType) );
     OUString sExt(u".rpt"_ustr);
     if ( pFilter )
@@ -165,11 +172,11 @@ OUString OReportEngineJFree::getNewOutputName()
     {
         xStorageProp->setPropertyValue( s_sMediaType, uno::Any(sMimeType));
     }
-    m_xReport->storeToStorage(xTemp,aEmpty); // store to temp file because it 
may contain information which isn't in the database yet.
+    m_pReport->storeToStorage(xTemp, aEmpty); // store to temp file because it 
may contain information which isn't in the database yet.
 
-    OUString sName = m_xReport->getCaption();
+    OUString sName = m_pReport->getCaption();
     if ( sName.isEmpty() )
-        sName = m_xReport->getName();
+        sName = m_pReport->getName();
     OUString sFileURL = ::utl::CreateTempURL(sName, false, sExt);
     if ( sFileURL.isEmpty() )
     {
@@ -201,11 +208,11 @@ OUString OReportEngineJFree::getNewOutputName()
     uno::Sequence< beans::NamedValue > aConvertedProperties{
         {u"InputStorage"_ustr, uno::Any(xTemp) },
         {u"OutputStorage"_ustr, uno::Any(xOut) },
-        {PROPERTY_REPORTDEFINITION, uno::Any(m_xReport) },
+        {PROPERTY_REPORTDEFINITION, 
uno::Any(uno::Reference<report::XReportDefinition>(m_pReport)) },
         {PROPERTY_ACTIVECONNECTION, uno::Any(m_xActiveConnection) },
         {PROPERTY_MAXROWS, uno::Any(m_nMaxRows) },
         {u"Author"_ustr, uno::Any(sAuthor) },
-        {u"Title"_ustr, uno::Any(m_xReport->getCaption()) }
+        {u"Title"_ustr, uno::Any(m_pReport->getCaption()) }
     };
 
     OUString sOutputName;
@@ -213,7 +220,7 @@ OUString OReportEngineJFree::getNewOutputName()
     // create job factory and initialize
     const OUString sReportEngineServiceName = 
::dbtools::getDefaultReportEngineServiceName(m_xContext);
     uno::Reference<task::XJob> 
xJob(m_xContext->getServiceManager()->createInstanceWithContext(sReportEngineServiceName,m_xContext),uno::UNO_QUERY_THROW);
-    if ( !m_xReport->getCommand().isEmpty() )
+    if (!m_pReport->getCommand().isEmpty())
     {
         xJob->execute(aConvertedProperties);
         if ( xStorageProp.is() )
diff --git a/reportdesign/source/core/inc/ReportEngineJFree.hxx 
b/reportdesign/source/core/inc/ReportEngineJFree.hxx
index e0ab1d60b34b..cd3af13fa2f1 100644
--- a/reportdesign/source/core/inc/ReportEngineJFree.hxx
+++ b/reportdesign/source/core/inc/ReportEngineJFree.hxx
@@ -21,6 +21,8 @@
 
 #include <sal/config.h>
 
+#include <ReportDefinition.hxx>
+
 #include <com/sun/star/report/XReportEngine.hpp>
 #include <cppuhelper/compbase.hxx>
 #include <comphelper/broadcasthelper.hxx>
@@ -40,7 +42,7 @@ namespace reportdesign
                     public ReportEnginePropertySet
     {
         css::uno::Reference< css::uno::XComponentContext >        m_xContext;
-        css::uno::Reference< css::report::XReportDefinition >     m_xReport;
+        rtl::Reference<reportdesign::OReportDefinition>           m_pReport;
         css::uno::Reference< css::task::XStatusIndicator>         
m_StatusIndicator;
         css::uno::Reference< css::sdbc::XConnection >             
m_xActiveConnection;
         ::sal_Int32                                               m_nMaxRows;

Reply via email to