LCOV - code coverage report
Current view: top level - dbaccess/source/core/misc - PropertyForward.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 22 53 41.5 %
Date: 2015-06-13 12:38:46 Functions: 4 6 66.7 %
Legend: Lines: hit not hit

          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 "PropertyForward.hxx"
      21             : #include "dbastrings.hrc"
      22             : 
      23             : #include <com/sun/star/beans/PropertyValue.hpp>
      24             : #include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp>
      25             : #include <com/sun/star/sdbcx/XAppend.hpp>
      26             : 
      27             : #include <comphelper/property.hxx>
      28             : #include <tools/debug.hxx>
      29             : #include <tools/diagnose_ex.h>
      30             : 
      31             : namespace dbaccess
      32             : {
      33             : 
      34             :     using namespace ::com::sun::star::uno;
      35             :     using namespace ::com::sun::star::beans;
      36             :     using namespace ::com::sun::star::container;
      37             :     using namespace ::com::sun::star::sdbcx;
      38             :     using namespace ::com::sun::star::lang;
      39             : 
      40             : 
      41         408 :     OPropertyForward::OPropertyForward( const Reference< XPropertySet>& _xSource, const Reference< XNameAccess>& _xDestContainer,
      42             :             const OUString& _sName, const ::std::vector< OUString>& _aPropertyList )
      43             :         :m_xSource( _xSource, UNO_SET_THROW )
      44             :         ,m_xDestContainer( _xDestContainer, UNO_SET_THROW )
      45             :         ,m_sName( _sName )
      46         408 :         ,m_bInInsert( false )
      47             :     {
      48             : 
      49         408 :         osl_atomic_increment(&m_refCount);
      50             :         try
      51             :         {
      52         408 :             if ( _aPropertyList.empty() )
      53           0 :                 _xSource->addPropertyChangeListener( OUString(), this );
      54             :             else
      55             :             {
      56         408 :                 ::std::vector< OUString >::const_iterator aIter = _aPropertyList.begin();
      57         408 :                 ::std::vector< OUString >::const_iterator aEnd = _aPropertyList.end();
      58        4216 :                 for (; aIter != aEnd ; ++aIter )
      59        3808 :                     _xSource->addPropertyChangeListener( *aIter, this );
      60             :             }
      61             :         }
      62           0 :         catch( const Exception& )
      63             :         {
      64             :             DBG_UNHANDLED_EXCEPTION();
      65             :         }
      66         408 :         osl_atomic_decrement( &m_refCount );
      67         408 :     }
      68             : 
      69         816 :     OPropertyForward::~OPropertyForward()
      70             :     {
      71         816 :     }
      72             : 
      73           0 :     void SAL_CALL OPropertyForward::propertyChange( const PropertyChangeEvent& evt ) throw(RuntimeException, std::exception)
      74             :     {
      75           0 :         ::osl::MutexGuard aGuard( m_aMutex );
      76             : 
      77           0 :         if ( !m_xDestContainer.is() )
      78           0 :             throw DisposedException( OUString(), *this );
      79             : 
      80             :         try
      81             :         {
      82           0 :             if ( !m_xDest.is() )
      83             :             {
      84           0 :                 if ( m_xDestContainer->hasByName( m_sName ) )
      85             :                 {
      86           0 :                     m_xDest.set( m_xDestContainer->getByName( m_sName ), UNO_QUERY_THROW );
      87             :                 }
      88             :                 else
      89             :                 {
      90           0 :                     Reference< XDataDescriptorFactory > xFactory( m_xDestContainer, UNO_QUERY_THROW );
      91           0 :                     m_xDest.set( xFactory->createDataDescriptor(), UNO_SET_THROW );
      92             : 
      93           0 :                     ::comphelper::copyProperties( m_xSource, m_xDest );
      94             : 
      95           0 :                     m_bInInsert = true;
      96           0 :                     Reference< XAppend > xAppend( m_xDestContainer, UNO_QUERY_THROW );
      97           0 :                     xAppend->appendByDescriptor( m_xDest );
      98           0 :                     m_bInInsert = false;
      99             :                 }
     100             : 
     101           0 :                 m_xDestInfo.set( m_xDest->getPropertySetInfo(), UNO_SET_THROW );
     102             :             }
     103             : 
     104           0 :             if ( m_xDestInfo->hasPropertyByName( evt.PropertyName ) )
     105             :             {
     106           0 :                 m_xDest->setPropertyValue( evt.PropertyName, evt.NewValue );
     107             :             }
     108             :         }
     109           0 :         catch( const Exception& )
     110             :         {
     111             :             DBG_UNHANDLED_EXCEPTION();
     112           0 :         }
     113           0 :     }
     114             : 
     115        3808 :     void SAL_CALL OPropertyForward::disposing( const ::com::sun::star::lang::EventObject& /*_rSource*/ ) throw (RuntimeException, std::exception)
     116             :     {
     117        3808 :         ::osl::MutexGuard aGuard(m_aMutex);
     118             : 
     119        3808 :         if ( !m_xSource.is() )
     120        3400 :             throw DisposedException( OUString(), *this );
     121             : 
     122         408 :         m_xSource->removePropertyChangeListener( OUString(), this );
     123         408 :         m_xSource = NULL;
     124         408 :         m_xDestContainer = NULL;
     125         408 :         m_xDestInfo = NULL;
     126        3808 :         m_xDest = NULL;
     127         408 :     }
     128             : 
     129           0 :     void OPropertyForward::setDefinition( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _xDest )
     130             :     {
     131           0 :         ::osl::MutexGuard aGuard( m_aMutex );
     132           0 :         if ( m_bInInsert )
     133           0 :             return;
     134             : 
     135             :         OSL_ENSURE( !m_xDest.is(), "OPropertyForward::setDefinition: definition object is already set!" );
     136             :         try
     137             :         {
     138           0 :             m_xDest.set( _xDest, UNO_SET_THROW );
     139           0 :             m_xDestInfo.set( m_xDest->getPropertySetInfo(), UNO_SET_THROW );
     140           0 :             ::comphelper::copyProperties( m_xDest, m_xSource );
     141             :         }
     142           0 :         catch( const Exception& )
     143             :         {
     144             :             DBG_UNHANDLED_EXCEPTION();
     145           0 :         }
     146             :     }
     147             : 
     148             : }   // namespace dbaccess
     149             : 
     150             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11