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