1*dde7d3faSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*dde7d3faSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*dde7d3faSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*dde7d3faSAndrew Rist * distributed with this work for additional information 6*dde7d3faSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*dde7d3faSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*dde7d3faSAndrew Rist * "License"); you may not use this file except in compliance 9*dde7d3faSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*dde7d3faSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*dde7d3faSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*dde7d3faSAndrew Rist * software distributed under the License is distributed on an 15*dde7d3faSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*dde7d3faSAndrew Rist * KIND, either express or implied. See the License for the 17*dde7d3faSAndrew Rist * specific language governing permissions and limitations 18*dde7d3faSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*dde7d3faSAndrew Rist *************************************************************/ 21*dde7d3faSAndrew Rist 22*dde7d3faSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_comphelper.hxx" 26cdf0e10cSrcweir #include <comphelper/ChainablePropertySet.hxx> 27cdf0e10cSrcweir #include <comphelper/ChainablePropertySetInfo.hxx> 28cdf0e10cSrcweir #include <vos/mutex.hxx> 29cdf0e10cSrcweir 30cdf0e10cSrcweir #include <memory> // STL auto_ptr 31cdf0e10cSrcweir 32cdf0e10cSrcweir 33cdf0e10cSrcweir using namespace ::rtl; 34cdf0e10cSrcweir using namespace ::comphelper; 35cdf0e10cSrcweir using namespace ::com::sun::star; 36cdf0e10cSrcweir using namespace ::com::sun::star::uno; 37cdf0e10cSrcweir using namespace ::com::sun::star::lang; 38cdf0e10cSrcweir using namespace ::com::sun::star::beans; 39cdf0e10cSrcweir using ::vos::IMutex; 40cdf0e10cSrcweir 41cdf0e10cSrcweir ChainablePropertySet::ChainablePropertySet( comphelper::ChainablePropertySetInfo* pInfo, vos::IMutex *pMutex ) 42cdf0e10cSrcweir throw() 43cdf0e10cSrcweir : mpInfo ( pInfo ) 44cdf0e10cSrcweir , mpMutex ( pMutex ) 45cdf0e10cSrcweir , mxInfo ( pInfo ) 46cdf0e10cSrcweir { 47cdf0e10cSrcweir } 48cdf0e10cSrcweir 49cdf0e10cSrcweir ChainablePropertySet::~ChainablePropertySet() 50cdf0e10cSrcweir throw() 51cdf0e10cSrcweir { 52cdf0e10cSrcweir } 53cdf0e10cSrcweir 54cdf0e10cSrcweir // XPropertySet 55cdf0e10cSrcweir Reference< XPropertySetInfo > SAL_CALL ChainablePropertySet::getPropertySetInfo( ) 56cdf0e10cSrcweir throw(RuntimeException) 57cdf0e10cSrcweir { 58cdf0e10cSrcweir return mxInfo; 59cdf0e10cSrcweir } 60cdf0e10cSrcweir 61cdf0e10cSrcweir void ChainablePropertySet::lockMutex() 62cdf0e10cSrcweir { 63cdf0e10cSrcweir if (mpMutex) 64cdf0e10cSrcweir mpMutex->acquire(); 65cdf0e10cSrcweir } 66cdf0e10cSrcweir 67cdf0e10cSrcweir void ChainablePropertySet::unlockMutex() 68cdf0e10cSrcweir { 69cdf0e10cSrcweir if (mpMutex) 70cdf0e10cSrcweir mpMutex->release(); 71cdf0e10cSrcweir } 72cdf0e10cSrcweir 73cdf0e10cSrcweir void SAL_CALL ChainablePropertySet::setPropertyValue( const ::rtl::OUString& rPropertyName, const Any& rValue ) 74cdf0e10cSrcweir throw(UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException) 75cdf0e10cSrcweir { 76cdf0e10cSrcweir // acquire mutex in c-tor and releases it in the d-tor (exception safe!). 77cdf0e10cSrcweir std::auto_ptr< vos::OGuard > pMutexGuard; 78cdf0e10cSrcweir if (mpMutex) 79cdf0e10cSrcweir pMutexGuard.reset( new vos::OGuard(mpMutex) ); 80cdf0e10cSrcweir 81cdf0e10cSrcweir PropertyInfoHash::const_iterator aIter = mpInfo->maMap.find ( rPropertyName ); 82cdf0e10cSrcweir 83cdf0e10cSrcweir if( aIter == mpInfo->maMap.end()) 84cdf0e10cSrcweir throw UnknownPropertyException( rPropertyName, static_cast< XPropertySet* >( this ) ); 85cdf0e10cSrcweir 86cdf0e10cSrcweir _preSetValues(); 87cdf0e10cSrcweir _setSingleValue( *((*aIter).second), rValue ); 88cdf0e10cSrcweir _postSetValues(); 89cdf0e10cSrcweir } 90cdf0e10cSrcweir 91cdf0e10cSrcweir Any SAL_CALL ChainablePropertySet::getPropertyValue( const ::rtl::OUString& rPropertyName ) 92cdf0e10cSrcweir throw(UnknownPropertyException, WrappedTargetException, RuntimeException) 93cdf0e10cSrcweir { 94cdf0e10cSrcweir // acquire mutex in c-tor and releases it in the d-tor (exception safe!). 95cdf0e10cSrcweir std::auto_ptr< vos::OGuard > pMutexGuard; 96cdf0e10cSrcweir if (mpMutex) 97cdf0e10cSrcweir pMutexGuard.reset( new vos::OGuard(mpMutex) ); 98cdf0e10cSrcweir 99cdf0e10cSrcweir PropertyInfoHash::const_iterator aIter = mpInfo->maMap.find ( rPropertyName ); 100cdf0e10cSrcweir 101cdf0e10cSrcweir if( aIter == mpInfo->maMap.end()) 102cdf0e10cSrcweir throw UnknownPropertyException( rPropertyName, static_cast< XPropertySet* >( this ) ); 103cdf0e10cSrcweir 104cdf0e10cSrcweir Any aAny; 105cdf0e10cSrcweir _preGetValues (); 106cdf0e10cSrcweir _getSingleValue( *((*aIter).second), aAny ); 107cdf0e10cSrcweir _postGetValues (); 108cdf0e10cSrcweir 109cdf0e10cSrcweir return aAny; 110cdf0e10cSrcweir } 111cdf0e10cSrcweir 112cdf0e10cSrcweir void SAL_CALL ChainablePropertySet::addPropertyChangeListener( const ::rtl::OUString&, const Reference< XPropertyChangeListener >& ) 113cdf0e10cSrcweir throw(UnknownPropertyException, WrappedTargetException, RuntimeException) 114cdf0e10cSrcweir { 115cdf0e10cSrcweir // todo 116cdf0e10cSrcweir } 117cdf0e10cSrcweir 118cdf0e10cSrcweir void SAL_CALL ChainablePropertySet::removePropertyChangeListener( const ::rtl::OUString&, const Reference< XPropertyChangeListener >& ) 119cdf0e10cSrcweir throw(UnknownPropertyException, WrappedTargetException, RuntimeException) 120cdf0e10cSrcweir { 121cdf0e10cSrcweir // todo 122cdf0e10cSrcweir } 123cdf0e10cSrcweir 124cdf0e10cSrcweir void SAL_CALL ChainablePropertySet::addVetoableChangeListener( const ::rtl::OUString&, const Reference< XVetoableChangeListener >& ) 125cdf0e10cSrcweir throw(UnknownPropertyException, WrappedTargetException, RuntimeException) 126cdf0e10cSrcweir { 127cdf0e10cSrcweir // todo 128cdf0e10cSrcweir } 129cdf0e10cSrcweir 130cdf0e10cSrcweir void SAL_CALL ChainablePropertySet::removeVetoableChangeListener( const ::rtl::OUString&, const Reference< XVetoableChangeListener >& ) 131cdf0e10cSrcweir throw(UnknownPropertyException, WrappedTargetException, RuntimeException) 132cdf0e10cSrcweir { 133cdf0e10cSrcweir // todo 134cdf0e10cSrcweir } 135cdf0e10cSrcweir 136cdf0e10cSrcweir // XMultiPropertySet 137cdf0e10cSrcweir void SAL_CALL ChainablePropertySet::setPropertyValues( const Sequence< ::rtl::OUString >& aPropertyNames, const Sequence< Any >& aValues ) 138cdf0e10cSrcweir throw(PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException) 139cdf0e10cSrcweir { 140cdf0e10cSrcweir // acquire mutex in c-tor and releases it in the d-tor (exception safe!). 141cdf0e10cSrcweir std::auto_ptr< vos::OGuard > pMutexGuard; 142cdf0e10cSrcweir if (mpMutex) 143cdf0e10cSrcweir pMutexGuard.reset( new vos::OGuard(mpMutex) ); 144cdf0e10cSrcweir 145cdf0e10cSrcweir const sal_Int32 nCount = aPropertyNames.getLength(); 146cdf0e10cSrcweir 147cdf0e10cSrcweir if( nCount != aValues.getLength() ) 148cdf0e10cSrcweir throw IllegalArgumentException(); 149cdf0e10cSrcweir 150cdf0e10cSrcweir if( nCount ) 151cdf0e10cSrcweir { 152cdf0e10cSrcweir _preSetValues(); 153cdf0e10cSrcweir 154cdf0e10cSrcweir const Any * pAny = aValues.getConstArray(); 155cdf0e10cSrcweir const OUString * pString = aPropertyNames.getConstArray(); 156cdf0e10cSrcweir PropertyInfoHash::const_iterator aEnd = mpInfo->maMap.end(), aIter; 157cdf0e10cSrcweir 158cdf0e10cSrcweir for ( sal_Int32 i = 0; i < nCount; ++i, ++pString, ++pAny ) 159cdf0e10cSrcweir { 160cdf0e10cSrcweir aIter = mpInfo->maMap.find ( *pString ); 161cdf0e10cSrcweir if ( aIter == aEnd ) 162cdf0e10cSrcweir throw UnknownPropertyException( *pString, static_cast< XPropertySet* >( this ) ); 163cdf0e10cSrcweir 164cdf0e10cSrcweir _setSingleValue ( *((*aIter).second), *pAny ); 165cdf0e10cSrcweir } 166cdf0e10cSrcweir 167cdf0e10cSrcweir _postSetValues(); 168cdf0e10cSrcweir } 169cdf0e10cSrcweir } 170cdf0e10cSrcweir 171cdf0e10cSrcweir Sequence< Any > SAL_CALL ChainablePropertySet::getPropertyValues( const Sequence< ::rtl::OUString >& aPropertyNames ) 172cdf0e10cSrcweir throw(RuntimeException) 173cdf0e10cSrcweir { 174cdf0e10cSrcweir // acquire mutex in c-tor and releases it in the d-tor (exception safe!). 175cdf0e10cSrcweir std::auto_ptr< vos::OGuard > pMutexGuard; 176cdf0e10cSrcweir if (mpMutex) 177cdf0e10cSrcweir pMutexGuard.reset( new vos::OGuard(mpMutex) ); 178cdf0e10cSrcweir 179cdf0e10cSrcweir const sal_Int32 nCount = aPropertyNames.getLength(); 180cdf0e10cSrcweir 181cdf0e10cSrcweir Sequence < Any > aValues ( nCount ); 182cdf0e10cSrcweir 183cdf0e10cSrcweir if( nCount ) 184cdf0e10cSrcweir { 185cdf0e10cSrcweir _preGetValues(); 186cdf0e10cSrcweir 187cdf0e10cSrcweir Any * pAny = aValues.getArray(); 188cdf0e10cSrcweir const OUString * pString = aPropertyNames.getConstArray(); 189cdf0e10cSrcweir PropertyInfoHash::const_iterator aEnd = mpInfo->maMap.end(), aIter; 190cdf0e10cSrcweir 191cdf0e10cSrcweir for ( sal_Int32 i = 0; i < nCount; ++i, ++pString, ++pAny ) 192cdf0e10cSrcweir { 193cdf0e10cSrcweir aIter = mpInfo->maMap.find ( *pString ); 194cdf0e10cSrcweir if ( aIter == aEnd ) 195cdf0e10cSrcweir throw UnknownPropertyException( *pString, static_cast< XPropertySet* >( this ) ); 196cdf0e10cSrcweir 197cdf0e10cSrcweir _getSingleValue ( *((*aIter).second), *pAny ); 198cdf0e10cSrcweir } 199cdf0e10cSrcweir 200cdf0e10cSrcweir _postGetValues(); 201cdf0e10cSrcweir } 202cdf0e10cSrcweir return aValues; 203cdf0e10cSrcweir } 204cdf0e10cSrcweir 205cdf0e10cSrcweir void SAL_CALL ChainablePropertySet::addPropertiesChangeListener( const Sequence< ::rtl::OUString >&, const Reference< XPropertiesChangeListener >& ) 206cdf0e10cSrcweir throw(RuntimeException) 207cdf0e10cSrcweir { 208cdf0e10cSrcweir // todo 209cdf0e10cSrcweir } 210cdf0e10cSrcweir 211cdf0e10cSrcweir void SAL_CALL ChainablePropertySet::removePropertiesChangeListener( const Reference< XPropertiesChangeListener >& ) 212cdf0e10cSrcweir throw(RuntimeException) 213cdf0e10cSrcweir { 214cdf0e10cSrcweir // todo 215cdf0e10cSrcweir } 216cdf0e10cSrcweir 217cdf0e10cSrcweir void SAL_CALL ChainablePropertySet::firePropertiesChangeEvent( const Sequence< ::rtl::OUString >&, const Reference< XPropertiesChangeListener >& ) 218cdf0e10cSrcweir throw(RuntimeException) 219cdf0e10cSrcweir { 220cdf0e10cSrcweir // todo 221cdf0e10cSrcweir } 222cdf0e10cSrcweir 223cdf0e10cSrcweir // XPropertyState 224cdf0e10cSrcweir PropertyState SAL_CALL ChainablePropertySet::getPropertyState( const ::rtl::OUString& PropertyName ) 225cdf0e10cSrcweir throw(UnknownPropertyException, RuntimeException) 226cdf0e10cSrcweir { 227cdf0e10cSrcweir PropertyInfoHash::const_iterator aIter = mpInfo->maMap.find( PropertyName ); 228cdf0e10cSrcweir if( aIter == mpInfo->maMap.end()) 229cdf0e10cSrcweir throw UnknownPropertyException( PropertyName, static_cast< XPropertySet* >( this ) ); 230cdf0e10cSrcweir 231cdf0e10cSrcweir PropertyState aState; 232cdf0e10cSrcweir 233cdf0e10cSrcweir _preGetPropertyState(); 234cdf0e10cSrcweir _getPropertyState( *((*aIter).second), aState ); 235cdf0e10cSrcweir _postGetPropertyState(); 236cdf0e10cSrcweir 237cdf0e10cSrcweir return aState; 238cdf0e10cSrcweir } 239cdf0e10cSrcweir 240cdf0e10cSrcweir Sequence< PropertyState > SAL_CALL ChainablePropertySet::getPropertyStates( const Sequence< ::rtl::OUString >& rPropertyNames ) 241cdf0e10cSrcweir throw(UnknownPropertyException, RuntimeException) 242cdf0e10cSrcweir { 243cdf0e10cSrcweir const sal_Int32 nCount = rPropertyNames.getLength(); 244cdf0e10cSrcweir 245cdf0e10cSrcweir Sequence< PropertyState > aStates( nCount ); 246cdf0e10cSrcweir if( nCount ) 247cdf0e10cSrcweir { 248cdf0e10cSrcweir PropertyState * pState = aStates.getArray(); 249cdf0e10cSrcweir const OUString * pString = rPropertyNames.getConstArray(); 250cdf0e10cSrcweir PropertyInfoHash::const_iterator aEnd = mpInfo->maMap.end(), aIter; 251cdf0e10cSrcweir _preGetPropertyState(); 252cdf0e10cSrcweir 253cdf0e10cSrcweir for ( sal_Int32 i = 0; i < nCount; ++i, ++pString, ++pState ) 254cdf0e10cSrcweir { 255cdf0e10cSrcweir aIter = mpInfo->maMap.find ( *pString ); 256cdf0e10cSrcweir if ( aIter == aEnd ) 257cdf0e10cSrcweir throw UnknownPropertyException( *pString, static_cast< XPropertySet* >( this ) ); 258cdf0e10cSrcweir 259cdf0e10cSrcweir _getPropertyState ( *((*aIter).second), *pState ); 260cdf0e10cSrcweir } 261cdf0e10cSrcweir _postGetPropertyState(); 262cdf0e10cSrcweir } 263cdf0e10cSrcweir return aStates; 264cdf0e10cSrcweir } 265cdf0e10cSrcweir 266cdf0e10cSrcweir void SAL_CALL ChainablePropertySet::setPropertyToDefault( const ::rtl::OUString& rPropertyName ) 267cdf0e10cSrcweir throw(UnknownPropertyException, RuntimeException) 268cdf0e10cSrcweir { 269cdf0e10cSrcweir PropertyInfoHash::const_iterator aIter = mpInfo->maMap.find ( rPropertyName ); 270cdf0e10cSrcweir 271cdf0e10cSrcweir if( aIter == mpInfo->maMap.end()) 272cdf0e10cSrcweir throw UnknownPropertyException( rPropertyName, static_cast< XPropertySet* >( this ) ); 273cdf0e10cSrcweir _setPropertyToDefault( *((*aIter).second) ); 274cdf0e10cSrcweir } 275cdf0e10cSrcweir 276cdf0e10cSrcweir Any SAL_CALL ChainablePropertySet::getPropertyDefault( const ::rtl::OUString& rPropertyName ) 277cdf0e10cSrcweir throw(UnknownPropertyException, WrappedTargetException, RuntimeException) 278cdf0e10cSrcweir { 279cdf0e10cSrcweir PropertyInfoHash::const_iterator aIter = mpInfo->maMap.find ( rPropertyName ); 280cdf0e10cSrcweir 281cdf0e10cSrcweir if( aIter == mpInfo->maMap.end()) 282cdf0e10cSrcweir throw UnknownPropertyException( rPropertyName, static_cast< XPropertySet* >( this ) ); 283cdf0e10cSrcweir return _getPropertyDefault( *((*aIter).second) ); 284cdf0e10cSrcweir } 285cdf0e10cSrcweir 286cdf0e10cSrcweir void ChainablePropertySet::_preGetPropertyState () 287cdf0e10cSrcweir throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException ) 288cdf0e10cSrcweir { 289cdf0e10cSrcweir OSL_ENSURE( sal_False, "you have to implement this yourself!"); 290cdf0e10cSrcweir } 291cdf0e10cSrcweir 292cdf0e10cSrcweir void ChainablePropertySet::_getPropertyState( const comphelper::PropertyInfo&, PropertyState& ) 293cdf0e10cSrcweir throw(UnknownPropertyException ) 294cdf0e10cSrcweir { 295cdf0e10cSrcweir OSL_ENSURE( sal_False, "you have to implement this yourself!"); 296cdf0e10cSrcweir } 297cdf0e10cSrcweir 298cdf0e10cSrcweir void ChainablePropertySet::_postGetPropertyState () 299cdf0e10cSrcweir throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException ) 300cdf0e10cSrcweir { 301cdf0e10cSrcweir OSL_ENSURE( sal_False, "you have to implement this yourself!"); 302cdf0e10cSrcweir } 303cdf0e10cSrcweir 304cdf0e10cSrcweir void ChainablePropertySet::_setPropertyToDefault( const comphelper::PropertyInfo& ) 305cdf0e10cSrcweir throw(UnknownPropertyException ) 306cdf0e10cSrcweir { 307cdf0e10cSrcweir OSL_ENSURE( sal_False, "you have to implement this yourself!"); 308cdf0e10cSrcweir } 309cdf0e10cSrcweir 310cdf0e10cSrcweir Any ChainablePropertySet::_getPropertyDefault( const comphelper::PropertyInfo& ) 311cdf0e10cSrcweir throw(UnknownPropertyException, WrappedTargetException ) 312cdf0e10cSrcweir { 313cdf0e10cSrcweir OSL_ENSURE( sal_False, "you have to implement this yourself!"); 314cdf0e10cSrcweir 315cdf0e10cSrcweir Any aAny; 316cdf0e10cSrcweir return aAny; 317cdf0e10cSrcweir } 318