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