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 <boost/scoped_ptr.hpp>
26 using namespace ::comphelper
;
27 using namespace ::com::sun::star
;
28 using namespace ::com::sun::star::uno
;
29 using namespace ::com::sun::star::lang
;
30 using namespace ::com::sun::star::beans
;
32 ChainablePropertySet::ChainablePropertySet( comphelper::ChainablePropertySetInfo
* pInfo
, comphelper::SolarMutex
* pMutex
)
40 ChainablePropertySet::~ChainablePropertySet()
46 Reference
< XPropertySetInfo
> SAL_CALL
ChainablePropertySet::getPropertySetInfo( )
47 throw(RuntimeException
, std::exception
)
52 void SAL_CALL
ChainablePropertySet::setPropertyValue( const OUString
& rPropertyName
, const Any
& rValue
)
53 throw(UnknownPropertyException
, PropertyVetoException
, IllegalArgumentException
, WrappedTargetException
, RuntimeException
, std::exception
)
55 // acquire mutex in c-tor and releases it in the d-tor (exception safe!).
56 boost::scoped_ptr
< osl::Guard
< comphelper::SolarMutex
> > pMutexGuard
;
58 pMutexGuard
.reset( new osl::Guard
< comphelper::SolarMutex
>(mpMutex
) );
60 PropertyInfoHash::const_iterator aIter
= mpInfo
->maMap
.find ( rPropertyName
);
62 if( aIter
== mpInfo
->maMap
.end())
63 throw UnknownPropertyException( rPropertyName
, static_cast< XPropertySet
* >( this ) );
66 _setSingleValue( *((*aIter
).second
), rValue
);
70 Any SAL_CALL
ChainablePropertySet::getPropertyValue( const OUString
& rPropertyName
)
71 throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
, std::exception
)
73 // acquire mutex in c-tor and releases it in the d-tor (exception safe!).
74 boost::scoped_ptr
< osl::Guard
< comphelper::SolarMutex
> > pMutexGuard
;
76 pMutexGuard
.reset( new osl::Guard
< comphelper::SolarMutex
>(mpMutex
) );
78 PropertyInfoHash::const_iterator aIter
= mpInfo
->maMap
.find ( rPropertyName
);
80 if( aIter
== mpInfo
->maMap
.end())
81 throw UnknownPropertyException( rPropertyName
, static_cast< XPropertySet
* >( this ) );
85 _getSingleValue( *((*aIter
).second
), aAny
);
91 void SAL_CALL
ChainablePropertySet::addPropertyChangeListener( const OUString
&, const Reference
< XPropertyChangeListener
>& )
92 throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
, std::exception
)
97 void SAL_CALL
ChainablePropertySet::removePropertyChangeListener( const OUString
&, const Reference
< XPropertyChangeListener
>& )
98 throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
, std::exception
)
103 void SAL_CALL
ChainablePropertySet::addVetoableChangeListener( const OUString
&, const Reference
< XVetoableChangeListener
>& )
104 throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
, std::exception
)
109 void SAL_CALL
ChainablePropertySet::removeVetoableChangeListener( const OUString
&, const Reference
< XVetoableChangeListener
>& )
110 throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
, std::exception
)
116 void SAL_CALL
ChainablePropertySet::setPropertyValues( const Sequence
< OUString
>& aPropertyNames
, const Sequence
< Any
>& aValues
)
117 throw(PropertyVetoException
, IllegalArgumentException
, WrappedTargetException
, RuntimeException
, std::exception
)
119 // acquire mutex in c-tor and releases it in the d-tor (exception safe!).
120 boost::scoped_ptr
< osl::Guard
< comphelper::SolarMutex
> > pMutexGuard
;
122 pMutexGuard
.reset( new osl::Guard
< comphelper::SolarMutex
>(mpMutex
) );
124 const sal_Int32 nCount
= aPropertyNames
.getLength();
126 if( nCount
!= aValues
.getLength() )
127 throw IllegalArgumentException();
133 const Any
* pAny
= aValues
.getConstArray();
134 const OUString
* pString
= aPropertyNames
.getConstArray();
135 PropertyInfoHash::const_iterator aEnd
= mpInfo
->maMap
.end(), aIter
;
137 for ( sal_Int32 i
= 0; i
< nCount
; ++i
, ++pString
, ++pAny
)
139 aIter
= mpInfo
->maMap
.find ( *pString
);
141 throw UnknownPropertyException( *pString
, static_cast< XPropertySet
* >( this ) );
143 _setSingleValue ( *((*aIter
).second
), *pAny
);
150 Sequence
< Any
> SAL_CALL
ChainablePropertySet::getPropertyValues( const Sequence
< OUString
>& aPropertyNames
)
151 throw(RuntimeException
, std::exception
)
153 // acquire mutex in c-tor and releases it in the d-tor (exception safe!).
154 boost::scoped_ptr
< osl::Guard
< comphelper::SolarMutex
> > pMutexGuard
;
156 pMutexGuard
.reset( new osl::Guard
< comphelper::SolarMutex
>(mpMutex
) );
158 const sal_Int32 nCount
= aPropertyNames
.getLength();
160 Sequence
< Any
> aValues ( nCount
);
166 Any
* pAny
= aValues
.getArray();
167 const OUString
* pString
= aPropertyNames
.getConstArray();
168 PropertyInfoHash::const_iterator aEnd
= mpInfo
->maMap
.end(), aIter
;
170 for ( sal_Int32 i
= 0; i
< nCount
; ++i
, ++pString
, ++pAny
)
172 aIter
= mpInfo
->maMap
.find ( *pString
);
174 throw UnknownPropertyException( *pString
, static_cast< XPropertySet
* >( this ) );
176 _getSingleValue ( *((*aIter
).second
), *pAny
);
184 void SAL_CALL
ChainablePropertySet::addPropertiesChangeListener( const Sequence
< OUString
>&, const Reference
< XPropertiesChangeListener
>& )
185 throw(RuntimeException
, std::exception
)
190 void SAL_CALL
ChainablePropertySet::removePropertiesChangeListener( const Reference
< XPropertiesChangeListener
>& )
191 throw(RuntimeException
, std::exception
)
196 void SAL_CALL
ChainablePropertySet::firePropertiesChangeEvent( const Sequence
< OUString
>&, const Reference
< XPropertiesChangeListener
>& )
197 throw(RuntimeException
, std::exception
)
203 PropertyState SAL_CALL
ChainablePropertySet::getPropertyState( const OUString
& PropertyName
)
204 throw(UnknownPropertyException
, RuntimeException
, std::exception
)
206 PropertyInfoHash::const_iterator aIter
= mpInfo
->maMap
.find( PropertyName
);
207 if( aIter
== mpInfo
->maMap
.end())
208 throw UnknownPropertyException( PropertyName
, static_cast< XPropertySet
* >( this ) );
210 PropertyState aState
;
212 _preGetPropertyState();
213 _getPropertyState( *((*aIter
).second
), aState
);
214 _postGetPropertyState();
219 Sequence
< PropertyState
> SAL_CALL
ChainablePropertySet::getPropertyStates( const Sequence
< OUString
>& rPropertyNames
)
220 throw(UnknownPropertyException
, RuntimeException
, std::exception
)
222 const sal_Int32 nCount
= rPropertyNames
.getLength();
224 Sequence
< PropertyState
> aStates( nCount
);
227 PropertyState
* pState
= aStates
.getArray();
228 const OUString
* pString
= rPropertyNames
.getConstArray();
229 PropertyInfoHash::const_iterator aEnd
= mpInfo
->maMap
.end(), aIter
;
230 _preGetPropertyState();
232 for ( sal_Int32 i
= 0; i
< nCount
; ++i
, ++pString
, ++pState
)
234 aIter
= mpInfo
->maMap
.find ( *pString
);
236 throw UnknownPropertyException( *pString
, static_cast< XPropertySet
* >( this ) );
238 _getPropertyState ( *((*aIter
).second
), *pState
);
240 _postGetPropertyState();
245 void SAL_CALL
ChainablePropertySet::setPropertyToDefault( const OUString
& rPropertyName
)
246 throw(UnknownPropertyException
, RuntimeException
, std::exception
)
248 PropertyInfoHash::const_iterator aIter
= mpInfo
->maMap
.find ( rPropertyName
);
250 if( aIter
== mpInfo
->maMap
.end())
251 throw UnknownPropertyException( rPropertyName
, static_cast< XPropertySet
* >( this ) );
252 _setPropertyToDefault( *((*aIter
).second
) );
255 Any SAL_CALL
ChainablePropertySet::getPropertyDefault( const OUString
& rPropertyName
)
256 throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
, std::exception
)
258 PropertyInfoHash::const_iterator aIter
= mpInfo
->maMap
.find ( rPropertyName
);
260 if( aIter
== mpInfo
->maMap
.end())
261 throw UnknownPropertyException( rPropertyName
, static_cast< XPropertySet
* >( this ) );
262 return _getPropertyDefault( *((*aIter
).second
) );
265 void ChainablePropertySet::_preGetPropertyState ()
266 throw(::com::sun::star::beans::UnknownPropertyException
, ::com::sun::star::beans::PropertyVetoException
, ::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::lang::WrappedTargetException
)
268 OSL_FAIL( "you have to implement this yourself!");
271 void ChainablePropertySet::_getPropertyState( const comphelper::PropertyInfo
&, PropertyState
& )
272 throw(UnknownPropertyException
)
274 OSL_FAIL( "you have to implement this yourself!");
277 void ChainablePropertySet::_postGetPropertyState ()
278 throw(::com::sun::star::beans::UnknownPropertyException
, ::com::sun::star::beans::PropertyVetoException
, ::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::lang::WrappedTargetException
)
280 OSL_FAIL( "you have to implement this yourself!");
283 void ChainablePropertySet::_setPropertyToDefault( const comphelper::PropertyInfo
& )
284 throw(UnknownPropertyException
)
286 OSL_FAIL( "you have to implement this yourself!");
289 Any
ChainablePropertySet::_getPropertyDefault( const comphelper::PropertyInfo
& )
290 throw(UnknownPropertyException
, WrappedTargetException
)
292 OSL_FAIL( "you have to implement this yourself!");
298 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */