bump product version to 4.1.6.2
[LibreOffice.git] / chart2 / source / tools / WrappedPropertySet.cxx
blob07a0cdfc614718f450efd50e88e79885d1b1b981
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 .
21 #include "WrappedPropertySet.hxx"
22 #include "macros.hxx"
24 // header for define DELETEZ
25 #include <tools/solar.h>
27 //.............................................................................
28 namespace chart
30 //.............................................................................
32 using namespace ::com::sun::star;
33 using ::com::sun::star::uno::Reference;
34 using ::com::sun::star::uno::Sequence;
35 using ::com::sun::star::uno::Any;
37 WrappedPropertySet::WrappedPropertySet()
38 : MutexContainer()
39 , m_xInfo(0)
40 , m_pPropertyArrayHelper(0)
41 , m_pWrappedPropertyMap(0)
44 WrappedPropertySet::~WrappedPropertySet()
46 clearWrappedPropertySet();
49 Reference< beans::XPropertyState > WrappedPropertySet::getInnerPropertyState()
51 return Reference< beans::XPropertyState >( getInnerPropertySet(), uno::UNO_QUERY );
54 void WrappedPropertySet::clearWrappedPropertySet()
56 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );//do not use different mutex than is already used for static property sequence
58 //delete all wrapped properties
59 if(m_pWrappedPropertyMap)
61 for( tWrappedPropertyMap::iterator aIt = m_pWrappedPropertyMap->begin()
62 ; aIt!= m_pWrappedPropertyMap->end(); ++aIt )
64 const WrappedProperty* pWrappedProperty = (*aIt).second;
65 DELETEZ(pWrappedProperty);
69 DELETEZ(m_pPropertyArrayHelper);
70 DELETEZ(m_pWrappedPropertyMap);
72 m_xInfo = NULL;
75 //XPropertySet
76 Reference< beans::XPropertySetInfo > SAL_CALL WrappedPropertySet::getPropertySetInfo( )
77 throw (uno::RuntimeException)
79 Reference< beans::XPropertySetInfo > xInfo = m_xInfo;
80 if( !xInfo.is() )
82 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );//do not use different mutex than is already used for static property sequence
83 xInfo = m_xInfo;
84 if( !xInfo.is() )
86 xInfo = ::cppu::OPropertySetHelper::createPropertySetInfo( getInfoHelper() );
87 OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
88 m_xInfo = xInfo;
91 else
93 OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
95 return m_xInfo;
98 void SAL_CALL WrappedPropertySet::setPropertyValue( const OUString& rPropertyName, const Any& rValue )
99 throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
103 sal_Int32 nHandle = getInfoHelper().getHandleByName( rPropertyName );
104 const WrappedProperty* pWrappedProperty = getWrappedProperty( nHandle );
105 Reference< beans::XPropertySet > xInnerPropertySet( this->getInnerPropertySet() );
106 if( pWrappedProperty )
107 pWrappedProperty->setPropertyValue( rValue, xInnerPropertySet );
108 else if( xInnerPropertySet.is() )
109 xInnerPropertySet->setPropertyValue( rPropertyName, rValue );
110 else
112 #if OSL_DEBUG_LEVEL > 1
113 OSL_FAIL("found no inner property set to map to");
114 #endif
117 catch( const beans::UnknownPropertyException& )
119 throw;
121 catch( const beans::PropertyVetoException& )
123 throw;
125 catch( const lang::IllegalArgumentException& )
127 throw;
129 catch( const lang::WrappedTargetException& )
131 throw;
133 catch( const uno::RuntimeException& )
135 throw;
137 catch( const uno::Exception& ex )
139 OSL_FAIL("invalid exception caught in WrappedPropertySet::setPropertyValue");
140 lang::WrappedTargetException aWrappedException;
141 aWrappedException.TargetException = uno::makeAny( ex );
142 throw aWrappedException;
145 Any SAL_CALL WrappedPropertySet::getPropertyValue( const OUString& rPropertyName )
146 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
148 Any aRet;
152 sal_Int32 nHandle = getInfoHelper().getHandleByName( rPropertyName );
153 const WrappedProperty* pWrappedProperty = getWrappedProperty( nHandle );
154 Reference< beans::XPropertySet > xInnerPropertySet( this->getInnerPropertySet() );
155 if( pWrappedProperty )
156 aRet = pWrappedProperty->getPropertyValue( xInnerPropertySet );
157 else if( xInnerPropertySet.is() )
158 aRet = xInnerPropertySet->getPropertyValue( rPropertyName );
159 else
161 #if OSL_DEBUG_LEVEL > 1
162 OSL_FAIL("found no inner property set to map to");
163 #endif
166 catch( const beans::UnknownPropertyException& )
168 throw;
170 catch( const lang::WrappedTargetException& )
172 throw;
174 catch( const uno::RuntimeException& )
176 throw;
178 catch( const uno::Exception& ex )
180 OSL_FAIL("invalid exception caught in WrappedPropertySet::setPropertyValue");
181 lang::WrappedTargetException aWrappedException;
182 aWrappedException.TargetException = uno::makeAny( ex );
183 throw aWrappedException;
186 return aRet;
189 void SAL_CALL WrappedPropertySet::addPropertyChangeListener( const OUString& rPropertyName, const Reference< beans::XPropertyChangeListener >& xListener )
190 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
192 Reference< beans::XPropertySet > xInnerPropertySet( this->getInnerPropertySet() );
193 if( xInnerPropertySet.is() )
195 const WrappedProperty* pWrappedProperty = getWrappedProperty( rPropertyName );
196 if( pWrappedProperty )
197 xInnerPropertySet->addPropertyChangeListener( pWrappedProperty->getInnerName(), xListener );
198 else
199 xInnerPropertySet->addPropertyChangeListener( rPropertyName, xListener );
202 void SAL_CALL WrappedPropertySet::removePropertyChangeListener( const OUString& rPropertyName, const Reference< beans::XPropertyChangeListener >& aListener )
203 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
205 Reference< beans::XPropertySet > xInnerPropertySet( this->getInnerPropertySet() );
206 if( xInnerPropertySet.is() )
208 const WrappedProperty* pWrappedProperty = getWrappedProperty( rPropertyName );
209 if( pWrappedProperty )
210 xInnerPropertySet->removePropertyChangeListener( pWrappedProperty->getInnerName(), aListener );
211 else
212 xInnerPropertySet->removePropertyChangeListener( rPropertyName, aListener );
215 void SAL_CALL WrappedPropertySet::addVetoableChangeListener( const OUString& rPropertyName, const Reference< beans::XVetoableChangeListener >& aListener )
216 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
218 Reference< beans::XPropertySet > xInnerPropertySet( this->getInnerPropertySet() );
219 if( xInnerPropertySet.is() )
221 const WrappedProperty* pWrappedProperty = getWrappedProperty( rPropertyName );
222 if( pWrappedProperty )
223 xInnerPropertySet->addVetoableChangeListener( pWrappedProperty->getInnerName(), aListener );
224 else
225 xInnerPropertySet->addVetoableChangeListener( rPropertyName, aListener );
228 void SAL_CALL WrappedPropertySet::removeVetoableChangeListener( const OUString& rPropertyName, const Reference< beans::XVetoableChangeListener >& aListener )
229 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
231 Reference< beans::XPropertySet > xInnerPropertySet( this->getInnerPropertySet() );
232 if( xInnerPropertySet.is() )
234 const WrappedProperty* pWrappedProperty = getWrappedProperty( rPropertyName );
235 if( pWrappedProperty )
236 xInnerPropertySet->removeVetoableChangeListener( pWrappedProperty->getInnerName(), aListener );
237 else
238 xInnerPropertySet->removeVetoableChangeListener( rPropertyName, aListener );
242 //XMultiPropertySet
243 void SAL_CALL WrappedPropertySet::setPropertyValues( const Sequence< OUString >& rNameSeq, const Sequence< Any >& rValueSeq )
244 throw (beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
246 bool bUnknownProperty = false;
247 sal_Int32 nMinCount = std::min( rValueSeq.getLength(), rNameSeq.getLength() );
248 for(sal_Int32 nN=0; nN<nMinCount; nN++)
250 OUString aPropertyName( rNameSeq[nN] );
253 this->setPropertyValue( aPropertyName, rValueSeq[nN] );
255 catch( const beans::UnknownPropertyException& ex )
257 ASSERT_EXCEPTION( ex );
258 bUnknownProperty = true;
261 //todo: store unknown properties elsewhere
262 OSL_ENSURE(!bUnknownProperty,"unknown property");
263 (void)bUnknownProperty;
264 // if( bUnknownProperty )
265 // throw beans::UnknownPropertyException();
267 Sequence< Any > SAL_CALL WrappedPropertySet::getPropertyValues( const Sequence< OUString >& rNameSeq )
268 throw (uno::RuntimeException)
270 Sequence< Any > aRetSeq;
271 if( rNameSeq.getLength() )
273 aRetSeq.realloc( rNameSeq.getLength() );
274 for(sal_Int32 nN=0; nN<rNameSeq.getLength(); nN++)
278 OUString aPropertyName( rNameSeq[nN] );
279 aRetSeq[nN] = this->getPropertyValue( aPropertyName );
281 catch( const beans::UnknownPropertyException& ex )
283 ASSERT_EXCEPTION( ex );
285 catch( const lang::WrappedTargetException& ex )
287 ASSERT_EXCEPTION( ex );
291 return aRetSeq;
293 void SAL_CALL WrappedPropertySet::addPropertiesChangeListener( const Sequence< OUString >& /* rNameSeq */, const Reference< beans::XPropertiesChangeListener >& /* xListener */ )
294 throw (uno::RuntimeException)
296 OSL_FAIL("not implemented yet");
297 //todo
299 void SAL_CALL WrappedPropertySet::removePropertiesChangeListener( const Reference< beans::XPropertiesChangeListener >& /* xListener */ )
300 throw (uno::RuntimeException)
302 OSL_FAIL("not implemented yet");
303 //todo
305 void SAL_CALL WrappedPropertySet::firePropertiesChangeEvent( const Sequence< OUString >& /* rNameSeq */, const Reference< beans::XPropertiesChangeListener >& /* xListener */ )
306 throw (uno::RuntimeException)
308 OSL_FAIL("not implemented yet");
309 //todo
312 //XPropertyState
313 beans::PropertyState SAL_CALL WrappedPropertySet::getPropertyState( const OUString& rPropertyName )
314 throw (beans::UnknownPropertyException, uno::RuntimeException)
316 beans::PropertyState aState( beans::PropertyState_DIRECT_VALUE );
318 Reference< beans::XPropertyState > xInnerPropertyState( this->getInnerPropertyState() );
319 if( xInnerPropertyState.is() )
321 const WrappedProperty* pWrappedProperty = getWrappedProperty( rPropertyName );
322 if( pWrappedProperty )
323 aState = pWrappedProperty->getPropertyState( xInnerPropertyState );
324 else
325 aState = xInnerPropertyState->getPropertyState( rPropertyName );
327 return aState;
330 const WrappedProperty* WrappedPropertySet::getWrappedProperty( const OUString& rOuterName )
332 sal_Int32 nHandle = getInfoHelper().getHandleByName( rOuterName );
333 return getWrappedProperty( nHandle );
336 const WrappedProperty* WrappedPropertySet::getWrappedProperty( sal_Int32 nHandle )
338 tWrappedPropertyMap::const_iterator aFound( getWrappedPropertyMap().find( nHandle ) );
339 if( aFound != getWrappedPropertyMap().end() )
340 return (*aFound).second;
341 return 0;
344 Sequence< beans::PropertyState > SAL_CALL WrappedPropertySet::getPropertyStates( const Sequence< OUString >& rNameSeq )
345 throw (beans::UnknownPropertyException, uno::RuntimeException)
347 Sequence< beans::PropertyState > aRetSeq;
348 if( rNameSeq.getLength() )
350 aRetSeq.realloc( rNameSeq.getLength() );
351 for(sal_Int32 nN=0; nN<rNameSeq.getLength(); nN++)
353 OUString aPropertyName( rNameSeq[nN] );
354 aRetSeq[nN] = this->getPropertyState( aPropertyName );
357 return aRetSeq;
360 void SAL_CALL WrappedPropertySet::setPropertyToDefault( const OUString& rPropertyName )
361 throw (beans::UnknownPropertyException, uno::RuntimeException)
363 Reference< beans::XPropertyState > xInnerPropertyState( this->getInnerPropertyState() );
364 if( xInnerPropertyState.is() )
366 const WrappedProperty* pWrappedProperty = getWrappedProperty( rPropertyName );
367 if( pWrappedProperty )
368 pWrappedProperty->setPropertyToDefault( xInnerPropertyState );
369 else
370 xInnerPropertyState->setPropertyToDefault( rPropertyName );
373 Any SAL_CALL WrappedPropertySet::getPropertyDefault( const OUString& rPropertyName )
374 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
376 Any aRet;
377 Reference< beans::XPropertyState > xInnerPropertyState( this->getInnerPropertyState() );
378 if( xInnerPropertyState.is() )
380 const WrappedProperty* pWrappedProperty = getWrappedProperty( rPropertyName );
381 if( pWrappedProperty )
382 aRet = pWrappedProperty->getPropertyDefault(xInnerPropertyState);
383 else
384 aRet = xInnerPropertyState->getPropertyDefault( rPropertyName );
386 return aRet;
389 //XMultiPropertyStates
390 void SAL_CALL WrappedPropertySet::setAllPropertiesToDefault( )
391 throw (uno::RuntimeException)
393 const Sequence< beans::Property >& rPropSeq = getPropertySequence();
394 for(sal_Int32 nN=0; nN<rPropSeq.getLength(); nN++)
396 OUString aPropertyName( rPropSeq[nN].Name );
397 this->setPropertyToDefault( aPropertyName );
400 void SAL_CALL WrappedPropertySet::setPropertiesToDefault( const Sequence< OUString >& rNameSeq )
401 throw (beans::UnknownPropertyException, uno::RuntimeException)
403 for(sal_Int32 nN=0; nN<rNameSeq.getLength(); nN++)
405 OUString aPropertyName( rNameSeq[nN] );
406 this->setPropertyToDefault( aPropertyName );
409 Sequence< Any > SAL_CALL WrappedPropertySet::getPropertyDefaults( const Sequence< OUString >& rNameSeq )
410 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
412 Sequence< Any > aRetSeq;
413 if( rNameSeq.getLength() )
415 aRetSeq.realloc( rNameSeq.getLength() );
416 for(sal_Int32 nN=0; nN<rNameSeq.getLength(); nN++)
418 OUString aPropertyName( rNameSeq[nN] );
419 aRetSeq[nN] = this->getPropertyDefault( aPropertyName );
422 return aRetSeq;
425 //-----------------------------------------------------------------------------
426 //-----------------------------------------------------------------------------
428 ::cppu::IPropertyArrayHelper& WrappedPropertySet::getInfoHelper()
430 ::cppu::OPropertyArrayHelper* p = m_pPropertyArrayHelper;
431 if(!p)
433 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );//do not use different mutex than is already used for static property sequence
434 p = m_pPropertyArrayHelper;
435 if(!p)
437 p = new ::cppu::OPropertyArrayHelper( getPropertySequence(), sal_True );
438 OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
439 m_pPropertyArrayHelper = p;
442 else
444 OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
446 return *m_pPropertyArrayHelper;
449 //-----------------------------------------------------------------------------
451 tWrappedPropertyMap& WrappedPropertySet::getWrappedPropertyMap()
453 tWrappedPropertyMap* p = m_pWrappedPropertyMap;
454 if(!p)
456 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );//do not use different mutex than is already used for static property sequence
457 p = m_pWrappedPropertyMap;
458 if(!p)
460 std::vector< WrappedProperty* > aPropList( createWrappedProperties() );
461 p = new tWrappedPropertyMap();
463 for( std::vector< WrappedProperty* >::const_iterator aIt = aPropList.begin(); aIt!=aPropList.end(); ++aIt )
465 WrappedProperty* pProperty = *aIt;
466 if(pProperty)
468 sal_Int32 nHandle = getInfoHelper().getHandleByName( pProperty->getOuterName() );
470 if( nHandle == -1 )
472 OSL_FAIL( "missing property in property list" );
473 delete pProperty;//we are owner or the created WrappedProperties
475 else if( p->find( nHandle ) != p->end() )
477 //duplicate Wrapped property
478 OSL_FAIL( "duplicate Wrapped property" );
479 delete pProperty;//we are owner or the created WrappedProperties
481 else
482 (*p)[ nHandle ] = pProperty;
486 OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
487 m_pWrappedPropertyMap = p;
490 else
492 OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
494 return *m_pWrappedPropertyMap;
497 //.............................................................................
498 } //namespace chart
499 //.............................................................................
501 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */