Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <comphelper/ChainablePropertySet.hxx>
21 : #include <comphelper/ChainablePropertySetInfo.hxx>
22 : #include <comphelper/solarmutex.hxx>
23 :
24 : #include <osl/diagnose.h>
25 :
26 : #include <memory>
27 :
28 : using namespace ::comphelper;
29 : using namespace ::com::sun::star;
30 : using namespace ::com::sun::star::uno;
31 : using namespace ::com::sun::star::lang;
32 : using namespace ::com::sun::star::beans;
33 :
34 5856 : ChainablePropertySet::ChainablePropertySet( comphelper::ChainablePropertySetInfo* pInfo, comphelper::SolarMutex* pMutex )
35 : throw()
36 : : mpInfo ( pInfo )
37 : , mpMutex ( pMutex )
38 5856 : , mxInfo ( pInfo )
39 : {
40 5856 : }
41 :
42 5856 : ChainablePropertySet::~ChainablePropertySet()
43 5856 : throw()
44 : {
45 5856 : }
46 :
47 : // XPropertySet
48 84 : Reference< XPropertySetInfo > SAL_CALL ChainablePropertySet::getPropertySetInfo( )
49 : throw(RuntimeException, std::exception)
50 : {
51 84 : return mxInfo;
52 : }
53 :
54 127 : void SAL_CALL ChainablePropertySet::setPropertyValue( const OUString& rPropertyName, const Any& rValue )
55 : throw(UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException, std::exception)
56 : {
57 : // acquire mutex in c-tor and releases it in the d-tor (exception safe!).
58 127 : std::unique_ptr< osl::Guard< comphelper::SolarMutex > > xMutexGuard;
59 127 : if (mpMutex)
60 127 : xMutexGuard.reset( new osl::Guard< comphelper::SolarMutex >(mpMutex) );
61 :
62 127 : PropertyInfoHash::const_iterator aIter = mpInfo->maMap.find ( rPropertyName );
63 :
64 127 : if( aIter == mpInfo->maMap.end())
65 0 : throw UnknownPropertyException( rPropertyName, static_cast< XPropertySet* >( this ) );
66 :
67 127 : _preSetValues();
68 127 : _setSingleValue( *((*aIter).second), rValue );
69 127 : _postSetValues();
70 126 : }
71 :
72 275 : Any SAL_CALL ChainablePropertySet::getPropertyValue( const OUString& rPropertyName )
73 : throw(UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception)
74 : {
75 : // acquire mutex in c-tor and releases it in the d-tor (exception safe!).
76 275 : std::unique_ptr< osl::Guard< comphelper::SolarMutex > > xMutexGuard;
77 275 : if (mpMutex)
78 275 : xMutexGuard.reset( new osl::Guard< comphelper::SolarMutex >(mpMutex) );
79 :
80 275 : PropertyInfoHash::const_iterator aIter = mpInfo->maMap.find ( rPropertyName );
81 :
82 275 : if( aIter == mpInfo->maMap.end())
83 0 : throw UnknownPropertyException( rPropertyName, static_cast< XPropertySet* >( this ) );
84 :
85 275 : Any aAny;
86 275 : _preGetValues ();
87 275 : _getSingleValue( *((*aIter).second), aAny );
88 275 : _postGetValues ();
89 :
90 275 : return aAny;
91 : }
92 :
93 0 : void SAL_CALL ChainablePropertySet::addPropertyChangeListener( const OUString&, const Reference< XPropertyChangeListener >& )
94 : throw(UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception)
95 : {
96 : // todo
97 0 : }
98 :
99 0 : void SAL_CALL ChainablePropertySet::removePropertyChangeListener( const OUString&, const Reference< XPropertyChangeListener >& )
100 : throw(UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception)
101 : {
102 : // todo
103 0 : }
104 :
105 0 : void SAL_CALL ChainablePropertySet::addVetoableChangeListener( const OUString&, const Reference< XVetoableChangeListener >& )
106 : throw(UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception)
107 : {
108 : // todo
109 0 : }
110 :
111 0 : void SAL_CALL ChainablePropertySet::removeVetoableChangeListener( const OUString&, const Reference< XVetoableChangeListener >& )
112 : throw(UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception)
113 : {
114 : // todo
115 0 : }
116 :
117 : // XMultiPropertySet
118 0 : void SAL_CALL ChainablePropertySet::setPropertyValues(const Sequence< OUString >& rPropertyNames, const Sequence< Any >& rValues)
119 : throw (PropertyVetoException, IllegalArgumentException,
120 : WrappedTargetException, RuntimeException, std::exception)
121 : {
122 : // acquire mutex in c-tor and releases it in the d-tor (exception safe!).
123 0 : std::unique_ptr< osl::Guard< comphelper::SolarMutex > > xMutexGuard;
124 0 : if (mpMutex)
125 0 : xMutexGuard.reset( new osl::Guard< comphelper::SolarMutex >(mpMutex) );
126 :
127 0 : const sal_Int32 nCount = rPropertyNames.getLength();
128 :
129 0 : if( nCount != rValues.getLength() )
130 0 : throw IllegalArgumentException();
131 :
132 0 : if( nCount )
133 : {
134 0 : _preSetValues();
135 :
136 0 : const Any * pAny = rValues.getConstArray();
137 0 : const OUString * pString = rPropertyNames.getConstArray();
138 0 : PropertyInfoHash::const_iterator aEnd = mpInfo->maMap.end(), aIter;
139 :
140 0 : for ( sal_Int32 i = 0; i < nCount; ++i, ++pString, ++pAny )
141 : {
142 0 : aIter = mpInfo->maMap.find ( *pString );
143 0 : if ( aIter == aEnd )
144 0 : throw RuntimeException( *pString, static_cast< XPropertySet* >( this ) );
145 :
146 0 : _setSingleValue ( *((*aIter).second), *pAny );
147 : }
148 :
149 0 : _postSetValues();
150 0 : }
151 0 : }
152 :
153 0 : Sequence< Any > SAL_CALL ChainablePropertySet::getPropertyValues(const Sequence< OUString >& rPropertyNames)
154 : throw (RuntimeException, std::exception)
155 : {
156 : // acquire mutex in c-tor and releases it in the d-tor (exception safe!).
157 0 : std::unique_ptr< osl::Guard< comphelper::SolarMutex > > xMutexGuard;
158 0 : if (mpMutex)
159 0 : xMutexGuard.reset( new osl::Guard< comphelper::SolarMutex >(mpMutex) );
160 :
161 0 : const sal_Int32 nCount = rPropertyNames.getLength();
162 :
163 0 : Sequence < Any > aValues ( nCount );
164 :
165 0 : if( nCount )
166 : {
167 0 : _preGetValues();
168 :
169 0 : Any * pAny = aValues.getArray();
170 0 : const OUString * pString = rPropertyNames.getConstArray();
171 0 : PropertyInfoHash::const_iterator aEnd = mpInfo->maMap.end(), aIter;
172 :
173 0 : for ( sal_Int32 i = 0; i < nCount; ++i, ++pString, ++pAny )
174 : {
175 0 : aIter = mpInfo->maMap.find ( *pString );
176 0 : if ( aIter == aEnd )
177 0 : throw RuntimeException( *pString, static_cast< XPropertySet* >( this ) );
178 :
179 0 : _getSingleValue ( *((*aIter).second), *pAny );
180 : }
181 :
182 0 : _postGetValues();
183 : }
184 0 : return aValues;
185 : }
186 :
187 0 : void SAL_CALL ChainablePropertySet::addPropertiesChangeListener( const Sequence< OUString >&, const Reference< XPropertiesChangeListener >& )
188 : throw(RuntimeException, std::exception)
189 : {
190 : // todo
191 0 : }
192 :
193 0 : void SAL_CALL ChainablePropertySet::removePropertiesChangeListener( const Reference< XPropertiesChangeListener >& )
194 : throw(RuntimeException, std::exception)
195 : {
196 : // todo
197 0 : }
198 :
199 0 : void SAL_CALL ChainablePropertySet::firePropertiesChangeEvent( const Sequence< OUString >&, const Reference< XPropertiesChangeListener >& )
200 : throw(RuntimeException, std::exception)
201 : {
202 : // todo
203 0 : }
204 :
205 : // XPropertyState
206 0 : PropertyState SAL_CALL ChainablePropertySet::getPropertyState( const OUString& PropertyName )
207 : throw(UnknownPropertyException, RuntimeException, std::exception)
208 : {
209 0 : PropertyInfoHash::const_iterator aIter = mpInfo->maMap.find( PropertyName );
210 0 : if( aIter == mpInfo->maMap.end())
211 0 : throw UnknownPropertyException( PropertyName, static_cast< XPropertySet* >( this ) );
212 :
213 0 : PropertyState aState(PropertyState_AMBIGUOUS_VALUE);
214 :
215 0 : _preGetPropertyState();
216 0 : _getPropertyState( *((*aIter).second), aState );
217 0 : _postGetPropertyState();
218 :
219 0 : return aState;
220 : }
221 :
222 0 : Sequence< PropertyState > SAL_CALL ChainablePropertySet::getPropertyStates( const Sequence< OUString >& rPropertyNames )
223 : throw(UnknownPropertyException, RuntimeException, std::exception)
224 : {
225 0 : const sal_Int32 nCount = rPropertyNames.getLength();
226 :
227 0 : Sequence< PropertyState > aStates( nCount );
228 0 : if( nCount )
229 : {
230 0 : PropertyState * pState = aStates.getArray();
231 0 : const OUString * pString = rPropertyNames.getConstArray();
232 0 : PropertyInfoHash::const_iterator aEnd = mpInfo->maMap.end(), aIter;
233 0 : _preGetPropertyState();
234 :
235 0 : for ( sal_Int32 i = 0; i < nCount; ++i, ++pString, ++pState )
236 : {
237 0 : aIter = mpInfo->maMap.find ( *pString );
238 0 : if ( aIter == aEnd )
239 0 : throw UnknownPropertyException( *pString, static_cast< XPropertySet* >( this ) );
240 :
241 0 : _getPropertyState ( *((*aIter).second), *pState );
242 : }
243 0 : _postGetPropertyState();
244 : }
245 0 : return aStates;
246 : }
247 :
248 0 : void SAL_CALL ChainablePropertySet::setPropertyToDefault( const OUString& rPropertyName )
249 : throw(UnknownPropertyException, RuntimeException, std::exception)
250 : {
251 0 : PropertyInfoHash::const_iterator aIter = mpInfo->maMap.find ( rPropertyName );
252 :
253 0 : if( aIter == mpInfo->maMap.end())
254 0 : throw UnknownPropertyException( rPropertyName, static_cast< XPropertySet* >( this ) );
255 0 : _setPropertyToDefault( *((*aIter).second) );
256 0 : }
257 :
258 0 : Any SAL_CALL ChainablePropertySet::getPropertyDefault( const OUString& rPropertyName )
259 : throw(UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception)
260 : {
261 0 : PropertyInfoHash::const_iterator aIter = mpInfo->maMap.find ( rPropertyName );
262 :
263 0 : if( aIter == mpInfo->maMap.end())
264 0 : throw UnknownPropertyException( rPropertyName, static_cast< XPropertySet* >( this ) );
265 0 : return _getPropertyDefault( *((*aIter).second) );
266 : }
267 :
268 0 : void ChainablePropertySet::_preGetPropertyState ()
269 : throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException )
270 : {
271 : OSL_FAIL( "you have to implement this yourself!");
272 0 : }
273 :
274 0 : void ChainablePropertySet::_getPropertyState( const comphelper::PropertyInfo&, PropertyState& )
275 : throw(UnknownPropertyException )
276 : {
277 : OSL_FAIL( "you have to implement this yourself!");
278 0 : }
279 :
280 0 : void ChainablePropertySet::_postGetPropertyState ()
281 : throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException )
282 : {
283 : OSL_FAIL( "you have to implement this yourself!");
284 0 : }
285 :
286 0 : void ChainablePropertySet::_setPropertyToDefault( const comphelper::PropertyInfo& )
287 : throw(UnknownPropertyException )
288 : {
289 : OSL_FAIL( "you have to implement this yourself!");
290 0 : }
291 :
292 0 : Any ChainablePropertySet::_getPropertyDefault( const comphelper::PropertyInfo& )
293 : throw(UnknownPropertyException, WrappedTargetException )
294 : {
295 : OSL_FAIL( "you have to implement this yourself!");
296 :
297 0 : Any aAny;
298 0 : return aAny;
299 : }
300 :
301 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|