bump product version to 5.0.4.1
[LibreOffice.git] / comphelper / source / property / propertysethelper.cxx
blob9c522c7216146b4d1c236eaa517907c658508a86
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <comphelper/propertysetinfo.hxx>
21 #include <comphelper/propertysethelper.hxx>
22 #include <osl/diagnose.h>
24 #include <boost/scoped_array.hpp>
26 using namespace ::comphelper;
27 using namespace ::com::sun::star;
28 using namespace ::com::sun::star::uno;
29 using namespace ::com::sun::star::beans;
30 using namespace ::com::sun::star::lang;
32 namespace comphelper
34 class PropertySetHelperImpl
36 public:
37 PropertyMapEntry const * find( const OUString& aName ) const throw();
39 PropertySetInfo* mpInfo;
43 PropertyMapEntry const * PropertySetHelperImpl::find( const OUString& aName ) const throw()
45 PropertyMap::const_iterator aIter = mpInfo->getPropertyMap().find( aName );
47 if( mpInfo->getPropertyMap().end() != aIter )
49 return (*aIter).second;
51 else
53 return NULL;
59 PropertySetHelper::PropertySetHelper( comphelper::PropertySetInfo* pInfo ) throw()
61 mp = new PropertySetHelperImpl;
62 mp->mpInfo = pInfo;
63 pInfo->acquire();
66 PropertySetHelper::PropertySetHelper( comphelper::PropertySetInfo* pInfo, __sal_NoAcquire ) throw()
68 mp = new PropertySetHelperImpl;
69 mp->mpInfo = pInfo;
72 PropertySetHelper::~PropertySetHelper() throw()
74 mp->mpInfo->release();
75 delete mp;
78 // XPropertySet
79 Reference< XPropertySetInfo > SAL_CALL PropertySetHelper::getPropertySetInfo( ) throw(RuntimeException, std::exception)
81 return mp->mpInfo;
84 void SAL_CALL PropertySetHelper::setPropertyValue( const OUString& aPropertyName, const Any& aValue ) throw(UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException, std::exception)
86 PropertyMapEntry const * aEntries[2];
87 aEntries[0] = mp->find( aPropertyName );
89 if( NULL == aEntries[0] )
90 throw UnknownPropertyException( aPropertyName, static_cast< XPropertySet* >( this ) );
92 aEntries[1] = NULL;
94 _setPropertyValues( (const PropertyMapEntry**)aEntries, &aValue );
97 Any SAL_CALL PropertySetHelper::getPropertyValue( const OUString& PropertyName ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception)
99 PropertyMapEntry const * aEntries[2];
100 aEntries[0] = mp->find( PropertyName );
102 if( NULL == aEntries[0] )
103 throw UnknownPropertyException( PropertyName, static_cast< XPropertySet* >( this ) );
105 aEntries[1] = NULL;
107 Any aAny;
108 _getPropertyValues( (const PropertyMapEntry**)aEntries, &aAny );
110 return aAny;
113 void SAL_CALL PropertySetHelper::addPropertyChangeListener( const OUString&, const Reference< XPropertyChangeListener >& ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception)
115 // todo
118 void SAL_CALL PropertySetHelper::removePropertyChangeListener( const OUString&, const Reference< XPropertyChangeListener >& ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception)
120 // todo
123 void SAL_CALL PropertySetHelper::addVetoableChangeListener( const OUString&, const Reference< XVetoableChangeListener >& ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception)
125 // todo
128 void SAL_CALL PropertySetHelper::removeVetoableChangeListener( const OUString&, const Reference< XVetoableChangeListener >& ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception)
130 // todo
133 // XMultiPropertySet
134 void SAL_CALL PropertySetHelper::setPropertyValues( const Sequence< OUString >& rPropertyNames, const Sequence< Any >& rValues )
135 throw (PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException, std::exception)
137 const sal_Int32 nCount = rPropertyNames.getLength();
139 if( nCount != rValues.getLength() )
140 throw IllegalArgumentException();
142 if( nCount )
144 boost::scoped_array<PropertyMapEntry const *> pEntries(new PropertyMapEntry const *[nCount+1]);
145 pEntries[nCount] = NULL;
146 const OUString* pNames = rPropertyNames.getConstArray();
148 bool bUnknown = false;
149 sal_Int32 n;
150 for( n = 0; !bUnknown && ( n < nCount ); n++, pNames++ )
152 pEntries[n] = mp->find( *pNames );
153 bUnknown = NULL == pEntries[n];
156 if( !bUnknown )
157 _setPropertyValues( (const PropertyMapEntry**)pEntries.get(), rValues.getConstArray() );
159 if( bUnknown )
160 throw RuntimeException( *pNames, static_cast< XPropertySet* >( this ) );
164 Sequence< Any > SAL_CALL PropertySetHelper::getPropertyValues(const Sequence< OUString >& rPropertyNames)
165 throw (RuntimeException, std::exception)
167 const sal_Int32 nCount = rPropertyNames.getLength();
169 Sequence< Any > aValues;
170 if( nCount )
172 boost::scoped_array<PropertyMapEntry const *> pEntries(new PropertyMapEntry const *[nCount+1]);
173 pEntries[nCount] = NULL;
174 const OUString* pNames = rPropertyNames.getConstArray();
176 bool bUnknown = false;
177 sal_Int32 n;
178 for( n = 0; !bUnknown && ( n < nCount ); n++, pNames++ )
180 pEntries[n] = mp->find( *pNames );
181 bUnknown = NULL == pEntries[n];
184 if( !bUnknown )
186 aValues.realloc(nCount);
187 _getPropertyValues( (const PropertyMapEntry**)pEntries.get(), aValues.getArray() );
190 if( bUnknown )
191 throw RuntimeException( *pNames, static_cast< XPropertySet* >( this ) );
194 return aValues;
197 void SAL_CALL PropertySetHelper::addPropertiesChangeListener( const Sequence< OUString >&, const Reference< XPropertiesChangeListener >& ) throw(RuntimeException, std::exception)
199 // todo
202 void SAL_CALL PropertySetHelper::removePropertiesChangeListener( const Reference< XPropertiesChangeListener >& ) throw(RuntimeException, std::exception)
204 // todo
207 void SAL_CALL PropertySetHelper::firePropertiesChangeEvent( const Sequence< OUString >&, const Reference< XPropertiesChangeListener >& ) throw(RuntimeException, std::exception)
209 // todo
212 // XPropertyState
213 PropertyState SAL_CALL PropertySetHelper::getPropertyState( const OUString& PropertyName ) throw(UnknownPropertyException, RuntimeException, std::exception)
215 PropertyMapEntry const * aEntries[2];
217 aEntries[0] = mp->find( PropertyName );
218 if( aEntries[0] == NULL )
219 throw UnknownPropertyException( PropertyName, static_cast< XPropertySet* >( this ) );
221 aEntries[1] = NULL;
223 PropertyState aState(PropertyState_AMBIGUOUS_VALUE);
224 _getPropertyStates( (const PropertyMapEntry**)aEntries, &aState );
226 return aState;
229 Sequence< PropertyState > SAL_CALL PropertySetHelper::getPropertyStates( const Sequence< OUString >& aPropertyName ) throw(UnknownPropertyException, RuntimeException, std::exception)
231 const sal_Int32 nCount = aPropertyName.getLength();
233 Sequence< PropertyState > aStates( nCount );
235 if( nCount )
237 const OUString* pNames = aPropertyName.getConstArray();
239 bool bUnknown = false;
241 boost::scoped_array<PropertyMapEntry const *> pEntries(new PropertyMapEntry const *[nCount+1]);
243 sal_Int32 n;
244 for( n = 0; !bUnknown && (n < nCount); n++, pNames++ )
246 pEntries[n] = mp->find( *pNames );
247 bUnknown = NULL == pEntries[n];
250 pEntries[nCount] = NULL;
252 if( !bUnknown )
253 _getPropertyStates( (const PropertyMapEntry**)pEntries.get(), aStates.getArray() );
255 if( bUnknown )
256 throw UnknownPropertyException( *pNames, static_cast< XPropertySet* >( this ) );
259 return aStates;
262 void SAL_CALL PropertySetHelper::setPropertyToDefault( const OUString& PropertyName ) throw(UnknownPropertyException, RuntimeException, std::exception)
264 PropertyMapEntry const *pEntry = mp->find( PropertyName );
265 if( NULL == pEntry )
266 throw UnknownPropertyException( PropertyName, static_cast< XPropertySet* >( this ) );
268 _setPropertyToDefault( pEntry );
271 Any SAL_CALL PropertySetHelper::getPropertyDefault( const OUString& aPropertyName ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception)
273 PropertyMapEntry const * pEntry = mp->find( aPropertyName );
274 if( NULL == pEntry )
275 throw UnknownPropertyException( aPropertyName, static_cast< XPropertySet* >( this ) );
277 return _getPropertyDefault( pEntry );
280 void PropertySetHelper::_getPropertyStates(
281 const comphelper::PropertyMapEntry**, PropertyState*)
282 throw (UnknownPropertyException, RuntimeException)
284 OSL_FAIL( "you have to implement this yourself!");
287 void
288 PropertySetHelper::_setPropertyToDefault(const comphelper::PropertyMapEntry*)
289 throw (UnknownPropertyException, RuntimeException)
291 OSL_FAIL( "you have to implement this yourself!");
294 Any PropertySetHelper::_getPropertyDefault(const comphelper::PropertyMapEntry*)
295 throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
297 OSL_FAIL( "you have to implement this yourself!");
299 Any aAny;
300 return aAny;
303 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */