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 #include <comphelper/ChainablePropertySet.hxx>
27 #include <comphelper/ChainablePropertySetInfo.hxx>
28 #include <vos/mutex.hxx>
29
30 #include <memory> // STL auto_ptr
31
32
33 using namespace ::rtl;
34 using namespace ::comphelper;
35 using namespace ::com::sun::star;
36 using namespace ::com::sun::star::uno;
37 using namespace ::com::sun::star::lang;
38 using namespace ::com::sun::star::beans;
39 using ::vos::IMutex;
40
ChainablePropertySet(comphelper::ChainablePropertySetInfo * pInfo,vos::IMutex * pMutex)41 ChainablePropertySet::ChainablePropertySet( comphelper::ChainablePropertySetInfo* pInfo, vos::IMutex *pMutex )
42 throw()
43 : mpInfo ( pInfo )
44 , mpMutex ( pMutex )
45 , mxInfo ( pInfo )
46 {
47 }
48
~ChainablePropertySet()49 ChainablePropertySet::~ChainablePropertySet()
50 throw()
51 {
52 }
53
54 // XPropertySet
getPropertySetInfo()55 Reference< XPropertySetInfo > SAL_CALL ChainablePropertySet::getPropertySetInfo( )
56 {
57 return mxInfo;
58 }
59
lockMutex()60 void ChainablePropertySet::lockMutex()
61 {
62 if (mpMutex)
63 mpMutex->acquire();
64 }
65
unlockMutex()66 void ChainablePropertySet::unlockMutex()
67 {
68 if (mpMutex)
69 mpMutex->release();
70 }
71
setPropertyValue(const::rtl::OUString & rPropertyName,const Any & rValue)72 void SAL_CALL ChainablePropertySet::setPropertyValue( const ::rtl::OUString& rPropertyName, const Any& rValue )
73 {
74 // acquire mutex in c-tor and releases it in the d-tor (exception safe!).
75 std::auto_ptr< vos::OGuard > pMutexGuard;
76 if (mpMutex)
77 pMutexGuard.reset( new vos::OGuard(mpMutex) );
78
79 PropertyInfoHash::const_iterator aIter = mpInfo->maMap.find ( rPropertyName );
80
81 if( aIter == mpInfo->maMap.end())
82 throw UnknownPropertyException( rPropertyName, static_cast< XPropertySet* >( this ) );
83
84 _preSetValues();
85 _setSingleValue( *((*aIter).second), rValue );
86 _postSetValues();
87 }
88
getPropertyValue(const::rtl::OUString & rPropertyName)89 Any SAL_CALL ChainablePropertySet::getPropertyValue( const ::rtl::OUString& rPropertyName )
90 {
91 // acquire mutex in c-tor and releases it in the d-tor (exception safe!).
92 std::auto_ptr< vos::OGuard > pMutexGuard;
93 if (mpMutex)
94 pMutexGuard.reset( new vos::OGuard(mpMutex) );
95
96 PropertyInfoHash::const_iterator aIter = mpInfo->maMap.find ( rPropertyName );
97
98 if( aIter == mpInfo->maMap.end())
99 throw UnknownPropertyException( rPropertyName, static_cast< XPropertySet* >( this ) );
100
101 Any aAny;
102 _preGetValues ();
103 _getSingleValue( *((*aIter).second), aAny );
104 _postGetValues ();
105
106 return aAny;
107 }
108
addPropertyChangeListener(const::rtl::OUString &,const Reference<XPropertyChangeListener> &)109 void SAL_CALL ChainablePropertySet::addPropertyChangeListener( const ::rtl::OUString&, const Reference< XPropertyChangeListener >& )
110 {
111 // todo
112 }
113
removePropertyChangeListener(const::rtl::OUString &,const Reference<XPropertyChangeListener> &)114 void SAL_CALL ChainablePropertySet::removePropertyChangeListener( const ::rtl::OUString&, const Reference< XPropertyChangeListener >& )
115 {
116 // todo
117 }
118
addVetoableChangeListener(const::rtl::OUString &,const Reference<XVetoableChangeListener> &)119 void SAL_CALL ChainablePropertySet::addVetoableChangeListener( const ::rtl::OUString&, const Reference< XVetoableChangeListener >& )
120 {
121 // todo
122 }
123
removeVetoableChangeListener(const::rtl::OUString &,const Reference<XVetoableChangeListener> &)124 void SAL_CALL ChainablePropertySet::removeVetoableChangeListener( const ::rtl::OUString&, const Reference< XVetoableChangeListener >& )
125 {
126 // todo
127 }
128
129 // XMultiPropertySet
setPropertyValues(const Sequence<::rtl::OUString> & aPropertyNames,const Sequence<Any> & aValues)130 void SAL_CALL ChainablePropertySet::setPropertyValues( const Sequence< ::rtl::OUString >& aPropertyNames, const Sequence< Any >& aValues )
131 {
132 // acquire mutex in c-tor and releases it in the d-tor (exception safe!).
133 std::auto_ptr< vos::OGuard > pMutexGuard;
134 if (mpMutex)
135 pMutexGuard.reset( new vos::OGuard(mpMutex) );
136
137 const sal_Int32 nCount = aPropertyNames.getLength();
138
139 if( nCount != aValues.getLength() )
140 throw IllegalArgumentException();
141
142 if( nCount )
143 {
144 _preSetValues();
145
146 const Any * pAny = aValues.getConstArray();
147 const OUString * pString = aPropertyNames.getConstArray();
148 PropertyInfoHash::const_iterator aEnd = mpInfo->maMap.end(), aIter;
149
150 for ( sal_Int32 i = 0; i < nCount; ++i, ++pString, ++pAny )
151 {
152 aIter = mpInfo->maMap.find ( *pString );
153 if ( aIter == aEnd )
154 throw UnknownPropertyException( *pString, static_cast< XPropertySet* >( this ) );
155
156 _setSingleValue ( *((*aIter).second), *pAny );
157 }
158
159 _postSetValues();
160 }
161 }
162
getPropertyValues(const Sequence<::rtl::OUString> & aPropertyNames)163 Sequence< Any > SAL_CALL ChainablePropertySet::getPropertyValues( const Sequence< ::rtl::OUString >& aPropertyNames )
164 {
165 // acquire mutex in c-tor and releases it in the d-tor (exception safe!).
166 std::auto_ptr< vos::OGuard > pMutexGuard;
167 if (mpMutex)
168 pMutexGuard.reset( new vos::OGuard(mpMutex) );
169
170 const sal_Int32 nCount = aPropertyNames.getLength();
171
172 Sequence < Any > aValues ( nCount );
173
174 if( nCount )
175 {
176 _preGetValues();
177
178 Any * pAny = aValues.getArray();
179 const OUString * pString = aPropertyNames.getConstArray();
180 PropertyInfoHash::const_iterator aEnd = mpInfo->maMap.end(), aIter;
181
182 for ( sal_Int32 i = 0; i < nCount; ++i, ++pString, ++pAny )
183 {
184 aIter = mpInfo->maMap.find ( *pString );
185 if ( aIter == aEnd )
186 throw UnknownPropertyException( *pString, static_cast< XPropertySet* >( this ) );
187
188 _getSingleValue ( *((*aIter).second), *pAny );
189 }
190
191 _postGetValues();
192 }
193 return aValues;
194 }
195
addPropertiesChangeListener(const Sequence<::rtl::OUString> &,const Reference<XPropertiesChangeListener> &)196 void SAL_CALL ChainablePropertySet::addPropertiesChangeListener( const Sequence< ::rtl::OUString >&, const Reference< XPropertiesChangeListener >& )
197 {
198 // todo
199 }
200
removePropertiesChangeListener(const Reference<XPropertiesChangeListener> &)201 void SAL_CALL ChainablePropertySet::removePropertiesChangeListener( const Reference< XPropertiesChangeListener >& )
202 {
203 // todo
204 }
205
firePropertiesChangeEvent(const Sequence<::rtl::OUString> &,const Reference<XPropertiesChangeListener> &)206 void SAL_CALL ChainablePropertySet::firePropertiesChangeEvent( const Sequence< ::rtl::OUString >&, const Reference< XPropertiesChangeListener >& )
207 {
208 // todo
209 }
210
211 // XPropertyState
getPropertyState(const::rtl::OUString & PropertyName)212 PropertyState SAL_CALL ChainablePropertySet::getPropertyState( const ::rtl::OUString& PropertyName )
213 {
214 PropertyInfoHash::const_iterator aIter = mpInfo->maMap.find( PropertyName );
215 if( aIter == mpInfo->maMap.end())
216 throw UnknownPropertyException( PropertyName, static_cast< XPropertySet* >( this ) );
217
218 PropertyState aState;
219
220 _preGetPropertyState();
221 _getPropertyState( *((*aIter).second), aState );
222 _postGetPropertyState();
223
224 return aState;
225 }
226
getPropertyStates(const Sequence<::rtl::OUString> & rPropertyNames)227 Sequence< PropertyState > SAL_CALL ChainablePropertySet::getPropertyStates( const Sequence< ::rtl::OUString >& rPropertyNames )
228 {
229 const sal_Int32 nCount = rPropertyNames.getLength();
230
231 Sequence< PropertyState > aStates( nCount );
232 if( nCount )
233 {
234 PropertyState * pState = aStates.getArray();
235 const OUString * pString = rPropertyNames.getConstArray();
236 PropertyInfoHash::const_iterator aEnd = mpInfo->maMap.end(), aIter;
237 _preGetPropertyState();
238
239 for ( sal_Int32 i = 0; i < nCount; ++i, ++pString, ++pState )
240 {
241 aIter = mpInfo->maMap.find ( *pString );
242 if ( aIter == aEnd )
243 throw UnknownPropertyException( *pString, static_cast< XPropertySet* >( this ) );
244
245 _getPropertyState ( *((*aIter).second), *pState );
246 }
247 _postGetPropertyState();
248 }
249 return aStates;
250 }
251
setPropertyToDefault(const::rtl::OUString & rPropertyName)252 void SAL_CALL ChainablePropertySet::setPropertyToDefault( const ::rtl::OUString& rPropertyName )
253 {
254 PropertyInfoHash::const_iterator aIter = mpInfo->maMap.find ( rPropertyName );
255
256 if( aIter == mpInfo->maMap.end())
257 throw UnknownPropertyException( rPropertyName, static_cast< XPropertySet* >( this ) );
258 _setPropertyToDefault( *((*aIter).second) );
259 }
260
getPropertyDefault(const::rtl::OUString & rPropertyName)261 Any SAL_CALL ChainablePropertySet::getPropertyDefault( const ::rtl::OUString& rPropertyName )
262 {
263 PropertyInfoHash::const_iterator aIter = mpInfo->maMap.find ( rPropertyName );
264
265 if( aIter == mpInfo->maMap.end())
266 throw UnknownPropertyException( rPropertyName, static_cast< XPropertySet* >( this ) );
267 return _getPropertyDefault( *((*aIter).second) );
268 }
269
_preGetPropertyState()270 void ChainablePropertySet::_preGetPropertyState ()
271 {
272 OSL_ENSURE( sal_False, "you have to implement this yourself!");
273 }
274
_getPropertyState(const comphelper::PropertyInfo &,PropertyState &)275 void ChainablePropertySet::_getPropertyState( const comphelper::PropertyInfo&, PropertyState& )
276 {
277 OSL_ENSURE( sal_False, "you have to implement this yourself!");
278 }
279
_postGetPropertyState()280 void ChainablePropertySet::_postGetPropertyState ()
281 {
282 OSL_ENSURE( sal_False, "you have to implement this yourself!");
283 }
284
_setPropertyToDefault(const comphelper::PropertyInfo &)285 void ChainablePropertySet::_setPropertyToDefault( const comphelper::PropertyInfo& )
286 {
287 OSL_ENSURE( sal_False, "you have to implement this yourself!");
288 }
289
_getPropertyDefault(const comphelper::PropertyInfo &)290 Any ChainablePropertySet::_getPropertyDefault( const comphelper::PropertyInfo& )
291 {
292 OSL_ENSURE( sal_False, "you have to implement this yourself!");
293
294 Any aAny;
295 return aAny;
296 }
297