1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_charttools.hxx" 26 27 #include "WrappedPropertySet.hxx" 28 #include "macros.hxx" 29 30 // header for define DELETEZ 31 #include <tools/solar.h> 32 33 #include <tools/debug.hxx> 34 35 //............................................................................. 36 namespace chart 37 { 38 //............................................................................. 39 40 using namespace ::com::sun::star; 41 using ::com::sun::star::uno::Reference; 42 using ::com::sun::star::uno::Sequence; 43 using ::com::sun::star::uno::Any; 44 using ::rtl::OUString; 45 46 WrappedPropertySet::WrappedPropertySet() 47 : MutexContainer() 48 , m_xInfo(0) 49 , m_pPropertyArrayHelper(0) 50 , m_pWrappedPropertyMap(0) 51 { 52 } 53 WrappedPropertySet::~WrappedPropertySet() 54 { 55 clearWrappedPropertySet(); 56 } 57 58 Reference< beans::XPropertyState > WrappedPropertySet::getInnerPropertyState() 59 { 60 return Reference< beans::XPropertyState >( getInnerPropertySet(), uno::UNO_QUERY ); 61 } 62 63 void WrappedPropertySet::clearWrappedPropertySet() 64 { 65 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );//do not use different mutex than is already used for static property sequence 66 67 //delete all wrapped properties 68 if(m_pWrappedPropertyMap) 69 { 70 for( tWrappedPropertyMap::iterator aIt = m_pWrappedPropertyMap->begin() 71 ; aIt!= m_pWrappedPropertyMap->end(); aIt++ ) 72 { 73 const WrappedProperty* pWrappedProperty = (*aIt).second; 74 DELETEZ(pWrappedProperty); 75 } 76 } 77 78 DELETEZ(m_pPropertyArrayHelper); 79 DELETEZ(m_pWrappedPropertyMap); 80 81 m_xInfo = NULL; 82 } 83 84 //XPropertySet 85 Reference< beans::XPropertySetInfo > SAL_CALL WrappedPropertySet::getPropertySetInfo( ) 86 { 87 Reference< beans::XPropertySetInfo > xInfo = m_xInfo; 88 if( !xInfo.is() ) 89 { 90 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );//do not use different mutex than is already used for static property sequence 91 xInfo = m_xInfo; 92 if( !xInfo.is() ) 93 { 94 xInfo = ::cppu::OPropertySetHelper::createPropertySetInfo( getInfoHelper() ); 95 OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER(); 96 m_xInfo = xInfo; 97 } 98 } 99 else 100 { 101 OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER(); 102 } 103 return m_xInfo; 104 } 105 106 void SAL_CALL WrappedPropertySet::setPropertyValue( const OUString& rPropertyName, const Any& rValue ) 107 { 108 try 109 { 110 sal_Int32 nHandle = getInfoHelper().getHandleByName( rPropertyName ); 111 const WrappedProperty* pWrappedProperty = getWrappedProperty( nHandle ); 112 Reference< beans::XPropertySet > xInnerPropertySet( this->getInnerPropertySet() ); 113 if( pWrappedProperty ) 114 pWrappedProperty->setPropertyValue( rValue, xInnerPropertySet ); 115 else if( xInnerPropertySet.is() ) 116 xInnerPropertySet->setPropertyValue( rPropertyName, rValue ); 117 else 118 { 119 #if OSL_DEBUG_LEVEL > 1 120 DBG_ERROR("found no inner property set to map to"); 121 #endif 122 } 123 } 124 catch( beans::UnknownPropertyException& ex ) 125 { 126 throw ex; 127 } 128 catch( beans::PropertyVetoException& ex ) 129 { 130 throw ex; 131 } 132 catch( lang::IllegalArgumentException& ex ) 133 { 134 throw ex; 135 } 136 catch( lang::WrappedTargetException& ex ) 137 { 138 throw ex; 139 } 140 catch( uno::RuntimeException& ex ) 141 { 142 throw ex; 143 } 144 catch( uno::Exception& ex ) 145 { 146 OSL_ENSURE(false,"invalid exception caught in WrappedPropertySet::setPropertyValue"); 147 lang::WrappedTargetException aWrappedException; 148 aWrappedException.TargetException = uno::makeAny( ex ); 149 throw aWrappedException; 150 } 151 } 152 Any SAL_CALL WrappedPropertySet::getPropertyValue( const OUString& rPropertyName ) 153 { 154 Any aRet; 155 156 try 157 { 158 sal_Int32 nHandle = getInfoHelper().getHandleByName( rPropertyName ); 159 const WrappedProperty* pWrappedProperty = getWrappedProperty( nHandle ); 160 Reference< beans::XPropertySet > xInnerPropertySet( this->getInnerPropertySet() ); 161 if( pWrappedProperty ) 162 aRet = pWrappedProperty->getPropertyValue( xInnerPropertySet ); 163 else if( xInnerPropertySet.is() ) 164 aRet = xInnerPropertySet->getPropertyValue( rPropertyName ); 165 else 166 { 167 #if OSL_DEBUG_LEVEL > 1 168 DBG_ERROR("found no inner property set to map to"); 169 #endif 170 } 171 } 172 catch( beans::UnknownPropertyException& ex ) 173 { 174 throw ex; 175 } 176 catch( lang::WrappedTargetException& ex ) 177 { 178 throw ex; 179 } 180 catch( uno::RuntimeException& ex ) 181 { 182 throw ex; 183 } 184 catch( uno::Exception& ex ) 185 { 186 OSL_ENSURE(false,"invalid exception caught in WrappedPropertySet::setPropertyValue"); 187 lang::WrappedTargetException aWrappedException; 188 aWrappedException.TargetException = uno::makeAny( ex ); 189 throw aWrappedException; 190 } 191 192 return aRet; 193 } 194 195 void SAL_CALL WrappedPropertySet::addPropertyChangeListener( const OUString& rPropertyName, const Reference< beans::XPropertyChangeListener >& xListener ) 196 { 197 Reference< beans::XPropertySet > xInnerPropertySet( this->getInnerPropertySet() ); 198 if( xInnerPropertySet.is() ) 199 { 200 const WrappedProperty* pWrappedProperty = getWrappedProperty( rPropertyName ); 201 if( pWrappedProperty ) 202 xInnerPropertySet->addPropertyChangeListener( pWrappedProperty->getInnerName(), xListener ); 203 else 204 xInnerPropertySet->addPropertyChangeListener( rPropertyName, xListener ); 205 } 206 // m_aBoundListenerContainer.addInterface( (sal_Int32)nHandle, xListener ); 207 } 208 void SAL_CALL WrappedPropertySet::removePropertyChangeListener( const OUString& rPropertyName, const Reference< beans::XPropertyChangeListener >& aListener ) 209 { 210 Reference< beans::XPropertySet > xInnerPropertySet( this->getInnerPropertySet() ); 211 if( xInnerPropertySet.is() ) 212 { 213 const WrappedProperty* pWrappedProperty = getWrappedProperty( rPropertyName ); 214 if( pWrappedProperty ) 215 xInnerPropertySet->removePropertyChangeListener( pWrappedProperty->getInnerName(), aListener ); 216 else 217 xInnerPropertySet->removePropertyChangeListener( rPropertyName, aListener ); 218 } 219 } 220 void SAL_CALL WrappedPropertySet::addVetoableChangeListener( const OUString& rPropertyName, const Reference< beans::XVetoableChangeListener >& aListener ) 221 { 222 Reference< beans::XPropertySet > xInnerPropertySet( this->getInnerPropertySet() ); 223 if( xInnerPropertySet.is() ) 224 { 225 const WrappedProperty* pWrappedProperty = getWrappedProperty( rPropertyName ); 226 if( pWrappedProperty ) 227 xInnerPropertySet->addVetoableChangeListener( pWrappedProperty->getInnerName(), aListener ); 228 else 229 xInnerPropertySet->addVetoableChangeListener( rPropertyName, aListener ); 230 } 231 } 232 void SAL_CALL WrappedPropertySet::removeVetoableChangeListener( const OUString& rPropertyName, const Reference< beans::XVetoableChangeListener >& aListener ) 233 { 234 Reference< beans::XPropertySet > xInnerPropertySet( this->getInnerPropertySet() ); 235 if( xInnerPropertySet.is() ) 236 { 237 const WrappedProperty* pWrappedProperty = getWrappedProperty( rPropertyName ); 238 if( pWrappedProperty ) 239 xInnerPropertySet->removeVetoableChangeListener( pWrappedProperty->getInnerName(), aListener ); 240 else 241 xInnerPropertySet->removeVetoableChangeListener( rPropertyName, aListener ); 242 } 243 } 244 245 //XMultiPropertySet 246 void SAL_CALL WrappedPropertySet::setPropertyValues( const Sequence< OUString >& rNameSeq, const Sequence< Any >& rValueSeq ) 247 { 248 bool bUnknownProperty = false; 249 sal_Int32 nMinCount = std::min( rValueSeq.getLength(), rNameSeq.getLength() ); 250 for(sal_Int32 nN=0; nN<nMinCount; nN++) 251 { 252 ::rtl::OUString aPropertyName( rNameSeq[nN] ); 253 try 254 { 255 this->setPropertyValue( aPropertyName, rValueSeq[nN] ); 256 } 257 catch( beans::UnknownPropertyException& ex ) 258 { 259 ASSERT_EXCEPTION( ex ); 260 bUnknownProperty = true; 261 } 262 } 263 //todo: store unknown properties elsewhere 264 // if( bUnknownProperty ) 265 // throw beans::UnknownPropertyException(); 266 } 267 Sequence< Any > SAL_CALL WrappedPropertySet::getPropertyValues( const Sequence< OUString >& rNameSeq ) 268 { 269 Sequence< Any > aRetSeq; 270 if( rNameSeq.getLength() ) 271 { 272 aRetSeq.realloc( rNameSeq.getLength() ); 273 for(sal_Int32 nN=0; nN<rNameSeq.getLength(); nN++) 274 { 275 try 276 { 277 ::rtl::OUString aPropertyName( rNameSeq[nN] ); 278 aRetSeq[nN] = this->getPropertyValue( aPropertyName ); 279 } 280 catch( beans::UnknownPropertyException& ex ) 281 { 282 ASSERT_EXCEPTION( ex ); 283 } 284 catch( lang::WrappedTargetException& ex ) 285 { 286 ASSERT_EXCEPTION( ex ); 287 } 288 } 289 } 290 return aRetSeq; 291 } 292 void SAL_CALL WrappedPropertySet::addPropertiesChangeListener( const Sequence< OUString >& /* rNameSeq */, const Reference< beans::XPropertiesChangeListener >& /* xListener */ ) 293 { 294 OSL_ENSURE(false,"not implemented yet"); 295 //todo 296 } 297 void SAL_CALL WrappedPropertySet::removePropertiesChangeListener( const Reference< beans::XPropertiesChangeListener >& /* xListener */ ) 298 { 299 OSL_ENSURE(false,"not implemented yet"); 300 //todo 301 } 302 void SAL_CALL WrappedPropertySet::firePropertiesChangeEvent( const Sequence< OUString >& /* rNameSeq */, const Reference< beans::XPropertiesChangeListener >& /* xListener */ ) 303 { 304 OSL_ENSURE(false,"not implemented yet"); 305 //todo 306 } 307 308 //XPropertyState 309 beans::PropertyState SAL_CALL WrappedPropertySet::getPropertyState( const OUString& rPropertyName ) 310 { 311 beans::PropertyState aState( beans::PropertyState_DIRECT_VALUE ); 312 313 Reference< beans::XPropertyState > xInnerPropertyState( this->getInnerPropertyState() ); 314 if( xInnerPropertyState.is() ) 315 { 316 const WrappedProperty* pWrappedProperty = getWrappedProperty( rPropertyName ); 317 if( pWrappedProperty ) 318 aState = pWrappedProperty->getPropertyState( xInnerPropertyState ); 319 else 320 aState = xInnerPropertyState->getPropertyState( rPropertyName ); 321 } 322 return aState; 323 } 324 325 const WrappedProperty* WrappedPropertySet::getWrappedProperty( const ::rtl::OUString& rOuterName ) 326 { 327 sal_Int32 nHandle = getInfoHelper().getHandleByName( rOuterName ); 328 return getWrappedProperty( nHandle ); 329 } 330 331 const WrappedProperty* WrappedPropertySet::getWrappedProperty( sal_Int32 nHandle ) 332 { 333 tWrappedPropertyMap::const_iterator aFound( getWrappedPropertyMap().find( nHandle ) ); 334 if( aFound != getWrappedPropertyMap().end() ) 335 return (*aFound).second; 336 return 0; 337 } 338 339 Sequence< beans::PropertyState > SAL_CALL WrappedPropertySet::getPropertyStates( const Sequence< OUString >& rNameSeq ) 340 { 341 Sequence< beans::PropertyState > aRetSeq; 342 if( rNameSeq.getLength() ) 343 { 344 aRetSeq.realloc( rNameSeq.getLength() ); 345 for(sal_Int32 nN=0; nN<rNameSeq.getLength(); nN++) 346 { 347 ::rtl::OUString aPropertyName( rNameSeq[nN] ); 348 aRetSeq[nN] = this->getPropertyState( aPropertyName ); 349 } 350 } 351 return aRetSeq; 352 } 353 354 void SAL_CALL WrappedPropertySet::setPropertyToDefault( const OUString& rPropertyName ) 355 { 356 Reference< beans::XPropertyState > xInnerPropertyState( this->getInnerPropertyState() ); 357 if( xInnerPropertyState.is() ) 358 { 359 const WrappedProperty* pWrappedProperty = getWrappedProperty( rPropertyName ); 360 if( pWrappedProperty ) 361 pWrappedProperty->setPropertyToDefault( xInnerPropertyState ); 362 else 363 xInnerPropertyState->setPropertyToDefault( rPropertyName ); 364 } 365 } 366 Any SAL_CALL WrappedPropertySet::getPropertyDefault( const OUString& rPropertyName ) 367 { 368 Any aRet; 369 Reference< beans::XPropertyState > xInnerPropertyState( this->getInnerPropertyState() ); 370 if( xInnerPropertyState.is() ) 371 { 372 const WrappedProperty* pWrappedProperty = getWrappedProperty( rPropertyName ); 373 if( pWrappedProperty ) 374 aRet = pWrappedProperty->getPropertyDefault(xInnerPropertyState); 375 else 376 aRet = xInnerPropertyState->getPropertyDefault( rPropertyName ); 377 } 378 return aRet; 379 } 380 381 //XMultiPropertyStates 382 void SAL_CALL WrappedPropertySet::setAllPropertiesToDefault( ) 383 { 384 const Sequence< beans::Property >& rPropSeq = getPropertySequence(); 385 for(sal_Int32 nN=0; nN<rPropSeq.getLength(); nN++) 386 { 387 ::rtl::OUString aPropertyName( rPropSeq[nN].Name ); 388 this->setPropertyToDefault( aPropertyName ); 389 } 390 } 391 void SAL_CALL WrappedPropertySet::setPropertiesToDefault( const Sequence< OUString >& rNameSeq ) 392 { 393 for(sal_Int32 nN=0; nN<rNameSeq.getLength(); nN++) 394 { 395 ::rtl::OUString aPropertyName( rNameSeq[nN] ); 396 this->setPropertyToDefault( aPropertyName ); 397 } 398 } 399 Sequence< Any > SAL_CALL WrappedPropertySet::getPropertyDefaults( const Sequence< OUString >& rNameSeq ) 400 { 401 Sequence< Any > aRetSeq; 402 if( rNameSeq.getLength() ) 403 { 404 aRetSeq.realloc( rNameSeq.getLength() ); 405 for(sal_Int32 nN=0; nN<rNameSeq.getLength(); nN++) 406 { 407 ::rtl::OUString aPropertyName( rNameSeq[nN] ); 408 aRetSeq[nN] = this->getPropertyDefault( aPropertyName ); 409 } 410 } 411 return aRetSeq; 412 } 413 414 //----------------------------------------------------------------------------- 415 //----------------------------------------------------------------------------- 416 417 ::cppu::IPropertyArrayHelper& WrappedPropertySet::getInfoHelper() 418 { 419 ::cppu::OPropertyArrayHelper* p = m_pPropertyArrayHelper; 420 if(!p) 421 { 422 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );//do not use different mutex than is already used for static property sequence 423 p = m_pPropertyArrayHelper; 424 if(!p) 425 { 426 p = new ::cppu::OPropertyArrayHelper( getPropertySequence(), sal_True ); 427 OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER(); 428 m_pPropertyArrayHelper = p; 429 } 430 } 431 else 432 { 433 OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER(); 434 } 435 return *m_pPropertyArrayHelper; 436 } 437 438 //----------------------------------------------------------------------------- 439 440 tWrappedPropertyMap& WrappedPropertySet::getWrappedPropertyMap() 441 { 442 tWrappedPropertyMap* p = m_pWrappedPropertyMap; 443 if(!p) 444 { 445 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );//do not use different mutex than is already used for static property sequence 446 p = m_pWrappedPropertyMap; 447 if(!p) 448 { 449 std::vector< WrappedProperty* > aPropList( createWrappedProperties() ); 450 p = new tWrappedPropertyMap(); 451 452 for( std::vector< WrappedProperty* >::const_iterator aIt = aPropList.begin(); aIt!=aPropList.end(); ++aIt ) 453 { 454 WrappedProperty* pProperty = *aIt; 455 if(pProperty) 456 { 457 sal_Int32 nHandle = getInfoHelper().getHandleByName( pProperty->getOuterName() ); 458 459 if( nHandle == -1 ) 460 { 461 OSL_ENSURE( false, "missing property in property list" ); 462 delete pProperty;//we are owner or the created WrappedProperties 463 } 464 else if( p->find( nHandle ) != p->end() ) 465 { 466 //duplicate Wrapped property 467 OSL_ENSURE( false, "duplicate Wrapped property" ); 468 delete pProperty;//we are owner or the created WrappedProperties 469 } 470 else 471 (*p)[ nHandle ] = pProperty; 472 } 473 } 474 475 OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER(); 476 m_pWrappedPropertyMap = p; 477 } 478 } 479 else 480 { 481 OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER(); 482 } 483 return *m_pWrappedPropertyMap; 484 } 485 486 //............................................................................. 487 } //namespace chart 488 //............................................................................. 489