merged tag ooo/OOO330_m14
[LibreOffice.git] / comphelper / source / property / ChainablePropertySet.cxx
blob936510f21309b69865e23e405fd368bb7b143078
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_comphelper.hxx"
30 #include <comphelper/ChainablePropertySet.hxx>
31 #include <comphelper/ChainablePropertySetInfo.hxx>
32 #include <vos/mutex.hxx>
34 #include <memory> // STL auto_ptr
37 using namespace ::rtl;
38 using namespace ::comphelper;
39 using namespace ::com::sun::star;
40 using namespace ::com::sun::star::uno;
41 using namespace ::com::sun::star::lang;
42 using namespace ::com::sun::star::beans;
43 using ::vos::IMutex;
45 ChainablePropertySet::ChainablePropertySet( comphelper::ChainablePropertySetInfo* pInfo, vos::IMutex *pMutex )
46 throw()
47 : mpInfo ( pInfo )
48 , mpMutex ( pMutex )
49 , mxInfo ( pInfo )
53 ChainablePropertySet::~ChainablePropertySet()
54 throw()
58 // XPropertySet
59 Reference< XPropertySetInfo > SAL_CALL ChainablePropertySet::getPropertySetInfo( )
60 throw(RuntimeException)
62 return mxInfo;
65 void ChainablePropertySet::lockMutex()
67 if (mpMutex)
68 mpMutex->acquire();
71 void ChainablePropertySet::unlockMutex()
73 if (mpMutex)
74 mpMutex->release();
77 void SAL_CALL ChainablePropertySet::setPropertyValue( const ::rtl::OUString& rPropertyName, const Any& rValue )
78 throw(UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException)
80 // acquire mutex in c-tor and releases it in the d-tor (exception safe!).
81 std::auto_ptr< vos::OGuard > pMutexGuard;
82 if (mpMutex)
83 pMutexGuard.reset( new vos::OGuard(mpMutex) );
85 PropertyInfoHash::const_iterator aIter = mpInfo->maMap.find ( rPropertyName );
87 if( aIter == mpInfo->maMap.end())
88 throw UnknownPropertyException( rPropertyName, static_cast< XPropertySet* >( this ) );
90 _preSetValues();
91 _setSingleValue( *((*aIter).second), rValue );
92 _postSetValues();
95 Any SAL_CALL ChainablePropertySet::getPropertyValue( const ::rtl::OUString& rPropertyName )
96 throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
98 // acquire mutex in c-tor and releases it in the d-tor (exception safe!).
99 std::auto_ptr< vos::OGuard > pMutexGuard;
100 if (mpMutex)
101 pMutexGuard.reset( new vos::OGuard(mpMutex) );
103 PropertyInfoHash::const_iterator aIter = mpInfo->maMap.find ( rPropertyName );
105 if( aIter == mpInfo->maMap.end())
106 throw UnknownPropertyException( rPropertyName, static_cast< XPropertySet* >( this ) );
108 Any aAny;
109 _preGetValues ();
110 _getSingleValue( *((*aIter).second), aAny );
111 _postGetValues ();
113 return aAny;
116 void SAL_CALL ChainablePropertySet::addPropertyChangeListener( const ::rtl::OUString&, const Reference< XPropertyChangeListener >& )
117 throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
119 // todo
122 void SAL_CALL ChainablePropertySet::removePropertyChangeListener( const ::rtl::OUString&, const Reference< XPropertyChangeListener >& )
123 throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
125 // todo
128 void SAL_CALL ChainablePropertySet::addVetoableChangeListener( const ::rtl::OUString&, const Reference< XVetoableChangeListener >& )
129 throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
131 // todo
134 void SAL_CALL ChainablePropertySet::removeVetoableChangeListener( const ::rtl::OUString&, const Reference< XVetoableChangeListener >& )
135 throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
137 // todo
140 // XMultiPropertySet
141 void SAL_CALL ChainablePropertySet::setPropertyValues( const Sequence< ::rtl::OUString >& aPropertyNames, const Sequence< Any >& aValues )
142 throw(PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException)
144 // acquire mutex in c-tor and releases it in the d-tor (exception safe!).
145 std::auto_ptr< vos::OGuard > pMutexGuard;
146 if (mpMutex)
147 pMutexGuard.reset( new vos::OGuard(mpMutex) );
149 const sal_Int32 nCount = aPropertyNames.getLength();
151 if( nCount != aValues.getLength() )
152 throw IllegalArgumentException();
154 if( nCount )
156 _preSetValues();
158 const Any * pAny = aValues.getConstArray();
159 const OUString * pString = aPropertyNames.getConstArray();
160 PropertyInfoHash::const_iterator aEnd = mpInfo->maMap.end(), aIter;
162 for ( sal_Int32 i = 0; i < nCount; ++i, ++pString, ++pAny )
164 aIter = mpInfo->maMap.find ( *pString );
165 if ( aIter == aEnd )
166 throw UnknownPropertyException( *pString, static_cast< XPropertySet* >( this ) );
168 _setSingleValue ( *((*aIter).second), *pAny );
171 _postSetValues();
175 Sequence< Any > SAL_CALL ChainablePropertySet::getPropertyValues( const Sequence< ::rtl::OUString >& aPropertyNames )
176 throw(RuntimeException)
178 // acquire mutex in c-tor and releases it in the d-tor (exception safe!).
179 std::auto_ptr< vos::OGuard > pMutexGuard;
180 if (mpMutex)
181 pMutexGuard.reset( new vos::OGuard(mpMutex) );
183 const sal_Int32 nCount = aPropertyNames.getLength();
185 Sequence < Any > aValues ( nCount );
187 if( nCount )
189 _preGetValues();
191 Any * pAny = aValues.getArray();
192 const OUString * pString = aPropertyNames.getConstArray();
193 PropertyInfoHash::const_iterator aEnd = mpInfo->maMap.end(), aIter;
195 for ( sal_Int32 i = 0; i < nCount; ++i, ++pString, ++pAny )
197 aIter = mpInfo->maMap.find ( *pString );
198 if ( aIter == aEnd )
199 throw UnknownPropertyException( *pString, static_cast< XPropertySet* >( this ) );
201 _getSingleValue ( *((*aIter).second), *pAny );
204 _postGetValues();
206 return aValues;
209 void SAL_CALL ChainablePropertySet::addPropertiesChangeListener( const Sequence< ::rtl::OUString >&, const Reference< XPropertiesChangeListener >& )
210 throw(RuntimeException)
212 // todo
215 void SAL_CALL ChainablePropertySet::removePropertiesChangeListener( const Reference< XPropertiesChangeListener >& )
216 throw(RuntimeException)
218 // todo
221 void SAL_CALL ChainablePropertySet::firePropertiesChangeEvent( const Sequence< ::rtl::OUString >&, const Reference< XPropertiesChangeListener >& )
222 throw(RuntimeException)
224 // todo
227 // XPropertyState
228 PropertyState SAL_CALL ChainablePropertySet::getPropertyState( const ::rtl::OUString& PropertyName )
229 throw(UnknownPropertyException, RuntimeException)
231 PropertyInfoHash::const_iterator aIter = mpInfo->maMap.find( PropertyName );
232 if( aIter == mpInfo->maMap.end())
233 throw UnknownPropertyException( PropertyName, static_cast< XPropertySet* >( this ) );
235 PropertyState aState;
237 _preGetPropertyState();
238 _getPropertyState( *((*aIter).second), aState );
239 _postGetPropertyState();
241 return aState;
244 Sequence< PropertyState > SAL_CALL ChainablePropertySet::getPropertyStates( const Sequence< ::rtl::OUString >& rPropertyNames )
245 throw(UnknownPropertyException, RuntimeException)
247 const sal_Int32 nCount = rPropertyNames.getLength();
249 Sequence< PropertyState > aStates( nCount );
250 if( nCount )
252 PropertyState * pState = aStates.getArray();
253 const OUString * pString = rPropertyNames.getConstArray();
254 PropertyInfoHash::const_iterator aEnd = mpInfo->maMap.end(), aIter;
255 _preGetPropertyState();
257 for ( sal_Int32 i = 0; i < nCount; ++i, ++pString, ++pState )
259 aIter = mpInfo->maMap.find ( *pString );
260 if ( aIter == aEnd )
261 throw UnknownPropertyException( *pString, static_cast< XPropertySet* >( this ) );
263 _getPropertyState ( *((*aIter).second), *pState );
265 _postGetPropertyState();
267 return aStates;
270 void SAL_CALL ChainablePropertySet::setPropertyToDefault( const ::rtl::OUString& rPropertyName )
271 throw(UnknownPropertyException, RuntimeException)
273 PropertyInfoHash::const_iterator aIter = mpInfo->maMap.find ( rPropertyName );
275 if( aIter == mpInfo->maMap.end())
276 throw UnknownPropertyException( rPropertyName, static_cast< XPropertySet* >( this ) );
277 _setPropertyToDefault( *((*aIter).second) );
280 Any SAL_CALL ChainablePropertySet::getPropertyDefault( const ::rtl::OUString& rPropertyName )
281 throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
283 PropertyInfoHash::const_iterator aIter = mpInfo->maMap.find ( rPropertyName );
285 if( aIter == mpInfo->maMap.end())
286 throw UnknownPropertyException( rPropertyName, static_cast< XPropertySet* >( this ) );
287 return _getPropertyDefault( *((*aIter).second) );
290 void ChainablePropertySet::_preGetPropertyState ()
291 throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException )
293 OSL_ENSURE( sal_False, "you have to implement this yourself!");
296 void ChainablePropertySet::_getPropertyState( const comphelper::PropertyInfo&, PropertyState& )
297 throw(UnknownPropertyException )
299 OSL_ENSURE( sal_False, "you have to implement this yourself!");
302 void ChainablePropertySet::_postGetPropertyState ()
303 throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException )
305 OSL_ENSURE( sal_False, "you have to implement this yourself!");
308 void ChainablePropertySet::_setPropertyToDefault( const comphelper::PropertyInfo& )
309 throw(UnknownPropertyException )
311 OSL_ENSURE( sal_False, "you have to implement this yourself!");
314 Any ChainablePropertySet::_getPropertyDefault( const comphelper::PropertyInfo& )
315 throw(UnknownPropertyException, WrappedTargetException )
317 OSL_ENSURE( sal_False, "you have to implement this yourself!");
319 Any aAny;
320 return aAny;