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 9976 : WrappedPropertySet::WrappedPropertySet()
34 : : MutexContainer()
35 : , m_xInfo(0)
36 : , m_pPropertyArrayHelper(0)
37 9976 : , m_pWrappedPropertyMap(0)
38 : {
39 9976 : }
40 19888 : WrappedPropertySet::~WrappedPropertySet()
41 : {
42 9944 : clearWrappedPropertySet();
43 9944 : }
44 :
45 707100 : Reference< beans::XPropertyState > WrappedPropertySet::getInnerPropertyState()
46 : {
47 707100 : return Reference< beans::XPropertyState >( getInnerPropertySet(), uno::UNO_QUERY );
48 : }
49 :
50 14540 : void WrappedPropertySet::clearWrappedPropertySet()
51 : {
52 14540 : ::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 14540 : if(m_pWrappedPropertyMap)
56 : {
57 1066932 : for( tWrappedPropertyMap::iterator aIt = m_pWrappedPropertyMap->begin()
58 711288 : ; aIt!= m_pWrappedPropertyMap->end(); ++aIt )
59 : {
60 345876 : const WrappedProperty* pWrappedProperty = (*aIt).second;
61 345876 : DELETEZ(pWrappedProperty);
62 : }
63 : }
64 :
65 14540 : DELETEZ(m_pPropertyArrayHelper);
66 14540 : DELETEZ(m_pWrappedPropertyMap);
67 :
68 14540 : m_xInfo = NULL;
69 14540 : }
70 :
71 : //XPropertySet
72 20042 : Reference< beans::XPropertySetInfo > SAL_CALL WrappedPropertySet::getPropertySetInfo( )
73 : throw (uno::RuntimeException, std::exception)
74 : {
75 20042 : Reference< beans::XPropertySetInfo > xInfo = m_xInfo;
76 20042 : if( !xInfo.is() )
77 : {
78 9039 : ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );//do not use different mutex than is already used for static property sequence
79 9039 : xInfo = m_xInfo;
80 9039 : if( !xInfo.is() )
81 : {
82 9039 : xInfo = ::cppu::OPropertySetHelper::createPropertySetInfo( getInfoHelper() );
83 : OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
84 9039 : m_xInfo = xInfo;
85 9039 : }
86 : }
87 : else
88 : {
89 : OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
90 : }
91 20042 : return m_xInfo;
92 : }
93 :
94 35938 : 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 35938 : sal_Int32 nHandle = getInfoHelper().getHandleByName( rPropertyName );
100 35938 : const WrappedProperty* pWrappedProperty = getWrappedProperty( nHandle );
101 35938 : Reference< beans::XPropertySet > xInnerPropertySet( this->getInnerPropertySet() );
102 35938 : if( pWrappedProperty )
103 24868 : pWrappedProperty->setPropertyValue( rValue, xInnerPropertySet );
104 11070 : else if( xInnerPropertySet.is() )
105 11070 : 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 35938 : }
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 35938 : }
141 397150 : Any SAL_CALL WrappedPropertySet::getPropertyValue( const OUString& rPropertyName )
142 : throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
143 : {
144 397150 : Any aRet;
145 :
146 : try
147 : {
148 397150 : sal_Int32 nHandle = getInfoHelper().getHandleByName( rPropertyName );
149 397150 : const WrappedProperty* pWrappedProperty = getWrappedProperty( nHandle );
150 397150 : Reference< beans::XPropertySet > xInnerPropertySet( this->getInnerPropertySet() );
151 397150 : if( pWrappedProperty )
152 221260 : aRet = pWrappedProperty->getPropertyValue( xInnerPropertySet );
153 175890 : else if( xInnerPropertySet.is() )
154 174354 : 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 397150 : }
161 : }
162 4316 : catch( const beans::UnknownPropertyException& )
163 : {
164 2158 : 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 394992 : return aRet;
183 : }
184 :
185 360 : 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 360 : Reference< beans::XPropertySet > xInnerPropertySet( this->getInnerPropertySet() );
189 360 : if( xInnerPropertySet.is() )
190 : {
191 360 : const WrappedProperty* pWrappedProperty = getWrappedProperty( rPropertyName );
192 360 : if( pWrappedProperty )
193 100 : xInnerPropertySet->addPropertyChangeListener( pWrappedProperty->getInnerName(), xListener );
194 : else
195 260 : xInnerPropertySet->addPropertyChangeListener( rPropertyName, xListener );
196 360 : }
197 360 : }
198 360 : 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 360 : Reference< beans::XPropertySet > xInnerPropertySet( this->getInnerPropertySet() );
202 360 : if( xInnerPropertySet.is() )
203 : {
204 360 : const WrappedProperty* pWrappedProperty = getWrappedProperty( rPropertyName );
205 360 : if( pWrappedProperty )
206 100 : xInnerPropertySet->removePropertyChangeListener( pWrappedProperty->getInnerName(), aListener );
207 : else
208 260 : xInnerPropertySet->removePropertyChangeListener( rPropertyName, aListener );
209 360 : }
210 360 : }
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 2820 : 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 2820 : bool bUnknownProperty = false;
243 2820 : sal_Int32 nMinCount = std::min( rValueSeq.getLength(), rNameSeq.getLength() );
244 25064 : for(sal_Int32 nN=0; nN<nMinCount; nN++)
245 : {
246 22244 : OUString aPropertyName( rNameSeq[nN] );
247 : try
248 : {
249 22244 : this->setPropertyValue( aPropertyName, rValueSeq[nN] );
250 : }
251 0 : catch( const beans::UnknownPropertyException& ex )
252 : {
253 : ASSERT_EXCEPTION( ex );
254 0 : bUnknownProperty = true;
255 : }
256 22244 : }
257 : //todo: store unknown properties elsewhere
258 : OSL_ENSURE(!bUnknownProperty,"unknown property");
259 : (void)bUnknownProperty;
260 : // if( bUnknownProperty )
261 : // throw beans::UnknownPropertyException();
262 2820 : }
263 14876 : Sequence< Any > SAL_CALL WrappedPropertySet::getPropertyValues( const Sequence< OUString >& rNameSeq )
264 : throw (uno::RuntimeException, std::exception)
265 : {
266 14876 : Sequence< Any > aRetSeq;
267 14876 : if( rNameSeq.getLength() )
268 : {
269 14876 : aRetSeq.realloc( rNameSeq.getLength() );
270 184512 : for(sal_Int32 nN=0; nN<rNameSeq.getLength(); nN++)
271 : {
272 : try
273 : {
274 169636 : OUString aPropertyName( rNameSeq[nN] );
275 169636 : 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 14876 : 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 707100 : beans::PropertyState SAL_CALL WrappedPropertySet::getPropertyState( const OUString& rPropertyName )
310 : throw (beans::UnknownPropertyException, uno::RuntimeException, std::exception)
311 : {
312 707100 : beans::PropertyState aState( beans::PropertyState_DIRECT_VALUE );
313 :
314 707100 : Reference< beans::XPropertyState > xInnerPropertyState( this->getInnerPropertyState() );
315 707100 : if( xInnerPropertyState.is() )
316 : {
317 705244 : const WrappedProperty* pWrappedProperty = getWrappedProperty( rPropertyName );
318 705244 : if( pWrappedProperty )
319 252580 : aState = pWrappedProperty->getPropertyState( xInnerPropertyState );
320 : else
321 452664 : aState = xInnerPropertyState->getPropertyState( rPropertyName );
322 : }
323 707100 : return aState;
324 : }
325 :
326 883292 : const WrappedProperty* WrappedPropertySet::getWrappedProperty( const OUString& rOuterName )
327 : {
328 883292 : sal_Int32 nHandle = getInfoHelper().getHandleByName( rOuterName );
329 883292 : return getWrappedProperty( nHandle );
330 : }
331 :
332 1324126 : const WrappedProperty* WrappedPropertySet::getWrappedProperty( sal_Int32 nHandle )
333 : {
334 1324126 : tWrappedPropertyMap::const_iterator aFound( getWrappedPropertyMap().find( nHandle ) );
335 1324126 : if( aFound != getWrappedPropertyMap().end() )
336 561282 : return (*aFound).second;
337 762844 : return 0;
338 : }
339 :
340 13788 : Sequence< beans::PropertyState > SAL_CALL WrappedPropertySet::getPropertyStates( const Sequence< OUString >& rNameSeq )
341 : throw (beans::UnknownPropertyException, uno::RuntimeException, std::exception)
342 : {
343 13788 : Sequence< beans::PropertyState > aRetSeq;
344 13788 : if( rNameSeq.getLength() )
345 : {
346 13788 : aRetSeq.realloc( rNameSeq.getLength() );
347 900920 : for(sal_Int32 nN=0; nN<rNameSeq.getLength(); nN++)
348 : {
349 887132 : OUString aPropertyName( rNameSeq[nN] );
350 887132 : aRetSeq[nN] = this->getPropertyState( aPropertyName );
351 887132 : }
352 : }
353 13788 : 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 1883959 : ::cppu::IPropertyArrayHelper& WrappedPropertySet::getInfoHelper()
422 : {
423 1883959 : ::cppu::OPropertyArrayHelper* p = m_pPropertyArrayHelper;
424 1883959 : if(!p)
425 : {
426 9768 : ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );//do not use different mutex than is already used for static property sequence
427 9768 : p = m_pPropertyArrayHelper;
428 9768 : if(!p)
429 : {
430 9768 : p = new ::cppu::OPropertyArrayHelper( getPropertySequence(), sal_True );
431 : OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
432 9768 : m_pPropertyArrayHelper = p;
433 9768 : }
434 : }
435 : else
436 : {
437 : OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
438 : }
439 1883959 : return *m_pPropertyArrayHelper;
440 : }
441 :
442 2648252 : tWrappedPropertyMap& WrappedPropertySet::getWrappedPropertyMap()
443 : {
444 2648252 : tWrappedPropertyMap* p = m_pWrappedPropertyMap;
445 2648252 : if(!p)
446 : {
447 9768 : ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );//do not use different mutex than is already used for static property sequence
448 9768 : p = m_pWrappedPropertyMap;
449 9768 : if(!p)
450 : {
451 9768 : std::vector< WrappedProperty* > aPropList( createWrappedProperties() );
452 9768 : p = new tWrappedPropertyMap();
453 :
454 355644 : for( std::vector< WrappedProperty* >::const_iterator aIt = aPropList.begin(); aIt!=aPropList.end(); ++aIt )
455 : {
456 345876 : WrappedProperty* pProperty = *aIt;
457 345876 : if(pProperty)
458 : {
459 345876 : sal_Int32 nHandle = getInfoHelper().getHandleByName( pProperty->getOuterName() );
460 :
461 345876 : 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 345876 : 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 345876 : (*p)[ nHandle ] = pProperty;
474 : }
475 : }
476 :
477 : OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
478 9768 : m_pWrappedPropertyMap = p;
479 9768 : }
480 : }
481 : else
482 : {
483 : OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
484 : }
485 2648252 : return *m_pWrappedPropertyMap;
486 : }
487 :
488 : } //namespace chart
489 :
490 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|