/src/libreoffice/ucbhelper/source/provider/propertyvalueset.cxx
Line | Count | Source |
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 <vector> |
21 | | #include <com/sun/star/beans/Property.hpp> |
22 | | #include <com/sun/star/beans/XPropertyAccess.hpp> |
23 | | #include <com/sun/star/beans/XPropertySet.hpp> |
24 | | #include <com/sun/star/beans/XPropertySetInfo.hpp> |
25 | | #include <com/sun/star/script/CannotConvertException.hpp> |
26 | | #include <com/sun/star/script/Converter.hpp> |
27 | | |
28 | | #include <osl/diagnose.h> |
29 | | #include <ucbhelper/propertyvalueset.hxx> |
30 | | #include <o3tl/safeint.hxx> |
31 | | #include <o3tl/typed_flags_set.hxx> |
32 | | |
33 | | using namespace com::sun::star::beans; |
34 | | using namespace com::sun::star::container; |
35 | | using namespace com::sun::star::io; |
36 | | using namespace com::sun::star::lang; |
37 | | using namespace com::sun::star::script; |
38 | | using namespace com::sun::star::sdbc; |
39 | | using namespace com::sun::star::uno; |
40 | | using namespace com::sun::star::util; |
41 | | |
42 | | enum class PropsSet { |
43 | | NONE = 0x00000000, |
44 | | String = 0x00000001, |
45 | | Boolean = 0x00000002, |
46 | | Byte = 0x00000004, |
47 | | Short = 0x00000008, |
48 | | Int = 0x00000010, |
49 | | Long = 0x00000020, |
50 | | Float = 0x00000040, |
51 | | Double = 0x00000080, |
52 | | Bytes = 0x00000100, |
53 | | Date = 0x00000200, |
54 | | Time = 0x00000400, |
55 | | Timestamp = 0x00000800, |
56 | | BinaryStream = 0x00001000, |
57 | | CharacterStream = 0x00002000, |
58 | | Ref = 0x00004000, |
59 | | Blob = 0x00008000, |
60 | | Clob = 0x00010000, |
61 | | Array = 0x00020000, |
62 | | Object = 0x00040000 |
63 | | }; |
64 | | namespace o3tl { |
65 | | template<> struct typed_flags<PropsSet> : is_typed_flags<PropsSet, 0x0007ffff> {}; |
66 | | } |
67 | | |
68 | | namespace ucbhelper_impl |
69 | | { |
70 | | |
71 | | |
72 | | struct PropertyValue |
73 | | { |
74 | | OUString sPropertyName; |
75 | | |
76 | | PropsSet nPropsSet; |
77 | | PropsSet nOrigValue; |
78 | | |
79 | | OUString aString; // getString |
80 | | bool bBoolean; // getBoolean |
81 | | sal_Int8 nByte; // getByte |
82 | | sal_Int16 nShort; // getShort |
83 | | sal_Int32 nInt; // getInt |
84 | | sal_Int64 nLong; // getLong |
85 | | float nFloat; // getFloat |
86 | | double nDouble; // getDouble |
87 | | |
88 | | Sequence< sal_Int8 > aBytes; // getBytes |
89 | | Date aDate; // getDate |
90 | | Time aTime; // getTime |
91 | | DateTime aTimestamp; // getTimestamp |
92 | | Reference< XInputStream > xBinaryStream; // getBinaryStream |
93 | | Reference< XInputStream > xCharacterStream; // getCharacterStream |
94 | | Reference< XRef > xRef; // getRef |
95 | | Reference< XBlob > xBlob; // getBlob |
96 | | Reference< XClob > xClob; // getClob |
97 | | Reference< XArray > xArray; // getArray |
98 | | Any aObject; // getObject |
99 | | |
100 | | PropertyValue() |
101 | 0 | : nPropsSet( PropsSet::NONE ), nOrigValue( PropsSet::NONE ), |
102 | 0 | bBoolean(false), |
103 | 0 | nByte(0), |
104 | 0 | nShort(0), |
105 | 0 | nInt(0), |
106 | 0 | nLong(0), |
107 | 0 | nFloat(0.0), |
108 | 0 | nDouble(0.0) |
109 | 0 | {} |
110 | | }; |
111 | | } // namespace ucbhelper_impl |
112 | | |
113 | | using namespace ucbhelper_impl; |
114 | | |
115 | | namespace ucbhelper |
116 | | { |
117 | | |
118 | | class PropertyValues : public std::vector< ucbhelper_impl::PropertyValue > {}; |
119 | | |
120 | | } // namespace ucbhelper |
121 | | |
122 | | |
123 | | namespace ucbhelper { |
124 | | |
125 | | |
126 | | // PropertyValueSet Implementation. |
127 | | |
128 | | |
129 | | PropertyValueSet::PropertyValueSet( |
130 | | const Reference< XComponentContext >& rxContext ) |
131 | 0 | : m_xContext( rxContext ), |
132 | 0 | m_pValues( new PropertyValues ), |
133 | 0 | m_bWasNull( false ), |
134 | 0 | m_bTriedToGetTypeConverter( false ) |
135 | | |
136 | 0 | { |
137 | 0 | } |
138 | | |
139 | | |
140 | | // virtual |
141 | | PropertyValueSet::~PropertyValueSet() |
142 | 0 | { |
143 | 0 | } |
144 | | |
145 | | |
146 | | // XRow methods. |
147 | | |
148 | | |
149 | | template <class T, T ucbhelper_impl::PropertyValue::*_member_name_> |
150 | | T PropertyValueSet::getValue(PropsSet nTypeName, sal_Int32 columnIndex) |
151 | 0 | { |
152 | 0 | std::unique_lock aGuard( m_aMutex ); |
153 | |
|
154 | 0 | T aValue {}; /* default ctor */ |
155 | |
|
156 | 0 | m_bWasNull = true; |
157 | |
|
158 | 0 | if ( ( columnIndex < 1 ) || ( o3tl::make_unsigned(columnIndex) > m_pValues->size() ) ) |
159 | 0 | { |
160 | 0 | OSL_FAIL( "PropertyValueSet - index out of range!" ); |
161 | 0 | return aValue; |
162 | 0 | } |
163 | 0 | ucbhelper_impl::PropertyValue& rValue = (*m_pValues)[ columnIndex - 1 ]; |
164 | |
|
165 | 0 | if ( rValue.nOrigValue == PropsSet::NONE ) |
166 | 0 | return aValue; |
167 | | |
168 | 0 | if ( rValue.nPropsSet & nTypeName ) |
169 | 0 | { |
170 | | /* Values is present natively... */ |
171 | 0 | aValue = rValue.*_member_name_; |
172 | 0 | m_bWasNull = false; |
173 | 0 | return aValue; |
174 | 0 | } |
175 | | |
176 | 0 | if ( !(rValue.nPropsSet & PropsSet::Object) ) |
177 | 0 | { |
178 | | /* Value is not (yet) available as Any. Create it. */ |
179 | 0 | getObjectImpl(aGuard, columnIndex); |
180 | 0 | } |
181 | |
|
182 | 0 | if ( rValue.nPropsSet & PropsSet::Object ) |
183 | 0 | { |
184 | | /* Value is available as Any. */ |
185 | |
|
186 | 0 | if ( rValue.aObject.hasValue() ) |
187 | 0 | { |
188 | | /* Try to convert into native value. */ |
189 | 0 | if ( rValue.aObject >>= aValue ) |
190 | 0 | { |
191 | 0 | rValue.*_member_name_ = aValue; |
192 | 0 | rValue.nPropsSet |= nTypeName; |
193 | 0 | m_bWasNull = false; |
194 | 0 | } |
195 | 0 | else |
196 | 0 | { |
197 | | /* Last chance. Try type converter service... */ |
198 | |
|
199 | 0 | Reference< XTypeConverter > xConverter = getTypeConverter(aGuard); |
200 | 0 | if ( xConverter.is() ) |
201 | 0 | { |
202 | 0 | try |
203 | 0 | { |
204 | 0 | Any aConvAny = xConverter->convertTo( |
205 | 0 | rValue.aObject, |
206 | 0 | cppu::UnoType<T>::get() ); |
207 | |
|
208 | 0 | if ( aConvAny >>= aValue ) |
209 | 0 | { |
210 | 0 | rValue.*_member_name_ = aValue; |
211 | 0 | rValue.nPropsSet |= nTypeName; |
212 | 0 | m_bWasNull = false; |
213 | 0 | } |
214 | 0 | } |
215 | 0 | catch (const IllegalArgumentException&) |
216 | 0 | { |
217 | 0 | } |
218 | 0 | catch (const CannotConvertException&) |
219 | 0 | { |
220 | 0 | } |
221 | 0 | } |
222 | 0 | } |
223 | 0 | } |
224 | 0 | } |
225 | |
|
226 | 0 | return aValue; |
227 | 0 | } Unexecuted instantiation: _ZN9ucbhelper16PropertyValueSet8getValueIN3rtl8OUStringETnMN14ucbhelper_impl13PropertyValueET_XadL_ZNS5_7aStringEEEEES6_8PropsSeti Unexecuted instantiation: _ZN9ucbhelper16PropertyValueSet8getValueIbTnMN14ucbhelper_impl13PropertyValueET_XadL_ZNS3_8bBooleanEEEEES4_8PropsSeti Unexecuted instantiation: _ZN9ucbhelper16PropertyValueSet8getValueIaTnMN14ucbhelper_impl13PropertyValueET_XadL_ZNS3_5nByteEEEEES4_8PropsSeti Unexecuted instantiation: _ZN9ucbhelper16PropertyValueSet8getValueIsTnMN14ucbhelper_impl13PropertyValueET_XadL_ZNS3_6nShortEEEEES4_8PropsSeti Unexecuted instantiation: _ZN9ucbhelper16PropertyValueSet8getValueIiTnMN14ucbhelper_impl13PropertyValueET_XadL_ZNS3_4nIntEEEEES4_8PropsSeti Unexecuted instantiation: _ZN9ucbhelper16PropertyValueSet8getValueIlTnMN14ucbhelper_impl13PropertyValueET_XadL_ZNS3_5nLongEEEEES4_8PropsSeti Unexecuted instantiation: _ZN9ucbhelper16PropertyValueSet8getValueIfTnMN14ucbhelper_impl13PropertyValueET_XadL_ZNS3_6nFloatEEEEES4_8PropsSeti Unexecuted instantiation: _ZN9ucbhelper16PropertyValueSet8getValueIdTnMN14ucbhelper_impl13PropertyValueET_XadL_ZNS3_7nDoubleEEEEES4_8PropsSeti Unexecuted instantiation: _ZN9ucbhelper16PropertyValueSet8getValueIN3com3sun4star3uno8SequenceIaEETnMN14ucbhelper_impl13PropertyValueET_XadL_ZNS9_6aBytesEEEEESA_8PropsSeti Unexecuted instantiation: _ZN9ucbhelper16PropertyValueSet8getValueIN3com3sun4star4util4DateETnMN14ucbhelper_impl13PropertyValueET_XadL_ZNS8_5aDateEEEEES9_8PropsSeti Unexecuted instantiation: _ZN9ucbhelper16PropertyValueSet8getValueIN3com3sun4star4util4TimeETnMN14ucbhelper_impl13PropertyValueET_XadL_ZNS8_5aTimeEEEEES9_8PropsSeti Unexecuted instantiation: _ZN9ucbhelper16PropertyValueSet8getValueIN3com3sun4star4util8DateTimeETnMN14ucbhelper_impl13PropertyValueET_XadL_ZNS8_10aTimestampEEEEES9_8PropsSeti Unexecuted instantiation: _ZN9ucbhelper16PropertyValueSet8getValueIN3com3sun4star3uno9ReferenceINS4_2io12XInputStreamEEETnMN14ucbhelper_impl13PropertyValueET_XadL_ZNSB_13xBinaryStreamEEEEESC_8PropsSeti Unexecuted instantiation: _ZN9ucbhelper16PropertyValueSet8getValueIN3com3sun4star3uno9ReferenceINS4_2io12XInputStreamEEETnMN14ucbhelper_impl13PropertyValueET_XadL_ZNSB_16xCharacterStreamEEEEESC_8PropsSeti Unexecuted instantiation: _ZN9ucbhelper16PropertyValueSet8getValueIN3com3sun4star3uno9ReferenceINS4_4sdbc4XRefEEETnMN14ucbhelper_impl13PropertyValueET_XadL_ZNSB_4xRefEEEEESC_8PropsSeti Unexecuted instantiation: _ZN9ucbhelper16PropertyValueSet8getValueIN3com3sun4star3uno9ReferenceINS4_4sdbc5XBlobEEETnMN14ucbhelper_impl13PropertyValueET_XadL_ZNSB_5xBlobEEEEESC_8PropsSeti Unexecuted instantiation: _ZN9ucbhelper16PropertyValueSet8getValueIN3com3sun4star3uno9ReferenceINS4_4sdbc5XClobEEETnMN14ucbhelper_impl13PropertyValueET_XadL_ZNSB_5xClobEEEEESC_8PropsSeti Unexecuted instantiation: _ZN9ucbhelper16PropertyValueSet8getValueIN3com3sun4star3uno9ReferenceINS4_4sdbc6XArrayEEETnMN14ucbhelper_impl13PropertyValueET_XadL_ZNSB_6xArrayEEEEESC_8PropsSeti |
228 | | |
229 | | |
230 | | // virtual |
231 | | sal_Bool SAL_CALL PropertyValueSet::wasNull() |
232 | 0 | { |
233 | | // This method can not be implemented correctly!!! Imagine different |
234 | | // threads doing a getXYZ - wasNull calling sequence on the same |
235 | | // implementation object... |
236 | 0 | return m_bWasNull; |
237 | 0 | } |
238 | | |
239 | | |
240 | | // virtual |
241 | | OUString SAL_CALL PropertyValueSet::getString( sal_Int32 columnIndex ) |
242 | 0 | { |
243 | 0 | return getValue<OUString, &ucbhelper_impl::PropertyValue::aString>(PropsSet::String, columnIndex); |
244 | 0 | } |
245 | | |
246 | | |
247 | | // virtual |
248 | | sal_Bool SAL_CALL PropertyValueSet::getBoolean( sal_Int32 columnIndex ) |
249 | 0 | { |
250 | 0 | return getValue<bool, &ucbhelper_impl::PropertyValue::bBoolean>(PropsSet::Boolean, columnIndex); |
251 | 0 | } |
252 | | |
253 | | |
254 | | // virtual |
255 | | sal_Int8 SAL_CALL PropertyValueSet::getByte( sal_Int32 columnIndex ) |
256 | 0 | { |
257 | 0 | return getValue<sal_Int8, &ucbhelper_impl::PropertyValue::nByte>(PropsSet::Byte, columnIndex); |
258 | 0 | } |
259 | | |
260 | | |
261 | | // virtual |
262 | | sal_Int16 SAL_CALL PropertyValueSet::getShort( sal_Int32 columnIndex ) |
263 | 0 | { |
264 | 0 | return getValue<sal_Int16, &ucbhelper_impl::PropertyValue::nShort>(PropsSet::Short, columnIndex); |
265 | 0 | } |
266 | | |
267 | | |
268 | | // virtual |
269 | | sal_Int32 SAL_CALL PropertyValueSet::getInt( sal_Int32 columnIndex ) |
270 | 0 | { |
271 | 0 | return getValue<sal_Int32, &ucbhelper_impl::PropertyValue::nInt>(PropsSet::Int, columnIndex); |
272 | 0 | } |
273 | | |
274 | | |
275 | | // virtual |
276 | | sal_Int64 SAL_CALL PropertyValueSet::getLong( sal_Int32 columnIndex ) |
277 | 0 | { |
278 | 0 | return getValue<sal_Int64, &ucbhelper_impl::PropertyValue::nLong>(PropsSet::Long, columnIndex); |
279 | 0 | } |
280 | | |
281 | | |
282 | | // virtual |
283 | | float SAL_CALL PropertyValueSet::getFloat( sal_Int32 columnIndex ) |
284 | 0 | { |
285 | 0 | return getValue<float, &ucbhelper_impl::PropertyValue::nFloat>(PropsSet::Float, columnIndex); |
286 | 0 | } |
287 | | |
288 | | |
289 | | // virtual |
290 | | double SAL_CALL PropertyValueSet::getDouble( sal_Int32 columnIndex ) |
291 | 0 | { |
292 | 0 | return getValue<double, &ucbhelper_impl::PropertyValue::nDouble>(PropsSet::Double, columnIndex); |
293 | 0 | } |
294 | | |
295 | | |
296 | | // virtual |
297 | | Sequence< sal_Int8 > SAL_CALL |
298 | | PropertyValueSet::getBytes( sal_Int32 columnIndex ) |
299 | 0 | { |
300 | 0 | return getValue<Sequence< sal_Int8 >, &ucbhelper_impl::PropertyValue::aBytes>(PropsSet::Bytes, columnIndex); |
301 | 0 | } |
302 | | |
303 | | |
304 | | // virtual |
305 | | Date SAL_CALL PropertyValueSet::getDate( sal_Int32 columnIndex ) |
306 | 0 | { |
307 | 0 | return getValue<Date, &ucbhelper_impl::PropertyValue::aDate>(PropsSet::Date, columnIndex); |
308 | 0 | } |
309 | | |
310 | | |
311 | | // virtual |
312 | | Time SAL_CALL PropertyValueSet::getTime( sal_Int32 columnIndex ) |
313 | 0 | { |
314 | 0 | return getValue<Time, &ucbhelper_impl::PropertyValue::aTime>(PropsSet::Time, columnIndex); |
315 | 0 | } |
316 | | |
317 | | |
318 | | // virtual |
319 | | DateTime SAL_CALL PropertyValueSet::getTimestamp( sal_Int32 columnIndex ) |
320 | 0 | { |
321 | 0 | return getValue<DateTime, &ucbhelper_impl::PropertyValue::aTimestamp>(PropsSet::Timestamp, columnIndex); |
322 | 0 | } |
323 | | |
324 | | |
325 | | // virtual |
326 | | Reference< XInputStream > SAL_CALL |
327 | | PropertyValueSet::getBinaryStream( sal_Int32 columnIndex ) |
328 | 0 | { |
329 | 0 | return getValue<Reference< XInputStream >, &ucbhelper_impl::PropertyValue::xBinaryStream>(PropsSet::BinaryStream, columnIndex); |
330 | 0 | } |
331 | | |
332 | | |
333 | | // virtual |
334 | | Reference< XInputStream > SAL_CALL |
335 | | PropertyValueSet::getCharacterStream( sal_Int32 columnIndex ) |
336 | 0 | { |
337 | 0 | return getValue<Reference< XInputStream >, &ucbhelper_impl::PropertyValue::xCharacterStream>(PropsSet::CharacterStream, columnIndex); |
338 | 0 | } |
339 | | |
340 | | Any PropertyValueSet::getObjectImpl(const std::unique_lock<std::mutex>& /*rGuard*/, sal_Int32 columnIndex) |
341 | 0 | { |
342 | 0 | Any aValue; |
343 | |
|
344 | 0 | m_bWasNull = true; |
345 | |
|
346 | 0 | if ( ( columnIndex < 1 ) |
347 | 0 | || ( o3tl::make_unsigned(columnIndex) > m_pValues->size() ) ) |
348 | 0 | { |
349 | 0 | OSL_FAIL( "PropertyValueSet - index out of range!" ); |
350 | 0 | } |
351 | 0 | else |
352 | 0 | { |
353 | 0 | ucbhelper_impl::PropertyValue& rValue |
354 | 0 | = (*m_pValues)[ columnIndex - 1 ]; |
355 | |
|
356 | 0 | if ( rValue.nPropsSet & PropsSet::Object ) |
357 | 0 | { |
358 | | // Values is present natively... |
359 | 0 | aValue = rValue.aObject; |
360 | 0 | m_bWasNull = false; |
361 | 0 | } |
362 | 0 | else |
363 | 0 | { |
364 | | // Make Any from original value. |
365 | |
|
366 | 0 | switch ( rValue.nOrigValue ) |
367 | 0 | { |
368 | 0 | case PropsSet::NONE: |
369 | 0 | break; |
370 | | |
371 | 0 | case PropsSet::String: |
372 | 0 | aValue <<= rValue.aString; |
373 | 0 | break; |
374 | | |
375 | 0 | case PropsSet::Boolean: |
376 | 0 | aValue <<= rValue.bBoolean; |
377 | 0 | break; |
378 | | |
379 | 0 | case PropsSet::Byte: |
380 | 0 | aValue <<= rValue.nByte; |
381 | 0 | break; |
382 | | |
383 | 0 | case PropsSet::Short: |
384 | 0 | aValue <<= rValue.nShort; |
385 | 0 | break; |
386 | | |
387 | 0 | case PropsSet::Int: |
388 | 0 | aValue <<= rValue.nInt; |
389 | 0 | break; |
390 | | |
391 | 0 | case PropsSet::Long: |
392 | 0 | aValue <<= rValue.nLong; |
393 | 0 | break; |
394 | | |
395 | 0 | case PropsSet::Float: |
396 | 0 | aValue <<= rValue.nFloat; |
397 | 0 | break; |
398 | | |
399 | 0 | case PropsSet::Double: |
400 | 0 | aValue <<= rValue.nDouble; |
401 | 0 | break; |
402 | | |
403 | 0 | case PropsSet::Bytes: |
404 | 0 | aValue <<= rValue.aBytes; |
405 | 0 | break; |
406 | | |
407 | 0 | case PropsSet::Date: |
408 | 0 | aValue <<= rValue.aDate; |
409 | 0 | break; |
410 | | |
411 | 0 | case PropsSet::Time: |
412 | 0 | aValue <<= rValue.aTime; |
413 | 0 | break; |
414 | | |
415 | 0 | case PropsSet::Timestamp: |
416 | 0 | aValue <<= rValue.aTimestamp; |
417 | 0 | break; |
418 | | |
419 | 0 | case PropsSet::BinaryStream: |
420 | 0 | aValue <<= rValue.xBinaryStream; |
421 | 0 | break; |
422 | | |
423 | 0 | case PropsSet::CharacterStream: |
424 | 0 | aValue <<= rValue.xCharacterStream; |
425 | 0 | break; |
426 | | |
427 | 0 | case PropsSet::Ref: |
428 | 0 | aValue <<= rValue.xRef; |
429 | 0 | break; |
430 | | |
431 | 0 | case PropsSet::Blob: |
432 | 0 | aValue <<= rValue.xBlob; |
433 | 0 | break; |
434 | | |
435 | 0 | case PropsSet::Clob: |
436 | 0 | aValue <<= rValue.xClob; |
437 | 0 | break; |
438 | | |
439 | 0 | case PropsSet::Array: |
440 | 0 | aValue <<= rValue.xArray; |
441 | 0 | break; |
442 | | |
443 | 0 | case PropsSet::Object: |
444 | | // Fall-through is intended! |
445 | 0 | default: |
446 | 0 | OSL_FAIL( "PropertyValueSet::getObject - " |
447 | 0 | "Wrong original type" ); |
448 | 0 | break; |
449 | 0 | } |
450 | | |
451 | 0 | if ( aValue.hasValue() ) |
452 | 0 | { |
453 | 0 | rValue.aObject = aValue; |
454 | 0 | rValue.nPropsSet |= PropsSet::Object; |
455 | 0 | m_bWasNull = false; |
456 | 0 | } |
457 | 0 | } |
458 | 0 | } |
459 | | |
460 | 0 | return aValue; |
461 | 0 | } |
462 | | |
463 | | // virtual |
464 | | Any SAL_CALL PropertyValueSet::getObject(sal_Int32 columnIndex, const Reference<XNameAccess>&) |
465 | 0 | { |
466 | 0 | std::unique_lock aGuard( m_aMutex ); |
467 | |
|
468 | 0 | return getObjectImpl(aGuard, columnIndex); |
469 | 0 | } |
470 | | |
471 | | // virtual |
472 | | Reference< XRef > SAL_CALL PropertyValueSet::getRef( sal_Int32 columnIndex ) |
473 | 0 | { |
474 | 0 | return getValue<Reference< XRef >, &ucbhelper_impl::PropertyValue::xRef>(PropsSet::Ref, columnIndex); |
475 | 0 | } |
476 | | |
477 | | |
478 | | // virtual |
479 | | Reference< XBlob > SAL_CALL PropertyValueSet::getBlob( sal_Int32 columnIndex ) |
480 | 0 | { |
481 | 0 | return getValue<Reference< XBlob >, &ucbhelper_impl::PropertyValue::xBlob>(PropsSet::Blob, columnIndex); |
482 | 0 | } |
483 | | |
484 | | |
485 | | // virtual |
486 | | Reference< XClob > SAL_CALL PropertyValueSet::getClob( sal_Int32 columnIndex ) |
487 | 0 | { |
488 | 0 | return getValue<Reference< XClob >, &ucbhelper_impl::PropertyValue::xClob>(PropsSet::Clob, columnIndex); |
489 | 0 | } |
490 | | |
491 | | |
492 | | // virtual |
493 | | Reference< XArray > SAL_CALL PropertyValueSet::getArray( sal_Int32 columnIndex ) |
494 | 0 | { |
495 | 0 | return getValue<Reference< XArray >, &ucbhelper_impl::PropertyValue::xArray>(PropsSet::Array, columnIndex); |
496 | 0 | } |
497 | | |
498 | | |
499 | | // XColumnLocate methods. |
500 | | |
501 | | |
502 | | // virtual |
503 | | sal_Int32 SAL_CALL PropertyValueSet::findColumn( const OUString& columnName ) |
504 | 0 | { |
505 | 0 | std::unique_lock aGuard( m_aMutex ); |
506 | |
|
507 | 0 | if ( !columnName.isEmpty() ) |
508 | 0 | { |
509 | 0 | sal_Int32 nCount = m_pValues->size(); |
510 | 0 | for ( sal_Int32 n = 0; n < nCount; ++n ) |
511 | 0 | { |
512 | 0 | if ( (*m_pValues)[ n ].sPropertyName == columnName ) |
513 | 0 | return n + 1; // Index is 1-based. |
514 | 0 | } |
515 | 0 | } |
516 | 0 | return 0; |
517 | 0 | } |
518 | | |
519 | | |
520 | | // Non-interface methods. |
521 | | |
522 | | |
523 | | const Reference< XTypeConverter >& PropertyValueSet::getTypeConverter(const std::unique_lock<std::mutex>& /*rGuard*/) |
524 | 0 | { |
525 | 0 | if ( !m_bTriedToGetTypeConverter && !m_xTypeConverter.is() ) |
526 | 0 | { |
527 | 0 | m_bTriedToGetTypeConverter = true; |
528 | 0 | m_xTypeConverter = Converter::create(m_xContext); |
529 | |
|
530 | 0 | OSL_ENSURE( m_xTypeConverter.is(), |
531 | 0 | "PropertyValueSet::getTypeConverter() - " |
532 | 0 | "Service 'com.sun.star.script.Converter' n/a!" ); |
533 | 0 | } |
534 | 0 | return m_xTypeConverter; |
535 | 0 | } |
536 | | |
537 | | template <class T, T ucbhelper_impl::PropertyValue::*_member_name_> |
538 | | void PropertyValueSet::appendValue(const OUString& rPropName, PropsSet nTypeName, const T& rValue) |
539 | 0 | { |
540 | 0 | std::unique_lock aGuard( m_aMutex ); |
541 | |
|
542 | 0 | ucbhelper_impl::PropertyValue aNewValue; |
543 | 0 | aNewValue.sPropertyName = rPropName; |
544 | 0 | aNewValue.nPropsSet = nTypeName; |
545 | 0 | aNewValue.nOrigValue = nTypeName; |
546 | 0 | aNewValue.*_member_name_ = rValue; |
547 | |
|
548 | 0 | m_pValues->push_back(std::move(aNewValue)); |
549 | 0 | } Unexecuted instantiation: _ZN9ucbhelper16PropertyValueSet11appendValueIN3rtl8OUStringETnMN14ucbhelper_impl13PropertyValueET_XadL_ZNS5_7aStringEEEEEvRKS3_8PropsSetRKS6_ Unexecuted instantiation: _ZN9ucbhelper16PropertyValueSet11appendValueIbTnMN14ucbhelper_impl13PropertyValueET_XadL_ZNS3_8bBooleanEEEEEvRKN3rtl8OUStringE8PropsSetRKS4_ Unexecuted instantiation: _ZN9ucbhelper16PropertyValueSet11appendValueIlTnMN14ucbhelper_impl13PropertyValueET_XadL_ZNS3_5nLongEEEEEvRKN3rtl8OUStringE8PropsSetRKS4_ Unexecuted instantiation: _ZN9ucbhelper16PropertyValueSet11appendValueIN3com3sun4star4util8DateTimeETnMN14ucbhelper_impl13PropertyValueET_XadL_ZNS8_10aTimestampEEEEEvRKN3rtl8OUStringE8PropsSetRKS9_ Unexecuted instantiation: _ZN9ucbhelper16PropertyValueSet11appendValueIN3com3sun4star3uno3AnyETnMN14ucbhelper_impl13PropertyValueET_XadL_ZNS8_7aObjectEEEEEvRKN3rtl8OUStringE8PropsSetRKS9_ |
550 | | |
551 | | void PropertyValueSet::appendString( const OUString& rPropName, |
552 | | const OUString& rValue ) |
553 | 0 | { |
554 | 0 | appendValue<OUString, &ucbhelper_impl::PropertyValue::aString>(rPropName, PropsSet::String, rValue); |
555 | 0 | } |
556 | | |
557 | | void PropertyValueSet::appendBoolean( const OUString& rPropName, |
558 | | bool bValue ) |
559 | 0 | { |
560 | 0 | appendValue<bool, &ucbhelper_impl::PropertyValue::bBoolean>(rPropName, PropsSet::Boolean, bValue); |
561 | 0 | } |
562 | | |
563 | | void PropertyValueSet::appendLong( const OUString& rPropName, |
564 | | sal_Int64 nValue ) |
565 | 0 | { |
566 | 0 | appendValue<sal_Int64, &ucbhelper_impl::PropertyValue::nLong>(rPropName, PropsSet::Long, nValue); |
567 | 0 | } |
568 | | |
569 | | |
570 | | void PropertyValueSet::appendTimestamp( const OUString& rPropName, |
571 | | const DateTime& rValue ) |
572 | 0 | { |
573 | 0 | appendValue<DateTime, &ucbhelper_impl::PropertyValue::aTimestamp>(rPropName, PropsSet::Timestamp, rValue); |
574 | 0 | } |
575 | | |
576 | | |
577 | | void PropertyValueSet::appendObject( const OUString& rPropName, |
578 | | const Any& rValue ) |
579 | 0 | { |
580 | 0 | appendValue<Any, &ucbhelper_impl::PropertyValue::aObject>(rPropName, PropsSet::Object, rValue); |
581 | 0 | } |
582 | | |
583 | | |
584 | | void PropertyValueSet::appendVoid( const OUString& rPropName ) |
585 | 0 | { |
586 | 0 | appendValue<Any, &ucbhelper_impl::PropertyValue::aObject>(rPropName, PropsSet::NONE, Any()); |
587 | 0 | } |
588 | | |
589 | | |
590 | | void PropertyValueSet::appendPropertySet( |
591 | | const Reference< XPropertySet >& rxSet ) |
592 | 0 | { |
593 | 0 | if ( !rxSet.is() ) |
594 | 0 | return; |
595 | | |
596 | 0 | Reference< XPropertySetInfo > xInfo = rxSet->getPropertySetInfo(); |
597 | 0 | if ( !xInfo.is() ) |
598 | 0 | return; |
599 | | |
600 | 0 | const Sequence< Property > aProps = xInfo->getProperties(); |
601 | |
|
602 | 0 | Reference< XPropertyAccess > xPropertyAccess( rxSet, UNO_QUERY ); |
603 | 0 | if ( xPropertyAccess.is() ) |
604 | 0 | { |
605 | | // Efficient: Get all prop values with one ( remote) call. |
606 | |
|
607 | 0 | const Sequence< css::beans::PropertyValue > aPropValues |
608 | 0 | = xPropertyAccess->getPropertyValues(); |
609 | |
|
610 | 0 | for ( const css::beans::PropertyValue& rPropValue : aPropValues ) |
611 | 0 | { |
612 | | // Find info for current property value. |
613 | 0 | auto pProp = std::find_if(aProps.begin(), aProps.end(), |
614 | 0 | [&rPropValue](const Property& rProp) { return rProp.Name == rPropValue.Name; }); |
615 | 0 | if (pProp != aProps.end()) |
616 | 0 | { |
617 | | // Found! |
618 | 0 | appendObject( *pProp, rPropValue.Value ); |
619 | 0 | } |
620 | 0 | } |
621 | 0 | } |
622 | 0 | else |
623 | 0 | { |
624 | | // Get every single prop value with one ( remote) call. |
625 | |
|
626 | 0 | for ( const Property& rProp : aProps ) |
627 | 0 | { |
628 | 0 | try |
629 | 0 | { |
630 | 0 | Any aValue = rxSet->getPropertyValue( rProp.Name ); |
631 | |
|
632 | 0 | if ( aValue.hasValue() ) |
633 | 0 | appendObject( rProp, aValue ); |
634 | 0 | } |
635 | 0 | catch (const UnknownPropertyException&) |
636 | 0 | { |
637 | 0 | } |
638 | 0 | catch (const WrappedTargetException&) |
639 | 0 | { |
640 | 0 | } |
641 | 0 | } |
642 | 0 | } |
643 | 0 | } |
644 | | |
645 | | |
646 | | bool PropertyValueSet::appendPropertySetValue( |
647 | | const Reference< XPropertySet >& rxSet, |
648 | | const Property& rProperty ) |
649 | 0 | { |
650 | 0 | if ( rxSet.is() ) |
651 | 0 | { |
652 | 0 | try |
653 | 0 | { |
654 | 0 | Any aValue = rxSet->getPropertyValue( rProperty.Name ); |
655 | 0 | if ( aValue.hasValue() ) |
656 | 0 | { |
657 | 0 | appendObject( rProperty, aValue ); |
658 | 0 | return true; |
659 | 0 | } |
660 | 0 | } |
661 | 0 | catch (const UnknownPropertyException&) |
662 | 0 | { |
663 | 0 | } |
664 | 0 | catch (const WrappedTargetException&) |
665 | 0 | { |
666 | 0 | } |
667 | 0 | } |
668 | | |
669 | | // Error. |
670 | 0 | return false; |
671 | 0 | } |
672 | | |
673 | | } // namespace ucbhelper |
674 | | |
675 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |