update dev300-m58
[ooovba.git] / unotools / source / property / propertysethelper.cxx
blob4a872cff521fccd6e70b057a2c2915ae0bb92ca6
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.6 $
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_unotools.hxx"
33 #include <tools/debug.hxx>
35 #include "unotools/propertysetinfo.hxx"
36 #include "unotools/propertysethelper.hxx"
38 ///////////////////////////////////////////////////////////////////////
40 using namespace ::utl;
41 using namespace ::rtl;
42 using namespace ::com::sun::star;
43 using namespace ::com::sun::star::uno;
44 using namespace ::com::sun::star::beans;
45 using namespace ::com::sun::star::lang;
47 namespace utl
49 class PropertySetHelperImpl
51 public:
52 PropertyMapEntry* find( const OUString& aName ) const throw();
54 PropertySetInfo* mpInfo;
58 PropertyMapEntry* PropertySetHelperImpl::find( const OUString& aName ) const throw()
60 PropertyMap::const_iterator aIter = mpInfo->getPropertyMap()->find( aName );
62 if( mpInfo->getPropertyMap()->end() != aIter )
64 return (*aIter).second;
66 else
68 return NULL;
72 ///////////////////////////////////////////////////////////////////////
74 PropertySetHelper::PropertySetHelper( utl::PropertySetInfo* pInfo ) throw()
76 mp = new PropertySetHelperImpl;
77 mp->mpInfo = pInfo;
78 pInfo->acquire();
81 PropertySetHelper::~PropertySetHelper() throw()
83 mp->mpInfo->release();
84 delete mp;
87 // XPropertySet
88 Reference< XPropertySetInfo > SAL_CALL PropertySetHelper::getPropertySetInfo( ) throw(RuntimeException)
90 return mp->mpInfo;
93 void SAL_CALL PropertySetHelper::setPropertyValue( const ::rtl::OUString& aPropertyName, const Any& aValue ) throw(UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException)
95 PropertyMapEntry* aEntries[2];
96 aEntries[0] = mp->find( aPropertyName );
98 if( NULL == aEntries[0] )
99 throw UnknownPropertyException();
101 aEntries[1] = NULL;
103 _setPropertyValues( (const PropertyMapEntry**)aEntries, &aValue );
106 Any SAL_CALL PropertySetHelper::getPropertyValue( const ::rtl::OUString& PropertyName ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
108 PropertyMapEntry* aEntries[2];
109 aEntries[0] = mp->find( PropertyName );
111 if( NULL == aEntries[0] )
112 throw UnknownPropertyException();
114 aEntries[1] = NULL;
116 Any aAny;
117 _getPropertyValues( (const PropertyMapEntry**)aEntries, &aAny );
119 return aAny;
122 void SAL_CALL PropertySetHelper::addPropertyChangeListener( const ::rtl::OUString& /*aPropertyName*/, const Reference< XPropertyChangeListener >& /*xListener*/ ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
124 // todo
127 void SAL_CALL PropertySetHelper::removePropertyChangeListener( const ::rtl::OUString& /*aPropertyName*/, const Reference< XPropertyChangeListener >& /*aListener*/ ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
129 // todo
132 void SAL_CALL PropertySetHelper::addVetoableChangeListener( const ::rtl::OUString& /*PropertyName*/, const Reference< XVetoableChangeListener >& /*aListener*/ ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
134 // todo
137 void SAL_CALL PropertySetHelper::removeVetoableChangeListener( const ::rtl::OUString& /*PropertyName*/, const Reference< XVetoableChangeListener >& /*aListener*/ ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
139 // todo
142 // XMultiPropertySet
143 void SAL_CALL PropertySetHelper::setPropertyValues( const Sequence< ::rtl::OUString >& aPropertyNames, const Sequence< Any >& aValues ) throw(PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException)
145 const sal_Int32 nCount = aPropertyNames.getLength();
147 if( nCount != aValues.getLength() )
148 throw IllegalArgumentException();
150 if( nCount )
152 PropertyMapEntry** pEntries = new PropertyMapEntry*[nCount+1];
153 const OUString* pNames = aPropertyNames.getConstArray();
155 sal_Bool bUnknown = sal_False;
156 sal_Int32 n;
157 for( n = 0; !bUnknown && ( n < nCount ); n++, pNames++ )
159 pEntries[n] = mp->find( *pNames );
160 bUnknown = NULL == pEntries[n];
163 if( !bUnknown )
164 _setPropertyValues( (const PropertyMapEntry**)pEntries, aValues.getConstArray() );
166 delete [] pEntries;
168 if( bUnknown )
169 throw UnknownPropertyException();
173 Sequence< Any > SAL_CALL PropertySetHelper::getPropertyValues( const Sequence< ::rtl::OUString >& aPropertyNames ) throw(RuntimeException)
175 const sal_Int32 nCount = aPropertyNames.getLength();
177 Sequence< Any > aValues;
178 if( nCount )
180 PropertyMapEntry** pEntries = new PropertyMapEntry*[nCount+1];
181 const OUString* pNames = aPropertyNames.getConstArray();
183 sal_Bool bUnknown = sal_False;
184 sal_Int32 n;
185 for( n = 0; !bUnknown && ( n < nCount ); n++, pNames++ )
187 pEntries[n] = mp->find( *pNames );
188 bUnknown = NULL == pEntries[n];
191 if( !bUnknown )
192 _getPropertyValues( (const PropertyMapEntry**)pEntries, aValues.getArray() );
194 delete [] pEntries;
196 if( bUnknown )
197 throw UnknownPropertyException();
200 return aValues;
203 void SAL_CALL PropertySetHelper::addPropertiesChangeListener( const Sequence< ::rtl::OUString >& /*aPropertyNames*/, const Reference< XPropertiesChangeListener >& /*xListener*/ ) throw(RuntimeException)
205 // todo
208 void SAL_CALL PropertySetHelper::removePropertiesChangeListener( const Reference< XPropertiesChangeListener >& /*xListener*/ ) throw(RuntimeException)
210 // todo
213 void SAL_CALL PropertySetHelper::firePropertiesChangeEvent( const Sequence< ::rtl::OUString >& /*aPropertyNames*/, const Reference< XPropertiesChangeListener >& /*xListener*/ ) throw(RuntimeException)
215 // todo
218 // XPropertyState
219 PropertyState SAL_CALL PropertySetHelper::getPropertyState( const ::rtl::OUString& PropertyName ) throw(UnknownPropertyException, RuntimeException)
221 PropertyMapEntry* aEntries[2];
223 aEntries[0] = mp->find( PropertyName );
224 if( aEntries[0] == NULL )
225 throw UnknownPropertyException();
227 aEntries[1] = NULL;
229 PropertyState aState;
230 _getPropertyStates( (const PropertyMapEntry**)aEntries, &aState );
232 return aState;
235 Sequence< PropertyState > SAL_CALL PropertySetHelper::getPropertyStates( const Sequence< ::rtl::OUString >& aPropertyName ) throw(UnknownPropertyException, RuntimeException)
237 const sal_Int32 nCount = aPropertyName.getLength();
239 Sequence< PropertyState > aStates( nCount );
241 if( nCount )
243 const OUString* pNames = aPropertyName.getConstArray();
245 sal_Bool bUnknown = sal_False;
247 PropertyMapEntry** pEntries = new PropertyMapEntry*[nCount+1];
249 sal_Int32 n;
250 for( n = 0; !bUnknown && (n < nCount); n++, pNames++ )
252 pEntries[n] = mp->find( *pNames );
253 bUnknown = NULL == pEntries[n];
256 pEntries[nCount] = NULL;
258 if( !bUnknown )
259 _getPropertyStates( (const PropertyMapEntry**)pEntries, aStates.getArray() );
261 delete [] pEntries;
263 if( bUnknown )
264 throw UnknownPropertyException();
267 return aStates;
270 void SAL_CALL PropertySetHelper::setPropertyToDefault( const ::rtl::OUString& PropertyName ) throw(UnknownPropertyException, RuntimeException)
272 PropertyMapEntry *pEntry = mp->find( PropertyName );
273 if( NULL == pEntry )
274 throw UnknownPropertyException();
276 _setPropertyToDefault( pEntry );
279 Any SAL_CALL PropertySetHelper::getPropertyDefault( const ::rtl::OUString& aPropertyName ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
281 PropertyMapEntry* pEntry = mp->find( aPropertyName );
282 if( NULL == pEntry )
283 throw UnknownPropertyException();
285 return _getPropertyDefault( pEntry );
288 void PropertySetHelper::_getPropertyStates( const utl::PropertyMapEntry** /*ppEntries*/, PropertyState* /*pStates*/ ) throw(UnknownPropertyException )
290 DBG_ERROR( "you have to implement this yourself!" );
293 void PropertySetHelper::_setPropertyToDefault( const utl::PropertyMapEntry* /*pEntry*/ ) throw(UnknownPropertyException )
295 DBG_ERROR( "you have to implement this yourself!" );
298 Any PropertySetHelper::_getPropertyDefault( const utl::PropertyMapEntry* /*pEntry*/ ) throw(UnknownPropertyException, WrappedTargetException )
300 DBG_ERROR( "you have to implement this yourself!" );
302 Any aAny;
303 return aAny;