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