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