Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / comphelper / source / property / ChainablePropertySet.cxx
blob1fb16b302f6f4ae08de7fa8f21b921af735cccf0
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 <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 )
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)
51 return mxInfo;
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;
59 if (mpMutex)
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 ) );
67 _preSetValues();
68 _setSingleValue( *((*aIter).second), rValue );
69 _postSetValues();
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;
77 if (mpMutex)
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 ) );
85 Any aAny;
86 _preGetValues ();
87 _getSingleValue( *((*aIter).second), aAny );
88 _postGetValues ();
90 return aAny;
93 void SAL_CALL ChainablePropertySet::addPropertyChangeListener( const ::rtl::OUString&, const Reference< XPropertyChangeListener >& )
94 throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
96 // todo
99 void SAL_CALL ChainablePropertySet::removePropertyChangeListener( const ::rtl::OUString&, const Reference< XPropertyChangeListener >& )
100 throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
102 // todo
105 void SAL_CALL ChainablePropertySet::addVetoableChangeListener( const ::rtl::OUString&, const Reference< XVetoableChangeListener >& )
106 throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
108 // todo
111 void SAL_CALL ChainablePropertySet::removeVetoableChangeListener( const ::rtl::OUString&, const Reference< XVetoableChangeListener >& )
112 throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
114 // todo
117 // XMultiPropertySet
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;
123 if (mpMutex)
124 pMutexGuard.reset( new osl::SolarGuard(mpMutex) );
126 const sal_Int32 nCount = aPropertyNames.getLength();
128 if( nCount != aValues.getLength() )
129 throw IllegalArgumentException();
131 if( nCount )
133 _preSetValues();
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 );
142 if ( aIter == aEnd )
143 throw UnknownPropertyException( *pString, static_cast< XPropertySet* >( this ) );
145 _setSingleValue ( *((*aIter).second), *pAny );
148 _postSetValues();
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;
157 if (mpMutex)
158 pMutexGuard.reset( new osl::SolarGuard(mpMutex) );
160 const sal_Int32 nCount = aPropertyNames.getLength();
162 Sequence < Any > aValues ( nCount );
164 if( nCount )
166 _preGetValues();
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 );
175 if ( aIter == aEnd )
176 throw UnknownPropertyException( *pString, static_cast< XPropertySet* >( this ) );
178 _getSingleValue ( *((*aIter).second), *pAny );
181 _postGetValues();
183 return aValues;
186 void SAL_CALL ChainablePropertySet::addPropertiesChangeListener( const Sequence< ::rtl::OUString >&, const Reference< XPropertiesChangeListener >& )
187 throw(RuntimeException)
189 // todo
192 void SAL_CALL ChainablePropertySet::removePropertiesChangeListener( const Reference< XPropertiesChangeListener >& )
193 throw(RuntimeException)
195 // todo
198 void SAL_CALL ChainablePropertySet::firePropertiesChangeEvent( const Sequence< ::rtl::OUString >&, const Reference< XPropertiesChangeListener >& )
199 throw(RuntimeException)
201 // todo
204 // XPropertyState
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();
218 return aState;
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 );
227 if( 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 );
237 if ( aIter == aEnd )
238 throw UnknownPropertyException( *pString, static_cast< XPropertySet* >( this ) );
240 _getPropertyState ( *((*aIter).second), *pState );
242 _postGetPropertyState();
244 return aStates;
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!");
296 Any aAny;
297 return aAny;
300 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */