merged tag ooo/OOO330_m14
[LibreOffice.git] / comphelper / source / property / propertysethelper.cxx
blob9d2abf784c1b824cf47d3d535b6118665e23a534
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_comphelper.hxx"
31 #include "comphelper/propertysetinfo.hxx"
32 #include "comphelper/propertysethelper.hxx"
34 ///////////////////////////////////////////////////////////////////////
36 using namespace ::rtl;
37 using namespace ::comphelper;
38 using namespace ::com::sun::star;
39 using namespace ::com::sun::star::uno;
40 using namespace ::com::sun::star::beans;
41 using namespace ::com::sun::star::lang;
43 namespace comphelper
45 class PropertySetHelperImpl
47 public:
48 PropertyMapEntry* find( const OUString& aName ) const throw();
50 PropertySetInfo* mpInfo;
54 PropertyMapEntry* PropertySetHelperImpl::find( const OUString& aName ) const throw()
56 PropertyMap::const_iterator aIter = mpInfo->getPropertyMap()->find( aName );
58 if( mpInfo->getPropertyMap()->end() != aIter )
60 return (*aIter).second;
62 else
64 return NULL;
68 ///////////////////////////////////////////////////////////////////////
70 PropertySetHelper::PropertySetHelper( )
72 mp = new PropertySetHelperImpl;
73 mp->mpInfo = new PropertySetInfo;
74 mp->mpInfo->acquire();
77 PropertySetHelper::PropertySetHelper( comphelper::PropertySetInfo* pInfo ) throw()
79 mp = new PropertySetHelperImpl;
80 mp->mpInfo = pInfo;
81 pInfo->acquire();
84 PropertySetHelper::PropertySetHelper( comphelper::PropertySetInfo* pInfo, __sal_NoAcquire ) throw()
86 mp = new PropertySetHelperImpl;
87 mp->mpInfo = pInfo;
90 PropertySetHelper::~PropertySetHelper() throw()
92 mp->mpInfo->release();
93 delete mp;
96 void PropertySetHelper::setInfo( comphelper::PropertySetInfo* pInfo ) throw()
98 OSL_ENSURE( pInfo != NULL, "need pInfo" );
99 OSL_ENSURE( mp->mpInfo != NULL, "where's the old pInfo?" );
101 mp->mpInfo->release();
102 mp->mpInfo = pInfo;
103 mp->mpInfo->acquire();
106 // XPropertySet
107 Reference< XPropertySetInfo > SAL_CALL PropertySetHelper::getPropertySetInfo( ) throw(RuntimeException)
109 return mp->mpInfo;
112 void SAL_CALL PropertySetHelper::setPropertyValue( const ::rtl::OUString& aPropertyName, const Any& aValue ) throw(UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException)
114 PropertyMapEntry* aEntries[2];
115 aEntries[0] = mp->find( aPropertyName );
117 if( NULL == aEntries[0] )
118 throw UnknownPropertyException( aPropertyName, static_cast< XPropertySet* >( this ) );
120 aEntries[1] = NULL;
122 _setPropertyValues( (const PropertyMapEntry**)aEntries, &aValue );
125 Any SAL_CALL PropertySetHelper::getPropertyValue( const ::rtl::OUString& PropertyName ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
127 PropertyMapEntry* aEntries[2];
128 aEntries[0] = mp->find( PropertyName );
130 if( NULL == aEntries[0] )
131 throw UnknownPropertyException( PropertyName, static_cast< XPropertySet* >( this ) );
133 aEntries[1] = NULL;
135 Any aAny;
136 _getPropertyValues( (const PropertyMapEntry**)aEntries, &aAny );
138 return aAny;
141 void SAL_CALL PropertySetHelper::addPropertyChangeListener( const ::rtl::OUString&, const Reference< XPropertyChangeListener >& ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
143 // todo
146 void SAL_CALL PropertySetHelper::removePropertyChangeListener( const ::rtl::OUString&, const Reference< XPropertyChangeListener >& ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
148 // todo
151 void SAL_CALL PropertySetHelper::addVetoableChangeListener( const ::rtl::OUString&, const Reference< XVetoableChangeListener >& ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
153 // todo
156 void SAL_CALL PropertySetHelper::removeVetoableChangeListener( const ::rtl::OUString&, const Reference< XVetoableChangeListener >& ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
158 // todo
161 // XMultiPropertySet
162 void SAL_CALL PropertySetHelper::setPropertyValues( const Sequence< ::rtl::OUString >& aPropertyNames, const Sequence< Any >& aValues ) throw(PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException)
164 const sal_Int32 nCount = aPropertyNames.getLength();
166 if( nCount != aValues.getLength() )
167 throw IllegalArgumentException();
169 if( nCount )
171 PropertyMapEntry** pEntries = new PropertyMapEntry*[nCount+1];
172 pEntries[nCount] = NULL;
173 const OUString* pNames = aPropertyNames.getConstArray();
175 sal_Bool bUnknown = sal_False;
176 sal_Int32 n;
177 for( n = 0; !bUnknown && ( n < nCount ); n++, pNames++ )
179 pEntries[n] = mp->find( *pNames );
180 bUnknown = NULL == pEntries[n];
183 if( !bUnknown )
184 _setPropertyValues( (const PropertyMapEntry**)pEntries, aValues.getConstArray() );
186 delete[] pEntries;
188 if( bUnknown )
189 throw UnknownPropertyException( *pNames, static_cast< XPropertySet* >( this ) );
193 Sequence< Any > SAL_CALL PropertySetHelper::getPropertyValues( const Sequence< ::rtl::OUString >& aPropertyNames ) throw(RuntimeException)
195 const sal_Int32 nCount = aPropertyNames.getLength();
197 Sequence< Any > aValues;
198 if( nCount )
200 PropertyMapEntry** pEntries = new PropertyMapEntry*[nCount+1];
201 pEntries[nCount] = NULL;
202 const OUString* pNames = aPropertyNames.getConstArray();
204 sal_Bool bUnknown = sal_False;
205 sal_Int32 n;
206 for( n = 0; !bUnknown && ( n < nCount ); n++, pNames++ )
208 pEntries[n] = mp->find( *pNames );
209 bUnknown = NULL == pEntries[n];
212 if( !bUnknown )
214 aValues.realloc(nCount);
215 _getPropertyValues( (const PropertyMapEntry**)pEntries, aValues.getArray() );
218 delete[] pEntries;
220 if( bUnknown )
221 throw UnknownPropertyException( *pNames, static_cast< XPropertySet* >( this ) );
224 return aValues;
227 void SAL_CALL PropertySetHelper::addPropertiesChangeListener( const Sequence< ::rtl::OUString >&, const Reference< XPropertiesChangeListener >& ) throw(RuntimeException)
229 // todo
232 void SAL_CALL PropertySetHelper::removePropertiesChangeListener( const Reference< XPropertiesChangeListener >& ) throw(RuntimeException)
234 // todo
237 void SAL_CALL PropertySetHelper::firePropertiesChangeEvent( const Sequence< ::rtl::OUString >&, const Reference< XPropertiesChangeListener >& ) throw(RuntimeException)
239 // todo
242 // XPropertyState
243 PropertyState SAL_CALL PropertySetHelper::getPropertyState( const ::rtl::OUString& PropertyName ) throw(UnknownPropertyException, RuntimeException)
245 PropertyMapEntry* aEntries[2];
247 aEntries[0] = mp->find( PropertyName );
248 if( aEntries[0] == NULL )
249 throw UnknownPropertyException( PropertyName, static_cast< XPropertySet* >( this ) );
251 aEntries[1] = NULL;
253 PropertyState aState;
254 _getPropertyStates( (const PropertyMapEntry**)aEntries, &aState );
256 return aState;
259 Sequence< PropertyState > SAL_CALL PropertySetHelper::getPropertyStates( const Sequence< ::rtl::OUString >& aPropertyName ) throw(UnknownPropertyException, RuntimeException)
261 const sal_Int32 nCount = aPropertyName.getLength();
263 Sequence< PropertyState > aStates( nCount );
265 if( nCount )
267 const OUString* pNames = aPropertyName.getConstArray();
269 sal_Bool bUnknown = sal_False;
271 PropertyMapEntry** pEntries = new PropertyMapEntry*[nCount+1];
273 sal_Int32 n;
274 for( n = 0; !bUnknown && (n < nCount); n++, pNames++ )
276 pEntries[n] = mp->find( *pNames );
277 bUnknown = NULL == pEntries[n];
280 pEntries[nCount] = NULL;
282 if( !bUnknown )
283 _getPropertyStates( (const PropertyMapEntry**)pEntries, aStates.getArray() );
285 delete[] pEntries;
287 if( bUnknown )
288 throw UnknownPropertyException( *pNames, static_cast< XPropertySet* >( this ) );
291 return aStates;
294 void SAL_CALL PropertySetHelper::setPropertyToDefault( const ::rtl::OUString& PropertyName ) throw(UnknownPropertyException, RuntimeException)
296 PropertyMapEntry *pEntry = mp->find( PropertyName );
297 if( NULL == pEntry )
298 throw UnknownPropertyException( PropertyName, static_cast< XPropertySet* >( this ) );
300 _setPropertyToDefault( pEntry );
303 Any SAL_CALL PropertySetHelper::getPropertyDefault( const ::rtl::OUString& aPropertyName ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
305 PropertyMapEntry* pEntry = mp->find( aPropertyName );
306 if( NULL == pEntry )
307 throw UnknownPropertyException( aPropertyName, static_cast< XPropertySet* >( this ) );
309 return _getPropertyDefault( pEntry );
312 void PropertySetHelper::_getPropertyStates( const comphelper::PropertyMapEntry**, PropertyState* ) throw(UnknownPropertyException )
314 OSL_ENSURE( sal_False, "you have to implement this yourself!");
317 void PropertySetHelper::_setPropertyToDefault( const comphelper::PropertyMapEntry* ) throw(UnknownPropertyException )
319 OSL_ENSURE( sal_False, "you have to implement this yourself!");
322 Any PropertySetHelper::_getPropertyDefault( const comphelper::PropertyMapEntry* ) throw(UnknownPropertyException, WrappedTargetException )
324 OSL_ENSURE( sal_False, "you have to implement this yourself!");
326 Any aAny;
327 return aAny;