Update ooo320-m1
[ooovba.git] / comphelper / source / property / ChainablePropertySet.cxx
blob2c4095b59ff3f91c4b4e3836a2fcefbd14daae63
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ChainablePropertySet.cxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_comphelper.hxx"
33 #include <comphelper/ChainablePropertySet.hxx>
34 #include <comphelper/ChainablePropertySetInfo.hxx>
35 #include <vos/mutex.hxx>
37 #include <memory> // STL auto_ptr
40 using namespace ::rtl;
41 using namespace ::comphelper;
42 using namespace ::com::sun::star;
43 using namespace ::com::sun::star::uno;
44 using namespace ::com::sun::star::lang;
45 using namespace ::com::sun::star::beans;
46 using ::vos::IMutex;
48 ChainablePropertySet::ChainablePropertySet( comphelper::ChainablePropertySetInfo* pInfo, vos::IMutex *pMutex )
49 throw()
50 : mpInfo ( pInfo )
51 , mpMutex ( pMutex )
52 , mxInfo ( pInfo )
56 ChainablePropertySet::~ChainablePropertySet()
57 throw()
61 // XPropertySet
62 Reference< XPropertySetInfo > SAL_CALL ChainablePropertySet::getPropertySetInfo( )
63 throw(RuntimeException)
65 return mxInfo;
68 void ChainablePropertySet::lockMutex()
70 if (mpMutex)
71 mpMutex->acquire();
74 void ChainablePropertySet::unlockMutex()
76 if (mpMutex)
77 mpMutex->release();
80 void SAL_CALL ChainablePropertySet::setPropertyValue( const ::rtl::OUString& rPropertyName, const Any& rValue )
81 throw(UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException)
83 // acquire mutex in c-tor and releases it in the d-tor (exception safe!).
84 std::auto_ptr< vos::OGuard > pMutexGuard;
85 if (mpMutex)
86 pMutexGuard.reset( new vos::OGuard(mpMutex) );
88 PropertyInfoHash::const_iterator aIter = mpInfo->maMap.find ( rPropertyName );
90 if( aIter == mpInfo->maMap.end())
91 throw UnknownPropertyException( rPropertyName, static_cast< XPropertySet* >( this ) );
93 _preSetValues();
94 _setSingleValue( *((*aIter).second), rValue );
95 _postSetValues();
98 Any SAL_CALL ChainablePropertySet::getPropertyValue( const ::rtl::OUString& rPropertyName )
99 throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
101 // acquire mutex in c-tor and releases it in the d-tor (exception safe!).
102 std::auto_ptr< vos::OGuard > pMutexGuard;
103 if (mpMutex)
104 pMutexGuard.reset( new vos::OGuard(mpMutex) );
106 PropertyInfoHash::const_iterator aIter = mpInfo->maMap.find ( rPropertyName );
108 if( aIter == mpInfo->maMap.end())
109 throw UnknownPropertyException( rPropertyName, static_cast< XPropertySet* >( this ) );
111 Any aAny;
112 _preGetValues ();
113 _getSingleValue( *((*aIter).second), aAny );
114 _postGetValues ();
116 return aAny;
119 void SAL_CALL ChainablePropertySet::addPropertyChangeListener( const ::rtl::OUString&, const Reference< XPropertyChangeListener >& )
120 throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
122 // todo
125 void SAL_CALL ChainablePropertySet::removePropertyChangeListener( const ::rtl::OUString&, const Reference< XPropertyChangeListener >& )
126 throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
128 // todo
131 void SAL_CALL ChainablePropertySet::addVetoableChangeListener( const ::rtl::OUString&, const Reference< XVetoableChangeListener >& )
132 throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
134 // todo
137 void SAL_CALL ChainablePropertySet::removeVetoableChangeListener( const ::rtl::OUString&, const Reference< XVetoableChangeListener >& )
138 throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
140 // todo
143 // XMultiPropertySet
144 void SAL_CALL ChainablePropertySet::setPropertyValues( const Sequence< ::rtl::OUString >& aPropertyNames, const Sequence< Any >& aValues )
145 throw(PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException)
147 // acquire mutex in c-tor and releases it in the d-tor (exception safe!).
148 std::auto_ptr< vos::OGuard > pMutexGuard;
149 if (mpMutex)
150 pMutexGuard.reset( new vos::OGuard(mpMutex) );
152 const sal_Int32 nCount = aPropertyNames.getLength();
154 if( nCount != aValues.getLength() )
155 throw IllegalArgumentException();
157 if( nCount )
159 _preSetValues();
161 const Any * pAny = aValues.getConstArray();
162 const OUString * pString = aPropertyNames.getConstArray();
163 PropertyInfoHash::const_iterator aEnd = mpInfo->maMap.end(), aIter;
165 for ( sal_Int32 i = 0; i < nCount; ++i, ++pString, ++pAny )
167 aIter = mpInfo->maMap.find ( *pString );
168 if ( aIter == aEnd )
169 throw UnknownPropertyException( *pString, static_cast< XPropertySet* >( this ) );
171 _setSingleValue ( *((*aIter).second), *pAny );
174 _postSetValues();
178 Sequence< Any > SAL_CALL ChainablePropertySet::getPropertyValues( const Sequence< ::rtl::OUString >& aPropertyNames )
179 throw(RuntimeException)
181 // acquire mutex in c-tor and releases it in the d-tor (exception safe!).
182 std::auto_ptr< vos::OGuard > pMutexGuard;
183 if (mpMutex)
184 pMutexGuard.reset( new vos::OGuard(mpMutex) );
186 const sal_Int32 nCount = aPropertyNames.getLength();
188 Sequence < Any > aValues ( nCount );
190 if( nCount )
192 _preGetValues();
194 Any * pAny = aValues.getArray();
195 const OUString * pString = aPropertyNames.getConstArray();
196 PropertyInfoHash::const_iterator aEnd = mpInfo->maMap.end(), aIter;
198 for ( sal_Int32 i = 0; i < nCount; ++i, ++pString, ++pAny )
200 aIter = mpInfo->maMap.find ( *pString );
201 if ( aIter == aEnd )
202 throw UnknownPropertyException( *pString, static_cast< XPropertySet* >( this ) );
204 _getSingleValue ( *((*aIter).second), *pAny );
207 _postGetValues();
209 return aValues;
212 void SAL_CALL ChainablePropertySet::addPropertiesChangeListener( const Sequence< ::rtl::OUString >&, const Reference< XPropertiesChangeListener >& )
213 throw(RuntimeException)
215 // todo
218 void SAL_CALL ChainablePropertySet::removePropertiesChangeListener( const Reference< XPropertiesChangeListener >& )
219 throw(RuntimeException)
221 // todo
224 void SAL_CALL ChainablePropertySet::firePropertiesChangeEvent( const Sequence< ::rtl::OUString >&, const Reference< XPropertiesChangeListener >& )
225 throw(RuntimeException)
227 // todo
230 // XPropertyState
231 PropertyState SAL_CALL ChainablePropertySet::getPropertyState( const ::rtl::OUString& PropertyName )
232 throw(UnknownPropertyException, RuntimeException)
234 PropertyInfoHash::const_iterator aIter = mpInfo->maMap.find( PropertyName );
235 if( aIter == mpInfo->maMap.end())
236 throw UnknownPropertyException( PropertyName, static_cast< XPropertySet* >( this ) );
238 PropertyState aState;
240 _preGetPropertyState();
241 _getPropertyState( *((*aIter).second), aState );
242 _postGetPropertyState();
244 return aState;
247 Sequence< PropertyState > SAL_CALL ChainablePropertySet::getPropertyStates( const Sequence< ::rtl::OUString >& rPropertyNames )
248 throw(UnknownPropertyException, RuntimeException)
250 const sal_Int32 nCount = rPropertyNames.getLength();
252 Sequence< PropertyState > aStates( nCount );
253 if( nCount )
255 PropertyState * pState = aStates.getArray();
256 const OUString * pString = rPropertyNames.getConstArray();
257 PropertyInfoHash::const_iterator aEnd = mpInfo->maMap.end(), aIter;
258 _preGetPropertyState();
260 for ( sal_Int32 i = 0; i < nCount; ++i, ++pString, ++pState )
262 aIter = mpInfo->maMap.find ( *pString );
263 if ( aIter == aEnd )
264 throw UnknownPropertyException( *pString, static_cast< XPropertySet* >( this ) );
266 _getPropertyState ( *((*aIter).second), *pState );
268 _postGetPropertyState();
270 return aStates;
273 void SAL_CALL ChainablePropertySet::setPropertyToDefault( const ::rtl::OUString& rPropertyName )
274 throw(UnknownPropertyException, RuntimeException)
276 PropertyInfoHash::const_iterator aIter = mpInfo->maMap.find ( rPropertyName );
278 if( aIter == mpInfo->maMap.end())
279 throw UnknownPropertyException( rPropertyName, static_cast< XPropertySet* >( this ) );
280 _setPropertyToDefault( *((*aIter).second) );
283 Any SAL_CALL ChainablePropertySet::getPropertyDefault( const ::rtl::OUString& rPropertyName )
284 throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
286 PropertyInfoHash::const_iterator aIter = mpInfo->maMap.find ( rPropertyName );
288 if( aIter == mpInfo->maMap.end())
289 throw UnknownPropertyException( rPropertyName, static_cast< XPropertySet* >( this ) );
290 return _getPropertyDefault( *((*aIter).second) );
293 void ChainablePropertySet::_preGetPropertyState ()
294 throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException )
296 OSL_ENSURE( sal_False, "you have to implement this yourself!");
299 void ChainablePropertySet::_getPropertyState( const comphelper::PropertyInfo&, PropertyState& )
300 throw(UnknownPropertyException )
302 OSL_ENSURE( sal_False, "you have to implement this yourself!");
305 void ChainablePropertySet::_postGetPropertyState ()
306 throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException )
308 OSL_ENSURE( sal_False, "you have to implement this yourself!");
311 void ChainablePropertySet::_setPropertyToDefault( const comphelper::PropertyInfo& )
312 throw(UnknownPropertyException )
314 OSL_ENSURE( sal_False, "you have to implement this yourself!");
317 Any ChainablePropertySet::_getPropertyDefault( const comphelper::PropertyInfo& )
318 throw(UnknownPropertyException, WrappedTargetException )
320 OSL_ENSURE( sal_False, "you have to implement this yourself!");
322 Any aAny;
323 return aAny;