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
;
45 ChainablePropertySet::ChainablePropertySet( comphelper::ChainablePropertySetInfo
* pInfo
, vos::IMutex
*pMutex
)
53 ChainablePropertySet::~ChainablePropertySet()
59 Reference
< XPropertySetInfo
> SAL_CALL
ChainablePropertySet::getPropertySetInfo( )
60 throw(RuntimeException
)
65 void ChainablePropertySet::lockMutex()
71 void ChainablePropertySet::unlockMutex()
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
;
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 ) );
91 _setSingleValue( *((*aIter
).second
), rValue
);
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
;
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 ) );
110 _getSingleValue( *((*aIter
).second
), aAny
);
116 void SAL_CALL
ChainablePropertySet::addPropertyChangeListener( const ::rtl::OUString
&, const Reference
< XPropertyChangeListener
>& )
117 throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
122 void SAL_CALL
ChainablePropertySet::removePropertyChangeListener( const ::rtl::OUString
&, const Reference
< XPropertyChangeListener
>& )
123 throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
128 void SAL_CALL
ChainablePropertySet::addVetoableChangeListener( const ::rtl::OUString
&, const Reference
< XVetoableChangeListener
>& )
129 throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
134 void SAL_CALL
ChainablePropertySet::removeVetoableChangeListener( const ::rtl::OUString
&, const Reference
< XVetoableChangeListener
>& )
135 throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
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
;
147 pMutexGuard
.reset( new vos::OGuard(mpMutex
) );
149 const sal_Int32 nCount
= aPropertyNames
.getLength();
151 if( nCount
!= aValues
.getLength() )
152 throw IllegalArgumentException();
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
);
166 throw UnknownPropertyException( *pString
, static_cast< XPropertySet
* >( this ) );
168 _setSingleValue ( *((*aIter
).second
), *pAny
);
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
;
181 pMutexGuard
.reset( new vos::OGuard(mpMutex
) );
183 const sal_Int32 nCount
= aPropertyNames
.getLength();
185 Sequence
< Any
> aValues ( nCount
);
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
);
199 throw UnknownPropertyException( *pString
, static_cast< XPropertySet
* >( this ) );
201 _getSingleValue ( *((*aIter
).second
), *pAny
);
209 void SAL_CALL
ChainablePropertySet::addPropertiesChangeListener( const Sequence
< ::rtl::OUString
>&, const Reference
< XPropertiesChangeListener
>& )
210 throw(RuntimeException
)
215 void SAL_CALL
ChainablePropertySet::removePropertiesChangeListener( const Reference
< XPropertiesChangeListener
>& )
216 throw(RuntimeException
)
221 void SAL_CALL
ChainablePropertySet::firePropertiesChangeEvent( const Sequence
< ::rtl::OUString
>&, const Reference
< XPropertiesChangeListener
>& )
222 throw(RuntimeException
)
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();
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
);
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
);
261 throw UnknownPropertyException( *pString
, static_cast< XPropertySet
* >( this ) );
263 _getPropertyState ( *((*aIter
).second
), *pState
);
265 _postGetPropertyState();
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!");