1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: WrappedPropertySet.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
34 #include "WrappedPropertySet.hxx"
37 // header for define DELETEZ
38 #include <tools/solar.h>
40 //.............................................................................
43 //.............................................................................
45 using namespace ::com::sun::star
;
46 using ::com::sun::star::uno::Reference
;
47 using ::com::sun::star::uno::Sequence
;
48 using ::com::sun::star::uno::Any
;
49 using ::rtl::OUString
;
51 WrappedPropertySet::WrappedPropertySet()
54 , m_pPropertyArrayHelper(0)
55 , m_pWrappedPropertyMap(0)
58 WrappedPropertySet::~WrappedPropertySet()
60 clearWrappedPropertySet();
63 Reference
< beans::XPropertyState
> WrappedPropertySet::getInnerPropertyState()
65 return Reference
< beans::XPropertyState
>( getInnerPropertySet(), uno::UNO_QUERY
);
68 void WrappedPropertySet::clearWrappedPropertySet()
71 ::osl::MutexGuard
aGuard( m_aMutex
);
73 //delete all wrapped properties
74 if(m_pWrappedPropertyMap
)
76 for( tWrappedPropertyMap::iterator aIt
= m_pWrappedPropertyMap
->begin()
77 ; aIt
!= m_pWrappedPropertyMap
->end(); aIt
++ )
79 const WrappedProperty
* pWrappedProperty
= (*aIt
).second
;
80 DELETEZ(pWrappedProperty
);
84 DELETEZ(m_pPropertyArrayHelper
);
85 DELETEZ(m_pWrappedPropertyMap
);
92 Reference
< beans::XPropertySetInfo
> SAL_CALL
WrappedPropertySet::getPropertySetInfo( )
93 throw (uno::RuntimeException
)
98 ::osl::MutexGuard
aGuard( m_aMutex
);
101 m_xInfo
= ::cppu::OPropertySetHelper::createPropertySetInfo( getInfoHelper() );
108 void SAL_CALL
WrappedPropertySet::setPropertyValue( const OUString
& rPropertyName
, const Any
& rValue
)
109 throw (beans::UnknownPropertyException
, beans::PropertyVetoException
, lang::IllegalArgumentException
, lang::WrappedTargetException
, uno::RuntimeException
)
113 sal_Int32 nHandle
= getInfoHelper().getHandleByName( rPropertyName
);
114 const WrappedProperty
* pWrappedProperty
= getWrappedProperty( nHandle
);
115 Reference
< beans::XPropertySet
> xInnerPropertySet( this->getInnerPropertySet() );
116 if( pWrappedProperty
)
117 pWrappedProperty
->setPropertyValue( rValue
, xInnerPropertySet
);
118 else if( xInnerPropertySet
.is() )
119 xInnerPropertySet
->setPropertyValue( rPropertyName
, rValue
);
121 throw beans::UnknownPropertyException();
123 catch( beans::UnknownPropertyException
& ex
)
127 catch( beans::PropertyVetoException
& ex
)
131 catch( lang::IllegalArgumentException
& ex
)
135 catch( lang::WrappedTargetException
& ex
)
139 catch( uno::RuntimeException
& ex
)
143 catch( uno::Exception
& ex
)
145 OSL_ENSURE(false,"invalid exception caught in WrappedPropertySet::setPropertyValue");
146 lang::WrappedTargetException aWrappedException
;
147 aWrappedException
.TargetException
= uno::makeAny( ex
);
148 throw aWrappedException
;
151 Any SAL_CALL
WrappedPropertySet::getPropertyValue( const OUString
& rPropertyName
)
152 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
158 sal_Int32 nHandle
= getInfoHelper().getHandleByName( rPropertyName
);
159 const WrappedProperty
* pWrappedProperty
= getWrappedProperty( nHandle
);
160 Reference
< beans::XPropertySet
> xInnerPropertySet( this->getInnerPropertySet() );
161 if( pWrappedProperty
)
162 aRet
= pWrappedProperty
->getPropertyValue( xInnerPropertySet
);
163 else if( xInnerPropertySet
.is() )
164 aRet
= xInnerPropertySet
->getPropertyValue( rPropertyName
);
166 throw beans::UnknownPropertyException();
168 catch( beans::UnknownPropertyException
& ex
)
172 catch( lang::WrappedTargetException
& ex
)
176 catch( uno::RuntimeException
& ex
)
180 catch( uno::Exception
& ex
)
182 OSL_ENSURE(false,"invalid exception caught in WrappedPropertySet::setPropertyValue");
183 lang::WrappedTargetException aWrappedException
;
184 aWrappedException
.TargetException
= uno::makeAny( ex
);
185 throw aWrappedException
;
191 void SAL_CALL
WrappedPropertySet::addPropertyChangeListener( const OUString
& rPropertyName
, const Reference
< beans::XPropertyChangeListener
>& xListener
)
192 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
194 Reference
< beans::XPropertySet
> xInnerPropertySet( this->getInnerPropertySet() );
195 if( xInnerPropertySet
.is() )
197 const WrappedProperty
* pWrappedProperty
= getWrappedProperty( rPropertyName
);
198 if( pWrappedProperty
)
199 xInnerPropertySet
->addPropertyChangeListener( pWrappedProperty
->getInnerName(), xListener
);
201 xInnerPropertySet
->addPropertyChangeListener( rPropertyName
, xListener
);
203 // m_aBoundListenerContainer.addInterface( (sal_Int32)nHandle, xListener );
205 void SAL_CALL
WrappedPropertySet::removePropertyChangeListener( const OUString
& rPropertyName
, const Reference
< beans::XPropertyChangeListener
>& aListener
)
206 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
208 Reference
< beans::XPropertySet
> xInnerPropertySet( this->getInnerPropertySet() );
209 if( xInnerPropertySet
.is() )
211 const WrappedProperty
* pWrappedProperty
= getWrappedProperty( rPropertyName
);
212 if( pWrappedProperty
)
213 xInnerPropertySet
->removePropertyChangeListener( pWrappedProperty
->getInnerName(), aListener
);
215 xInnerPropertySet
->removePropertyChangeListener( rPropertyName
, aListener
);
218 void SAL_CALL
WrappedPropertySet::addVetoableChangeListener( const OUString
& rPropertyName
, const Reference
< beans::XVetoableChangeListener
>& aListener
)
219 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
221 Reference
< beans::XPropertySet
> xInnerPropertySet( this->getInnerPropertySet() );
222 if( xInnerPropertySet
.is() )
224 const WrappedProperty
* pWrappedProperty
= getWrappedProperty( rPropertyName
);
225 if( pWrappedProperty
)
226 xInnerPropertySet
->addVetoableChangeListener( pWrappedProperty
->getInnerName(), aListener
);
228 xInnerPropertySet
->addVetoableChangeListener( rPropertyName
, aListener
);
231 void SAL_CALL
WrappedPropertySet::removeVetoableChangeListener( const OUString
& rPropertyName
, const Reference
< beans::XVetoableChangeListener
>& aListener
)
232 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
234 Reference
< beans::XPropertySet
> xInnerPropertySet( this->getInnerPropertySet() );
235 if( xInnerPropertySet
.is() )
237 const WrappedProperty
* pWrappedProperty
= getWrappedProperty( rPropertyName
);
238 if( pWrappedProperty
)
239 xInnerPropertySet
->removeVetoableChangeListener( pWrappedProperty
->getInnerName(), aListener
);
241 xInnerPropertySet
->removeVetoableChangeListener( rPropertyName
, aListener
);
246 void SAL_CALL
WrappedPropertySet::setPropertyValues( const Sequence
< OUString
>& rNameSeq
, const Sequence
< Any
>& rValueSeq
)
247 throw (beans::PropertyVetoException
, lang::IllegalArgumentException
, lang::WrappedTargetException
, uno::RuntimeException
)
249 bool bUnknownProperty
= false;
250 sal_Int32 nMinCount
= std::min( rValueSeq
.getLength(), rNameSeq
.getLength() );
251 for(sal_Int32 nN
=0; nN
<nMinCount
; nN
++)
253 ::rtl::OUString
aPropertyName( rNameSeq
[nN
] );
256 this->setPropertyValue( aPropertyName
, rValueSeq
[nN
] );
258 catch( beans::UnknownPropertyException
& ex
)
260 ASSERT_EXCEPTION( ex
);
261 bUnknownProperty
= true;
264 //todo: store unknown properties elsewhere
265 // if( bUnknownProperty )
266 // throw beans::UnknownPropertyException();
268 Sequence
< Any
> SAL_CALL
WrappedPropertySet::getPropertyValues( const Sequence
< OUString
>& rNameSeq
)
269 throw (uno::RuntimeException
)
271 Sequence
< Any
> aRetSeq
;
272 if( rNameSeq
.getLength() )
274 aRetSeq
.realloc( rNameSeq
.getLength() );
275 for(sal_Int32 nN
=0; nN
<rNameSeq
.getLength(); nN
++)
279 ::rtl::OUString
aPropertyName( rNameSeq
[nN
] );
280 aRetSeq
[nN
] = this->getPropertyValue( aPropertyName
);
282 catch( beans::UnknownPropertyException
& ex
)
284 ASSERT_EXCEPTION( ex
);
286 catch( lang::WrappedTargetException
& ex
)
288 ASSERT_EXCEPTION( ex
);
294 void SAL_CALL
WrappedPropertySet::addPropertiesChangeListener( const Sequence
< OUString
>& /* rNameSeq */, const Reference
< beans::XPropertiesChangeListener
>& /* xListener */ )
295 throw (uno::RuntimeException
)
297 OSL_ENSURE(false,"not implemented yet");
300 void SAL_CALL
WrappedPropertySet::removePropertiesChangeListener( const Reference
< beans::XPropertiesChangeListener
>& /* xListener */ )
301 throw (uno::RuntimeException
)
303 OSL_ENSURE(false,"not implemented yet");
306 void SAL_CALL
WrappedPropertySet::firePropertiesChangeEvent( const Sequence
< OUString
>& /* rNameSeq */, const Reference
< beans::XPropertiesChangeListener
>& /* xListener */ )
307 throw (uno::RuntimeException
)
309 OSL_ENSURE(false,"not implemented yet");
314 beans::PropertyState SAL_CALL
WrappedPropertySet::getPropertyState( const OUString
& rPropertyName
)
315 throw (beans::UnknownPropertyException
, uno::RuntimeException
)
317 beans::PropertyState
aState( beans::PropertyState_DIRECT_VALUE
);
319 Reference
< beans::XPropertyState
> xInnerPropertyState( this->getInnerPropertyState() );
320 if( xInnerPropertyState
.is() )
322 const WrappedProperty
* pWrappedProperty
= getWrappedProperty( rPropertyName
);
323 if( pWrappedProperty
)
324 aState
= pWrappedProperty
->getPropertyState( xInnerPropertyState
);
326 aState
= xInnerPropertyState
->getPropertyState( rPropertyName
);
331 const WrappedProperty
* WrappedPropertySet::getWrappedProperty( const ::rtl::OUString
& rOuterName
)
333 sal_Int32 nHandle
= getInfoHelper().getHandleByName( rOuterName
);
334 return getWrappedProperty( nHandle
);
337 const WrappedProperty
* WrappedPropertySet::getWrappedProperty( sal_Int32 nHandle
)
339 tWrappedPropertyMap::const_iterator
aFound( getWrappedPropertyMap().find( nHandle
) );
340 if( aFound
!= getWrappedPropertyMap().end() )
341 return (*aFound
).second
;
345 Sequence
< beans::PropertyState
> SAL_CALL
WrappedPropertySet::getPropertyStates( const Sequence
< OUString
>& rNameSeq
)
346 throw (beans::UnknownPropertyException
, uno::RuntimeException
)
348 Sequence
< beans::PropertyState
> aRetSeq
;
349 if( rNameSeq
.getLength() )
351 aRetSeq
.realloc( rNameSeq
.getLength() );
352 for(sal_Int32 nN
=0; nN
<rNameSeq
.getLength(); nN
++)
354 ::rtl::OUString
aPropertyName( rNameSeq
[nN
] );
355 aRetSeq
[nN
] = this->getPropertyState( aPropertyName
);
361 void SAL_CALL
WrappedPropertySet::setPropertyToDefault( const OUString
& rPropertyName
)
362 throw (beans::UnknownPropertyException
, uno::RuntimeException
)
364 Reference
< beans::XPropertyState
> xInnerPropertyState( this->getInnerPropertyState() );
365 if( xInnerPropertyState
.is() )
367 const WrappedProperty
* pWrappedProperty
= getWrappedProperty( rPropertyName
);
368 if( pWrappedProperty
)
369 pWrappedProperty
->setPropertyToDefault( xInnerPropertyState
);
371 xInnerPropertyState
->setPropertyToDefault( rPropertyName
);
374 Any SAL_CALL
WrappedPropertySet::getPropertyDefault( const OUString
& rPropertyName
)
375 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
378 Reference
< beans::XPropertyState
> xInnerPropertyState( this->getInnerPropertyState() );
379 if( xInnerPropertyState
.is() )
381 const WrappedProperty
* pWrappedProperty
= getWrappedProperty( rPropertyName
);
382 if( pWrappedProperty
)
383 aRet
= pWrappedProperty
->getPropertyDefault(xInnerPropertyState
);
385 aRet
= xInnerPropertyState
->getPropertyDefault( rPropertyName
);
390 //XMultiPropertyStates
391 void SAL_CALL
WrappedPropertySet::setAllPropertiesToDefault( )
392 throw (uno::RuntimeException
)
394 const Sequence
< beans::Property
>& rPropSeq
= getPropertySequence();
395 for(sal_Int32 nN
=0; nN
<rPropSeq
.getLength(); nN
++)
397 ::rtl::OUString
aPropertyName( rPropSeq
[nN
].Name
);
398 this->setPropertyToDefault( aPropertyName
);
401 void SAL_CALL
WrappedPropertySet::setPropertiesToDefault( const Sequence
< OUString
>& rNameSeq
)
402 throw (beans::UnknownPropertyException
, uno::RuntimeException
)
404 for(sal_Int32 nN
=0; nN
<rNameSeq
.getLength(); nN
++)
406 ::rtl::OUString
aPropertyName( rNameSeq
[nN
] );
407 this->setPropertyToDefault( aPropertyName
);
410 Sequence
< Any
> SAL_CALL
WrappedPropertySet::getPropertyDefaults( const Sequence
< OUString
>& rNameSeq
)
411 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
413 Sequence
< Any
> aRetSeq
;
414 if( rNameSeq
.getLength() )
416 aRetSeq
.realloc( rNameSeq
.getLength() );
417 for(sal_Int32 nN
=0; nN
<rNameSeq
.getLength(); nN
++)
419 ::rtl::OUString
aPropertyName( rNameSeq
[nN
] );
420 aRetSeq
[nN
] = this->getPropertyDefault( aPropertyName
);
426 //-----------------------------------------------------------------------------
427 //-----------------------------------------------------------------------------
429 ::cppu::IPropertyArrayHelper
& WrappedPropertySet::getInfoHelper()
431 if(!m_pPropertyArrayHelper
)
434 ::osl::MutexGuard
aGuard( m_aMutex
);
435 if(!m_pPropertyArrayHelper
)
437 sal_Bool bSorted
= sal_True
;
438 m_pPropertyArrayHelper
= new ::cppu::OPropertyArrayHelper( getPropertySequence(), bSorted
);
442 return *m_pPropertyArrayHelper
;
445 //-----------------------------------------------------------------------------
447 tWrappedPropertyMap
& WrappedPropertySet::getWrappedPropertyMap()
449 if(!m_pWrappedPropertyMap
)
452 ::osl::MutexGuard
aGuard( m_aMutex
);
453 if(!m_pWrappedPropertyMap
)
455 std::vector
< WrappedProperty
* > aPropList( createWrappedProperties() );
456 m_pWrappedPropertyMap
= new tWrappedPropertyMap();
458 for( std::vector
< WrappedProperty
* >::const_iterator aIt
= aPropList
.begin(); aIt
!=aPropList
.end(); ++aIt
)
460 WrappedProperty
* pProperty
= *aIt
;
463 sal_Int32 nHandle
= getInfoHelper().getHandleByName( pProperty
->getOuterName() );
467 OSL_ENSURE( false, "missing property in property list" );
468 delete pProperty
;//we are owner or the created WrappedProperties
470 else if( m_pWrappedPropertyMap
->find( nHandle
) != m_pWrappedPropertyMap
->end() )
472 //duplicate Wrapped property
473 OSL_ENSURE( false, "duplicate Wrapped property" );
474 delete pProperty
;//we are owner or the created WrappedProperties
477 (*m_pWrappedPropertyMap
)[ nHandle
] = pProperty
;
483 return *m_pWrappedPropertyMap
;
486 //.............................................................................
488 //.............................................................................