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