1dde7d3faSAndrew Rist /**************************************************************
2*d75c37aeSmseidel  *
3dde7d3faSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4dde7d3faSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5dde7d3faSAndrew Rist  * distributed with this work for additional information
6dde7d3faSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7dde7d3faSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8dde7d3faSAndrew Rist  * "License"); you may not use this file except in compliance
9dde7d3faSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*d75c37aeSmseidel  *
11dde7d3faSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*d75c37aeSmseidel  *
13dde7d3faSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14dde7d3faSAndrew Rist  * software distributed under the License is distributed on an
15dde7d3faSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16dde7d3faSAndrew Rist  * KIND, either express or implied.  See the License for the
17dde7d3faSAndrew Rist  * specific language governing permissions and limitations
18dde7d3faSAndrew Rist  * under the License.
19*d75c37aeSmseidel  *
20dde7d3faSAndrew Rist  *************************************************************/
21dde7d3faSAndrew Rist 
22dde7d3faSAndrew 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 
30*d75c37aeSmseidel #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 
ChainablePropertySet(comphelper::ChainablePropertySetInfo * pInfo,vos::IMutex * pMutex)41*d75c37aeSmseidel ChainablePropertySet::ChainablePropertySet( comphelper::ChainablePropertySetInfo* pInfo, vos::IMutex *pMutex )
42cdf0e10cSrcweir 	throw()
43cdf0e10cSrcweir : mpInfo ( pInfo )
44cdf0e10cSrcweir , mpMutex ( pMutex )
45cdf0e10cSrcweir , mxInfo ( pInfo )
46cdf0e10cSrcweir {
47cdf0e10cSrcweir }
48cdf0e10cSrcweir 
~ChainablePropertySet()49*d75c37aeSmseidel ChainablePropertySet::~ChainablePropertySet()
50cdf0e10cSrcweir 	throw()
51cdf0e10cSrcweir {
52cdf0e10cSrcweir }
53cdf0e10cSrcweir 
54cdf0e10cSrcweir // XPropertySet
getPropertySetInfo()55*d75c37aeSmseidel Reference< XPropertySetInfo > SAL_CALL ChainablePropertySet::getPropertySetInfo(  )
56cdf0e10cSrcweir 	throw(RuntimeException)
57cdf0e10cSrcweir {
58cdf0e10cSrcweir 	return mxInfo;
59cdf0e10cSrcweir }
60cdf0e10cSrcweir 
lockMutex()61cdf0e10cSrcweir void ChainablePropertySet::lockMutex()
62cdf0e10cSrcweir {
63cdf0e10cSrcweir 	if (mpMutex)
64cdf0e10cSrcweir 		mpMutex->acquire();
65cdf0e10cSrcweir }
66cdf0e10cSrcweir 
unlockMutex()67cdf0e10cSrcweir void ChainablePropertySet::unlockMutex()
68cdf0e10cSrcweir {
69cdf0e10cSrcweir 	if (mpMutex)
70cdf0e10cSrcweir 		mpMutex->release();
71cdf0e10cSrcweir }
72cdf0e10cSrcweir 
setPropertyValue(const::rtl::OUString & rPropertyName,const Any & rValue)73*d75c37aeSmseidel void SAL_CALL ChainablePropertySet::setPropertyValue( const ::rtl::OUString& rPropertyName, const Any& rValue )
74cdf0e10cSrcweir 	throw(UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException)
75cdf0e10cSrcweir {
76*d75c37aeSmseidel 	// acquire mutex in c-tor and releases it in the d-tor (exception safe!).
77*d75c37aeSmseidel 	std::auto_ptr< vos::OGuard > pMutexGuard;
78*d75c37aeSmseidel 	if (mpMutex)
79*d75c37aeSmseidel 		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 
getPropertyValue(const::rtl::OUString & rPropertyName)91*d75c37aeSmseidel Any SAL_CALL ChainablePropertySet::getPropertyValue( const ::rtl::OUString& rPropertyName )
92cdf0e10cSrcweir 	throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
93cdf0e10cSrcweir {
94*d75c37aeSmseidel 	// acquire mutex in c-tor and releases it in the d-tor (exception safe!).
95*d75c37aeSmseidel 	std::auto_ptr< vos::OGuard > pMutexGuard;
96*d75c37aeSmseidel 	if (mpMutex)
97*d75c37aeSmseidel 		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 
addPropertyChangeListener(const::rtl::OUString &,const Reference<XPropertyChangeListener> &)112*d75c37aeSmseidel void SAL_CALL ChainablePropertySet::addPropertyChangeListener( const ::rtl::OUString&, const Reference< XPropertyChangeListener >& )
113cdf0e10cSrcweir 	throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
114cdf0e10cSrcweir {
115cdf0e10cSrcweir 	// todo
116cdf0e10cSrcweir }
117cdf0e10cSrcweir 
removePropertyChangeListener(const::rtl::OUString &,const Reference<XPropertyChangeListener> &)118*d75c37aeSmseidel void SAL_CALL ChainablePropertySet::removePropertyChangeListener( const ::rtl::OUString&, const Reference< XPropertyChangeListener >& )
119cdf0e10cSrcweir 	throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
120cdf0e10cSrcweir {
121cdf0e10cSrcweir 	// todo
122cdf0e10cSrcweir }
123cdf0e10cSrcweir 
addVetoableChangeListener(const::rtl::OUString &,const Reference<XVetoableChangeListener> &)124*d75c37aeSmseidel void SAL_CALL ChainablePropertySet::addVetoableChangeListener( const ::rtl::OUString&, const Reference< XVetoableChangeListener >& )
125cdf0e10cSrcweir 	throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
126cdf0e10cSrcweir {
127cdf0e10cSrcweir 	// todo
128cdf0e10cSrcweir }
129cdf0e10cSrcweir 
removeVetoableChangeListener(const::rtl::OUString &,const Reference<XVetoableChangeListener> &)130*d75c37aeSmseidel void SAL_CALL ChainablePropertySet::removeVetoableChangeListener( const ::rtl::OUString&, const Reference< XVetoableChangeListener >& )
131cdf0e10cSrcweir 	throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
132cdf0e10cSrcweir {
133cdf0e10cSrcweir 	// todo
134cdf0e10cSrcweir }
135cdf0e10cSrcweir 
136cdf0e10cSrcweir // XMultiPropertySet
setPropertyValues(const Sequence<::rtl::OUString> & aPropertyNames,const Sequence<Any> & aValues)137*d75c37aeSmseidel void SAL_CALL ChainablePropertySet::setPropertyValues( const Sequence< ::rtl::OUString >& aPropertyNames, const Sequence< Any >& aValues )
138cdf0e10cSrcweir 	throw(PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException)
139cdf0e10cSrcweir {
140*d75c37aeSmseidel 	// acquire mutex in c-tor and releases it in the d-tor (exception safe!).
141*d75c37aeSmseidel 	std::auto_ptr< vos::OGuard > pMutexGuard;
142*d75c37aeSmseidel 	if (mpMutex)
143*d75c37aeSmseidel 		pMutexGuard.reset( new vos::OGuard(mpMutex) );
144cdf0e10cSrcweir 
145*d75c37aeSmseidel 	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 
getPropertyValues(const Sequence<::rtl::OUString> & aPropertyNames)171*d75c37aeSmseidel Sequence< Any > SAL_CALL ChainablePropertySet::getPropertyValues( const Sequence< ::rtl::OUString >& aPropertyNames )
172cdf0e10cSrcweir 	throw(RuntimeException)
173cdf0e10cSrcweir {
174*d75c37aeSmseidel 	// acquire mutex in c-tor and releases it in the d-tor (exception safe!).
175*d75c37aeSmseidel 	std::auto_ptr< vos::OGuard > pMutexGuard;
176*d75c37aeSmseidel 	if (mpMutex)
177*d75c37aeSmseidel 		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 
addPropertiesChangeListener(const Sequence<::rtl::OUString> &,const Reference<XPropertiesChangeListener> &)205*d75c37aeSmseidel void SAL_CALL ChainablePropertySet::addPropertiesChangeListener( const Sequence< ::rtl::OUString >&, const Reference< XPropertiesChangeListener >& )
206cdf0e10cSrcweir 	throw(RuntimeException)
207cdf0e10cSrcweir {
208cdf0e10cSrcweir 	// todo
209cdf0e10cSrcweir }
210cdf0e10cSrcweir 
removePropertiesChangeListener(const Reference<XPropertiesChangeListener> &)211*d75c37aeSmseidel void SAL_CALL ChainablePropertySet::removePropertiesChangeListener( const Reference< XPropertiesChangeListener >& )
212cdf0e10cSrcweir 	throw(RuntimeException)
213cdf0e10cSrcweir {
214cdf0e10cSrcweir 	// todo
215cdf0e10cSrcweir }
216cdf0e10cSrcweir 
firePropertiesChangeEvent(const Sequence<::rtl::OUString> &,const Reference<XPropertiesChangeListener> &)217*d75c37aeSmseidel void SAL_CALL ChainablePropertySet::firePropertiesChangeEvent( const Sequence< ::rtl::OUString >&, const Reference< XPropertiesChangeListener >& )
218cdf0e10cSrcweir 	throw(RuntimeException)
219cdf0e10cSrcweir {
220cdf0e10cSrcweir 	// todo
221cdf0e10cSrcweir }
222cdf0e10cSrcweir 
223cdf0e10cSrcweir // XPropertyState
getPropertyState(const::rtl::OUString & PropertyName)224*d75c37aeSmseidel PropertyState SAL_CALL ChainablePropertySet::getPropertyState( const ::rtl::OUString& PropertyName )
225cdf0e10cSrcweir 	throw(UnknownPropertyException, RuntimeException)
226cdf0e10cSrcweir {
227*d75c37aeSmseidel 	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 
getPropertyStates(const Sequence<::rtl::OUString> & rPropertyNames)240*d75c37aeSmseidel 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 
setPropertyToDefault(const::rtl::OUString & rPropertyName)266*d75c37aeSmseidel 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 
getPropertyDefault(const::rtl::OUString & rPropertyName)276*d75c37aeSmseidel 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 
_preGetPropertyState()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 
_getPropertyState(const comphelper::PropertyInfo &,PropertyState &)292*d75c37aeSmseidel void ChainablePropertySet::_getPropertyState( const comphelper::PropertyInfo&, PropertyState& )
293cdf0e10cSrcweir 	throw(UnknownPropertyException )
294cdf0e10cSrcweir {
295cdf0e10cSrcweir 	OSL_ENSURE( sal_False, "you have to implement this yourself!");
296cdf0e10cSrcweir }
297cdf0e10cSrcweir 
_postGetPropertyState()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 
_setPropertyToDefault(const comphelper::PropertyInfo &)304*d75c37aeSmseidel void ChainablePropertySet::_setPropertyToDefault( const comphelper::PropertyInfo& )
305cdf0e10cSrcweir 	throw(UnknownPropertyException )
306cdf0e10cSrcweir {
307cdf0e10cSrcweir 	OSL_ENSURE( sal_False, "you have to implement this yourself!");
308cdf0e10cSrcweir }
309cdf0e10cSrcweir 
_getPropertyDefault(const comphelper::PropertyInfo &)310*d75c37aeSmseidel 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