1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_chart2.hxx"
31 #include "WrappedPropertySet.hxx"
34 // header for define DELETEZ
35 #include <tools/solar.h>
37 #include <tools/debug.hxx>
39 //.............................................................................
42 //.............................................................................
44 using namespace ::com::sun::star
;
45 using ::com::sun::star::uno::Reference
;
46 using ::com::sun::star::uno::Sequence
;
47 using ::com::sun::star::uno::Any
;
48 using ::rtl::OUString
;
50 WrappedPropertySet::WrappedPropertySet()
53 , m_pPropertyArrayHelper(0)
54 , m_pWrappedPropertyMap(0)
57 WrappedPropertySet::~WrappedPropertySet()
59 clearWrappedPropertySet();
62 Reference
< beans::XPropertyState
> WrappedPropertySet::getInnerPropertyState()
64 return Reference
< beans::XPropertyState
>( getInnerPropertySet(), uno::UNO_QUERY
);
67 void WrappedPropertySet::clearWrappedPropertySet()
70 ::osl::MutexGuard
aGuard( m_aMutex
);
72 //delete all wrapped properties
73 if(m_pWrappedPropertyMap
)
75 for( tWrappedPropertyMap::iterator aIt
= m_pWrappedPropertyMap
->begin()
76 ; aIt
!= m_pWrappedPropertyMap
->end(); aIt
++ )
78 const WrappedProperty
* pWrappedProperty
= (*aIt
).second
;
79 DELETEZ(pWrappedProperty
);
83 DELETEZ(m_pPropertyArrayHelper
);
84 DELETEZ(m_pWrappedPropertyMap
);
91 Reference
< beans::XPropertySetInfo
> SAL_CALL
WrappedPropertySet::getPropertySetInfo( )
92 throw (uno::RuntimeException
)
97 ::osl::MutexGuard
aGuard( m_aMutex
);
100 m_xInfo
= ::cppu::OPropertySetHelper::createPropertySetInfo( getInfoHelper() );
107 void SAL_CALL
WrappedPropertySet::setPropertyValue( const OUString
& rPropertyName
, const Any
& rValue
)
108 throw (beans::UnknownPropertyException
, beans::PropertyVetoException
, lang::IllegalArgumentException
, lang::WrappedTargetException
, uno::RuntimeException
)
112 sal_Int32 nHandle
= getInfoHelper().getHandleByName( rPropertyName
);
113 const WrappedProperty
* pWrappedProperty
= getWrappedProperty( nHandle
);
114 Reference
< beans::XPropertySet
> xInnerPropertySet( this->getInnerPropertySet() );
115 if( pWrappedProperty
)
116 pWrappedProperty
->setPropertyValue( rValue
, xInnerPropertySet
);
117 else if( xInnerPropertySet
.is() )
118 xInnerPropertySet
->setPropertyValue( rPropertyName
, rValue
);
121 #if OSL_DEBUG_LEVEL > 1
122 DBG_ERROR("found no inner property set to map to");
126 catch( beans::UnknownPropertyException
& ex
)
130 catch( beans::PropertyVetoException
& ex
)
134 catch( lang::IllegalArgumentException
& ex
)
138 catch( lang::WrappedTargetException
& ex
)
142 catch( uno::RuntimeException
& ex
)
146 catch( uno::Exception
& ex
)
148 OSL_ENSURE(false,"invalid exception caught in WrappedPropertySet::setPropertyValue");
149 lang::WrappedTargetException aWrappedException
;
150 aWrappedException
.TargetException
= uno::makeAny( ex
);
151 throw aWrappedException
;
154 Any SAL_CALL
WrappedPropertySet::getPropertyValue( const OUString
& rPropertyName
)
155 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
161 sal_Int32 nHandle
= getInfoHelper().getHandleByName( rPropertyName
);
162 const WrappedProperty
* pWrappedProperty
= getWrappedProperty( nHandle
);
163 Reference
< beans::XPropertySet
> xInnerPropertySet( this->getInnerPropertySet() );
164 if( pWrappedProperty
)
165 aRet
= pWrappedProperty
->getPropertyValue( xInnerPropertySet
);
166 else if( xInnerPropertySet
.is() )
167 aRet
= xInnerPropertySet
->getPropertyValue( rPropertyName
);
170 #if OSL_DEBUG_LEVEL > 1
171 DBG_ERROR("found no inner property set to map to");
175 catch( beans::UnknownPropertyException
& ex
)
179 catch( lang::WrappedTargetException
& ex
)
183 catch( uno::RuntimeException
& ex
)
187 catch( uno::Exception
& ex
)
189 OSL_ENSURE(false,"invalid exception caught in WrappedPropertySet::setPropertyValue");
190 lang::WrappedTargetException aWrappedException
;
191 aWrappedException
.TargetException
= uno::makeAny( ex
);
192 throw aWrappedException
;
198 void SAL_CALL
WrappedPropertySet::addPropertyChangeListener( const OUString
& rPropertyName
, const Reference
< beans::XPropertyChangeListener
>& xListener
)
199 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
201 Reference
< beans::XPropertySet
> xInnerPropertySet( this->getInnerPropertySet() );
202 if( xInnerPropertySet
.is() )
204 const WrappedProperty
* pWrappedProperty
= getWrappedProperty( rPropertyName
);
205 if( pWrappedProperty
)
206 xInnerPropertySet
->addPropertyChangeListener( pWrappedProperty
->getInnerName(), xListener
);
208 xInnerPropertySet
->addPropertyChangeListener( rPropertyName
, xListener
);
210 // m_aBoundListenerContainer.addInterface( (sal_Int32)nHandle, xListener );
212 void SAL_CALL
WrappedPropertySet::removePropertyChangeListener( const OUString
& rPropertyName
, const Reference
< beans::XPropertyChangeListener
>& aListener
)
213 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
215 Reference
< beans::XPropertySet
> xInnerPropertySet( this->getInnerPropertySet() );
216 if( xInnerPropertySet
.is() )
218 const WrappedProperty
* pWrappedProperty
= getWrappedProperty( rPropertyName
);
219 if( pWrappedProperty
)
220 xInnerPropertySet
->removePropertyChangeListener( pWrappedProperty
->getInnerName(), aListener
);
222 xInnerPropertySet
->removePropertyChangeListener( rPropertyName
, aListener
);
225 void SAL_CALL
WrappedPropertySet::addVetoableChangeListener( const OUString
& rPropertyName
, const Reference
< beans::XVetoableChangeListener
>& aListener
)
226 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
228 Reference
< beans::XPropertySet
> xInnerPropertySet( this->getInnerPropertySet() );
229 if( xInnerPropertySet
.is() )
231 const WrappedProperty
* pWrappedProperty
= getWrappedProperty( rPropertyName
);
232 if( pWrappedProperty
)
233 xInnerPropertySet
->addVetoableChangeListener( pWrappedProperty
->getInnerName(), aListener
);
235 xInnerPropertySet
->addVetoableChangeListener( rPropertyName
, aListener
);
238 void SAL_CALL
WrappedPropertySet::removeVetoableChangeListener( const OUString
& rPropertyName
, const Reference
< beans::XVetoableChangeListener
>& aListener
)
239 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
241 Reference
< beans::XPropertySet
> xInnerPropertySet( this->getInnerPropertySet() );
242 if( xInnerPropertySet
.is() )
244 const WrappedProperty
* pWrappedProperty
= getWrappedProperty( rPropertyName
);
245 if( pWrappedProperty
)
246 xInnerPropertySet
->removeVetoableChangeListener( pWrappedProperty
->getInnerName(), aListener
);
248 xInnerPropertySet
->removeVetoableChangeListener( rPropertyName
, aListener
);
253 void SAL_CALL
WrappedPropertySet::setPropertyValues( const Sequence
< OUString
>& rNameSeq
, const Sequence
< Any
>& rValueSeq
)
254 throw (beans::PropertyVetoException
, lang::IllegalArgumentException
, lang::WrappedTargetException
, uno::RuntimeException
)
256 bool bUnknownProperty
= false;
257 sal_Int32 nMinCount
= std::min( rValueSeq
.getLength(), rNameSeq
.getLength() );
258 for(sal_Int32 nN
=0; nN
<nMinCount
; nN
++)
260 ::rtl::OUString
aPropertyName( rNameSeq
[nN
] );
263 this->setPropertyValue( aPropertyName
, rValueSeq
[nN
] );
265 catch( beans::UnknownPropertyException
& ex
)
267 ASSERT_EXCEPTION( ex
);
268 bUnknownProperty
= true;
271 //todo: store unknown properties elsewhere
272 // if( bUnknownProperty )
273 // throw beans::UnknownPropertyException();
275 Sequence
< Any
> SAL_CALL
WrappedPropertySet::getPropertyValues( const Sequence
< OUString
>& rNameSeq
)
276 throw (uno::RuntimeException
)
278 Sequence
< Any
> aRetSeq
;
279 if( rNameSeq
.getLength() )
281 aRetSeq
.realloc( rNameSeq
.getLength() );
282 for(sal_Int32 nN
=0; nN
<rNameSeq
.getLength(); nN
++)
286 ::rtl::OUString
aPropertyName( rNameSeq
[nN
] );
287 aRetSeq
[nN
] = this->getPropertyValue( aPropertyName
);
289 catch( beans::UnknownPropertyException
& ex
)
291 ASSERT_EXCEPTION( ex
);
293 catch( lang::WrappedTargetException
& ex
)
295 ASSERT_EXCEPTION( ex
);
301 void SAL_CALL
WrappedPropertySet::addPropertiesChangeListener( const Sequence
< OUString
>& /* rNameSeq */, const Reference
< beans::XPropertiesChangeListener
>& /* xListener */ )
302 throw (uno::RuntimeException
)
304 OSL_ENSURE(false,"not implemented yet");
307 void SAL_CALL
WrappedPropertySet::removePropertiesChangeListener( const Reference
< beans::XPropertiesChangeListener
>& /* xListener */ )
308 throw (uno::RuntimeException
)
310 OSL_ENSURE(false,"not implemented yet");
313 void SAL_CALL
WrappedPropertySet::firePropertiesChangeEvent( const Sequence
< OUString
>& /* rNameSeq */, const Reference
< beans::XPropertiesChangeListener
>& /* xListener */ )
314 throw (uno::RuntimeException
)
316 OSL_ENSURE(false,"not implemented yet");
321 beans::PropertyState SAL_CALL
WrappedPropertySet::getPropertyState( const OUString
& rPropertyName
)
322 throw (beans::UnknownPropertyException
, uno::RuntimeException
)
324 beans::PropertyState
aState( beans::PropertyState_DIRECT_VALUE
);
326 Reference
< beans::XPropertyState
> xInnerPropertyState( this->getInnerPropertyState() );
327 if( xInnerPropertyState
.is() )
329 const WrappedProperty
* pWrappedProperty
= getWrappedProperty( rPropertyName
);
330 if( pWrappedProperty
)
331 aState
= pWrappedProperty
->getPropertyState( xInnerPropertyState
);
333 aState
= xInnerPropertyState
->getPropertyState( rPropertyName
);
338 const WrappedProperty
* WrappedPropertySet::getWrappedProperty( const ::rtl::OUString
& rOuterName
)
340 sal_Int32 nHandle
= getInfoHelper().getHandleByName( rOuterName
);
341 return getWrappedProperty( nHandle
);
344 const WrappedProperty
* WrappedPropertySet::getWrappedProperty( sal_Int32 nHandle
)
346 tWrappedPropertyMap::const_iterator
aFound( getWrappedPropertyMap().find( nHandle
) );
347 if( aFound
!= getWrappedPropertyMap().end() )
348 return (*aFound
).second
;
352 Sequence
< beans::PropertyState
> SAL_CALL
WrappedPropertySet::getPropertyStates( const Sequence
< OUString
>& rNameSeq
)
353 throw (beans::UnknownPropertyException
, uno::RuntimeException
)
355 Sequence
< beans::PropertyState
> aRetSeq
;
356 if( rNameSeq
.getLength() )
358 aRetSeq
.realloc( rNameSeq
.getLength() );
359 for(sal_Int32 nN
=0; nN
<rNameSeq
.getLength(); nN
++)
361 ::rtl::OUString
aPropertyName( rNameSeq
[nN
] );
362 aRetSeq
[nN
] = this->getPropertyState( aPropertyName
);
368 void SAL_CALL
WrappedPropertySet::setPropertyToDefault( const OUString
& rPropertyName
)
369 throw (beans::UnknownPropertyException
, uno::RuntimeException
)
371 Reference
< beans::XPropertyState
> xInnerPropertyState( this->getInnerPropertyState() );
372 if( xInnerPropertyState
.is() )
374 const WrappedProperty
* pWrappedProperty
= getWrappedProperty( rPropertyName
);
375 if( pWrappedProperty
)
376 pWrappedProperty
->setPropertyToDefault( xInnerPropertyState
);
378 xInnerPropertyState
->setPropertyToDefault( rPropertyName
);
381 Any SAL_CALL
WrappedPropertySet::getPropertyDefault( const OUString
& rPropertyName
)
382 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
385 Reference
< beans::XPropertyState
> xInnerPropertyState( this->getInnerPropertyState() );
386 if( xInnerPropertyState
.is() )
388 const WrappedProperty
* pWrappedProperty
= getWrappedProperty( rPropertyName
);
389 if( pWrappedProperty
)
390 aRet
= pWrappedProperty
->getPropertyDefault(xInnerPropertyState
);
392 aRet
= xInnerPropertyState
->getPropertyDefault( rPropertyName
);
397 //XMultiPropertyStates
398 void SAL_CALL
WrappedPropertySet::setAllPropertiesToDefault( )
399 throw (uno::RuntimeException
)
401 const Sequence
< beans::Property
>& rPropSeq
= getPropertySequence();
402 for(sal_Int32 nN
=0; nN
<rPropSeq
.getLength(); nN
++)
404 ::rtl::OUString
aPropertyName( rPropSeq
[nN
].Name
);
405 this->setPropertyToDefault( aPropertyName
);
408 void SAL_CALL
WrappedPropertySet::setPropertiesToDefault( const Sequence
< OUString
>& rNameSeq
)
409 throw (beans::UnknownPropertyException
, uno::RuntimeException
)
411 for(sal_Int32 nN
=0; nN
<rNameSeq
.getLength(); nN
++)
413 ::rtl::OUString
aPropertyName( rNameSeq
[nN
] );
414 this->setPropertyToDefault( aPropertyName
);
417 Sequence
< Any
> SAL_CALL
WrappedPropertySet::getPropertyDefaults( const Sequence
< OUString
>& rNameSeq
)
418 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
420 Sequence
< Any
> aRetSeq
;
421 if( rNameSeq
.getLength() )
423 aRetSeq
.realloc( rNameSeq
.getLength() );
424 for(sal_Int32 nN
=0; nN
<rNameSeq
.getLength(); nN
++)
426 ::rtl::OUString
aPropertyName( rNameSeq
[nN
] );
427 aRetSeq
[nN
] = this->getPropertyDefault( aPropertyName
);
433 //-----------------------------------------------------------------------------
434 //-----------------------------------------------------------------------------
436 ::cppu::IPropertyArrayHelper
& WrappedPropertySet::getInfoHelper()
438 if(!m_pPropertyArrayHelper
)
441 ::osl::MutexGuard
aGuard( m_aMutex
);
442 if(!m_pPropertyArrayHelper
)
444 sal_Bool bSorted
= sal_True
;
445 m_pPropertyArrayHelper
= new ::cppu::OPropertyArrayHelper( getPropertySequence(), bSorted
);
449 return *m_pPropertyArrayHelper
;
452 //-----------------------------------------------------------------------------
454 tWrappedPropertyMap
& WrappedPropertySet::getWrappedPropertyMap()
456 if(!m_pWrappedPropertyMap
)
459 ::osl::MutexGuard
aGuard( m_aMutex
);
460 if(!m_pWrappedPropertyMap
)
462 std::vector
< WrappedProperty
* > aPropList( createWrappedProperties() );
463 m_pWrappedPropertyMap
= new tWrappedPropertyMap();
465 for( std::vector
< WrappedProperty
* >::const_iterator aIt
= aPropList
.begin(); aIt
!=aPropList
.end(); ++aIt
)
467 WrappedProperty
* pProperty
= *aIt
;
470 sal_Int32 nHandle
= getInfoHelper().getHandleByName( pProperty
->getOuterName() );
474 OSL_ENSURE( false, "missing property in property list" );
475 delete pProperty
;//we are owner or the created WrappedProperties
477 else if( m_pWrappedPropertyMap
->find( nHandle
) != m_pWrappedPropertyMap
->end() )
479 //duplicate Wrapped property
480 OSL_ENSURE( false, "duplicate Wrapped property" );
481 delete pProperty
;//we are owner or the created WrappedProperties
484 (*m_pWrappedPropertyMap
)[ nHandle
] = pProperty
;
490 return *m_pWrappedPropertyMap
;
493 //.............................................................................
495 //.............................................................................