Bump version to 4.3-4
[LibreOffice.git] / comphelper / source / property / ChainablePropertySet.cxx
blob8e8fc59842b7c49444b4b869325be62d2fd1647f
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 <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 )
33 throw()
34 : mpInfo ( pInfo )
35 , mpMutex ( pMutex )
36 , mxInfo ( pInfo )
40 ChainablePropertySet::~ChainablePropertySet()
41 throw()
45 // XPropertySet
46 Reference< XPropertySetInfo > SAL_CALL ChainablePropertySet::getPropertySetInfo( )
47 throw(RuntimeException, std::exception)
49 return mxInfo;
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;
57 if (mpMutex)
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 ) );
65 _preSetValues();
66 _setSingleValue( *((*aIter).second), rValue );
67 _postSetValues();
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;
75 if (mpMutex)
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 ) );
83 Any aAny;
84 _preGetValues ();
85 _getSingleValue( *((*aIter).second), aAny );
86 _postGetValues ();
88 return aAny;
91 void SAL_CALL ChainablePropertySet::addPropertyChangeListener( const OUString&, const Reference< XPropertyChangeListener >& )
92 throw(UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception)
94 // todo
97 void SAL_CALL ChainablePropertySet::removePropertyChangeListener( const OUString&, const Reference< XPropertyChangeListener >& )
98 throw(UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception)
100 // todo
103 void SAL_CALL ChainablePropertySet::addVetoableChangeListener( const OUString&, const Reference< XVetoableChangeListener >& )
104 throw(UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception)
106 // todo
109 void SAL_CALL ChainablePropertySet::removeVetoableChangeListener( const OUString&, const Reference< XVetoableChangeListener >& )
110 throw(UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception)
112 // todo
115 // XMultiPropertySet
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;
121 if (mpMutex)
122 pMutexGuard.reset( new osl::Guard< comphelper::SolarMutex >(mpMutex) );
124 const sal_Int32 nCount = aPropertyNames.getLength();
126 if( nCount != aValues.getLength() )
127 throw IllegalArgumentException();
129 if( nCount )
131 _preSetValues();
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 );
140 if ( aIter == aEnd )
141 throw UnknownPropertyException( *pString, static_cast< XPropertySet* >( this ) );
143 _setSingleValue ( *((*aIter).second), *pAny );
146 _postSetValues();
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;
155 if (mpMutex)
156 pMutexGuard.reset( new osl::Guard< comphelper::SolarMutex >(mpMutex) );
158 const sal_Int32 nCount = aPropertyNames.getLength();
160 Sequence < Any > aValues ( nCount );
162 if( nCount )
164 _preGetValues();
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 );
173 if ( aIter == aEnd )
174 throw UnknownPropertyException( *pString, static_cast< XPropertySet* >( this ) );
176 _getSingleValue ( *((*aIter).second), *pAny );
179 _postGetValues();
181 return aValues;
184 void SAL_CALL ChainablePropertySet::addPropertiesChangeListener( const Sequence< OUString >&, const Reference< XPropertiesChangeListener >& )
185 throw(RuntimeException, std::exception)
187 // todo
190 void SAL_CALL ChainablePropertySet::removePropertiesChangeListener( const Reference< XPropertiesChangeListener >& )
191 throw(RuntimeException, std::exception)
193 // todo
196 void SAL_CALL ChainablePropertySet::firePropertiesChangeEvent( const Sequence< OUString >&, const Reference< XPropertiesChangeListener >& )
197 throw(RuntimeException, std::exception)
199 // todo
202 // XPropertyState
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();
216 return aState;
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 );
225 if( 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 );
235 if ( aIter == aEnd )
236 throw UnknownPropertyException( *pString, static_cast< XPropertySet* >( this ) );
238 _getPropertyState ( *((*aIter).second), *pState );
240 _postGetPropertyState();
242 return aStates;
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!");
294 Any aAny;
295 return aAny;
298 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */