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