LCOV - code coverage report
Current view: top level - dbaccess/source/core/misc - ContainerMediator.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 53 105 50.5 %
Date: 2012-08-25 Functions: 7 10 70.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 69 238 29.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*
       3                 :            :  * This file is part of the LibreOffice project.
       4                 :            :  *
       5                 :            :  * This Source Code Form is subject to the terms of the Mozilla Public
       6                 :            :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7                 :            :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8                 :            :  *
       9                 :            :  * This file incorporates work covered by the following license notice:
      10                 :            :  *
      11                 :            :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12                 :            :  *   contributor license agreements. See the NOTICE file distributed
      13                 :            :  *   with this work for additional information regarding copyright
      14                 :            :  *   ownership. The ASF licenses this file to you under the Apache
      15                 :            :  *   License, Version 2.0 (the "License"); you may not use this file
      16                 :            :  *   except in compliance with the License. You may obtain a copy of
      17                 :            :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18                 :            :  */
      19                 :            : 
      20                 :            : #include "ContainerMediator.hxx"
      21                 :            : #include "dbastrings.hrc"
      22                 :            : #include "PropertyForward.hxx"
      23                 :            : 
      24                 :            : #include <com/sun/star/beans/PropertyAttribute.hpp>
      25                 :            : #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
      26                 :            : #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
      27                 :            : #include <com/sun/star/sdbcx/XRename.hpp>
      28                 :            : #include <connectivity/dbtools.hxx>
      29                 :            : #include <comphelper/property.hxx>
      30                 :            : #include <tools/debug.hxx>
      31                 :            : #include <tools/diagnose_ex.h>
      32                 :            : 
      33                 :            : 
      34                 :            : //........................................................................
      35                 :            : namespace dbaccess
      36                 :            : {
      37                 :            : //........................................................................
      38                 :            :     using namespace ::com::sun::star::uno;
      39                 :            :     using namespace ::com::sun::star::lang;
      40                 :            :     using namespace ::com::sun::star::sdbc;
      41                 :            :     using namespace ::com::sun::star::sdbcx;
      42                 :            :     using namespace ::com::sun::star::beans;
      43                 :            :     using namespace ::com::sun::star::container;
      44                 :            : 
      45                 :            : DBG_NAME(OContainerMediator)
      46                 :         56 : OContainerMediator::OContainerMediator( const Reference< XContainer >& _xContainer, const Reference< XNameAccess >& _xSettings,
      47                 :            :     const Reference< XConnection >& _rxConnection, ContainerType _eType )
      48                 :            :     : m_xSettings( _xSettings )
      49                 :            :     , m_xContainer( _xContainer )
      50                 :            :     , m_aConnection( _rxConnection )
      51 [ +  - ][ +  - ]:         56 :     , m_eType( _eType )
                 [ +  - ]
      52                 :            : {
      53                 :            :     DBG_CTOR(OContainerMediator,NULL);
      54                 :            : 
      55 [ +  - ][ +  - ]:         56 :     if ( _xSettings.is() && _xContainer.is() )
                 [ +  - ]
      56                 :            :     {
      57         [ +  - ]:         56 :         osl_incrementInterlockedCount(&m_refCount);
      58                 :            :         try
      59                 :            :         {
      60 [ +  - ][ +  - ]:         56 :             m_xContainer->addContainerListener(this);
                 [ +  - ]
      61         [ +  - ]:         56 :             Reference< XContainer > xContainer(_xSettings, UNO_QUERY);
      62         [ +  - ]:         56 :             if ( xContainer.is() )
      63 [ +  - ][ +  - ]:         56 :                 xContainer->addContainerListener(this);
         [ +  - ][ #  # ]
      64                 :            :         }
      65         [ #  # ]:          0 :         catch(Exception&)
      66                 :            :         {
      67                 :            :             OSL_FAIL("OContainerMediator::OContainerMediator: caught an exception!");
      68                 :            :         }
      69         [ +  - ]:         56 :         osl_decrementInterlockedCount( &m_refCount );
      70                 :            :     }
      71                 :            :     else
      72                 :            :     {
      73                 :          0 :         m_xSettings.clear();
      74                 :          0 :         m_xContainer.clear();
      75                 :            :     }
      76                 :         56 : }
      77                 :            : // -----------------------------------------------------------------------------
      78 [ +  - ][ +  - ]:         56 : OContainerMediator::~OContainerMediator()
      79                 :            : {
      80                 :            :     DBG_DTOR(OContainerMediator,NULL);
      81                 :         56 :     acquire();
      82         [ +  - ]:         56 :     impl_cleanup_nothrow();
      83         [ -  + ]:        112 : }
      84                 :            : 
      85                 :            : // -----------------------------------------------------------------------------
      86                 :        112 : void OContainerMediator::impl_cleanup_nothrow()
      87                 :            : {
      88                 :            :     try
      89                 :            :     {
      90         [ +  - ]:        112 :         Reference< XContainer > xContainer( m_xSettings, UNO_QUERY );
      91         [ +  + ]:        112 :         if ( xContainer.is() )
      92 [ +  - ][ +  - ]:         56 :             xContainer->removeContainerListener( this );
                 [ +  - ]
      93                 :        112 :         m_xSettings.clear();
      94                 :            : 
      95         [ +  - ]:        112 :         xContainer = m_xContainer;
      96         [ +  + ]:        112 :         if ( xContainer.is() )
      97 [ +  - ][ +  - ]:         56 :             xContainer->removeContainerListener( this );
                 [ +  - ]
      98                 :        112 :         m_xContainer.clear();
      99                 :            : 
     100         [ #  # ]:        112 :         m_aForwardList.clear();
     101                 :            :     }
     102                 :          0 :     catch( const Exception& )
     103                 :            :     {
     104                 :            :         DBG_UNHANDLED_EXCEPTION();
     105                 :            :     }
     106                 :        112 : }
     107                 :            : 
     108                 :            : // -----------------------------------------------------------------------------
     109                 :          0 : void SAL_CALL OContainerMediator::elementInserted( const ContainerEvent& _rEvent ) throw(RuntimeException)
     110                 :            : {
     111         [ #  # ]:          0 :     ::osl::MutexGuard aGuard(m_aMutex);
     112 [ #  # ][ #  # ]:          0 :     if ( _rEvent.Source == m_xSettings && m_xSettings.is() )
         [ #  # ][ #  # ]
     113                 :            :     {
     114                 :          0 :         ::rtl::OUString sElementName;
     115                 :          0 :         _rEvent.Accessor >>= sElementName;
     116         [ #  # ]:          0 :         PropertyForwardList::iterator aFind = m_aForwardList.find(sElementName);
     117         [ #  # ]:          0 :         if ( aFind != m_aForwardList.end() )
     118                 :            :         {
     119         [ #  # ]:          0 :             Reference< XPropertySet> xDest(_rEvent.Element,UNO_QUERY);
     120         [ #  # ]:          0 :             aFind->second->setDefinition( xDest );
     121                 :          0 :         }
     122         [ #  # ]:          0 :     }
     123                 :          0 : }
     124                 :            : // -----------------------------------------------------------------------------
     125                 :          0 : void SAL_CALL OContainerMediator::elementRemoved( const ContainerEvent& _rEvent ) throw(RuntimeException)
     126                 :            : {
     127         [ #  # ]:          0 :     ::osl::MutexGuard aGuard(m_aMutex);
     128                 :          0 :     Reference< XContainer > xContainer = m_xContainer;
     129 [ #  # ][ #  # ]:          0 :     if ( _rEvent.Source == xContainer && xContainer.is() )
         [ #  # ][ #  # ]
     130                 :            :     {
     131                 :          0 :         ::rtl::OUString sElementName;
     132                 :          0 :         _rEvent.Accessor >>= sElementName;
     133         [ #  # ]:          0 :         m_aForwardList.erase(sElementName);
     134                 :            :         try
     135                 :            :         {
     136         [ #  # ]:          0 :             Reference<XNameContainer> xNameContainer( m_xSettings, UNO_QUERY );
     137 [ #  # ][ #  # ]:          0 :             if ( xNameContainer.is() && m_xSettings->hasByName( sElementName ) )
         [ #  # ][ #  # ]
                 [ #  # ]
     138 [ #  # ][ #  # ]:          0 :                 xNameContainer->removeByName( sElementName );
                 [ #  # ]
     139                 :            :         }
     140         [ #  # ]:          0 :         catch( const Exception& )
     141                 :            :         {
     142                 :            :             DBG_UNHANDLED_EXCEPTION();
     143                 :          0 :         }
     144         [ #  # ]:          0 :     }
     145                 :          0 : }
     146                 :            : // -----------------------------------------------------------------------------
     147                 :          0 : void SAL_CALL OContainerMediator::elementReplaced( const ContainerEvent& _rEvent ) throw(RuntimeException)
     148                 :            : {
     149                 :          0 :     Reference< XContainer > xContainer = m_xContainer;
     150 [ #  # ][ #  # ]:          0 :     if ( _rEvent.Source == xContainer && xContainer.is() )
         [ #  # ][ #  # ]
     151                 :            :     {
     152                 :          0 :         ::rtl::OUString sElementName;
     153                 :          0 :         _rEvent.ReplacedElement >>= sElementName;
     154                 :            : 
     155         [ #  # ]:          0 :         PropertyForwardList::iterator aFind = m_aForwardList.find(sElementName);
     156         [ #  # ]:          0 :         if ( aFind != m_aForwardList.end() )
     157                 :            :         {
     158                 :          0 :             ::rtl::OUString sNewName;
     159                 :          0 :             _rEvent.Accessor >>= sNewName;
     160                 :            :             try
     161                 :            :             {
     162         [ #  # ]:          0 :                 Reference<XNameContainer> xNameContainer( m_xSettings, UNO_QUERY_THROW );
     163 [ #  # ][ #  # ]:          0 :                 if ( xNameContainer.is() && m_xSettings->hasByName( sElementName ) )
         [ #  # ][ #  # ]
                 [ #  # ]
     164                 :            :                 {
     165 [ #  # ][ #  # ]:          0 :                     Reference<XRename> xSource(m_xSettings->getByName(sElementName),UNO_QUERY_THROW);
                 [ #  # ]
     166 [ #  # ][ #  # ]:          0 :                     xSource->rename(sNewName);
     167         [ #  # ]:          0 :                 }
     168                 :            :             }
     169         [ #  # ]:          0 :             catch( const Exception& )
     170                 :            :             {
     171                 :            :                 DBG_UNHANDLED_EXCEPTION();
     172                 :            :             }
     173                 :            : 
     174                 :          0 :             aFind->second->setName(sNewName);
     175                 :          0 :         }
     176                 :          0 :     }
     177                 :          0 : }
     178                 :            : 
     179                 :            : // -----------------------------------------------------------------------------
     180                 :         56 : void SAL_CALL OContainerMediator::disposing( const EventObject& /*Source*/ ) throw(RuntimeException)
     181                 :            : {
     182         [ +  - ]:         56 :     ::osl::MutexGuard aGuard(m_aMutex);
     183                 :            : 
     184 [ +  - ][ +  - ]:         56 :     impl_cleanup_nothrow();
     185                 :         56 : }
     186                 :            : 
     187                 :            : // -----------------------------------------------------------------------------
     188                 :        456 : void OContainerMediator::impl_initSettings_nothrow( const ::rtl::OUString& _rName, const Reference< XPropertySet >& _rxDestination )
     189                 :            : {
     190                 :            :     try
     191                 :            :     {
     192 [ +  - ][ +  - ]:        456 :         if ( m_xSettings.is() && m_xSettings->hasByName( _rName ) )
         [ +  - ][ +  + ]
                 [ +  + ]
     193                 :            :         {
     194 [ +  - ][ +  - ]:        272 :             Reference< XPropertySet > xSettings( m_xSettings->getByName( _rName ), UNO_QUERY_THROW );
                 [ +  - ]
     195 [ #  # ][ +  - ]:        272 :             ::comphelper::copyProperties( xSettings, _rxDestination );
     196                 :            :         }
     197                 :            :     }
     198                 :          0 :     catch( const Exception& )
     199                 :            :     {
     200                 :            :         DBG_UNHANDLED_EXCEPTION();
     201                 :            :     }
     202                 :        456 : }
     203                 :            : 
     204                 :            : // -----------------------------------------------------------------------------
     205                 :        456 : void OContainerMediator::notifyElementCreated( const ::rtl::OUString& _sName, const Reference< XPropertySet >& _xDest )
     206                 :            : {
     207         [ +  - ]:        456 :     if ( !m_xSettings.is() )
     208                 :            :         return;
     209                 :            : 
     210         [ +  - ]:        456 :     PropertyForwardList::iterator aFind = m_aForwardList.find( _sName );
     211   [ -  +  #  # ]:        912 :     if  (   aFind != m_aForwardList.end()
                 [ +  - ]
           [ +  -  #  # ]
     212 [ #  # ][ -  + ]:        456 :         &&  aFind->second->getDefinition().is()
                 [ #  # ]
     213                 :            :         )
     214                 :            :     {
     215                 :            :         OSL_FAIL( "OContainerMediator::notifyElementCreated: is this really a valid case?" );
     216                 :            :         return;
     217                 :            :     }
     218                 :            : 
     219         [ +  - ]:        456 :     ::std::vector< ::rtl::OUString > aPropertyList;
     220                 :            :     try
     221                 :            :     {
     222                 :            :         // initially copy from the settings object (if existent) to the newly created object
     223         [ +  - ]:        456 :         impl_initSettings_nothrow( _sName, _xDest );
     224                 :            : 
     225                 :            :         // collect the to-be-monitored properties
     226 [ +  - ][ +  - ]:        456 :         Reference< XPropertySetInfo > xPSI( _xDest->getPropertySetInfo(), UNO_QUERY_THROW );
                 [ +  - ]
     227 [ +  - ][ +  - ]:        456 :         Sequence< Property > aProperties( xPSI->getProperties() );
     228                 :        456 :         const Property* property = aProperties.getConstArray();
     229                 :        456 :         const Property* propertyEnd = aProperties.getConstArray() + aProperties.getLength();
     230         [ +  + ]:       9456 :         for ( ; property != propertyEnd; ++property )
     231                 :            :         {
     232         [ +  + ]:       9000 :             if ( ( property->Attributes & PropertyAttribute::READONLY ) != 0 )
     233                 :       4876 :                 continue;
     234         [ -  + ]:       4124 :             if ( ( property->Attributes & PropertyAttribute::BOUND ) == 0 )
     235                 :          0 :                 continue;
     236                 :            : 
     237         [ +  - ]:       4124 :             aPropertyList.push_back( property->Name );
     238 [ +  - ][ #  # ]:        456 :         }
     239                 :            :     }
     240         [ #  # ]:          0 :     catch( const Exception& )
     241                 :            :     {
     242                 :            :         DBG_UNHANDLED_EXCEPTION();
     243                 :            :     }
     244                 :            : 
     245         [ +  - ]:        456 :     ::rtl::Reference< OPropertyForward > pForward( new OPropertyForward( _xDest, m_xSettings, _sName, aPropertyList ) );
     246 [ +  - ][ +  - ]:        456 :     m_aForwardList[ _sName ] = pForward;
     247                 :            : }
     248                 :            : // -----------------------------------------------------------------------------
     249                 :            : //........................................................................
     250                 :            : }   // namespace dbaccess
     251                 :            : //........................................................................
     252                 :            : 
     253                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10