1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <comphelper/ChainablePropertySet.hxx>
21 #include <comphelper/ChainablePropertySetInfo.hxx>
22 #include <osl/mutex.hxx>
24 #include <boost/scoped_ptr.hpp>
27 using namespace ::rtl
;
28 using namespace ::comphelper
;
29 using namespace ::com::sun::star
;
30 using namespace ::com::sun::star::uno
;
31 using namespace ::com::sun::star::lang
;
32 using namespace ::com::sun::star::beans
;
34 ChainablePropertySet::ChainablePropertySet( comphelper::ChainablePropertySetInfo
* pInfo
, osl::SolarMutex
* pMutex
)
42 ChainablePropertySet::~ChainablePropertySet()
48 Reference
< XPropertySetInfo
> SAL_CALL
ChainablePropertySet::getPropertySetInfo( )
49 throw(RuntimeException
)
54 void SAL_CALL
ChainablePropertySet::setPropertyValue( const ::rtl::OUString
& rPropertyName
, const Any
& rValue
)
55 throw(UnknownPropertyException
, PropertyVetoException
, IllegalArgumentException
, WrappedTargetException
, RuntimeException
)
57 // acquire mutex in c-tor and releases it in the d-tor (exception safe!).
58 boost::scoped_ptr
< osl::SolarGuard
> pMutexGuard
;
60 pMutexGuard
.reset( new osl::SolarGuard(mpMutex
) );
62 PropertyInfoHash::const_iterator aIter
= mpInfo
->maMap
.find ( rPropertyName
);
64 if( aIter
== mpInfo
->maMap
.end())
65 throw UnknownPropertyException( rPropertyName
, static_cast< XPropertySet
* >( this ) );
68 _setSingleValue( *((*aIter
).second
), rValue
);
72 Any SAL_CALL
ChainablePropertySet::getPropertyValue( const ::rtl::OUString
& rPropertyName
)
73 throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
75 // acquire mutex in c-tor and releases it in the d-tor (exception safe!).
76 boost::scoped_ptr
< osl::SolarGuard
> pMutexGuard
;
78 pMutexGuard
.reset( new osl::SolarGuard(mpMutex
) );
80 PropertyInfoHash::const_iterator aIter
= mpInfo
->maMap
.find ( rPropertyName
);
82 if( aIter
== mpInfo
->maMap
.end())
83 throw UnknownPropertyException( rPropertyName
, static_cast< XPropertySet
* >( this ) );
87 _getSingleValue( *((*aIter
).second
), aAny
);
93 void SAL_CALL
ChainablePropertySet::addPropertyChangeListener( const ::rtl::OUString
&, const Reference
< XPropertyChangeListener
>& )
94 throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
99 void SAL_CALL
ChainablePropertySet::removePropertyChangeListener( const ::rtl::OUString
&, const Reference
< XPropertyChangeListener
>& )
100 throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
105 void SAL_CALL
ChainablePropertySet::addVetoableChangeListener( const ::rtl::OUString
&, const Reference
< XVetoableChangeListener
>& )
106 throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
111 void SAL_CALL
ChainablePropertySet::removeVetoableChangeListener( const ::rtl::OUString
&, const Reference
< XVetoableChangeListener
>& )
112 throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
118 void SAL_CALL
ChainablePropertySet::setPropertyValues( const Sequence
< ::rtl::OUString
>& aPropertyNames
, const Sequence
< Any
>& aValues
)
119 throw(PropertyVetoException
, IllegalArgumentException
, WrappedTargetException
, RuntimeException
)
121 // acquire mutex in c-tor and releases it in the d-tor (exception safe!).
122 boost::scoped_ptr
< osl::SolarGuard
> pMutexGuard
;
124 pMutexGuard
.reset( new osl::SolarGuard(mpMutex
) );
126 const sal_Int32 nCount
= aPropertyNames
.getLength();
128 if( nCount
!= aValues
.getLength() )
129 throw IllegalArgumentException();
135 const Any
* pAny
= aValues
.getConstArray();
136 const OUString
* pString
= aPropertyNames
.getConstArray();
137 PropertyInfoHash::const_iterator aEnd
= mpInfo
->maMap
.end(), aIter
;
139 for ( sal_Int32 i
= 0; i
< nCount
; ++i
, ++pString
, ++pAny
)
141 aIter
= mpInfo
->maMap
.find ( *pString
);
143 throw UnknownPropertyException( *pString
, static_cast< XPropertySet
* >( this ) );
145 _setSingleValue ( *((*aIter
).second
), *pAny
);
152 Sequence
< Any
> SAL_CALL
ChainablePropertySet::getPropertyValues( const Sequence
< ::rtl::OUString
>& aPropertyNames
)
153 throw(RuntimeException
)
155 // acquire mutex in c-tor and releases it in the d-tor (exception safe!).
156 boost::scoped_ptr
< osl::SolarGuard
> pMutexGuard
;
158 pMutexGuard
.reset( new osl::SolarGuard(mpMutex
) );
160 const sal_Int32 nCount
= aPropertyNames
.getLength();
162 Sequence
< Any
> aValues ( nCount
);
168 Any
* pAny
= aValues
.getArray();
169 const OUString
* pString
= aPropertyNames
.getConstArray();
170 PropertyInfoHash::const_iterator aEnd
= mpInfo
->maMap
.end(), aIter
;
172 for ( sal_Int32 i
= 0; i
< nCount
; ++i
, ++pString
, ++pAny
)
174 aIter
= mpInfo
->maMap
.find ( *pString
);
176 throw UnknownPropertyException( *pString
, static_cast< XPropertySet
* >( this ) );
178 _getSingleValue ( *((*aIter
).second
), *pAny
);
186 void SAL_CALL
ChainablePropertySet::addPropertiesChangeListener( const Sequence
< ::rtl::OUString
>&, const Reference
< XPropertiesChangeListener
>& )
187 throw(RuntimeException
)
192 void SAL_CALL
ChainablePropertySet::removePropertiesChangeListener( const Reference
< XPropertiesChangeListener
>& )
193 throw(RuntimeException
)
198 void SAL_CALL
ChainablePropertySet::firePropertiesChangeEvent( const Sequence
< ::rtl::OUString
>&, const Reference
< XPropertiesChangeListener
>& )
199 throw(RuntimeException
)
205 PropertyState SAL_CALL
ChainablePropertySet::getPropertyState( const ::rtl::OUString
& PropertyName
)
206 throw(UnknownPropertyException
, RuntimeException
)
208 PropertyInfoHash::const_iterator aIter
= mpInfo
->maMap
.find( PropertyName
);
209 if( aIter
== mpInfo
->maMap
.end())
210 throw UnknownPropertyException( PropertyName
, static_cast< XPropertySet
* >( this ) );
212 PropertyState aState
;
214 _preGetPropertyState();
215 _getPropertyState( *((*aIter
).second
), aState
);
216 _postGetPropertyState();
221 Sequence
< PropertyState
> SAL_CALL
ChainablePropertySet::getPropertyStates( const Sequence
< ::rtl::OUString
>& rPropertyNames
)
222 throw(UnknownPropertyException
, RuntimeException
)
224 const sal_Int32 nCount
= rPropertyNames
.getLength();
226 Sequence
< PropertyState
> aStates( nCount
);
229 PropertyState
* pState
= aStates
.getArray();
230 const OUString
* pString
= rPropertyNames
.getConstArray();
231 PropertyInfoHash::const_iterator aEnd
= mpInfo
->maMap
.end(), aIter
;
232 _preGetPropertyState();
234 for ( sal_Int32 i
= 0; i
< nCount
; ++i
, ++pString
, ++pState
)
236 aIter
= mpInfo
->maMap
.find ( *pString
);
238 throw UnknownPropertyException( *pString
, static_cast< XPropertySet
* >( this ) );
240 _getPropertyState ( *((*aIter
).second
), *pState
);
242 _postGetPropertyState();
247 void SAL_CALL
ChainablePropertySet::setPropertyToDefault( const ::rtl::OUString
& rPropertyName
)
248 throw(UnknownPropertyException
, RuntimeException
)
250 PropertyInfoHash::const_iterator aIter
= mpInfo
->maMap
.find ( rPropertyName
);
252 if( aIter
== mpInfo
->maMap
.end())
253 throw UnknownPropertyException( rPropertyName
, static_cast< XPropertySet
* >( this ) );
254 _setPropertyToDefault( *((*aIter
).second
) );
257 Any SAL_CALL
ChainablePropertySet::getPropertyDefault( const ::rtl::OUString
& rPropertyName
)
258 throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
260 PropertyInfoHash::const_iterator aIter
= mpInfo
->maMap
.find ( rPropertyName
);
262 if( aIter
== mpInfo
->maMap
.end())
263 throw UnknownPropertyException( rPropertyName
, static_cast< XPropertySet
* >( this ) );
264 return _getPropertyDefault( *((*aIter
).second
) );
267 void ChainablePropertySet::_preGetPropertyState ()
268 throw(::com::sun::star::beans::UnknownPropertyException
, ::com::sun::star::beans::PropertyVetoException
, ::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::lang::WrappedTargetException
)
270 OSL_FAIL( "you have to implement this yourself!");
273 void ChainablePropertySet::_getPropertyState( const comphelper::PropertyInfo
&, PropertyState
& )
274 throw(UnknownPropertyException
)
276 OSL_FAIL( "you have to implement this yourself!");
279 void ChainablePropertySet::_postGetPropertyState ()
280 throw(::com::sun::star::beans::UnknownPropertyException
, ::com::sun::star::beans::PropertyVetoException
, ::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::lang::WrappedTargetException
)
282 OSL_FAIL( "you have to implement this yourself!");
285 void ChainablePropertySet::_setPropertyToDefault( const comphelper::PropertyInfo
& )
286 throw(UnknownPropertyException
)
288 OSL_FAIL( "you have to implement this yourself!");
291 Any
ChainablePropertySet::_getPropertyDefault( const comphelper::PropertyInfo
& )
292 throw(UnknownPropertyException
, WrappedTargetException
)
294 OSL_FAIL( "you have to implement this yourself!");
300 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */