Update ooo320-m1
[ooovba.git] / comphelper / source / property / propertysethelper.cxx
blobc084286b9de5536ed3f13403e6bbcd4187d0e037
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: propertysethelper.cxx,v $
10 * $Revision: 1.12 $
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_comphelper.hxx"
34 #include "comphelper/propertysetinfo.hxx"
35 #include "comphelper/propertysethelper.hxx"
37 ///////////////////////////////////////////////////////////////////////
39 using namespace ::rtl;
40 using namespace ::comphelper;
41 using namespace ::com::sun::star;
42 using namespace ::com::sun::star::uno;
43 using namespace ::com::sun::star::beans;
44 using namespace ::com::sun::star::lang;
46 namespace comphelper
48 class PropertySetHelperImpl
50 public:
51 PropertyMapEntry* find( const OUString& aName ) const throw();
53 PropertySetInfo* mpInfo;
57 PropertyMapEntry* PropertySetHelperImpl::find( const OUString& aName ) const throw()
59 PropertyMap::const_iterator aIter = mpInfo->getPropertyMap()->find( aName );
61 if( mpInfo->getPropertyMap()->end() != aIter )
63 return (*aIter).second;
65 else
67 return NULL;
71 ///////////////////////////////////////////////////////////////////////
73 PropertySetHelper::PropertySetHelper( )
75 mp = new PropertySetHelperImpl;
76 mp->mpInfo = new PropertySetInfo;
77 mp->mpInfo->acquire();
80 PropertySetHelper::PropertySetHelper( comphelper::PropertySetInfo* pInfo ) throw()
82 mp = new PropertySetHelperImpl;
83 mp->mpInfo = pInfo;
84 pInfo->acquire();
87 PropertySetHelper::PropertySetHelper( comphelper::PropertySetInfo* pInfo, __sal_NoAcquire ) throw()
89 mp = new PropertySetHelperImpl;
90 mp->mpInfo = pInfo;
93 PropertySetHelper::~PropertySetHelper() throw()
95 mp->mpInfo->release();
96 delete mp;
99 void PropertySetHelper::setInfo( comphelper::PropertySetInfo* pInfo ) throw()
101 OSL_ENSURE( pInfo != NULL, "need pInfo" );
102 OSL_ENSURE( mp->mpInfo != NULL, "where's the old pInfo?" );
104 mp->mpInfo->release();
105 mp->mpInfo = pInfo;
106 mp->mpInfo->acquire();
109 // XPropertySet
110 Reference< XPropertySetInfo > SAL_CALL PropertySetHelper::getPropertySetInfo( ) throw(RuntimeException)
112 return mp->mpInfo;
115 void SAL_CALL PropertySetHelper::setPropertyValue( const ::rtl::OUString& aPropertyName, const Any& aValue ) throw(UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException)
117 PropertyMapEntry* aEntries[2];
118 aEntries[0] = mp->find( aPropertyName );
120 if( NULL == aEntries[0] )
121 throw UnknownPropertyException( aPropertyName, static_cast< XPropertySet* >( this ) );
123 aEntries[1] = NULL;
125 _setPropertyValues( (const PropertyMapEntry**)aEntries, &aValue );
128 Any SAL_CALL PropertySetHelper::getPropertyValue( const ::rtl::OUString& PropertyName ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
130 PropertyMapEntry* aEntries[2];
131 aEntries[0] = mp->find( PropertyName );
133 if( NULL == aEntries[0] )
134 throw UnknownPropertyException( PropertyName, static_cast< XPropertySet* >( this ) );
136 aEntries[1] = NULL;
138 Any aAny;
139 _getPropertyValues( (const PropertyMapEntry**)aEntries, &aAny );
141 return aAny;
144 void SAL_CALL PropertySetHelper::addPropertyChangeListener( const ::rtl::OUString&, const Reference< XPropertyChangeListener >& ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
146 // todo
149 void SAL_CALL PropertySetHelper::removePropertyChangeListener( const ::rtl::OUString&, const Reference< XPropertyChangeListener >& ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
151 // todo
154 void SAL_CALL PropertySetHelper::addVetoableChangeListener( const ::rtl::OUString&, const Reference< XVetoableChangeListener >& ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
156 // todo
159 void SAL_CALL PropertySetHelper::removeVetoableChangeListener( const ::rtl::OUString&, const Reference< XVetoableChangeListener >& ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
161 // todo
164 // XMultiPropertySet
165 void SAL_CALL PropertySetHelper::setPropertyValues( const Sequence< ::rtl::OUString >& aPropertyNames, const Sequence< Any >& aValues ) throw(PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException)
167 const sal_Int32 nCount = aPropertyNames.getLength();
169 if( nCount != aValues.getLength() )
170 throw IllegalArgumentException();
172 if( nCount )
174 PropertyMapEntry** pEntries = new PropertyMapEntry*[nCount+1];
175 pEntries[nCount] = NULL;
176 const OUString* pNames = aPropertyNames.getConstArray();
178 sal_Bool bUnknown = sal_False;
179 sal_Int32 n;
180 for( n = 0; !bUnknown && ( n < nCount ); n++, pNames++ )
182 pEntries[n] = mp->find( *pNames );
183 bUnknown = NULL == pEntries[n];
186 if( !bUnknown )
187 _setPropertyValues( (const PropertyMapEntry**)pEntries, aValues.getConstArray() );
189 delete[] pEntries;
191 if( bUnknown )
192 throw UnknownPropertyException( *pNames, static_cast< XPropertySet* >( this ) );
196 Sequence< Any > SAL_CALL PropertySetHelper::getPropertyValues( const Sequence< ::rtl::OUString >& aPropertyNames ) throw(RuntimeException)
198 const sal_Int32 nCount = aPropertyNames.getLength();
200 Sequence< Any > aValues;
201 if( nCount )
203 PropertyMapEntry** pEntries = new PropertyMapEntry*[nCount+1];
204 pEntries[nCount] = NULL;
205 const OUString* pNames = aPropertyNames.getConstArray();
207 sal_Bool bUnknown = sal_False;
208 sal_Int32 n;
209 for( n = 0; !bUnknown && ( n < nCount ); n++, pNames++ )
211 pEntries[n] = mp->find( *pNames );
212 bUnknown = NULL == pEntries[n];
215 if( !bUnknown )
217 aValues.realloc(nCount);
218 _getPropertyValues( (const PropertyMapEntry**)pEntries, aValues.getArray() );
221 delete[] pEntries;
223 if( bUnknown )
224 throw UnknownPropertyException( *pNames, static_cast< XPropertySet* >( this ) );
227 return aValues;
230 void SAL_CALL PropertySetHelper::addPropertiesChangeListener( const Sequence< ::rtl::OUString >&, const Reference< XPropertiesChangeListener >& ) throw(RuntimeException)
232 // todo
235 void SAL_CALL PropertySetHelper::removePropertiesChangeListener( const Reference< XPropertiesChangeListener >& ) throw(RuntimeException)
237 // todo
240 void SAL_CALL PropertySetHelper::firePropertiesChangeEvent( const Sequence< ::rtl::OUString >&, const Reference< XPropertiesChangeListener >& ) throw(RuntimeException)
242 // todo
245 // XPropertyState
246 PropertyState SAL_CALL PropertySetHelper::getPropertyState( const ::rtl::OUString& PropertyName ) throw(UnknownPropertyException, RuntimeException)
248 PropertyMapEntry* aEntries[2];
250 aEntries[0] = mp->find( PropertyName );
251 if( aEntries[0] == NULL )
252 throw UnknownPropertyException( PropertyName, static_cast< XPropertySet* >( this ) );
254 aEntries[1] = NULL;
256 PropertyState aState;
257 _getPropertyStates( (const PropertyMapEntry**)aEntries, &aState );
259 return aState;
262 Sequence< PropertyState > SAL_CALL PropertySetHelper::getPropertyStates( const Sequence< ::rtl::OUString >& aPropertyName ) throw(UnknownPropertyException, RuntimeException)
264 const sal_Int32 nCount = aPropertyName.getLength();
266 Sequence< PropertyState > aStates( nCount );
268 if( nCount )
270 const OUString* pNames = aPropertyName.getConstArray();
272 sal_Bool bUnknown = sal_False;
274 PropertyMapEntry** pEntries = new PropertyMapEntry*[nCount+1];
276 sal_Int32 n;
277 for( n = 0; !bUnknown && (n < nCount); n++, pNames++ )
279 pEntries[n] = mp->find( *pNames );
280 bUnknown = NULL == pEntries[n];
283 pEntries[nCount] = NULL;
285 if( !bUnknown )
286 _getPropertyStates( (const PropertyMapEntry**)pEntries, aStates.getArray() );
288 delete[] pEntries;
290 if( bUnknown )
291 throw UnknownPropertyException( *pNames, static_cast< XPropertySet* >( this ) );
294 return aStates;
297 void SAL_CALL PropertySetHelper::setPropertyToDefault( const ::rtl::OUString& PropertyName ) throw(UnknownPropertyException, RuntimeException)
299 PropertyMapEntry *pEntry = mp->find( PropertyName );
300 if( NULL == pEntry )
301 throw UnknownPropertyException( PropertyName, static_cast< XPropertySet* >( this ) );
303 _setPropertyToDefault( pEntry );
306 Any SAL_CALL PropertySetHelper::getPropertyDefault( const ::rtl::OUString& aPropertyName ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
308 PropertyMapEntry* pEntry = mp->find( aPropertyName );
309 if( NULL == pEntry )
310 throw UnknownPropertyException( aPropertyName, static_cast< XPropertySet* >( this ) );
312 return _getPropertyDefault( pEntry );
315 void PropertySetHelper::_getPropertyStates( const comphelper::PropertyMapEntry**, PropertyState* ) throw(UnknownPropertyException )
317 OSL_ENSURE( sal_False, "you have to implement this yourself!");
320 void PropertySetHelper::_setPropertyToDefault( const comphelper::PropertyMapEntry* ) throw(UnknownPropertyException )
322 OSL_ENSURE( sal_False, "you have to implement this yourself!");
325 Any PropertySetHelper::_getPropertyDefault( const comphelper::PropertyMapEntry* ) throw(UnknownPropertyException, WrappedTargetException )
327 OSL_ENSURE( sal_False, "you have to implement this yourself!");
329 Any aAny;
330 return aAny;