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

Generated by: LCOV version 1.10