xref: /AOO41X/main/comphelper/source/property/propertysethelper.cxx (revision dde7d3faf6dcd9cbeb7b48ba6d0cea5ffcc883d0)
1*dde7d3faSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*dde7d3faSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*dde7d3faSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*dde7d3faSAndrew Rist  * distributed with this work for additional information
6*dde7d3faSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*dde7d3faSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*dde7d3faSAndrew Rist  * "License"); you may not use this file except in compliance
9*dde7d3faSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*dde7d3faSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*dde7d3faSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*dde7d3faSAndrew Rist  * software distributed under the License is distributed on an
15*dde7d3faSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*dde7d3faSAndrew Rist  * KIND, either express or implied.  See the License for the
17*dde7d3faSAndrew Rist  * specific language governing permissions and limitations
18*dde7d3faSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*dde7d3faSAndrew Rist  *************************************************************/
21*dde7d3faSAndrew Rist 
22*dde7d3faSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_comphelper.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "comphelper/propertysetinfo.hxx"
28cdf0e10cSrcweir #include "comphelper/propertysethelper.hxx"
29cdf0e10cSrcweir 
30cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////
31cdf0e10cSrcweir 
32cdf0e10cSrcweir using namespace ::rtl;
33cdf0e10cSrcweir using namespace ::comphelper;
34cdf0e10cSrcweir using namespace ::com::sun::star;
35cdf0e10cSrcweir using namespace ::com::sun::star::uno;
36cdf0e10cSrcweir using namespace ::com::sun::star::beans;
37cdf0e10cSrcweir using namespace ::com::sun::star::lang;
38cdf0e10cSrcweir 
39cdf0e10cSrcweir namespace comphelper
40cdf0e10cSrcweir {
41cdf0e10cSrcweir class PropertySetHelperImpl
42cdf0e10cSrcweir {
43cdf0e10cSrcweir public:
44cdf0e10cSrcweir 	PropertyMapEntry* find( const OUString& aName ) const throw();
45cdf0e10cSrcweir 
46cdf0e10cSrcweir 	PropertySetInfo* mpInfo;
47cdf0e10cSrcweir };
48cdf0e10cSrcweir }
49cdf0e10cSrcweir 
find(const OUString & aName) const50cdf0e10cSrcweir PropertyMapEntry* PropertySetHelperImpl::find( const OUString& aName ) const throw()
51cdf0e10cSrcweir {
52cdf0e10cSrcweir 	PropertyMap::const_iterator aIter = mpInfo->getPropertyMap()->find( aName );
53cdf0e10cSrcweir 
54cdf0e10cSrcweir 	if( mpInfo->getPropertyMap()->end() != aIter )
55cdf0e10cSrcweir 	{
56cdf0e10cSrcweir 		return (*aIter).second;
57cdf0e10cSrcweir 	}
58cdf0e10cSrcweir 	else
59cdf0e10cSrcweir 	{
60cdf0e10cSrcweir 		return NULL;
61cdf0e10cSrcweir 	}
62cdf0e10cSrcweir }
63cdf0e10cSrcweir 
64cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////
65cdf0e10cSrcweir 
PropertySetHelper()66cdf0e10cSrcweir PropertySetHelper::PropertySetHelper( )
67cdf0e10cSrcweir {
68cdf0e10cSrcweir     mp = new PropertySetHelperImpl;
69cdf0e10cSrcweir     mp->mpInfo = new PropertySetInfo;
70cdf0e10cSrcweir     mp->mpInfo->acquire();
71cdf0e10cSrcweir }
72cdf0e10cSrcweir 
PropertySetHelper(comphelper::PropertySetInfo * pInfo)73cdf0e10cSrcweir PropertySetHelper::PropertySetHelper( comphelper::PropertySetInfo* pInfo ) throw()
74cdf0e10cSrcweir {
75cdf0e10cSrcweir 	mp = new PropertySetHelperImpl;
76cdf0e10cSrcweir 	mp->mpInfo = pInfo;
77cdf0e10cSrcweir 	pInfo->acquire();
78cdf0e10cSrcweir }
79cdf0e10cSrcweir 
PropertySetHelper(comphelper::PropertySetInfo * pInfo,__sal_NoAcquire)80cdf0e10cSrcweir PropertySetHelper::PropertySetHelper( comphelper::PropertySetInfo* pInfo, __sal_NoAcquire ) throw()
81cdf0e10cSrcweir {
82cdf0e10cSrcweir 	mp = new PropertySetHelperImpl;
83cdf0e10cSrcweir 	mp->mpInfo = pInfo;
84cdf0e10cSrcweir }
85cdf0e10cSrcweir 
~PropertySetHelper()86cdf0e10cSrcweir PropertySetHelper::~PropertySetHelper() throw()
87cdf0e10cSrcweir {
88cdf0e10cSrcweir 	mp->mpInfo->release();
89cdf0e10cSrcweir 	delete mp;
90cdf0e10cSrcweir }
91cdf0e10cSrcweir 
setInfo(comphelper::PropertySetInfo * pInfo)92cdf0e10cSrcweir void PropertySetHelper::setInfo( comphelper::PropertySetInfo* pInfo ) throw()
93cdf0e10cSrcweir {
94cdf0e10cSrcweir     OSL_ENSURE( pInfo != NULL, "need pInfo" );
95cdf0e10cSrcweir     OSL_ENSURE( mp->mpInfo != NULL, "where's the old pInfo?" );
96cdf0e10cSrcweir 
97cdf0e10cSrcweir     mp->mpInfo->release();
98cdf0e10cSrcweir     mp->mpInfo = pInfo;
99cdf0e10cSrcweir     mp->mpInfo->acquire();
100cdf0e10cSrcweir }
101cdf0e10cSrcweir 
102cdf0e10cSrcweir // XPropertySet
getPropertySetInfo()103cdf0e10cSrcweir Reference< XPropertySetInfo > SAL_CALL PropertySetHelper::getPropertySetInfo(  ) throw(RuntimeException)
104cdf0e10cSrcweir {
105cdf0e10cSrcweir 	return mp->mpInfo;
106cdf0e10cSrcweir }
107cdf0e10cSrcweir 
setPropertyValue(const::rtl::OUString & aPropertyName,const Any & aValue)108cdf0e10cSrcweir void SAL_CALL PropertySetHelper::setPropertyValue( const ::rtl::OUString& aPropertyName, const Any& aValue ) throw(UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException)
109cdf0e10cSrcweir {
110cdf0e10cSrcweir 	PropertyMapEntry* aEntries[2];
111cdf0e10cSrcweir 	aEntries[0] = mp->find( aPropertyName );
112cdf0e10cSrcweir 
113cdf0e10cSrcweir 	if( NULL == aEntries[0] )
114cdf0e10cSrcweir 		throw UnknownPropertyException( aPropertyName, static_cast< XPropertySet* >( this ) );
115cdf0e10cSrcweir 
116cdf0e10cSrcweir 	aEntries[1] = NULL;
117cdf0e10cSrcweir 
118cdf0e10cSrcweir 	_setPropertyValues( (const PropertyMapEntry**)aEntries, &aValue );
119cdf0e10cSrcweir }
120cdf0e10cSrcweir 
getPropertyValue(const::rtl::OUString & PropertyName)121cdf0e10cSrcweir Any SAL_CALL PropertySetHelper::getPropertyValue( const ::rtl::OUString& PropertyName ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
122cdf0e10cSrcweir {
123cdf0e10cSrcweir 	PropertyMapEntry* aEntries[2];
124cdf0e10cSrcweir 	aEntries[0] = mp->find( PropertyName );
125cdf0e10cSrcweir 
126cdf0e10cSrcweir 	if( NULL == aEntries[0] )
127cdf0e10cSrcweir 		throw UnknownPropertyException( PropertyName, static_cast< XPropertySet* >( this ) );
128cdf0e10cSrcweir 
129cdf0e10cSrcweir 	aEntries[1] = NULL;
130cdf0e10cSrcweir 
131cdf0e10cSrcweir 	Any aAny;
132cdf0e10cSrcweir 	_getPropertyValues( (const PropertyMapEntry**)aEntries, &aAny );
133cdf0e10cSrcweir 
134cdf0e10cSrcweir 	return aAny;
135cdf0e10cSrcweir }
136cdf0e10cSrcweir 
addPropertyChangeListener(const::rtl::OUString &,const Reference<XPropertyChangeListener> &)137cdf0e10cSrcweir void SAL_CALL PropertySetHelper::addPropertyChangeListener( const ::rtl::OUString&, const Reference< XPropertyChangeListener >& ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
138cdf0e10cSrcweir {
139cdf0e10cSrcweir 	// todo
140cdf0e10cSrcweir }
141cdf0e10cSrcweir 
removePropertyChangeListener(const::rtl::OUString &,const Reference<XPropertyChangeListener> &)142cdf0e10cSrcweir void SAL_CALL PropertySetHelper::removePropertyChangeListener( const ::rtl::OUString&, const Reference< XPropertyChangeListener >& ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
143cdf0e10cSrcweir {
144cdf0e10cSrcweir 	// todo
145cdf0e10cSrcweir }
146cdf0e10cSrcweir 
addVetoableChangeListener(const::rtl::OUString &,const Reference<XVetoableChangeListener> &)147cdf0e10cSrcweir void SAL_CALL PropertySetHelper::addVetoableChangeListener( const ::rtl::OUString&, const Reference< XVetoableChangeListener >& ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
148cdf0e10cSrcweir {
149cdf0e10cSrcweir 	// todo
150cdf0e10cSrcweir }
151cdf0e10cSrcweir 
removeVetoableChangeListener(const::rtl::OUString &,const Reference<XVetoableChangeListener> &)152cdf0e10cSrcweir void SAL_CALL PropertySetHelper::removeVetoableChangeListener( const ::rtl::OUString&, const Reference< XVetoableChangeListener >& ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
153cdf0e10cSrcweir {
154cdf0e10cSrcweir 	// todo
155cdf0e10cSrcweir }
156cdf0e10cSrcweir 
157cdf0e10cSrcweir // XMultiPropertySet
setPropertyValues(const Sequence<::rtl::OUString> & aPropertyNames,const Sequence<Any> & aValues)158cdf0e10cSrcweir void SAL_CALL PropertySetHelper::setPropertyValues( const Sequence< ::rtl::OUString >& aPropertyNames, const Sequence< Any >& aValues ) throw(PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException)
159cdf0e10cSrcweir {
160cdf0e10cSrcweir 	const sal_Int32 nCount = aPropertyNames.getLength();
161cdf0e10cSrcweir 
162cdf0e10cSrcweir 	if( nCount != aValues.getLength() )
163cdf0e10cSrcweir 		throw IllegalArgumentException();
164cdf0e10cSrcweir 
165cdf0e10cSrcweir 	if( nCount )
166cdf0e10cSrcweir 	{
167cdf0e10cSrcweir 		PropertyMapEntry** pEntries = new PropertyMapEntry*[nCount+1];
168cdf0e10cSrcweir 		pEntries[nCount] = NULL;
169cdf0e10cSrcweir 		const OUString* pNames = aPropertyNames.getConstArray();
170cdf0e10cSrcweir 
171cdf0e10cSrcweir 		sal_Bool bUnknown = sal_False;
172cdf0e10cSrcweir 		sal_Int32 n;
173cdf0e10cSrcweir 		for( n = 0; !bUnknown && ( n < nCount ); n++, pNames++ )
174cdf0e10cSrcweir 		{
175cdf0e10cSrcweir 			pEntries[n] = mp->find( *pNames );
176cdf0e10cSrcweir 			bUnknown = NULL == pEntries[n];
177cdf0e10cSrcweir 		}
178cdf0e10cSrcweir 
179cdf0e10cSrcweir 		if( !bUnknown )
180cdf0e10cSrcweir 			_setPropertyValues( (const PropertyMapEntry**)pEntries, aValues.getConstArray() );
181cdf0e10cSrcweir 
182cdf0e10cSrcweir 		delete[] pEntries;
183cdf0e10cSrcweir 
184cdf0e10cSrcweir 		if( bUnknown )
185cdf0e10cSrcweir 			throw UnknownPropertyException( *pNames, static_cast< XPropertySet* >( this ) );
186cdf0e10cSrcweir 	}
187cdf0e10cSrcweir }
188cdf0e10cSrcweir 
getPropertyValues(const Sequence<::rtl::OUString> & aPropertyNames)189cdf0e10cSrcweir Sequence< Any > SAL_CALL PropertySetHelper::getPropertyValues( const Sequence< ::rtl::OUString >& aPropertyNames ) throw(RuntimeException)
190cdf0e10cSrcweir {
191cdf0e10cSrcweir 	const sal_Int32 nCount = aPropertyNames.getLength();
192cdf0e10cSrcweir 
193cdf0e10cSrcweir 	Sequence< Any > aValues;
194cdf0e10cSrcweir 	if( nCount )
195cdf0e10cSrcweir 	{
196cdf0e10cSrcweir 		PropertyMapEntry** pEntries = new PropertyMapEntry*[nCount+1];
197cdf0e10cSrcweir         pEntries[nCount] = NULL;
198cdf0e10cSrcweir 		const OUString* pNames = aPropertyNames.getConstArray();
199cdf0e10cSrcweir 
200cdf0e10cSrcweir 		sal_Bool bUnknown = sal_False;
201cdf0e10cSrcweir 		sal_Int32 n;
202cdf0e10cSrcweir 		for( n = 0; !bUnknown && ( n < nCount ); n++, pNames++ )
203cdf0e10cSrcweir 		{
204cdf0e10cSrcweir 			pEntries[n] = mp->find( *pNames );
205cdf0e10cSrcweir 			bUnknown = NULL == pEntries[n];
206cdf0e10cSrcweir 		}
207cdf0e10cSrcweir 
208cdf0e10cSrcweir 		if( !bUnknown )
209cdf0e10cSrcweir         {
210cdf0e10cSrcweir             aValues.realloc(nCount);
211cdf0e10cSrcweir 			_getPropertyValues( (const PropertyMapEntry**)pEntries, aValues.getArray() );
212cdf0e10cSrcweir         }
213cdf0e10cSrcweir 
214cdf0e10cSrcweir 		delete[] pEntries;
215cdf0e10cSrcweir 
216cdf0e10cSrcweir 		if( bUnknown )
217cdf0e10cSrcweir 			throw UnknownPropertyException( *pNames, static_cast< XPropertySet* >( this ) );
218cdf0e10cSrcweir 	}
219cdf0e10cSrcweir 
220cdf0e10cSrcweir 	return aValues;
221cdf0e10cSrcweir }
222cdf0e10cSrcweir 
addPropertiesChangeListener(const Sequence<::rtl::OUString> &,const Reference<XPropertiesChangeListener> &)223cdf0e10cSrcweir void SAL_CALL PropertySetHelper::addPropertiesChangeListener( const Sequence< ::rtl::OUString >&, const Reference< XPropertiesChangeListener >& ) throw(RuntimeException)
224cdf0e10cSrcweir {
225cdf0e10cSrcweir 	// todo
226cdf0e10cSrcweir }
227cdf0e10cSrcweir 
removePropertiesChangeListener(const Reference<XPropertiesChangeListener> &)228cdf0e10cSrcweir void SAL_CALL PropertySetHelper::removePropertiesChangeListener( const Reference< XPropertiesChangeListener >& ) throw(RuntimeException)
229cdf0e10cSrcweir {
230cdf0e10cSrcweir 	// todo
231cdf0e10cSrcweir }
232cdf0e10cSrcweir 
firePropertiesChangeEvent(const Sequence<::rtl::OUString> &,const Reference<XPropertiesChangeListener> &)233cdf0e10cSrcweir void SAL_CALL PropertySetHelper::firePropertiesChangeEvent( const Sequence< ::rtl::OUString >&, const Reference< XPropertiesChangeListener >& ) throw(RuntimeException)
234cdf0e10cSrcweir {
235cdf0e10cSrcweir 	// todo
236cdf0e10cSrcweir }
237cdf0e10cSrcweir 
238cdf0e10cSrcweir // XPropertyState
getPropertyState(const::rtl::OUString & PropertyName)239cdf0e10cSrcweir PropertyState SAL_CALL PropertySetHelper::getPropertyState( const ::rtl::OUString& PropertyName ) throw(UnknownPropertyException, RuntimeException)
240cdf0e10cSrcweir {
241cdf0e10cSrcweir 	PropertyMapEntry* aEntries[2];
242cdf0e10cSrcweir 
243cdf0e10cSrcweir 	aEntries[0] = mp->find( PropertyName );
244cdf0e10cSrcweir 	if( aEntries[0] == NULL )
245cdf0e10cSrcweir 		throw UnknownPropertyException( PropertyName, static_cast< XPropertySet* >( this ) );
246cdf0e10cSrcweir 
247cdf0e10cSrcweir 	aEntries[1] = NULL;
248cdf0e10cSrcweir 
249cdf0e10cSrcweir 	PropertyState aState;
250cdf0e10cSrcweir 	_getPropertyStates( (const PropertyMapEntry**)aEntries, &aState );
251cdf0e10cSrcweir 
252cdf0e10cSrcweir 	return aState;
253cdf0e10cSrcweir }
254cdf0e10cSrcweir 
getPropertyStates(const Sequence<::rtl::OUString> & aPropertyName)255cdf0e10cSrcweir Sequence< PropertyState > SAL_CALL PropertySetHelper::getPropertyStates( const Sequence< ::rtl::OUString >& aPropertyName ) throw(UnknownPropertyException, RuntimeException)
256cdf0e10cSrcweir {
257cdf0e10cSrcweir 	const sal_Int32 nCount = aPropertyName.getLength();
258cdf0e10cSrcweir 
259cdf0e10cSrcweir 	Sequence< PropertyState > aStates( nCount );
260cdf0e10cSrcweir 
261cdf0e10cSrcweir 	if( nCount )
262cdf0e10cSrcweir 	{
263cdf0e10cSrcweir 		const OUString* pNames = aPropertyName.getConstArray();
264cdf0e10cSrcweir 
265cdf0e10cSrcweir 		sal_Bool bUnknown = sal_False;
266cdf0e10cSrcweir 
267cdf0e10cSrcweir 		PropertyMapEntry** pEntries = new PropertyMapEntry*[nCount+1];
268cdf0e10cSrcweir 
269cdf0e10cSrcweir 		sal_Int32 n;
270cdf0e10cSrcweir 		for( n = 0; !bUnknown && (n < nCount); n++, pNames++ )
271cdf0e10cSrcweir 		{
272cdf0e10cSrcweir 			pEntries[n] = mp->find( *pNames );
273cdf0e10cSrcweir 			bUnknown = NULL == pEntries[n];
274cdf0e10cSrcweir 		}
275cdf0e10cSrcweir 
276cdf0e10cSrcweir 		pEntries[nCount] = NULL;
277cdf0e10cSrcweir 
278cdf0e10cSrcweir 		if( !bUnknown )
279cdf0e10cSrcweir 			_getPropertyStates( (const PropertyMapEntry**)pEntries, aStates.getArray() );
280cdf0e10cSrcweir 
281cdf0e10cSrcweir 		delete[] pEntries;
282cdf0e10cSrcweir 
283cdf0e10cSrcweir 		if( bUnknown )
284cdf0e10cSrcweir 			throw UnknownPropertyException( *pNames, static_cast< XPropertySet* >( this ) );
285cdf0e10cSrcweir 	}
286cdf0e10cSrcweir 
287cdf0e10cSrcweir 	return aStates;
288cdf0e10cSrcweir }
289cdf0e10cSrcweir 
setPropertyToDefault(const::rtl::OUString & PropertyName)290cdf0e10cSrcweir void SAL_CALL PropertySetHelper::setPropertyToDefault( const ::rtl::OUString& PropertyName ) throw(UnknownPropertyException, RuntimeException)
291cdf0e10cSrcweir {
292cdf0e10cSrcweir 	PropertyMapEntry *pEntry  = mp->find( PropertyName );
293cdf0e10cSrcweir 	if( NULL == pEntry )
294cdf0e10cSrcweir 		throw UnknownPropertyException( PropertyName, static_cast< XPropertySet* >( this ) );
295cdf0e10cSrcweir 
296cdf0e10cSrcweir 	_setPropertyToDefault( pEntry );
297cdf0e10cSrcweir }
298cdf0e10cSrcweir 
getPropertyDefault(const::rtl::OUString & aPropertyName)299cdf0e10cSrcweir Any SAL_CALL PropertySetHelper::getPropertyDefault( const ::rtl::OUString& aPropertyName ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
300cdf0e10cSrcweir {
301cdf0e10cSrcweir 	PropertyMapEntry* pEntry = mp->find( aPropertyName );
302cdf0e10cSrcweir 	if( NULL == pEntry )
303cdf0e10cSrcweir 		throw UnknownPropertyException( aPropertyName, static_cast< XPropertySet* >( this ) );
304cdf0e10cSrcweir 
305cdf0e10cSrcweir 	return _getPropertyDefault( pEntry );
306cdf0e10cSrcweir }
307cdf0e10cSrcweir 
_getPropertyStates(const comphelper::PropertyMapEntry **,PropertyState *)308cdf0e10cSrcweir void PropertySetHelper::_getPropertyStates( const comphelper::PropertyMapEntry**, PropertyState* ) throw(UnknownPropertyException )
309cdf0e10cSrcweir {
310cdf0e10cSrcweir 	OSL_ENSURE( sal_False, "you have to implement this yourself!");
311cdf0e10cSrcweir }
312cdf0e10cSrcweir 
_setPropertyToDefault(const comphelper::PropertyMapEntry *)313cdf0e10cSrcweir void PropertySetHelper::_setPropertyToDefault( const comphelper::PropertyMapEntry* )  throw(UnknownPropertyException )
314cdf0e10cSrcweir {
315cdf0e10cSrcweir 	OSL_ENSURE( sal_False, "you have to implement this yourself!");
316cdf0e10cSrcweir }
317cdf0e10cSrcweir 
_getPropertyDefault(const comphelper::PropertyMapEntry *)318cdf0e10cSrcweir Any PropertySetHelper::_getPropertyDefault( const comphelper::PropertyMapEntry* ) throw(UnknownPropertyException, WrappedTargetException )
319cdf0e10cSrcweir {
320cdf0e10cSrcweir 	OSL_ENSURE( sal_False, "you have to implement this yourself!");
321cdf0e10cSrcweir 
322cdf0e10cSrcweir 	Any aAny;
323cdf0e10cSrcweir 	return aAny;
324cdf0e10cSrcweir }
325