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 <comphelper/solarmutex.hxx>
24 #include <osl/diagnose.h>
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
, comphelper::SolarMutex
* pMutex
)
42 ChainablePropertySet::~ChainablePropertySet()
48 Reference
< XPropertySetInfo
> SAL_CALL
ChainablePropertySet::getPropertySetInfo( )
49 throw(RuntimeException
, std::exception
)
54 void SAL_CALL
ChainablePropertySet::setPropertyValue( const OUString
& rPropertyName
, const Any
& rValue
)
55 throw(UnknownPropertyException
, PropertyVetoException
, IllegalArgumentException
, WrappedTargetException
, RuntimeException
, std::exception
)
57 // acquire mutex in c-tor and releases it in the d-tor (exception safe!).
58 std::unique_ptr
< osl::Guard
< comphelper::SolarMutex
> > xMutexGuard
;
60 xMutexGuard
.reset( new osl::Guard
< comphelper::SolarMutex
>(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 OUString
& rPropertyName
)
73 throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
, std::exception
)
75 // acquire mutex in c-tor and releases it in the d-tor (exception safe!).
76 std::unique_ptr
< osl::Guard
< comphelper::SolarMutex
> > xMutexGuard
;
78 xMutexGuard
.reset( new osl::Guard
< comphelper::SolarMutex
>(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 OUString
&, const Reference
< XPropertyChangeListener
>& )
94 throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
, std::exception
)
99 void SAL_CALL
ChainablePropertySet::removePropertyChangeListener( const OUString
&, const Reference
< XPropertyChangeListener
>& )
100 throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
, std::exception
)
105 void SAL_CALL
ChainablePropertySet::addVetoableChangeListener( const OUString
&, const Reference
< XVetoableChangeListener
>& )
106 throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
, std::exception
)
111 void SAL_CALL
ChainablePropertySet::removeVetoableChangeListener( const OUString
&, const Reference
< XVetoableChangeListener
>& )
112 throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
, std::exception
)
118 void SAL_CALL
ChainablePropertySet::setPropertyValues(const Sequence
< OUString
>& rPropertyNames
, const Sequence
< Any
>& rValues
)
119 throw (PropertyVetoException
, IllegalArgumentException
,
120 WrappedTargetException
, RuntimeException
, std::exception
)
122 // acquire mutex in c-tor and releases it in the d-tor (exception safe!).
123 std::unique_ptr
< osl::Guard
< comphelper::SolarMutex
> > xMutexGuard
;
125 xMutexGuard
.reset( new osl::Guard
< comphelper::SolarMutex
>(mpMutex
) );
127 const sal_Int32 nCount
= rPropertyNames
.getLength();
129 if( nCount
!= rValues
.getLength() )
130 throw IllegalArgumentException();
136 const Any
* pAny
= rValues
.getConstArray();
137 const OUString
* pString
= rPropertyNames
.getConstArray();
138 PropertyInfoHash::const_iterator aEnd
= mpInfo
->maMap
.end(), aIter
;
140 for ( sal_Int32 i
= 0; i
< nCount
; ++i
, ++pString
, ++pAny
)
142 aIter
= mpInfo
->maMap
.find ( *pString
);
144 throw RuntimeException( *pString
, static_cast< XPropertySet
* >( this ) );
146 _setSingleValue ( *((*aIter
).second
), *pAny
);
153 Sequence
< Any
> SAL_CALL
ChainablePropertySet::getPropertyValues(const Sequence
< OUString
>& rPropertyNames
)
154 throw (RuntimeException
, std::exception
)
156 // acquire mutex in c-tor and releases it in the d-tor (exception safe!).
157 std::unique_ptr
< osl::Guard
< comphelper::SolarMutex
> > xMutexGuard
;
159 xMutexGuard
.reset( new osl::Guard
< comphelper::SolarMutex
>(mpMutex
) );
161 const sal_Int32 nCount
= rPropertyNames
.getLength();
163 Sequence
< Any
> aValues ( nCount
);
169 Any
* pAny
= aValues
.getArray();
170 const OUString
* pString
= rPropertyNames
.getConstArray();
171 PropertyInfoHash::const_iterator aEnd
= mpInfo
->maMap
.end(), aIter
;
173 for ( sal_Int32 i
= 0; i
< nCount
; ++i
, ++pString
, ++pAny
)
175 aIter
= mpInfo
->maMap
.find ( *pString
);
177 throw RuntimeException( *pString
, static_cast< XPropertySet
* >( this ) );
179 _getSingleValue ( *((*aIter
).second
), *pAny
);
187 void SAL_CALL
ChainablePropertySet::addPropertiesChangeListener( const Sequence
< OUString
>&, const Reference
< XPropertiesChangeListener
>& )
188 throw(RuntimeException
, std::exception
)
193 void SAL_CALL
ChainablePropertySet::removePropertiesChangeListener( const Reference
< XPropertiesChangeListener
>& )
194 throw(RuntimeException
, std::exception
)
199 void SAL_CALL
ChainablePropertySet::firePropertiesChangeEvent( const Sequence
< OUString
>&, const Reference
< XPropertiesChangeListener
>& )
200 throw(RuntimeException
, std::exception
)
206 PropertyState SAL_CALL
ChainablePropertySet::getPropertyState( const OUString
& PropertyName
)
207 throw(UnknownPropertyException
, RuntimeException
, std::exception
)
209 PropertyInfoHash::const_iterator aIter
= mpInfo
->maMap
.find( PropertyName
);
210 if( aIter
== mpInfo
->maMap
.end())
211 throw UnknownPropertyException( PropertyName
, static_cast< XPropertySet
* >( this ) );
213 PropertyState
aState(PropertyState_AMBIGUOUS_VALUE
);
215 _preGetPropertyState();
216 _getPropertyState( *((*aIter
).second
), aState
);
217 _postGetPropertyState();
222 Sequence
< PropertyState
> SAL_CALL
ChainablePropertySet::getPropertyStates( const Sequence
< OUString
>& rPropertyNames
)
223 throw(UnknownPropertyException
, RuntimeException
, std::exception
)
225 const sal_Int32 nCount
= rPropertyNames
.getLength();
227 Sequence
< PropertyState
> aStates( nCount
);
230 PropertyState
* pState
= aStates
.getArray();
231 const OUString
* pString
= rPropertyNames
.getConstArray();
232 PropertyInfoHash::const_iterator aEnd
= mpInfo
->maMap
.end(), aIter
;
233 _preGetPropertyState();
235 for ( sal_Int32 i
= 0; i
< nCount
; ++i
, ++pString
, ++pState
)
237 aIter
= mpInfo
->maMap
.find ( *pString
);
239 throw UnknownPropertyException( *pString
, static_cast< XPropertySet
* >( this ) );
241 _getPropertyState ( *((*aIter
).second
), *pState
);
243 _postGetPropertyState();
248 void SAL_CALL
ChainablePropertySet::setPropertyToDefault( const OUString
& rPropertyName
)
249 throw(UnknownPropertyException
, RuntimeException
, std::exception
)
251 PropertyInfoHash::const_iterator aIter
= mpInfo
->maMap
.find ( rPropertyName
);
253 if( aIter
== mpInfo
->maMap
.end())
254 throw UnknownPropertyException( rPropertyName
, static_cast< XPropertySet
* >( this ) );
255 _setPropertyToDefault( *((*aIter
).second
) );
258 Any SAL_CALL
ChainablePropertySet::getPropertyDefault( const OUString
& rPropertyName
)
259 throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
, std::exception
)
261 PropertyInfoHash::const_iterator aIter
= mpInfo
->maMap
.find ( rPropertyName
);
263 if( aIter
== mpInfo
->maMap
.end())
264 throw UnknownPropertyException( rPropertyName
, static_cast< XPropertySet
* >( this ) );
265 return _getPropertyDefault( *((*aIter
).second
) );
268 void ChainablePropertySet::_preGetPropertyState ()
269 throw(::com::sun::star::beans::UnknownPropertyException
, ::com::sun::star::beans::PropertyVetoException
, ::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::lang::WrappedTargetException
)
271 OSL_FAIL( "you have to implement this yourself!");
274 void ChainablePropertySet::_getPropertyState( const comphelper::PropertyInfo
&, PropertyState
& )
275 throw(UnknownPropertyException
)
277 OSL_FAIL( "you have to implement this yourself!");
280 void ChainablePropertySet::_postGetPropertyState ()
281 throw(::com::sun::star::beans::UnknownPropertyException
, ::com::sun::star::beans::PropertyVetoException
, ::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::lang::WrappedTargetException
)
283 OSL_FAIL( "you have to implement this yourself!");
286 void ChainablePropertySet::_setPropertyToDefault( const comphelper::PropertyInfo
& )
287 throw(UnknownPropertyException
)
289 OSL_FAIL( "you have to implement this yourself!");
292 Any
ChainablePropertySet::_getPropertyDefault( const comphelper::PropertyInfo
& )
293 throw(UnknownPropertyException
, WrappedTargetException
)
295 OSL_FAIL( "you have to implement this yourself!");
301 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */