bump product version to 5.0.4.1
[LibreOffice.git] / comphelper / source / property / ChainablePropertySet.cxx
blobaf36f0ce2170ecc7a6d26d881d8bd1c58b0f2759
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
26 #include <memory>
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 )
35 throw()
36 : mpInfo ( pInfo )
37 , mpMutex ( pMutex )
38 , mxInfo ( pInfo )
42 ChainablePropertySet::~ChainablePropertySet()
43 throw()
47 // XPropertySet
48 Reference< XPropertySetInfo > SAL_CALL ChainablePropertySet::getPropertySetInfo( )
49 throw(RuntimeException, std::exception)
51 return mxInfo;
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;
59 if (mpMutex)
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 ) );
67 _preSetValues();
68 _setSingleValue( *((*aIter).second), rValue );
69 _postSetValues();
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;
77 if (mpMutex)
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 ) );
85 Any aAny;
86 _preGetValues ();
87 _getSingleValue( *((*aIter).second), aAny );
88 _postGetValues ();
90 return aAny;
93 void SAL_CALL ChainablePropertySet::addPropertyChangeListener( const OUString&, const Reference< XPropertyChangeListener >& )
94 throw(UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception)
96 // todo
99 void SAL_CALL ChainablePropertySet::removePropertyChangeListener( const OUString&, const Reference< XPropertyChangeListener >& )
100 throw(UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception)
102 // todo
105 void SAL_CALL ChainablePropertySet::addVetoableChangeListener( const OUString&, const Reference< XVetoableChangeListener >& )
106 throw(UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception)
108 // todo
111 void SAL_CALL ChainablePropertySet::removeVetoableChangeListener( const OUString&, const Reference< XVetoableChangeListener >& )
112 throw(UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception)
114 // todo
117 // XMultiPropertySet
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;
124 if (mpMutex)
125 xMutexGuard.reset( new osl::Guard< comphelper::SolarMutex >(mpMutex) );
127 const sal_Int32 nCount = rPropertyNames.getLength();
129 if( nCount != rValues.getLength() )
130 throw IllegalArgumentException();
132 if( nCount )
134 _preSetValues();
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 );
143 if ( aIter == aEnd )
144 throw RuntimeException( *pString, static_cast< XPropertySet* >( this ) );
146 _setSingleValue ( *((*aIter).second), *pAny );
149 _postSetValues();
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;
158 if (mpMutex)
159 xMutexGuard.reset( new osl::Guard< comphelper::SolarMutex >(mpMutex) );
161 const sal_Int32 nCount = rPropertyNames.getLength();
163 Sequence < Any > aValues ( nCount );
165 if( nCount )
167 _preGetValues();
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 );
176 if ( aIter == aEnd )
177 throw RuntimeException( *pString, static_cast< XPropertySet* >( this ) );
179 _getSingleValue ( *((*aIter).second), *pAny );
182 _postGetValues();
184 return aValues;
187 void SAL_CALL ChainablePropertySet::addPropertiesChangeListener( const Sequence< OUString >&, const Reference< XPropertiesChangeListener >& )
188 throw(RuntimeException, std::exception)
190 // todo
193 void SAL_CALL ChainablePropertySet::removePropertiesChangeListener( const Reference< XPropertiesChangeListener >& )
194 throw(RuntimeException, std::exception)
196 // todo
199 void SAL_CALL ChainablePropertySet::firePropertiesChangeEvent( const Sequence< OUString >&, const Reference< XPropertiesChangeListener >& )
200 throw(RuntimeException, std::exception)
202 // todo
205 // XPropertyState
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();
219 return aState;
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 );
228 if( 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 );
238 if ( aIter == aEnd )
239 throw UnknownPropertyException( *pString, static_cast< XPropertySet* >( this ) );
241 _getPropertyState ( *((*aIter).second), *pState );
243 _postGetPropertyState();
245 return aStates;
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!");
297 Any aAny;
298 return aAny;
301 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */