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_ucbhelper.hxx"
26
27 /**************************************************************************
28 TODO
29 **************************************************************************
30
31 *************************************************************************/
32
33 #ifndef __VECTOR__
34 #include <vector>
35 #endif
36 #include <com/sun/star/beans/Property.hpp>
37 #include <com/sun/star/beans/XPropertyAccess.hpp>
38 #include <com/sun/star/beans/XPropertySet.hpp>
39 #include <com/sun/star/beans/XPropertySetInfo.hpp>
40 #include <com/sun/star/script/XTypeConverter.hpp>
41
42 #include "osl/diagnose.h"
43 #include "osl/mutex.hxx"
44 #include <ucbhelper/propertyvalueset.hxx>
45
46 using namespace com::sun::star::beans;
47 using namespace com::sun::star::container;
48 using namespace com::sun::star::io;
49 using namespace com::sun::star::lang;
50 using namespace com::sun::star::script;
51 using namespace com::sun::star::sdbc;
52 using namespace com::sun::star::uno;
53 using namespace com::sun::star::util;
54 using namespace rtl;
55
56 namespace ucbhelper_impl
57 {
58
59 //=========================================================================
60 //
61 // PropertyValue.
62 //
63 //=========================================================================
64
65 const sal_uInt32 NO_VALUE_SET = 0x00000000;
66 const sal_uInt32 STRING_VALUE_SET = 0x00000001;
67 const sal_uInt32 BOOLEAN_VALUE_SET = 0x00000002;
68 const sal_uInt32 BYTE_VALUE_SET = 0x00000004;
69 const sal_uInt32 SHORT_VALUE_SET = 0x00000008;
70 const sal_uInt32 INT_VALUE_SET = 0x00000010;
71 const sal_uInt32 LONG_VALUE_SET = 0x00000020;
72 const sal_uInt32 FLOAT_VALUE_SET = 0x00000040;
73 const sal_uInt32 DOUBLE_VALUE_SET = 0x00000080;
74 const sal_uInt32 BYTES_VALUE_SET = 0x00000100;
75 const sal_uInt32 DATE_VALUE_SET = 0x00000200;
76 const sal_uInt32 TIME_VALUE_SET = 0x00000400;
77 const sal_uInt32 TIMESTAMP_VALUE_SET = 0x00000800;
78 const sal_uInt32 BINARYSTREAM_VALUE_SET = 0x00001000;
79 const sal_uInt32 CHARACTERSTREAM_VALUE_SET = 0x00002000;
80 const sal_uInt32 REF_VALUE_SET = 0x00004000;
81 const sal_uInt32 BLOB_VALUE_SET = 0x00008000;
82 const sal_uInt32 CLOB_VALUE_SET = 0x00010000;
83 const sal_uInt32 ARRAY_VALUE_SET = 0x00020000;
84 const sal_uInt32 OBJECT_VALUE_SET = 0x00040000;
85
86 struct PropertyValue
87 {
88 ::rtl::OUString
89 sPropertyName;
90
91 sal_uInt32 nPropsSet;
92 sal_uInt32 nOrigValue;
93
94 OUString aString; // getString
95 sal_Bool bBoolean; // getBoolean
96 sal_Int8 nByte; // getByte
97 sal_Int16 nShort; // getShort
98 sal_Int32 nInt; // getInt
99 sal_Int64 nLong; // getLong
100 float nFloat; // getFloat
101 double nDouble; // getDouble
102
103 Sequence< sal_Int8 > aBytes; // getBytes
104 Date aDate; // getDate
105 Time aTime; // getTime
106 DateTime aTimestamp; // getTimestamp
107 Reference< XInputStream > xBinaryStream; // getBinaryStream
108 Reference< XInputStream > xCharacterStream; // getCharacterStream
109 Reference< XRef > xRef; // getRef
110 Reference< XBlob > xBlob; // getBlob
111 Reference< XClob > xClob; // getClob
112 Reference< XArray > xArray; // getArray
113 Any aObject; // getObject
114
PropertyValueucbhelper_impl::PropertyValue115 inline PropertyValue()
116 : nPropsSet( NO_VALUE_SET ), nOrigValue( NO_VALUE_SET ),
117 bBoolean(false),
118 nByte(0),
119 nShort(0),
120 nInt(0),
121 nLong(0),
122 nFloat(0.0),
123 nDouble(0.0)
124 {}
125 };
126 } // namespace ucbhelper_impl
127
128 using namespace ucbhelper_impl;
129
130 namespace ucbhelper
131 {
132
133 //=========================================================================
134 //
135 // class PropertyValues.
136 //
137 //=========================================================================
138
139 typedef std::vector< ucbhelper_impl::PropertyValue > PropertyValuesVector;
140
141 class PropertyValues : public PropertyValuesVector {};
142
143 } // namespace ucbhelper
144
145 //=========================================================================
146 //
147 // Welcome to the macro hell...
148 //
149 //=========================================================================
150
151 #define GETVALUE_IMPL_TYPE( _type_, _type_name_, _member_name_, _cppu_type_ ) \
152 \
153 osl::MutexGuard aGuard( m_aMutex ); \
154 \
155 _type_ aValue = _type_(); /* default ctor */ \
156 \
157 m_bWasNull = sal_True; \
158 \
159 if ( ( columnIndex < 1 ) \
160 || ( columnIndex > sal_Int32( m_pValues->size() ) ) ) \
161 { \
162 OSL_ENSURE( sal_False, "PropertyValueSet - index out of range!" ); \
163 } \
164 else \
165 { \
166 ucbhelper_impl::PropertyValue& rValue \
167 = (*m_pValues)[ columnIndex - 1 ]; \
168 \
169 if ( rValue.nOrigValue != NO_VALUE_SET ) \
170 { \
171 if ( rValue.nPropsSet & _type_name_ ) \
172 { \
173 /* Values is present natively... */ \
174 aValue = rValue._member_name_; \
175 m_bWasNull = sal_False; \
176 } \
177 else \
178 { \
179 if ( !(rValue.nPropsSet & OBJECT_VALUE_SET) ) \
180 { \
181 /* Value is not (yet) available as Any. Create it. */ \
182 getObject( columnIndex, Reference< XNameAccess >() ); \
183 } \
184 \
185 if ( rValue.nPropsSet & OBJECT_VALUE_SET ) \
186 { \
187 /* Value is available as Any. */ \
188 \
189 if ( rValue.aObject.hasValue() ) \
190 { \
191 /* Try to convert into native value. */ \
192 if ( rValue.aObject >>= aValue ) \
193 { \
194 rValue._member_name_ = aValue; \
195 rValue.nPropsSet |= _type_name_; \
196 m_bWasNull = sal_False; \
197 } \
198 else \
199 { \
200 /* Last chance. Try type converter service... */ \
201 \
202 Reference< XTypeConverter > xConverter \
203 = getTypeConverter(); \
204 if ( xConverter.is() ) \
205 { \
206 try \
207 { \
208 Any aConvAny = xConverter->convertTo( \
209 rValue.aObject, \
210 _cppu_type_ ); \
211 \
212 if ( aConvAny >>= aValue ) \
213 { \
214 rValue._member_name_ = aValue; \
215 rValue.nPropsSet |= _type_name_; \
216 m_bWasNull = sal_False; \
217 } \
218 } \
219 catch ( IllegalArgumentException ) \
220 { \
221 } \
222 catch ( CannotConvertException ) \
223 { \
224 } \
225 } \
226 } \
227 } \
228 } \
229 } \
230 } \
231 } \
232 return aValue;
233
234 #define GETVALUE_IMPL( _type_, _type_name_, _member_name_ ) \
235 GETVALUE_IMPL_TYPE( _type_, \
236 _type_name_, \
237 _member_name_, \
238 getCppuType( static_cast< const _type_ * >( 0 ) ) )
239
240 #define SETVALUE_IMPL( _prop_name_, _type_name_, _member_name_, _value_ ) \
241 \
242 osl::MutexGuard aGuard( m_aMutex ); \
243 \
244 ucbhelper_impl::PropertyValue aNewValue; \
245 aNewValue.sPropertyName = _prop_name_; \
246 aNewValue.nPropsSet = _type_name_; \
247 aNewValue.nOrigValue = _type_name_; \
248 aNewValue._member_name_ = _value_; \
249 \
250 m_pValues->push_back( aNewValue );
251
252 namespace ucbhelper {
253
254 //=========================================================================
255 //=========================================================================
256 //
257 // PropertyValueSet Implementation.
258 //
259 //=========================================================================
260 //=========================================================================
261
262 #define PROPERTYVALUESET_INIT() \
263 m_xSMgr( rxSMgr ), \
264 m_pValues( new PropertyValues ), \
265 m_bWasNull( sal_False ), \
266 m_bTriedToGetTypeConverter( sal_False )
267
268 //=========================================================================
PropertyValueSet(const Reference<XMultiServiceFactory> & rxSMgr)269 PropertyValueSet::PropertyValueSet(
270 const Reference< XMultiServiceFactory >& rxSMgr )
271 : PROPERTYVALUESET_INIT()
272 {
273 }
274
275 //=========================================================================
PropertyValueSet(const Reference<XMultiServiceFactory> & rxSMgr,const Sequence<com::sun::star::beans::PropertyValue> & rValues)276 PropertyValueSet::PropertyValueSet(
277 const Reference< XMultiServiceFactory >& rxSMgr,
278 const Sequence< com::sun::star::beans::PropertyValue >& rValues )
279 : PROPERTYVALUESET_INIT()
280 {
281 sal_Int32 nCount = rValues.getLength();
282 if ( nCount )
283 {
284 const com::sun::star::beans::PropertyValue* pValues
285 = rValues.getConstArray();
286
287 for ( sal_Int32 n = 0; n < nCount; ++n )
288 {
289 const com::sun::star::beans::PropertyValue& rValue = pValues[ n ];
290 appendObject( Property( rValue.Name,
291 rValue.Handle,
292 rValue.Value.getValueType(),
293 0 ),
294 rValue.Value );
295 }
296 }
297 }
298
299 //=========================================================================
300 // virtual
~PropertyValueSet()301 PropertyValueSet::~PropertyValueSet()
302 {
303 delete m_pValues;
304 }
305
306 //=========================================================================
307 //
308 // XInterface methods.
309 //
310 //=========================================================================
311
312 XINTERFACE_IMPL_3( PropertyValueSet,
313 XTypeProvider,
314 XRow,
315 XColumnLocate );
316
317 //=========================================================================
318 //
319 // XTypeProvider methods.
320 //
321 //=========================================================================
322
323 XTYPEPROVIDER_IMPL_3( PropertyValueSet,
324 XTypeProvider,
325 XRow,
326 XColumnLocate );
327
328 //=========================================================================
329 //
330 // XRow methods.
331 //
332 //=========================================================================
333
334 // virtual
wasNull()335 sal_Bool SAL_CALL PropertyValueSet::wasNull()
336 {
337 // This method can not be implemented correctly!!! Imagine different
338 // threads doing a getXYZ - wasNull calling sequence on the same
339 // implementation object...
340 return m_bWasNull;
341 }
342
343 //=========================================================================
344 // virtual
getString(sal_Int32 columnIndex)345 OUString SAL_CALL PropertyValueSet::getString( sal_Int32 columnIndex )
346 {
347 GETVALUE_IMPL( OUString, STRING_VALUE_SET, aString );
348 }
349
350 //=========================================================================
351 // virtual
getBoolean(sal_Int32 columnIndex)352 sal_Bool SAL_CALL PropertyValueSet::getBoolean( sal_Int32 columnIndex )
353 {
354 GETVALUE_IMPL_TYPE(
355 sal_Bool, BOOLEAN_VALUE_SET, bBoolean, getCppuBooleanType() );
356 }
357
358 //=========================================================================
359 // virtual
getByte(sal_Int32 columnIndex)360 sal_Int8 SAL_CALL PropertyValueSet::getByte( sal_Int32 columnIndex )
361 {
362 GETVALUE_IMPL( sal_Int8, BYTE_VALUE_SET, nByte );
363 }
364
365 //=========================================================================
366 // virtual
getShort(sal_Int32 columnIndex)367 sal_Int16 SAL_CALL PropertyValueSet::getShort( sal_Int32 columnIndex )
368 {
369 GETVALUE_IMPL( sal_Int16, SHORT_VALUE_SET, nShort );
370 }
371
372 //=========================================================================
373 // virtual
getInt(sal_Int32 columnIndex)374 sal_Int32 SAL_CALL PropertyValueSet::getInt( sal_Int32 columnIndex )
375 {
376 GETVALUE_IMPL( sal_Int32, INT_VALUE_SET, nInt );
377 }
378
379 //=========================================================================
380 // virtual
getLong(sal_Int32 columnIndex)381 sal_Int64 SAL_CALL PropertyValueSet::getLong( sal_Int32 columnIndex )
382 {
383 GETVALUE_IMPL( sal_Int64, LONG_VALUE_SET, nLong );
384 }
385
386 //=========================================================================
387 // virtual
getFloat(sal_Int32 columnIndex)388 float SAL_CALL PropertyValueSet::getFloat( sal_Int32 columnIndex )
389 {
390 GETVALUE_IMPL( float, FLOAT_VALUE_SET, nFloat );
391 }
392
393 //=========================================================================
394 // virtual
getDouble(sal_Int32 columnIndex)395 double SAL_CALL PropertyValueSet::getDouble( sal_Int32 columnIndex )
396 {
397 GETVALUE_IMPL( double, DOUBLE_VALUE_SET, nDouble );
398 }
399
400 //=========================================================================
401 // virtual
402 Sequence< sal_Int8 > SAL_CALL
getBytes(sal_Int32 columnIndex)403 PropertyValueSet::getBytes( sal_Int32 columnIndex )
404 {
405 GETVALUE_IMPL( Sequence< sal_Int8 >, BYTES_VALUE_SET, aBytes );
406 }
407
408 //=========================================================================
409 // virtual
getDate(sal_Int32 columnIndex)410 Date SAL_CALL PropertyValueSet::getDate( sal_Int32 columnIndex )
411 {
412 GETVALUE_IMPL( Date, DATE_VALUE_SET, aDate );
413 }
414
415 //=========================================================================
416 // virtual
getTime(sal_Int32 columnIndex)417 Time SAL_CALL PropertyValueSet::getTime( sal_Int32 columnIndex )
418 {
419 GETVALUE_IMPL( Time, TIME_VALUE_SET, aTime );
420 }
421
422 //=========================================================================
423 // virtual
getTimestamp(sal_Int32 columnIndex)424 DateTime SAL_CALL PropertyValueSet::getTimestamp( sal_Int32 columnIndex )
425 {
426 GETVALUE_IMPL( DateTime, TIMESTAMP_VALUE_SET, aTimestamp );
427 }
428
429 //=========================================================================
430 // virtual
431 Reference< XInputStream > SAL_CALL
getBinaryStream(sal_Int32 columnIndex)432 PropertyValueSet::getBinaryStream( sal_Int32 columnIndex )
433 {
434 GETVALUE_IMPL(
435 Reference< XInputStream >, BINARYSTREAM_VALUE_SET, xBinaryStream );
436 }
437
438 //=========================================================================
439 // virtual
440 Reference< XInputStream > SAL_CALL
getCharacterStream(sal_Int32 columnIndex)441 PropertyValueSet::getCharacterStream( sal_Int32 columnIndex )
442 {
443 GETVALUE_IMPL(
444 Reference< XInputStream >, CHARACTERSTREAM_VALUE_SET, xCharacterStream );
445 }
446
447 //=========================================================================
448 // virtual
getObject(sal_Int32 columnIndex,const Reference<XNameAccess> &)449 Any SAL_CALL PropertyValueSet::getObject(
450 sal_Int32 columnIndex,
451 const Reference< XNameAccess >& )
452 {
453 osl::MutexGuard aGuard( m_aMutex );
454
455 Any aValue;
456
457 m_bWasNull = sal_True;
458
459 if ( ( columnIndex < 1 )
460 || ( columnIndex > sal_Int32( m_pValues->size() ) ) )
461 {
462 OSL_ENSURE( sal_False, "PropertyValueSet - index out of range!" );
463 }
464 else
465 {
466 ucbhelper_impl::PropertyValue& rValue
467 = (*m_pValues)[ columnIndex - 1 ];
468
469 if ( rValue.nPropsSet & OBJECT_VALUE_SET )
470 {
471 // Values is present natively...
472 aValue = rValue.aObject;
473 m_bWasNull = sal_False;
474 }
475 else
476 {
477 // Make Any from original value.
478
479 switch ( rValue.nOrigValue )
480 {
481 case NO_VALUE_SET:
482 break;
483
484 case STRING_VALUE_SET:
485 aValue <<= rValue.aString;
486 break;
487
488 case BOOLEAN_VALUE_SET:
489 aValue <<= rValue.bBoolean;
490 break;
491
492 case BYTE_VALUE_SET:
493 aValue <<= rValue.nByte;
494 break;
495
496 case SHORT_VALUE_SET:
497 aValue <<= rValue.nShort;
498 break;
499
500 case INT_VALUE_SET:
501 aValue <<= rValue.nInt;
502 break;
503
504 case LONG_VALUE_SET:
505 aValue <<= rValue.nLong;
506 break;
507
508 case FLOAT_VALUE_SET:
509 aValue <<= rValue.nFloat;
510 break;
511
512 case DOUBLE_VALUE_SET:
513 aValue <<= rValue.nDouble;
514 break;
515
516 case BYTES_VALUE_SET:
517 aValue <<= rValue.aBytes;
518 break;
519
520 case DATE_VALUE_SET:
521 aValue <<= rValue.aDate;
522 break;
523
524 case TIME_VALUE_SET:
525 aValue <<= rValue.aTime;
526 break;
527
528 case TIMESTAMP_VALUE_SET:
529 aValue <<= rValue.aTimestamp;
530 break;
531
532 case BINARYSTREAM_VALUE_SET:
533 aValue <<= rValue.xBinaryStream;
534 break;
535
536 case CHARACTERSTREAM_VALUE_SET:
537 aValue <<= rValue.xCharacterStream;
538 break;
539
540 case REF_VALUE_SET:
541 aValue <<= rValue.xRef;
542 break;
543
544 case BLOB_VALUE_SET:
545 aValue <<= rValue.xBlob;
546 break;
547
548 case CLOB_VALUE_SET:
549 aValue <<= rValue.xClob;
550 break;
551
552 case ARRAY_VALUE_SET:
553 aValue <<= rValue.xArray;
554 break;
555
556 case OBJECT_VALUE_SET:
557 // Fall-through is intended!
558 default:
559 OSL_ENSURE( sal_False,
560 "PropertyValueSet::getObject - "
561 "Wrong original type" );
562 break;
563 }
564
565 if ( aValue.hasValue() )
566 {
567 rValue.aObject = aValue;
568 rValue.nPropsSet |= OBJECT_VALUE_SET;
569 m_bWasNull = sal_False;
570 }
571 }
572 }
573
574 return aValue;
575 }
576
577 //=========================================================================
578 // virtual
getRef(sal_Int32 columnIndex)579 Reference< XRef > SAL_CALL PropertyValueSet::getRef( sal_Int32 columnIndex )
580 {
581 GETVALUE_IMPL( Reference< XRef >, REF_VALUE_SET, xRef );
582 }
583
584 //=========================================================================
585 // virtual
getBlob(sal_Int32 columnIndex)586 Reference< XBlob > SAL_CALL PropertyValueSet::getBlob( sal_Int32 columnIndex )
587 {
588 GETVALUE_IMPL( Reference< XBlob >, BLOB_VALUE_SET, xBlob );
589 }
590
591 //=========================================================================
592 // virtual
getClob(sal_Int32 columnIndex)593 Reference< XClob > SAL_CALL PropertyValueSet::getClob( sal_Int32 columnIndex )
594 {
595 GETVALUE_IMPL( Reference< XClob >, CLOB_VALUE_SET, xClob );
596 }
597
598 //=========================================================================
599 // virtual
getArray(sal_Int32 columnIndex)600 Reference< XArray > SAL_CALL PropertyValueSet::getArray( sal_Int32 columnIndex )
601 {
602 GETVALUE_IMPL( Reference< XArray >, ARRAY_VALUE_SET, xArray );
603 }
604
605 //=========================================================================
606 //
607 // XColumnLocate methods.
608 //
609 //=========================================================================
610
611 // virtual
findColumn(const OUString & columnName)612 sal_Int32 SAL_CALL PropertyValueSet::findColumn( const OUString& columnName )
613 {
614 osl::MutexGuard aGuard( m_aMutex );
615
616 if ( columnName.getLength() )
617 {
618 sal_Int32 nCount = m_pValues->size();
619 for ( sal_Int32 n = 0; n < nCount; ++n )
620 {
621 if ( (*m_pValues)[ n ].sPropertyName.equals( columnName ) )
622 return sal_Int32( n + 1 ); // Index is 1-based.
623 }
624 }
625 return 0;
626 }
627
628 //=========================================================================
629 //
630 // Non-interface methods.
631 //
632 //=========================================================================
633
getTypeConverter()634 const Reference< XTypeConverter >& PropertyValueSet::getTypeConverter()
635 {
636 osl::MutexGuard aGuard( m_aMutex );
637
638 if ( !m_bTriedToGetTypeConverter && !m_xTypeConverter.is() )
639 {
640 m_bTriedToGetTypeConverter = sal_True;
641 m_xTypeConverter = Reference< XTypeConverter >(
642 m_xSMgr->createInstance(
643 OUString::createFromAscii(
644 "com.sun.star.script.Converter" ) ),
645 UNO_QUERY );
646
647 OSL_ENSURE( m_xTypeConverter.is(),
648 "PropertyValueSet::getTypeConverter() - "
649 "Service 'com.sun.star.script.Converter' n/a!" );
650 }
651 return m_xTypeConverter;
652 }
653
654 //=========================================================================
getLength() const655 sal_Int32 PropertyValueSet::getLength() const
656 {
657 return m_pValues->size();
658 }
659
660 //=========================================================================
appendString(const::rtl::OUString & rPropName,const OUString & rValue)661 void PropertyValueSet::appendString( const ::rtl::OUString& rPropName,
662 const OUString& rValue )
663 {
664 SETVALUE_IMPL( rPropName, STRING_VALUE_SET, aString, rValue );
665 }
666
667 //=========================================================================
appendBoolean(const::rtl::OUString & rPropName,sal_Bool bValue)668 void PropertyValueSet::appendBoolean( const ::rtl::OUString& rPropName,
669 sal_Bool bValue )
670 {
671 SETVALUE_IMPL( rPropName, BOOLEAN_VALUE_SET, bBoolean, bValue );
672 }
673
674 //=========================================================================
appendByte(const::rtl::OUString & rPropName,sal_Int8 nValue)675 void PropertyValueSet::appendByte( const ::rtl::OUString& rPropName,
676 sal_Int8 nValue )
677 {
678 SETVALUE_IMPL( rPropName, BYTE_VALUE_SET, nByte, nValue );
679 }
680
681 //=========================================================================
appendShort(const::rtl::OUString & rPropName,sal_Int16 nValue)682 void PropertyValueSet::appendShort( const ::rtl::OUString& rPropName,
683 sal_Int16 nValue )
684 {
685 SETVALUE_IMPL( rPropName, SHORT_VALUE_SET, nShort, nValue );
686 }
687
688 //=========================================================================
appendInt(const::rtl::OUString & rPropName,sal_Int32 nValue)689 void PropertyValueSet::appendInt( const ::rtl::OUString& rPropName,
690 sal_Int32 nValue )
691 {
692 SETVALUE_IMPL( rPropName, INT_VALUE_SET, nInt, nValue );
693 }
694
695 //=========================================================================
appendLong(const::rtl::OUString & rPropName,sal_Int64 nValue)696 void PropertyValueSet::appendLong( const ::rtl::OUString& rPropName,
697 sal_Int64 nValue )
698 {
699 SETVALUE_IMPL( rPropName, LONG_VALUE_SET, nLong, nValue );
700 }
701
702 //=========================================================================
appendFloat(const::rtl::OUString & rPropName,float nValue)703 void PropertyValueSet::appendFloat( const ::rtl::OUString& rPropName,
704 float nValue )
705 {
706 SETVALUE_IMPL( rPropName, FLOAT_VALUE_SET, nFloat, nValue );
707 }
708
709 //=========================================================================
appendDouble(const::rtl::OUString & rPropName,double nValue)710 void PropertyValueSet::appendDouble( const ::rtl::OUString& rPropName,
711 double nValue )
712 {
713 SETVALUE_IMPL( rPropName, DOUBLE_VALUE_SET, nDouble, nValue );
714 }
715
716 //=========================================================================
appendBytes(const::rtl::OUString & rPropName,const Sequence<sal_Int8> & rValue)717 void PropertyValueSet::appendBytes( const ::rtl::OUString& rPropName,
718 const Sequence< sal_Int8 >& rValue )
719 {
720 SETVALUE_IMPL( rPropName, BYTES_VALUE_SET, aBytes, rValue );
721 }
722
723 //=========================================================================
appendDate(const::rtl::OUString & rPropName,const Date & rValue)724 void PropertyValueSet::appendDate( const ::rtl::OUString& rPropName,
725 const Date& rValue )
726 {
727 SETVALUE_IMPL( rPropName, DATE_VALUE_SET, aDate, rValue );
728 }
729
730 //=========================================================================
appendTime(const::rtl::OUString & rPropName,const Time & rValue)731 void PropertyValueSet::appendTime( const ::rtl::OUString& rPropName,
732 const Time& rValue )
733 {
734 SETVALUE_IMPL( rPropName, TIME_VALUE_SET, aTime, rValue );
735 }
736
737 //=========================================================================
appendTimestamp(const::rtl::OUString & rPropName,const DateTime & rValue)738 void PropertyValueSet::appendTimestamp( const ::rtl::OUString& rPropName,
739 const DateTime& rValue )
740 {
741 SETVALUE_IMPL( rPropName, TIMESTAMP_VALUE_SET, aTimestamp, rValue );
742 }
743
744 //=========================================================================
appendBinaryStream(const::rtl::OUString & rPropName,const Reference<XInputStream> & rValue)745 void PropertyValueSet::appendBinaryStream(
746 const ::rtl::OUString& rPropName,
747 const Reference< XInputStream >& rValue )
748 {
749 SETVALUE_IMPL( rPropName, BINARYSTREAM_VALUE_SET, xBinaryStream, rValue );
750 }
751
752 //=========================================================================
appendCharacterStream(const::rtl::OUString & rPropName,const Reference<XInputStream> & rValue)753 void PropertyValueSet::appendCharacterStream(
754 const ::rtl::OUString& rPropName,
755 const Reference< XInputStream >& rValue )
756 {
757 SETVALUE_IMPL( rPropName, CHARACTERSTREAM_VALUE_SET, xCharacterStream, rValue );
758 }
759
760 //=========================================================================
appendObject(const::rtl::OUString & rPropName,const Any & rValue)761 void PropertyValueSet::appendObject( const ::rtl::OUString& rPropName,
762 const Any& rValue )
763 {
764 SETVALUE_IMPL( rPropName, OBJECT_VALUE_SET, aObject, rValue );
765 }
766
767 //=========================================================================
appendRef(const::rtl::OUString & rPropName,const Reference<XRef> & rValue)768 void PropertyValueSet::appendRef( const ::rtl::OUString& rPropName,
769 const Reference< XRef >& rValue )
770 {
771 SETVALUE_IMPL( rPropName, REF_VALUE_SET, xRef, rValue );
772 }
773
774 //=========================================================================
appendBlob(const::rtl::OUString & rPropName,const Reference<XBlob> & rValue)775 void PropertyValueSet::appendBlob( const ::rtl::OUString& rPropName,
776 const Reference< XBlob >& rValue )
777 {
778 SETVALUE_IMPL( rPropName, BLOB_VALUE_SET, xBlob, rValue );
779 }
780
781 //=========================================================================
appendClob(const::rtl::OUString & rPropName,const Reference<XClob> & rValue)782 void PropertyValueSet::appendClob( const ::rtl::OUString& rPropName,
783 const Reference< XClob >& rValue )
784 {
785 SETVALUE_IMPL( rPropName, CLOB_VALUE_SET, xClob, rValue );
786 }
787
788 //=========================================================================
appendArray(const::rtl::OUString & rPropName,const Reference<XArray> & rValue)789 void PropertyValueSet::appendArray( const ::rtl::OUString& rPropName,
790 const Reference< XArray >& rValue )
791 {
792 SETVALUE_IMPL( rPropName, ARRAY_VALUE_SET, xArray, rValue );
793 }
794
795 //=========================================================================
appendVoid(const::rtl::OUString & rPropName)796 void PropertyValueSet::appendVoid( const ::rtl::OUString& rPropName )
797 {
798 SETVALUE_IMPL( rPropName, NO_VALUE_SET, aObject, Any() );
799 }
800
801 //=========================================================================
appendPropertySet(const Reference<XPropertySet> & rxSet)802 void PropertyValueSet::appendPropertySet(
803 const Reference< XPropertySet >& rxSet )
804 {
805 if ( rxSet.is() )
806 {
807 Reference< XPropertySetInfo > xInfo = rxSet->getPropertySetInfo();
808 if ( xInfo.is() )
809 {
810 Sequence< Property > aProps = xInfo->getProperties();
811 const Property* pProps = aProps.getConstArray();
812 sal_Int32 nPropsCount = aProps.getLength();
813
814 Reference< XPropertyAccess > xPropertyAccess( rxSet, UNO_QUERY );
815 if ( xPropertyAccess.is() )
816 {
817 // Efficient: Get all prop values with one ( remote) call.
818
819 Sequence< ::com::sun::star::beans::PropertyValue > aPropValues
820 = xPropertyAccess->getPropertyValues();
821
822 const ::com::sun::star::beans::PropertyValue* pPropValues
823 = aPropValues.getConstArray();
824
825 sal_Int32 nValuesCount = aPropValues.getLength();
826 for ( sal_Int32 n = 0; n < nValuesCount; ++n )
827 {
828 const ::com::sun::star::beans::PropertyValue& rPropValue
829 = pPropValues[ n ];
830
831 // Find info for current property value.
832 for ( sal_Int32 m = 0; m < nPropsCount; ++m )
833 {
834 const Property& rProp = pProps[ m ];
835 if ( rProp.Name == rPropValue.Name )
836 {
837 // Found!
838 appendObject( rProp, rPropValue.Value );
839 break;
840 }
841 }
842 }
843 }
844 else
845 {
846 // Get every single prop value with one ( remote) call.
847
848 for ( sal_Int32 n = 0; n < nPropsCount; ++n )
849 {
850 const Property& rProp = pProps[ n ];
851
852 try
853 {
854 Any aValue = rxSet->getPropertyValue( rProp.Name );
855
856 if ( aValue.hasValue() )
857 appendObject( rProp, aValue );
858 }
859 catch ( UnknownPropertyException )
860 {
861 }
862 catch ( WrappedTargetException )
863 {
864 }
865 }
866 }
867 }
868 }
869 }
870
871 //=========================================================================
appendPropertySetValue(const Reference<XPropertySet> & rxSet,const Property & rProperty)872 sal_Bool PropertyValueSet::appendPropertySetValue(
873 const Reference< XPropertySet >& rxSet,
874 const Property& rProperty )
875 {
876 if ( rxSet.is() )
877 {
878 try
879 {
880 Any aValue = rxSet->getPropertyValue( rProperty.Name );
881 if ( aValue.hasValue() )
882 {
883 appendObject( rProperty, aValue );
884 return sal_True;
885 }
886 }
887 catch ( UnknownPropertyException )
888 {
889 }
890 catch ( WrappedTargetException )
891 {
892 }
893 }
894
895 // Error.
896 return sal_False;
897 }
898
899 } // namespace ucbhelper
900