Tag: cws_src680_odbmacros2
User: fs      
Date: 2008-02-06 21:43:26+0000
Modified:
   dba/dbaccess/source/ui/misc/singledoccontroller.cxx

Log:
 #i49133# don't support XScriptInvocationContext if our associated document 
does not support XEmbeddedScripts

File Changes:

Directory: /dba/dbaccess/source/ui/misc/
========================================

File [changed]: singledoccontroller.cxx
Url: 
http://dba.openoffice.org/source/browse/dba/dbaccess/source/ui/misc/singledoccontroller.cxx?r1=1.22.98.3&r2=1.22.98.4
Delta lines:  +137 -84
----------------------
--- singledoccontroller.cxx     2008-01-26 21:22:12+0000        1.22.98.3
+++ singledoccontroller.cxx     2008-02-06 21:43:23+0000        1.22.98.4
@@ -4,9 +4,9 @@
  *
  *  $RCSfile: singledoccontroller.cxx,v $
  *
- *  $Revision: 1.22.98.3 $
+ *  $Revision: 1.22.98.4 $
  *
- *  last change: $Author: fs $ $Date: 2008/01/26 21:22:12 $
+ *  last change: $Author: fs $ $Date: 2008/02/06 21:43:23 $
  *
  *  The Contents of this file are made available subject to
  *  the terms of GNU Lesser General Public License Version 2.1.
@@ -36,69 +36,33 @@
 // MARKER(update_precomp.py): autogen include statement, do not remove
 #include "precompiled_dbaccess.hxx"
 
-#ifndef DBAUI_SINGLEDOCCONTROLLER_HXX
-#include "singledoccontroller.hxx"
-#endif
-#ifndef _COMPHELPER_SEQUENCE_HXX_ 
-#include <comphelper/sequence.hxx>
-#endif
-#ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
+#include "browserids.hxx"
+#include "commontypes.hxx"
+#include "dataview.hxx"
+#include "dbu_misc.hrc"
 #include "dbustrings.hrc"
-#endif
-#ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBUTE_HPP_
+#include "moduledbu.hxx"
+#include "singledoccontroller.hxx"
+
+/** === begin UNO includes === **/
 #include <com/sun/star/beans/PropertyAttribute.hpp>
-#endif
-#ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_ 
+#include <com/sun/star/container/XChild.hpp>
 #include <com/sun/star/container/XNameAccess.hpp>
-#endif
-#ifndef _COM_SUN_STAR_SDBC_XDATASOURCE_HPP_ 
-#include <com/sun/star/sdbc/XDataSource.hpp>
-#endif
-#ifndef _COM_SUN_STAR_SDB_XDOCUMENTDATASOURCE_HPP_
 #include <com/sun/star/sdb/XDocumentDataSource.hpp>
-#endif
-#ifndef _COM_SUN_STAR_SDB_XOFFICEDATABASEDOCUMENT_HPP_
 #include <com/sun/star/sdb/XOfficeDatabaseDocument.hpp>
-#endif
-#ifndef _COM_SUN_STAR_CONTAINER_XCHILD_HPP_ 
-#include <com/sun/star/container/XChild.hpp>
-#endif
-#ifndef _TOOLS_DEBUG_HXX 
-#include <tools/debug.hxx>
-#endif
-#ifndef _COMPHELPER_TYPES_HXX_ 
+#include <com/sun/star/sdbc/XDataSource.hpp>
+#include <com/sun/star/lang/IllegalArgumentException.hpp>
+/** === end UNO includes === **/
+
+#include <comphelper/sequence.hxx>
 #include <comphelper/types.hxx>
-#endif
-#ifndef _SV_MSGBOX_HXX 
-#include <vcl/msgbox.hxx>
-#endif
-#ifndef _DBU_MISC_HRC_
-#include "dbu_misc.hrc"
-#endif
-#ifndef DBAUI_DATAVIEW_HXX
-#include "dataview.hxx"
-#endif
-#ifndef _CPPUHELPER_TYPEPROVIDER_HXX_ 
-#include <cppuhelper/typeprovider.hxx>
-#endif
-#ifndef _DBHELPER_DBEXCEPTION_HXX_
 #include <connectivity/dbexception.hxx>
-#endif
-#ifndef _CONNECTIVITY_DBTOOLS_HXX_
 #include <connectivity/dbtools.hxx>
-#endif
-#ifndef DBACCESS_UI_BROWSER_ID_HXX
-#include "browserids.hxx"
-#endif
-#ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
+#include <cppuhelper/typeprovider.hxx>
 #include <toolkit/unohlp.hxx>
-#endif
-#ifndef _DBAUI_MODULE_DBU_HXX_
-#include "moduledbu.hxx"
-#endif
-#ifndef _DBAUI_COMMON_TYPES_HXX_
-#include "commontypes.hxx"
-#endif
+#include <tools/debug.hxx>
+#include <vcl/msgbox.hxx>
+
 //........................................................................
 namespace dbaui
 {
@@ -130,6 +94,9 @@
     using ::com::sun::star::sdbc::XDatabaseMetaData;
     using ::com::sun::star::sdb::XDocumentDataSource;
     using ::com::sun::star::document::XEmbeddedScripts;
+    using ::com::sun::star::lang::IllegalArgumentException;
+    using ::com::sun::star::uno::UNO_SET_THROW;
+    using ::com::sun::star::uno::UNO_QUERY_THROW;
     /** === end UNO using === **/
 
     class DataSourceHolder
@@ -169,6 +136,10 @@
 
     struct OSingleDocumentControllerImpl
     {
+    private:
+        ::boost::optional< bool >       m_aDocScriptSupport;
+
+    public:
         OModuleClient                   m_aModuleClient;
                Any                             m_aCurrentError; // contains 
the current error which can be set through IEnvironment
 
@@ -180,15 +151,30 @@
                DataSourceHolder                m_aDataSource;
         Reference< XModel >             m_xDocument;
                Reference< XNumberFormatter >   m_xFormatter;   // a number 
formatter working with the connection's NumberFormatsSupplier
-               sal_Bool                                m_bSuspended     : 1;   
// is true when the controller was already suspended
-               sal_Bool                                m_bEditable             
 : 1;   // is the control readonly or not
-               sal_Bool                                m_bModified             
 : 1;   // is the data modified
+               sal_Bool                                m_bSuspended;   // is 
true when the controller was already suspended
+               sal_Bool                                m_bEditable;    // is 
the control readonly or not
+               sal_Bool                                m_bModified;    // is 
the data modified
 
         OSingleDocumentControllerImpl() : 
             m_bSuspended( sal_False )
                    ,m_bEditable(sal_True)
                    ,m_bModified(sal_False)
+            ,m_aDocScriptSupport()
+        {
+        }
+
+        bool    documentHasScriptSupport() const
         {
+            OSL_PRECOND( !!m_aDocScriptSupport,
+                "OSingleDocumentControllerImpl::documentHasScriptSupport: not 
completely initialized, yet - don't know!?" );
+            return !!m_aDocScriptSupport && *m_aDocScriptSupport;
+        }
+
+        void    setDocumentScriptSupport( const bool _bSupport )
+        {
+            OSL_PRECOND( !m_aDocScriptSupport,
+                "OSingleDocumentControllerImpl::setDocumentScriptSupport: 
already initialized!" );
+            m_aDocScriptSupport = ::boost::optional< bool >( _bSupport );
         }
     };
 
@@ -201,12 +187,74 @@
         ,m_pImpl(new OSingleDocumentControllerImpl())
        {
        }
+
     //--------------------------------------------------------------------
     OSingleDocumentController::~OSingleDocumentController()
     {
     }
 
        //--------------------------------------------------------------------
+    void OSingleDocumentController::impl_initialize()
+    {
+        OGenericUnoController::impl_initialize();
+
+        const ::comphelper::NamedValueCollection& rArguments( getInitParams() 
);
+
+               Reference< XConnection > xConnection;
+        xConnection = rArguments.getOrDefault( 
(::rtl::OUString)PROPERTY_ACTIVE_CONNECTION, xConnection );
+
+        if ( !xConnection.is() )
+            ::dbtools::isEmbeddedInDatabase( getModel(), xConnection );
+
+               if ( xConnection.is() )
+            initializeConnection( xConnection );
+
+               bool bShowError = true;
+               if ( !isConnected() )
+        {
+                       reconnect( sal_False );
+                       bShowError = false;
+               }
+               if ( !isConnected() )
+               {
+                       if ( bShowError )
+                               connectionLostMessage();
+                       throw IllegalArgumentException();
+               }
+    }
+
+    //--------------------------------------------------------------------
+    Any SAL_CALL OSingleDocumentController::queryInterface(const Type& _rType) 
throw (RuntimeException)
+    {
+        if ( _rType.equals( XScriptInvocationContext::static_type() ) )
+        {
+            if ( m_pImpl->documentHasScriptSupport() )
+                return makeAny( Reference< XScriptInvocationContext >( this ) 
);
+            return Any();
+        }
+
+        return OSingleDocumentController_Base::queryInterface( _rType );
+    }
+    
+    //--------------------------------------------------------------------
+    Sequence< Type > SAL_CALL OSingleDocumentController::getTypes(  ) throw 
(RuntimeException)
+    {
+        Sequence< Type > aTypes( OSingleDocumentController_Base::getTypes() );
+        if ( !m_pImpl->documentHasScriptSupport() )
+        {
+            Sequence< Type > aStrippedTypes( aTypes.getLength() - 1 );
+            ::std::remove_copy_if(
+                aTypes.getConstArray(),
+                aTypes.getConstArray() + aTypes.getLength(),
+                aStrippedTypes.getArray(),
+                ::std::bind2nd( ::std::equal_to< Type >(), 
XScriptInvocationContext::static_type() )
+            );
+            aTypes = aStrippedTypes;
+        }
+        return aTypes;
+    }
+    
+       //--------------------------------------------------------------------
        void OSingleDocumentController::initializeConnection( const Reference< 
XConnection >& _rxForeignConn )
        {
                DBG_ASSERT( !isConnected(), 
"OSingleDocumentController::initializeConnection: not to be called when already 
connected!" );
@@ -221,7 +269,8 @@
                // get the data source the connection belongs to
                try
                {
-                       if ( !m_pImpl->m_aDataSource.is() )
+            // determine our data source
+            OSL_PRECOND( !m_pImpl->m_aDataSource.is(), 
"OSingleDocumentController::initializeConnection: already a data source in this 
phase?" );
                        {
                                Reference< XChild > xConnAsChild( 
m_pImpl->m_xConnection, UNO_QUERY );
                                Reference< XDataSource > xDS;
@@ -231,11 +280,14 @@
                                // (take the indirection through XDataSource to 
ensure we have a correct object ....)
                                m_pImpl->m_aDataSource = xDS;
                        }
+            OSL_POSTCOND( m_pImpl->m_aDataSource.is(), 
"OSingleDocumentController::initializeConnection: unable to obtain the data 
source object!" );
 
-            Reference< XPropertySet > xDataSourceProps( 
m_pImpl->m_aDataSource.getDataSourceProps() );
-                       DBG_ASSERT( xDataSourceProps.is(), 
"OSingleDocumentController::initializeConnection: could not retrieve a valid 
data source!" );
-                       if ( xDataSourceProps.is() )
-                       {
+            // determine the availability of script support in our document. 
Our own XScriptInvocationContext
+            // interface depends on this
+            m_pImpl->setDocumentScriptSupport( Reference< XEmbeddedScripts >( 
getDatabaseDocument(), UNO_QUERY ).is() );
+
+            // get a number formatter
+            Reference< XPropertySet > xDataSourceProps( 
m_pImpl->m_aDataSource.getDataSourceProps(), UNO_SET_THROW );
                                xDataSourceProps->getPropertyValue( 
PROPERTY_NAME ) >>= m_pImpl->m_sDataSourceName;
                                DBG_ASSERT( 
m_pImpl->m_sDataSourceName.getLength(), 
"OSingleDocumentController::initializeConnection: invalid data source name!" );
                                Reference< XNumberFormatsSupplier> xSupplier = 
::dbtools::getNumberFormats(m_pImpl->m_xConnection);
@@ -247,7 +299,6 @@
                                }
                                OSL_ENSURE(m_pImpl->m_xFormatter.is(),"No 
NumberFormatter!");
                        }
-               }
                catch( const Exception& )
                {
                        DBG_ERROR( 
"OSingleDocumentController::initializeConnection: caught an exception!" );
@@ -586,9 +637,11 @@
     // 
-----------------------------------------------------------------------------
     Reference< XEmbeddedScripts > SAL_CALL 
OSingleDocumentController::getScriptContainer() throw (RuntimeException)
     {
-        Reference< XEmbeddedScripts > xScripts( 
m_pImpl->m_aDataSource.getDatabaseDocument(), UNO_QUERY );
-        OSL_ENSURE( xScripts.is(), 
"OSingleDocumentController::getScriptContainer: no document with scripts!" );
-        return xScripts;
+        ::osl::MutexGuard aGuard( m_aMutex );
+        if ( !m_pImpl->documentHasScriptSupport() )
+            return NULL;
+
+        return Reference< XEmbeddedScripts >( getDatabaseDocument(), 
UNO_QUERY_THROW );
     }
 
 //........................................................................




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to