LCOV - code coverage report
Current view: top level - libreoffice/xmloff/source/core - PropertySetMerger.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 19 78 24.4 %
Date: 2012-12-17 Functions: 7 18 38.9 %
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 <com/sun/star/beans/XPropertyState.hpp>
      21             : #include "PropertySetMerger.hxx"
      22             : 
      23             : using ::rtl::OUString;
      24             : 
      25             : using namespace ::com::sun::star;
      26             : using namespace ::com::sun::star::uno;
      27             : using namespace ::com::sun::star::beans;
      28             : using namespace ::com::sun::star::lang;
      29             : 
      30             : #include <cppuhelper/implbase3.hxx>
      31             : 
      32             : class PropertySetMergerImpl : public ::cppu::WeakAggImplHelper3< XPropertySet, XPropertyState, XPropertySetInfo >
      33             : {
      34             : private:
      35             :     Reference< XPropertySet > mxPropSet1;
      36             :     Reference< XPropertyState > mxPropSet1State;
      37             :     Reference< XPropertySetInfo > mxPropSet1Info;
      38             : 
      39             :     Reference< XPropertySet > mxPropSet2;
      40             :     Reference< XPropertyState > mxPropSet2State;
      41             :     Reference< XPropertySetInfo > mxPropSet2Info;
      42             : 
      43             : public:
      44             :     PropertySetMergerImpl( const Reference< XPropertySet > rPropSet1, const Reference< XPropertySet > rPropSet2 );
      45             :     virtual ~PropertySetMergerImpl();
      46             : 
      47             :     // XPropertySet
      48             :     virtual Reference< XPropertySetInfo > SAL_CALL getPropertySetInfo(  ) throw(RuntimeException);
      49             :     virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const Any& aValue ) throw(UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException);
      50             :     virtual Any SAL_CALL getPropertyValue( const OUString& PropertyName ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException);
      51             :     virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName, const Reference< XPropertyChangeListener >& xListener ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException);
      52             :     virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName, const Reference< XPropertyChangeListener >& aListener ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException);
      53             :     virtual void SAL_CALL addVetoableChangeListener( const OUString& PropertyName, const Reference< XVetoableChangeListener >& aListener ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException);
      54             :     virtual void SAL_CALL removeVetoableChangeListener( const OUString& PropertyName, const Reference< XVetoableChangeListener >& aListener ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException);
      55             : 
      56             :     // XPropertyState
      57             :     virtual PropertyState SAL_CALL getPropertyState( const OUString& PropertyName ) throw(UnknownPropertyException, RuntimeException);
      58             :     virtual Sequence< PropertyState > SAL_CALL getPropertyStates( const Sequence< OUString >& aPropertyName ) throw(UnknownPropertyException, RuntimeException);
      59             :     virtual void SAL_CALL setPropertyToDefault( const OUString& PropertyName ) throw(UnknownPropertyException, RuntimeException);
      60             :     virtual Any SAL_CALL getPropertyDefault( const OUString& aPropertyName ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException);
      61             : 
      62             :     // XPropertySetInfo
      63             :     virtual Sequence< Property > SAL_CALL getProperties(  ) throw(RuntimeException);
      64             :     virtual Property SAL_CALL getPropertyByName( const OUString& aName ) throw(UnknownPropertyException, RuntimeException);
      65             :     virtual sal_Bool SAL_CALL hasPropertyByName( const OUString& Name ) throw(RuntimeException);
      66             : };
      67             : 
      68             : // --------------------------------------------------------------------
      69             : // Interface implementation
      70             : // --------------------------------------------------------------------
      71             : 
      72          22 : PropertySetMergerImpl::PropertySetMergerImpl( Reference< XPropertySet > rPropSet1, Reference< XPropertySet > rPropSet2 )
      73             : : mxPropSet1( rPropSet1 )
      74             : , mxPropSet1State( rPropSet1, UNO_QUERY )
      75          22 : , mxPropSet1Info( rPropSet1->getPropertySetInfo() )
      76             : , mxPropSet2( rPropSet2 )
      77             : , mxPropSet2State( rPropSet2, UNO_QUERY )
      78          44 : , mxPropSet2Info( rPropSet2->getPropertySetInfo() )
      79             : {
      80          22 : }
      81             : 
      82          44 : PropertySetMergerImpl::~PropertySetMergerImpl()
      83             : {
      84          44 : }
      85             : 
      86             : // XPropertySet
      87          22 : Reference< XPropertySetInfo > SAL_CALL PropertySetMergerImpl::getPropertySetInfo(  ) throw(RuntimeException)
      88             : {
      89          22 :     return this;
      90             : }
      91             : 
      92          88 : void SAL_CALL PropertySetMergerImpl::setPropertyValue( const OUString& aPropertyName, const Any& aValue ) throw(UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException)
      93             : {
      94          88 :     if( mxPropSet1Info->hasPropertyByName( aPropertyName ) )
      95             :     {
      96          84 :         mxPropSet1->setPropertyValue( aPropertyName, aValue );
      97             :     }
      98             :     else
      99             :     {
     100           4 :         mxPropSet2->setPropertyValue( aPropertyName, aValue );
     101             :     }
     102          88 : }
     103             : 
     104           0 : Any SAL_CALL PropertySetMergerImpl::getPropertyValue( const OUString& PropertyName ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
     105             : {
     106           0 :     if( mxPropSet1Info->hasPropertyByName( PropertyName ) )
     107             :     {
     108           0 :         return mxPropSet1->getPropertyValue( PropertyName );
     109             :     }
     110             :     else
     111             :     {
     112           0 :         return mxPropSet2->getPropertyValue( PropertyName );
     113             :     }
     114             : }
     115             : 
     116           0 : void SAL_CALL PropertySetMergerImpl::addPropertyChangeListener( const OUString& /*aPropertyName*/, const Reference< XPropertyChangeListener >& /*xListener*/ ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
     117             : {
     118           0 : }
     119             : 
     120           0 : void SAL_CALL PropertySetMergerImpl::removePropertyChangeListener( const OUString& /*aPropertyName*/, const Reference< XPropertyChangeListener >& /*aListener*/ ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
     121             : {
     122           0 : }
     123             : 
     124           0 : void SAL_CALL PropertySetMergerImpl::addVetoableChangeListener( const OUString& /*PropertyName*/, const Reference< XVetoableChangeListener >& /*aListener*/ ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
     125             : {
     126           0 : }
     127             : 
     128           0 : void SAL_CALL PropertySetMergerImpl::removeVetoableChangeListener( const OUString& /*PropertyName*/, const Reference< XVetoableChangeListener >& /*aListener*/ ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
     129             : {
     130           0 : }
     131             : 
     132             : // XPropertyState
     133           0 : PropertyState SAL_CALL PropertySetMergerImpl::getPropertyState( const OUString& PropertyName ) throw(UnknownPropertyException, RuntimeException)
     134             : {
     135           0 :     if( mxPropSet1Info->hasPropertyByName( PropertyName ) )
     136             :     {
     137           0 :         if( mxPropSet1State.is() )
     138             :         {
     139           0 :             return mxPropSet1State->getPropertyState( PropertyName );
     140             :         }
     141             :         else
     142             :         {
     143           0 :             return PropertyState_DIRECT_VALUE;
     144             :         }
     145             :     }
     146             :     else
     147             :     {
     148           0 :         if( mxPropSet2State.is() )
     149             :         {
     150           0 :             return mxPropSet2State->getPropertyState( PropertyName );
     151             :         }
     152             :         else
     153             :         {
     154           0 :             return PropertyState_DIRECT_VALUE;
     155             :         }
     156             :     }
     157             : }
     158             : 
     159           0 : Sequence< PropertyState > SAL_CALL PropertySetMergerImpl::getPropertyStates( const Sequence< OUString >& aPropertyName ) throw(UnknownPropertyException, RuntimeException)
     160             : {
     161           0 :     const sal_Int32 nCount = aPropertyName.getLength();
     162           0 :     Sequence< PropertyState > aPropStates( nCount );
     163           0 :     PropertyState* pPropStates = aPropStates.getArray();
     164           0 :     const OUString* pPropNames = aPropertyName.getConstArray();
     165             : 
     166             :     sal_Int32 nIndex;
     167           0 :     for( nIndex = 0; nIndex < nCount; nIndex++ )
     168           0 :         *pPropStates++ = getPropertyState( *pPropNames++ );
     169             : 
     170           0 :     return aPropStates;
     171             : }
     172             : 
     173           0 : void SAL_CALL PropertySetMergerImpl::setPropertyToDefault( const OUString& PropertyName ) throw(UnknownPropertyException, RuntimeException)
     174             : {
     175           0 :     if( mxPropSet1State.is() && mxPropSet1Info->hasPropertyByName( PropertyName ) )
     176             :     {
     177           0 :         mxPropSet1State->setPropertyToDefault( PropertyName );
     178             :     }
     179             :     else
     180             :     {
     181           0 :         if( mxPropSet2State.is() )
     182             :         {
     183           0 :             mxPropSet2State->setPropertyToDefault( PropertyName );
     184             :         }
     185             :     }
     186           0 : }
     187             : 
     188           0 : Any SAL_CALL PropertySetMergerImpl::getPropertyDefault( const OUString& aPropertyName ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
     189             : {
     190           0 :     if( mxPropSet1State.is() && mxPropSet1Info->hasPropertyByName( aPropertyName ) )
     191             :     {
     192           0 :         return mxPropSet1State->getPropertyDefault( aPropertyName );
     193             :     }
     194             :     else
     195             :     {
     196           0 :         if( mxPropSet2State.is() )
     197             :         {
     198           0 :             return mxPropSet2State->getPropertyDefault( aPropertyName );
     199             :         }
     200             :         else
     201             :         {
     202           0 :             Any aAny;
     203           0 :             return aAny;
     204             :         }
     205             :     }
     206             : }
     207             : 
     208             : // XPropertySetInfo
     209           0 : Sequence< Property > SAL_CALL PropertySetMergerImpl::getProperties() throw(RuntimeException)
     210             : {
     211           0 :     Sequence< Property > aProps1( mxPropSet1Info->getProperties() );
     212           0 :     const Property* pProps1 = aProps1.getArray();
     213           0 :     const sal_Int32 nCount1 = aProps1.getLength();
     214             : 
     215           0 :     Sequence< Property > aProps2( mxPropSet1Info->getProperties() );
     216           0 :     const Property* pProps2 = aProps2.getArray();
     217           0 :     const sal_Int32 nCount2 = aProps2.getLength();
     218             : 
     219           0 :     Sequence< Property > aProperties( nCount1 + nCount2 );
     220             : 
     221             :     sal_Int32 nIndex;
     222             : 
     223           0 :     Property* pProperties = aProperties.getArray();
     224             : 
     225           0 :     for( nIndex = 0; nIndex < nCount1; nIndex++ )
     226           0 :         *pProperties++ = *pProps1++;
     227             : 
     228           0 :     for( nIndex = 0; nIndex < nCount2; nIndex++ )
     229           0 :         *pProperties++ = *pProps2++;
     230             : 
     231           0 :     return aProperties;
     232             : }
     233             : 
     234           0 : Property SAL_CALL PropertySetMergerImpl::getPropertyByName( const OUString& aName ) throw(UnknownPropertyException, RuntimeException)
     235             : {
     236           0 :     if( mxPropSet1Info->hasPropertyByName( aName ) )
     237           0 :         return mxPropSet1Info->getPropertyByName( aName );
     238             : 
     239           0 :     return mxPropSet2Info->getPropertyByName( aName );
     240             : }
     241             : 
     242          88 : sal_Bool SAL_CALL PropertySetMergerImpl::hasPropertyByName( const OUString& Name ) throw(RuntimeException)
     243             : {
     244          88 :     if(mxPropSet1Info->hasPropertyByName( Name ) )
     245          84 :         return sal_True;
     246             : 
     247           4 :     return mxPropSet2Info->hasPropertyByName( Name );
     248             : }
     249             : 
     250          22 : Reference< XPropertySet > PropertySetMerger_CreateInstance( Reference< XPropertySet > rPropSet1, Reference< XPropertySet > rPropSet2 ) throw()
     251             : {
     252          22 :     return new PropertySetMergerImpl( rPropSet1, rPropSet2 );
     253             : }
     254             : 
     255             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10