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