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