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_unotools.hxx"
26 #include <tools/debug.hxx>
27
28 #include "unotools/propertysetinfo.hxx"
29 #include "unotools/propertysethelper.hxx"
30
31 ///////////////////////////////////////////////////////////////////////
32
33 using namespace ::utl;
34 using namespace ::rtl;
35 using namespace ::com::sun::star;
36 using namespace ::com::sun::star::uno;
37 using namespace ::com::sun::star::beans;
38 using namespace ::com::sun::star::lang;
39
40 namespace utl
41 {
42 class PropertySetHelperImpl
43 {
44 public:
45 PropertyMapEntry* find( const OUString& aName ) const throw();
46
47 PropertySetInfo* mpInfo;
48 };
49 }
50
find(const OUString & aName) const51 PropertyMapEntry* PropertySetHelperImpl::find( const OUString& aName ) const throw()
52 {
53 PropertyMap::const_iterator aIter = mpInfo->getPropertyMap()->find( aName );
54
55 if( mpInfo->getPropertyMap()->end() != aIter )
56 {
57 return (*aIter).second;
58 }
59 else
60 {
61 return NULL;
62 }
63 }
64
65 ///////////////////////////////////////////////////////////////////////
66
PropertySetHelper(utl::PropertySetInfo * pInfo)67 PropertySetHelper::PropertySetHelper( utl::PropertySetInfo* pInfo ) throw()
68 {
69 mp = new PropertySetHelperImpl;
70 mp->mpInfo = pInfo;
71 pInfo->acquire();
72 }
73
~PropertySetHelper()74 PropertySetHelper::~PropertySetHelper() throw()
75 {
76 mp->mpInfo->release();
77 delete mp;
78 }
79
80 // XPropertySet
getPropertySetInfo()81 Reference< XPropertySetInfo > SAL_CALL PropertySetHelper::getPropertySetInfo( ) throw(RuntimeException)
82 {
83 return mp->mpInfo;
84 }
85
setPropertyValue(const::rtl::OUString & aPropertyName,const Any & aValue)86 void SAL_CALL PropertySetHelper::setPropertyValue( const ::rtl::OUString& aPropertyName, const Any& aValue ) throw(UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException)
87 {
88 PropertyMapEntry* aEntries[2];
89 aEntries[0] = mp->find( aPropertyName );
90
91 if( NULL == aEntries[0] )
92 throw UnknownPropertyException();
93
94 aEntries[1] = NULL;
95
96 _setPropertyValues( (const PropertyMapEntry**)aEntries, &aValue );
97 }
98
getPropertyValue(const::rtl::OUString & PropertyName)99 Any SAL_CALL PropertySetHelper::getPropertyValue( const ::rtl::OUString& PropertyName ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
100 {
101 PropertyMapEntry* aEntries[2];
102 aEntries[0] = mp->find( PropertyName );
103
104 if( NULL == aEntries[0] )
105 throw UnknownPropertyException();
106
107 aEntries[1] = NULL;
108
109 Any aAny;
110 _getPropertyValues( (const PropertyMapEntry**)aEntries, &aAny );
111
112 return aAny;
113 }
114
addPropertyChangeListener(const::rtl::OUString &,const Reference<XPropertyChangeListener> &)115 void SAL_CALL PropertySetHelper::addPropertyChangeListener( const ::rtl::OUString& /*aPropertyName*/, const Reference< XPropertyChangeListener >& /*xListener*/ ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
116 {
117 // todo
118 }
119
removePropertyChangeListener(const::rtl::OUString &,const Reference<XPropertyChangeListener> &)120 void SAL_CALL PropertySetHelper::removePropertyChangeListener( const ::rtl::OUString& /*aPropertyName*/, const Reference< XPropertyChangeListener >& /*aListener*/ ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
121 {
122 // todo
123 }
124
addVetoableChangeListener(const::rtl::OUString &,const Reference<XVetoableChangeListener> &)125 void SAL_CALL PropertySetHelper::addVetoableChangeListener( const ::rtl::OUString& /*PropertyName*/, const Reference< XVetoableChangeListener >& /*aListener*/ ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
126 {
127 // todo
128 }
129
removeVetoableChangeListener(const::rtl::OUString &,const Reference<XVetoableChangeListener> &)130 void SAL_CALL PropertySetHelper::removeVetoableChangeListener( const ::rtl::OUString& /*PropertyName*/, const Reference< XVetoableChangeListener >& /*aListener*/ ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
131 {
132 // todo
133 }
134
135 // XMultiPropertySet
setPropertyValues(const Sequence<::rtl::OUString> & aPropertyNames,const Sequence<Any> & aValues)136 void SAL_CALL PropertySetHelper::setPropertyValues( const Sequence< ::rtl::OUString >& aPropertyNames, const Sequence< Any >& aValues ) throw(PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException)
137 {
138 const sal_Int32 nCount = aPropertyNames.getLength();
139
140 if( nCount != aValues.getLength() )
141 throw IllegalArgumentException();
142
143 if( nCount )
144 {
145 PropertyMapEntry** pEntries = new PropertyMapEntry*[nCount+1];
146 const OUString* pNames = aPropertyNames.getConstArray();
147
148 sal_Bool bUnknown = sal_False;
149 sal_Int32 n;
150 for( n = 0; !bUnknown && ( n < nCount ); n++, pNames++ )
151 {
152 pEntries[n] = mp->find( *pNames );
153 bUnknown = NULL == pEntries[n];
154 }
155
156 if( !bUnknown )
157 _setPropertyValues( (const PropertyMapEntry**)pEntries, aValues.getConstArray() );
158
159 delete [] pEntries;
160
161 if( bUnknown )
162 throw UnknownPropertyException();
163 }
164 }
165
getPropertyValues(const Sequence<::rtl::OUString> & aPropertyNames)166 Sequence< Any > SAL_CALL PropertySetHelper::getPropertyValues( const Sequence< ::rtl::OUString >& aPropertyNames ) throw(RuntimeException)
167 {
168 const sal_Int32 nCount = aPropertyNames.getLength();
169
170 Sequence< Any > aValues;
171 if( nCount )
172 {
173 PropertyMapEntry** pEntries = new PropertyMapEntry*[nCount+1];
174 const OUString* pNames = aPropertyNames.getConstArray();
175
176 sal_Bool bUnknown = sal_False;
177 sal_Int32 n;
178 for( n = 0; !bUnknown && ( n < nCount ); n++, pNames++ )
179 {
180 pEntries[n] = mp->find( *pNames );
181 bUnknown = NULL == pEntries[n];
182 }
183
184 if( !bUnknown )
185 _getPropertyValues( (const PropertyMapEntry**)pEntries, aValues.getArray() );
186
187 delete [] pEntries;
188
189 if( bUnknown )
190 throw UnknownPropertyException();
191 }
192
193 return aValues;
194 }
195
addPropertiesChangeListener(const Sequence<::rtl::OUString> &,const Reference<XPropertiesChangeListener> &)196 void SAL_CALL PropertySetHelper::addPropertiesChangeListener( const Sequence< ::rtl::OUString >& /*aPropertyNames*/, const Reference< XPropertiesChangeListener >& /*xListener*/ ) throw(RuntimeException)
197 {
198 // todo
199 }
200
removePropertiesChangeListener(const Reference<XPropertiesChangeListener> &)201 void SAL_CALL PropertySetHelper::removePropertiesChangeListener( const Reference< XPropertiesChangeListener >& /*xListener*/ ) throw(RuntimeException)
202 {
203 // todo
204 }
205
firePropertiesChangeEvent(const Sequence<::rtl::OUString> &,const Reference<XPropertiesChangeListener> &)206 void SAL_CALL PropertySetHelper::firePropertiesChangeEvent( const Sequence< ::rtl::OUString >& /*aPropertyNames*/, const Reference< XPropertiesChangeListener >& /*xListener*/ ) throw(RuntimeException)
207 {
208 // todo
209 }
210
211 // XPropertyState
getPropertyState(const::rtl::OUString & PropertyName)212 PropertyState SAL_CALL PropertySetHelper::getPropertyState( const ::rtl::OUString& PropertyName ) throw(UnknownPropertyException, RuntimeException)
213 {
214 PropertyMapEntry* aEntries[2];
215
216 aEntries[0] = mp->find( PropertyName );
217 if( aEntries[0] == NULL )
218 throw UnknownPropertyException();
219
220 aEntries[1] = NULL;
221
222 PropertyState aState;
223 _getPropertyStates( (const PropertyMapEntry**)aEntries, &aState );
224
225 return aState;
226 }
227
getPropertyStates(const Sequence<::rtl::OUString> & aPropertyName)228 Sequence< PropertyState > SAL_CALL PropertySetHelper::getPropertyStates( const Sequence< ::rtl::OUString >& aPropertyName ) throw(UnknownPropertyException, RuntimeException)
229 {
230 const sal_Int32 nCount = aPropertyName.getLength();
231
232 Sequence< PropertyState > aStates( nCount );
233
234 if( nCount )
235 {
236 const OUString* pNames = aPropertyName.getConstArray();
237
238 sal_Bool bUnknown = sal_False;
239
240 PropertyMapEntry** pEntries = new PropertyMapEntry*[nCount+1];
241
242 sal_Int32 n;
243 for( n = 0; !bUnknown && (n < nCount); n++, pNames++ )
244 {
245 pEntries[n] = mp->find( *pNames );
246 bUnknown = NULL == pEntries[n];
247 }
248
249 pEntries[nCount] = NULL;
250
251 if( !bUnknown )
252 _getPropertyStates( (const PropertyMapEntry**)pEntries, aStates.getArray() );
253
254 delete [] pEntries;
255
256 if( bUnknown )
257 throw UnknownPropertyException();
258 }
259
260 return aStates;
261 }
262
setPropertyToDefault(const::rtl::OUString & PropertyName)263 void SAL_CALL PropertySetHelper::setPropertyToDefault( const ::rtl::OUString& PropertyName ) throw(UnknownPropertyException, RuntimeException)
264 {
265 PropertyMapEntry *pEntry = mp->find( PropertyName );
266 if( NULL == pEntry )
267 throw UnknownPropertyException();
268
269 _setPropertyToDefault( pEntry );
270 }
271
getPropertyDefault(const::rtl::OUString & aPropertyName)272 Any SAL_CALL PropertySetHelper::getPropertyDefault( const ::rtl::OUString& aPropertyName ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
273 {
274 PropertyMapEntry* pEntry = mp->find( aPropertyName );
275 if( NULL == pEntry )
276 throw UnknownPropertyException();
277
278 return _getPropertyDefault( pEntry );
279 }
280
_getPropertyStates(const utl::PropertyMapEntry **,PropertyState *)281 void PropertySetHelper::_getPropertyStates( const utl::PropertyMapEntry** /*ppEntries*/, PropertyState* /*pStates*/ ) throw(UnknownPropertyException )
282 {
283 DBG_ERROR( "you have to implement this yourself!" );
284 }
285
_setPropertyToDefault(const utl::PropertyMapEntry *)286 void PropertySetHelper::_setPropertyToDefault( const utl::PropertyMapEntry* /*pEntry*/ ) throw(UnknownPropertyException )
287 {
288 DBG_ERROR( "you have to implement this yourself!" );
289 }
290
_getPropertyDefault(const utl::PropertyMapEntry *)291 Any PropertySetHelper::_getPropertyDefault( const utl::PropertyMapEntry* /*pEntry*/ ) throw(UnknownPropertyException, WrappedTargetException )
292 {
293 DBG_ERROR( "you have to implement this yourself!" );
294
295 Any aAny;
296 return aAny;
297 }
298