Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : /**************************************************************************
31 : : TODO
32 : : **************************************************************************
33 : :
34 : : *************************************************************************/
35 : :
36 : : #include <list>
37 : : #include <boost/unordered_map.hpp>
38 : : #include <osl/diagnose.h>
39 : : #include <rtl/ustrbuf.hxx>
40 : : #include <cppuhelper/interfacecontainer.hxx>
41 : : #include <com/sun/star/beans/PropertyAttribute.hpp>
42 : : #include <com/sun/star/beans/PropertySetInfoChange.hpp>
43 : : #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
44 : : #include <com/sun/star/container/XNameContainer.hpp>
45 : : #include <com/sun/star/container/XNameReplace.hpp>
46 : : #include <com/sun/star/util/XChangesBatch.hpp>
47 : : #include "ucbstore.hxx"
48 : :
49 : : using namespace com::sun::star::beans;
50 : : using namespace com::sun::star::container;
51 : : using namespace com::sun::star::lang;
52 : : using namespace com::sun::star::ucb;
53 : : using namespace com::sun::star::uno;
54 : : using namespace com::sun::star::util;
55 : : using namespace cppu;
56 : :
57 : : using ::rtl::OUString;
58 : : using ::rtl::OUStringBuffer;
59 : :
60 : : //=========================================================================
61 : 156 : OUString makeHierarchalNameSegment( const OUString & rIn )
62 : : {
63 : 156 : OUStringBuffer aBuffer;
64 [ + - ]: 156 : aBuffer.appendAscii( "['" );
65 : :
66 : 156 : sal_Int32 nCount = rIn.getLength();
67 [ + + ]: 8840 : for ( sal_Int32 n = 0; n < nCount; ++n )
68 : : {
69 : 8684 : const sal_Unicode c = rIn.getStr()[ n ];
70 [ - - - - : 8684 : switch ( c )
- + ]
71 : : {
72 : : case '&':
73 [ # # ]: 0 : aBuffer.appendAscii( "&" );
74 : 0 : break;
75 : :
76 : : case '"':
77 [ # # ]: 0 : aBuffer.appendAscii( """ );
78 : 0 : break;
79 : :
80 : : case '\'':
81 [ # # ]: 0 : aBuffer.appendAscii( "'" );
82 : 0 : break;
83 : :
84 : : case '<':
85 [ # # ]: 0 : aBuffer.appendAscii( "<" );
86 : 0 : break;
87 : :
88 : : case '>':
89 [ # # ]: 0 : aBuffer.appendAscii( ">" );
90 : 0 : break;
91 : :
92 : : default:
93 [ + - ]: 8684 : aBuffer.append( c );
94 : 8684 : break;
95 : : }
96 : : }
97 : :
98 [ + - ]: 156 : aBuffer.appendAscii( "']" );
99 [ + - ]: 156 : return OUString( aBuffer.makeStringAndClear() );
100 : : }
101 : :
102 : : //=========================================================================
103 : :
104 : : #define STORE_CONTENTPROPERTIES_KEY "/org.openoffice.ucb.Store/ContentProperties"
105 : :
106 : : // describe path of cfg entry
107 : : #define CFGPROPERTY_NODEPATH "nodepath"
108 : : // true->async. update; false->sync. update
109 : : #define CFGPROPERTY_LAZYWRITE "lazywrite"
110 : :
111 : : //=========================================================================
112 : :
113 : : struct equalString_Impl
114 : : {
115 : 72 : bool operator()( const OUString& s1, const OUString& s2 ) const
116 : : {
117 : 72 : return !!( s1 == s2 );
118 : : }
119 : : };
120 : :
121 : : struct hashString_Impl
122 : : {
123 : 144 : size_t operator()( const OUString & rName ) const
124 : : {
125 : 144 : return rName.hashCode();
126 : : }
127 : : };
128 : :
129 : : //=========================================================================
130 : : //
131 : : // PropertySetMap_Impl.
132 : : //
133 : : //=========================================================================
134 : :
135 : : typedef boost::unordered_map
136 : : <
137 : : OUString,
138 : : PersistentPropertySet*,
139 : : hashString_Impl,
140 : : equalString_Impl
141 : : >
142 : : PropertySetMap_Impl;
143 : :
144 : : //=========================================================================
145 : : //
146 : : // class PropertySetInfo_Impl
147 : : //
148 : : //=========================================================================
149 : :
150 : : class PropertySetInfo_Impl :
151 : : public OWeakObject, public XTypeProvider, public XPropertySetInfo
152 : : {
153 : : Reference< XMultiServiceFactory > m_xSMgr;
154 : : Sequence< Property >* m_pProps;
155 : : PersistentPropertySet* m_pOwner;
156 : :
157 : : public:
158 : : PropertySetInfo_Impl( const Reference< XMultiServiceFactory >& rxSMgr,
159 : : PersistentPropertySet* pOwner );
160 : : virtual ~PropertySetInfo_Impl();
161 : :
162 : : // XInterface
163 : : XINTERFACE_DECL()
164 : :
165 : : // XTypeProvider
166 : : XTYPEPROVIDER_DECL()
167 : :
168 : : // XPropertySetInfo
169 : : virtual Sequence< Property > SAL_CALL getProperties()
170 : : throw( RuntimeException );
171 : : virtual Property SAL_CALL getPropertyByName( const OUString& aName )
172 : : throw( UnknownPropertyException, RuntimeException );
173 : : virtual sal_Bool SAL_CALL hasPropertyByName( const OUString& Name )
174 : : throw( RuntimeException );
175 : :
176 : : // Non-interface methods.
177 [ # # ]: 0 : void reset() { delete m_pProps; m_pProps = 0; }
178 : : };
179 : :
180 : : //=========================================================================
181 : : //
182 : : // UcbStore_Impl.
183 : : //
184 : : //=========================================================================
185 : :
186 [ + - ][ + - ]: 472 : struct UcbStore_Impl
187 : : {
188 : : osl::Mutex m_aMutex;
189 : : Sequence< Any > m_aInitArgs;
190 : : Reference< XPropertySetRegistry > m_xTheRegistry;
191 : : };
192 : :
193 : : //=========================================================================
194 : : //=========================================================================
195 : : //=========================================================================
196 : : //
197 : : // UcbStore Implementation.
198 : : //
199 : : //=========================================================================
200 : : //=========================================================================
201 : : //=========================================================================
202 : :
203 : 236 : UcbStore::UcbStore( const Reference< XMultiServiceFactory >& rXSMgr )
204 : : : m_xSMgr( rXSMgr ),
205 [ + - ][ + - ]: 236 : m_pImpl( new UcbStore_Impl() )
206 : : {
207 : 236 : }
208 : :
209 : : //=========================================================================
210 : : // virtual
211 : 236 : UcbStore::~UcbStore()
212 : : {
213 [ + - ][ + - ]: 236 : delete m_pImpl;
214 [ - + ]: 472 : }
215 : :
216 : : //=========================================================================
217 : : //
218 : : // XInterface methods.
219 : : //
220 : : //=========================================================================
221 : :
222 [ + - ][ + + ]: 7680 : XINTERFACE_IMPL_4( UcbStore,
[ + - ]
223 : : XTypeProvider,
224 : : XServiceInfo,
225 : : XPropertySetRegistryFactory,
226 : : XInitialization );
227 : :
228 : : //=========================================================================
229 : : //
230 : : // XTypeProvider methods.
231 : : //
232 : : //=========================================================================
233 : :
234 [ # # ][ # # ]: 0 : XTYPEPROVIDER_IMPL_4( UcbStore,
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
235 : : XTypeProvider,
236 : : XServiceInfo,
237 : : XPropertySetRegistryFactory,
238 : : XInitialization );
239 : :
240 : : //=========================================================================
241 : : //
242 : : // XServiceInfo methods.
243 : : //
244 : : //=========================================================================
245 : :
246 [ + - ][ + - ]: 1209 : XSERVICEINFO_IMPL_1( UcbStore,
[ + - ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
247 : : OUString( "com.sun.star.comp.ucb.UcbStore" ),
248 : 236 : OUString( STORE_SERVICE_NAME ) );
249 : :
250 : : //=========================================================================
251 : : //
252 : : // Service factory implementation.
253 : : //
254 : : //=========================================================================
255 : :
256 [ + - ][ + - ]: 236 : ONE_INSTANCE_SERVICE_FACTORY_IMPL( UcbStore );
257 : :
258 : : //=========================================================================
259 : : //
260 : : // XPropertySetRegistryFactory methods.
261 : : //
262 : : //=========================================================================
263 : :
264 : : // virtual
265 : : Reference< XPropertySetRegistry > SAL_CALL
266 : 820 : UcbStore::createPropertySetRegistry( const OUString& )
267 : : throw( RuntimeException )
268 : : {
269 : : // The URL parameter is ignored by this interface implementation. It always
270 : : // uses the configuration server as storage medium.
271 : :
272 [ + + ]: 820 : if ( !m_pImpl->m_xTheRegistry.is() )
273 : : {
274 [ + - ]: 236 : osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
275 [ + - ]: 236 : if ( !m_pImpl->m_xTheRegistry.is() )
276 [ + - ][ + - ]: 236 : m_pImpl->m_xTheRegistry = new PropertySetRegistry( m_xSMgr, getInitArgs() );
[ + - ][ + - ]
277 : : }
278 : :
279 : 820 : return m_pImpl->m_xTheRegistry;
280 : : }
281 : :
282 : : //=========================================================================
283 : : //
284 : : // XInitialization methods.
285 : : //
286 : : //=========================================================================
287 : :
288 : : // virtual
289 : 0 : void SAL_CALL UcbStore::initialize( const Sequence< Any >& aArguments )
290 : : throw( Exception, RuntimeException )
291 : : {
292 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
293 [ # # ][ # # ]: 0 : m_pImpl->m_aInitArgs = aArguments;
294 : 0 : }
295 : :
296 : : //=========================================================================
297 : 236 : const Sequence< Any >& UcbStore::getInitArgs() const
298 : : {
299 : 236 : return m_pImpl->m_aInitArgs;
300 : : }
301 : :
302 : : //=========================================================================
303 : : //
304 : : // PropertySetRegistry_Impl.
305 : : //
306 : : //=========================================================================
307 : :
308 [ + - ][ + - ]: 209 : struct PropertySetRegistry_Impl
309 : : {
310 : : const Sequence< Any > m_aInitArgs;
311 : : PropertySetMap_Impl m_aPropSets;
312 : : Reference< XMultiServiceFactory > m_xConfigProvider;
313 : : Reference< XInterface > m_xRootReadAccess;
314 : : Reference< XInterface > m_xRootWriteAccess;
315 : : osl::Mutex m_aMutex;
316 : : sal_Bool m_bTriedToGetRootReadAccess; // #82494#
317 : : sal_Bool m_bTriedToGetRootWriteAccess; // #82494#
318 : :
319 : 236 : PropertySetRegistry_Impl( const Sequence< Any > &rInitArgs )
320 : : : m_aInitArgs( rInitArgs ),
321 : : m_bTriedToGetRootReadAccess( sal_False ),
322 [ + - ][ + - ]: 236 : m_bTriedToGetRootWriteAccess( sal_False )
323 : : {
324 : 236 : }
325 : : };
326 : :
327 : : //=========================================================================
328 : : //=========================================================================
329 : : //=========================================================================
330 : : //
331 : : // PropertySetRegistry Implementation.
332 : : //
333 : : //=========================================================================
334 : : //=========================================================================
335 : : //=========================================================================
336 : :
337 : 236 : PropertySetRegistry::PropertySetRegistry(
338 : : const Reference< XMultiServiceFactory >& rXSMgr,
339 : : const Sequence< Any > &rInitArgs )
340 : : : m_xSMgr( rXSMgr ),
341 [ + - ][ + - ]: 236 : m_pImpl( new PropertySetRegistry_Impl( rInitArgs ) )
342 : : {
343 : 236 : }
344 : :
345 : : //=========================================================================
346 : : // virtual
347 : 209 : PropertySetRegistry::~PropertySetRegistry()
348 : : {
349 [ + - ][ + - ]: 209 : delete m_pImpl;
350 [ - + ]: 418 : }
351 : :
352 : : //=========================================================================
353 : : //
354 : : // XInterface methods.
355 : : //
356 : : //=========================================================================
357 : :
358 [ + - ][ + + ]: 4314 : XINTERFACE_IMPL_5( PropertySetRegistry,
[ + - ]
359 : : XTypeProvider,
360 : : XServiceInfo,
361 : : XPropertySetRegistry,
362 : : XElementAccess, /* base of XNameAccess */
363 : : XNameAccess );
364 : :
365 : : //=========================================================================
366 : : //
367 : : // XTypeProvider methods.
368 : : //
369 : : //=========================================================================
370 : :
371 [ # # ][ # # ]: 0 : XTYPEPROVIDER_IMPL_4( PropertySetRegistry,
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
372 : : XTypeProvider,
373 : : XServiceInfo,
374 : : XPropertySetRegistry,
375 : : XNameAccess );
376 : :
377 : : //=========================================================================
378 : : //
379 : : // XServiceInfo methods.
380 : : //
381 : : //=========================================================================
382 : :
383 [ # # ][ # # ]: 0 : XSERVICEINFO_NOFACTORY_IMPL_1( PropertySetRegistry,
[ # # ][ # # ]
[ # # ][ # # ]
384 : : OUString( "com.sun.star.comp.ucb.PropertySetRegistry" ),
385 : : OUString( PROPSET_REG_SERVICE_NAME ) );
386 : :
387 : : //=========================================================================
388 : : //
389 : : // XPropertySetRegistry methods.
390 : : //
391 : : //=========================================================================
392 : :
393 : : // virtual
394 : : Reference< XPersistentPropertySet > SAL_CALL
395 : 107312 : PropertySetRegistry::openPropertySet( const OUString& key, sal_Bool create )
396 : : throw( RuntimeException )
397 : : {
398 [ + - ]: 107312 : if ( !key.isEmpty() )
399 : : {
400 [ + - ]: 107312 : osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
401 : :
402 : 107312 : PropertySetMap_Impl& rSets = m_pImpl->m_aPropSets;
403 : :
404 [ + - ]: 107312 : PropertySetMap_Impl::const_iterator it = rSets.find( key );
405 [ - + ][ + - ]: 107312 : if ( it != rSets.end() )
406 : : {
407 : : // Already instanciated.
408 [ # # ][ # # ]: 0 : return Reference< XPersistentPropertySet >( (*it).second );
[ # # ]
409 : : }
410 : : else
411 : : {
412 : : // Create new instance.
413 : : Reference< XNameAccess > xRootNameAccess(
414 [ + - ][ + - ]: 107312 : getRootConfigReadAccess(), UNO_QUERY );
415 [ + - ]: 107312 : if ( xRootNameAccess.is() )
416 : : {
417 : : // Propertyset in registry?
418 [ + - ][ + - ]: 107312 : if ( xRootNameAccess->hasByName( key ) )
[ + + ]
419 : : {
420 : : // Yep!
421 : : return Reference< XPersistentPropertySet >(
422 : : new PersistentPropertySet(
423 [ + - ][ + - ]: 44 : m_xSMgr, *this, key ) );
[ + - ]
424 : : }
425 [ + + ]: 107268 : else if ( create )
426 : : {
427 : : // No. Create entry for propertyset.
428 : :
429 : : Reference< XSingleServiceFactory > xFac(
430 [ + - ][ + - ]: 28 : getConfigWriteAccess( OUString() ), UNO_QUERY );
431 [ + - ]: 28 : Reference< XChangesBatch > xBatch( xFac, UNO_QUERY );
432 [ + - ]: 28 : Reference< XNameContainer > xContainer( xFac, UNO_QUERY );
433 : :
434 : : OSL_ENSURE( xFac.is(),
435 : : "PropertySetRegistry::openPropertySet - "
436 : : "No factory!" );
437 : :
438 : : OSL_ENSURE( xBatch.is(),
439 : : "PropertySetRegistry::openPropertySet - "
440 : : "No batch!" );
441 : :
442 : : OSL_ENSURE( xContainer.is(),
443 : : "PropertySetRegistry::openPropertySet - "
444 : : "No conteiner!" );
445 : :
446 [ + - ][ + - ]: 28 : if ( xFac.is() && xBatch.is() && xContainer.is() )
[ + - ][ + - ]
447 : : {
448 : : try
449 : : {
450 : : // Create new "Properties" config item.
451 : : Reference< XNameReplace > xNameReplace(
452 [ + - ][ + - ]: 28 : xFac->createInstance(), UNO_QUERY );
[ + - ]
453 : :
454 [ + - ]: 28 : if ( xNameReplace.is() )
455 : : {
456 : : // Fill new item...
457 : :
458 : : // // Set Values
459 : : // xNameReplace->replaceByName(
460 : : // OUString("Values"),
461 : : // makeAny( ... ) );
462 : :
463 : : // Insert new item.
464 [ + - ]: 28 : xContainer->insertByName(
465 [ + - ][ + - ]: 28 : key, makeAny( xNameReplace ) );
466 : : // Commit changes.
467 [ + - ][ + - ]: 28 : xBatch->commitChanges();
468 : :
469 : : return Reference< XPersistentPropertySet >(
470 : : new PersistentPropertySet(
471 [ + - ][ + - ]: 28 : m_xSMgr, *this, key ) );
[ + - ]
472 [ - + ][ # # : 28 : }
# # # # ]
473 : : }
474 [ # # ]: 0 : catch (const IllegalArgumentException&)
475 : : {
476 : : // insertByName
477 : :
478 : : OSL_FAIL( "PropertySetRegistry::openPropertySet - "
479 : : "caught IllegalArgumentException!" );
480 : : }
481 [ # # ]: 0 : catch (const ElementExistException&)
482 : : {
483 : : // insertByName
484 : :
485 : : OSL_FAIL( "PropertySetRegistry::openPropertySet - "
486 : : "caught ElementExistException!" );
487 : : }
488 [ # # ]: 0 : catch (const WrappedTargetException&)
489 : : {
490 : : // insertByName, commitChanges
491 : :
492 : : OSL_FAIL( "PropertySetRegistry::openPropertySet - "
493 : : "caught WrappedTargetException!" );
494 : : }
495 [ # # ]: 0 : catch (const RuntimeException&)
496 : : {
497 : : OSL_FAIL( "PropertySetRegistry::openPropertySet - "
498 : : "caught RuntimeException!" );
499 : : }
500 [ # # ]: 0 : catch (const Exception&)
501 : : {
502 : : // createInstance
503 : :
504 : : OSL_FAIL( "PropertySetRegistry::openPropertySet - "
505 : : "caught Exception!" );
506 : : }
507 [ + - ][ + - ]: 28 : }
[ - + ]
508 : : }
509 : : else
510 : : {
511 : : // No entry. Fail, but no error.
512 : 107240 : return Reference< XPersistentPropertySet >();
513 : : }
514 : : }
515 : :
516 [ - + ]: 107312 : OSL_TRACE( "PropertySetRegistry::openPropertySet no root access" );
517 [ + - ][ - + ]: 107312 : }
518 : : }
519 : :
520 : 107312 : return Reference< XPersistentPropertySet >();
521 : : }
522 : :
523 : : //=========================================================================
524 : : // virtual
525 : 4244 : void SAL_CALL PropertySetRegistry::removePropertySet( const OUString& key )
526 : : throw( RuntimeException )
527 : : {
528 [ + - ]: 4244 : if ( key.isEmpty() )
529 : : return;
530 : :
531 [ + - ]: 4244 : osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
532 : :
533 : : Reference< XNameAccess > xRootNameAccess(
534 [ + - ][ + - ]: 4244 : getRootConfigReadAccess(), UNO_QUERY );
535 [ + - ]: 4244 : if ( xRootNameAccess.is() )
536 : : {
537 : : // Propertyset in registry?
538 [ + - ][ + - ]: 4244 : if ( !xRootNameAccess->hasByName( key ) )
[ - + ]
539 : : return;
540 : : Reference< XChangesBatch > xBatch(
541 [ # # ][ # # ]: 0 : getConfigWriteAccess( OUString() ), UNO_QUERY );
[ # # # ]
542 [ # # ]: 0 : Reference< XNameContainer > xContainer( xBatch, UNO_QUERY );
543 : :
544 [ # # ][ # # ]: 0 : if ( xBatch.is() && xContainer.is() )
[ # # ]
545 : : {
546 : : try
547 : : {
548 : : // Remove item.
549 [ # # ][ # # ]: 0 : xContainer->removeByName( key );
550 : : // Commit changes.
551 [ # # ][ # # ]: 0 : xBatch->commitChanges();
552 : :
553 : : // Success.
554 : : return;
555 : : }
556 [ # # ]: 0 : catch (const NoSuchElementException&)
557 : : {
558 : : // removeByName
559 : :
560 : : OSL_FAIL( "PropertySetRegistry::removePropertySet - "
561 : : "caught NoSuchElementException!" );
562 : : return;
563 : : }
564 [ # # ]: 0 : catch (const WrappedTargetException&)
565 : : {
566 : : // commitChanges
567 : :
568 : : OSL_FAIL( "PropertySetRegistry::removePropertySet - "
569 : : "caught WrappedTargetException!" );
570 : : return;
571 : : }
572 : : }
573 : :
574 : 4244 : return;
575 : : }
576 : :
577 [ + - ][ + - ]: 4244 : OSL_TRACE( "PropertySetRegistry::removePropertySet - no root access" );
[ - + ]
578 : : }
579 : :
580 : : //=========================================================================
581 : : //
582 : : // XElementAccess methods.
583 : : //
584 : : //=========================================================================
585 : :
586 : : // virtual
587 : 0 : com::sun::star::uno::Type SAL_CALL PropertySetRegistry::getElementType()
588 : : throw( RuntimeException )
589 : : {
590 : 0 : return getCppuType( ( Reference< XPersistentPropertySet > * ) 0 );
591 : : }
592 : :
593 : : //=========================================================================
594 : : // virtual
595 : 0 : sal_Bool SAL_CALL PropertySetRegistry::hasElements()
596 : : throw( RuntimeException )
597 : : {
598 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
599 : :
600 : : Reference< XElementAccess > xElemAccess(
601 [ # # ][ # # ]: 0 : getRootConfigReadAccess(), UNO_QUERY );
602 [ # # ]: 0 : if ( xElemAccess.is() )
603 [ # # ][ # # ]: 0 : return xElemAccess->hasElements();
604 : :
605 [ # # ]: 0 : return sal_False;
606 : : }
607 : :
608 : : //=========================================================================
609 : : //
610 : : // XNameAccess methods.
611 : : //
612 : : //=========================================================================
613 : :
614 : : // virtual
615 : 0 : Any SAL_CALL PropertySetRegistry::getByName( const OUString& aName )
616 : : throw( NoSuchElementException, WrappedTargetException, RuntimeException )
617 : : {
618 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
619 : :
620 : : Reference< XNameAccess > xNameAccess(
621 [ # # ][ # # ]: 0 : getRootConfigReadAccess(), UNO_QUERY );
[ # # # ]
622 [ # # ]: 0 : if ( xNameAccess.is() )
623 : : {
624 : :
625 : : try
626 : : {
627 [ # # ][ # # ]: 0 : return xNameAccess->getByName( aName );
628 : : }
629 [ # # ]: 0 : catch (const NoSuchElementException&)
630 : : {
631 : : // getByName
632 : : }
633 [ # # ]: 0 : catch (const WrappedTargetException&)
634 : : {
635 : : // getByName
636 : : }
637 : : }
638 : :
639 [ # # ]: 0 : return Any();
640 : : }
641 : :
642 : : //=========================================================================
643 : : // virtual
644 : 2 : Sequence< OUString > SAL_CALL PropertySetRegistry::getElementNames()
645 : : throw( RuntimeException )
646 : : {
647 [ + - ]: 2 : osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
648 : :
649 : : Reference< XNameAccess > xNameAccess(
650 [ + - ][ + - ]: 2 : getRootConfigReadAccess(), UNO_QUERY );
651 [ + - ]: 2 : if ( xNameAccess.is() )
652 : : {
653 [ + - ][ + - ]: 2 : return xNameAccess->getElementNames();
654 : : }
655 [ # # ][ + - ]: 2 : return Sequence< OUString >( 0 );
656 : : }
657 : :
658 : : //=========================================================================
659 : : // virtual
660 : 0 : sal_Bool SAL_CALL PropertySetRegistry::hasByName( const OUString& aName )
661 : : throw( RuntimeException )
662 : : {
663 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
664 : :
665 : : Reference< XNameAccess > xNameAccess(
666 [ # # ][ # # ]: 0 : getRootConfigReadAccess(), UNO_QUERY );
667 [ # # ]: 0 : if ( xNameAccess.is() )
668 : : {
669 [ # # ][ # # ]: 0 : return xNameAccess->hasByName( aName );
670 : : }
671 : :
672 [ # # ]: 0 : return sal_False;
673 : : }
674 : :
675 : : //=========================================================================
676 : 72 : void PropertySetRegistry::add( PersistentPropertySet* pSet )
677 : : {
678 [ + - ]: 72 : OUString key( pSet->getKey() );
679 : :
680 [ + - ]: 72 : if ( !key.isEmpty() )
681 : : {
682 [ + - ]: 72 : osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
683 [ + - ][ + - ]: 72 : m_pImpl->m_aPropSets[ key ] = pSet;
684 : 72 : }
685 : 72 : }
686 : :
687 : : //=========================================================================
688 : 72 : void PropertySetRegistry::remove( PersistentPropertySet* pSet )
689 : : {
690 [ + - ]: 72 : OUString key( pSet->getKey() );
691 : :
692 [ + - ]: 72 : if ( !key.isEmpty() )
693 : : {
694 [ + - ]: 72 : osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
695 : :
696 : 72 : PropertySetMap_Impl& rSets = m_pImpl->m_aPropSets;
697 : :
698 [ + - ]: 72 : PropertySetMap_Impl::iterator it = rSets.find( key );
699 [ + - ][ + - ]: 72 : if ( it != rSets.end() )
700 : : {
701 : : // Found.
702 [ + - ]: 72 : rSets.erase( it );
703 [ + - ]: 72 : }
704 : 72 : }
705 : 72 : }
706 : :
707 : : //=========================================================================
708 : 0 : void PropertySetRegistry::renamePropertySet( const OUString& rOldKey,
709 : : const OUString& rNewKey )
710 : : {
711 [ # # ]: 0 : if ( rOldKey == rNewKey )
712 : : return;
713 : :
714 : : Reference< XNameAccess > xRootNameAccess(
715 [ # # ][ # # ]: 0 : getConfigWriteAccess( OUString() ), UNO_QUERY );
716 [ # # ]: 0 : if ( xRootNameAccess.is() )
717 : : {
718 : : // Old key present?
719 [ # # ][ # # ]: 0 : if ( xRootNameAccess->hasByName( rOldKey ) )
[ # # ]
720 : : {
721 : : // New key not present?
722 [ # # ][ # # ]: 0 : if ( xRootNameAccess->hasByName( rNewKey ) )
[ # # ]
723 : : {
724 : : OSL_FAIL( "PropertySetRegistry::renamePropertySet - "
725 : : "New key exists!" );
726 : : return;
727 : : }
728 : : Reference< XSingleServiceFactory > xFac(
729 [ # # ]: 0 : xRootNameAccess, UNO_QUERY );
730 [ # # ]: 0 : Reference< XChangesBatch > xBatch( xFac, UNO_QUERY );
731 [ # # ]: 0 : Reference< XNameContainer > xContainer( xFac, UNO_QUERY );
732 : :
733 : : OSL_ENSURE( xFac.is(),
734 : : "PropertySetRegistry::renamePropertySet - "
735 : : "No factory!" );
736 : :
737 : : OSL_ENSURE( xBatch.is(),
738 : : "PropertySetRegistry::renamePropertySet - "
739 : : "No batch!" );
740 : :
741 : : OSL_ENSURE( xContainer.is(),
742 : : "PropertySetRegistry::renamePropertySet - "
743 : : "No container!" );
744 : :
745 [ # # ][ # # ]: 0 : if ( xFac.is() && xBatch.is() && xContainer.is() )
[ # # ][ # # ]
746 : : {
747 : : //////////////////////////////////////////////////////
748 : : // Create new "Properties" config item.
749 : : //////////////////////////////////////////////////////
750 : :
751 : : try
752 : : {
753 : : Reference< XNameReplace > xNameReplace(
754 [ # # ][ # # ]: 0 : xFac->createInstance(), UNO_QUERY );
[ # # ]
755 : :
756 [ # # ]: 0 : if ( xNameReplace.is() )
757 : : {
758 : : // Insert new item.
759 [ # # ]: 0 : xContainer->insertByName(
760 [ # # ][ # # ]: 0 : rNewKey, makeAny( xNameReplace ) );
761 : : // Commit changes.
762 [ # # ][ # # ]: 0 : xBatch->commitChanges();
763 [ # # # # : 0 : }
# # ]
764 : : }
765 [ # # ]: 0 : catch (const IllegalArgumentException&)
766 : : {
767 : : // insertByName
768 : :
769 : : OSL_FAIL( "PropertySetRegistry::renamePropertySet - "
770 : : "caught IllegalArgumentException!" );
771 : : return;
772 : : }
773 [ # # ]: 0 : catch (const ElementExistException&)
774 : : {
775 : : // insertByName
776 : :
777 : : OSL_FAIL( "PropertySetRegistry::renamePropertySet - "
778 : : "caught ElementExistException!" );
779 : : return;
780 : : }
781 [ # # ]: 0 : catch (const WrappedTargetException&)
782 : : {
783 : : // insertByName, commitChanges
784 : :
785 : : OSL_FAIL( "PropertySetRegistry::renamePropertySet - "
786 : : "caught WrappedTargetException!" );
787 : : return;
788 : : }
789 [ # # ]: 0 : catch (const RuntimeException&)
790 : : {
791 : : OSL_FAIL( "PropertySetRegistry::renamePropertySet - "
792 : : "caught RuntimeException!" );
793 : : return;
794 : : }
795 [ # # ]: 0 : catch (const Exception&)
796 : : {
797 : : // createInstance
798 : :
799 : : OSL_FAIL( "PropertySetRegistry::renamePropertySet - "
800 : : "caught Exception!" );
801 : : return;
802 : : }
803 : :
804 : : //////////////////////////////////////////////////////
805 : : // Copy data...
806 : : //////////////////////////////////////////////////////
807 : :
808 : : Reference< XHierarchicalNameAccess > xRootHierNameAccess(
809 [ # # ]: 0 : xRootNameAccess, UNO_QUERY );
810 [ # # ]: 0 : if ( !xRootHierNameAccess.is() )
811 : : {
812 : : OSL_FAIL( "PropertySetRegistry::renamePropertySet - "
813 : : "No hierarchical name access!" );
814 : : return;
815 : : }
816 : :
817 : : try
818 : : {
819 : : OUString aOldValuesKey
820 [ # # ]: 0 : = makeHierarchalNameSegment( rOldKey );
821 : 0 : aOldValuesKey += OUString("/Values");
822 : :
823 : 0 : Reference< XNameAccess > xOldNameAccess;
824 [ # # ]: 0 : xRootHierNameAccess->getByHierarchicalName(
825 : 0 : aOldValuesKey )
826 [ # # ][ # # ]: 0 : >>= xOldNameAccess;
827 [ # # ]: 0 : if ( !xOldNameAccess.is() )
828 : : {
829 : : OSL_FAIL( "PersistentPropertySet::renamePropertySet - "
830 : : "No old name access!" );
831 : : return;
832 : : }
833 : :
834 : : // Obtain property names.
835 : : Sequence< OUString > aElems
836 [ # # ][ # # ]: 0 : = xOldNameAccess->getElementNames();
837 : 0 : sal_Int32 nCount = aElems.getLength();
838 [ # # ]: 0 : if ( nCount )
839 : : {
840 : : OUString aNewValuesKey
841 [ # # ]: 0 : = makeHierarchalNameSegment( rNewKey );
842 : 0 : aNewValuesKey += OUString("/Values");
843 : :
844 : 0 : Reference< XSingleServiceFactory > xNewFac;
845 [ # # ]: 0 : xRootHierNameAccess->getByHierarchicalName(
846 : 0 : aNewValuesKey )
847 [ # # ][ # # ]: 0 : >>= xNewFac;
848 [ # # ]: 0 : if ( !xNewFac.is() )
849 : : {
850 : : OSL_FAIL( "PersistentPropertySet::renamePropertySet - "
851 : : "No new factory!" );
852 : : return;
853 : : }
854 : :
855 : : Reference< XNameContainer > xNewContainer(
856 [ # # ]: 0 : xNewFac, UNO_QUERY );
857 [ # # ]: 0 : if ( !xNewContainer.is() )
858 : : {
859 : : OSL_FAIL( "PersistentPropertySet::renamePropertySet - "
860 : : "No new container!" );
861 : : return;
862 : : }
863 : :
864 : 0 : aOldValuesKey += OUString("/");
865 : :
866 : 0 : OUString aHandleKey("/Handle");
867 : 0 : OUString aValueKey("/Value");
868 : 0 : OUString aStateKey("/State");
869 : 0 : OUString aAttrKey("/Attributes");
870 : :
871 [ # # ]: 0 : for ( sal_Int32 n = 0; n < nCount; ++n )
872 : : {
873 [ # # ]: 0 : const OUString& rPropName = aElems[ n ];
874 : :
875 : : // Create new item.
876 : : Reference< XNameReplace > xNewPropNameReplace(
877 [ # # ][ # # ]: 0 : xNewFac->createInstance(), UNO_QUERY );
[ # # ]
878 : :
879 [ # # ]: 0 : if ( !xNewPropNameReplace.is() )
880 : : {
881 : : OSL_FAIL( "PersistentPropertySet::renamePropertySet - "
882 : : "No new prop name replace!" );
883 : : return;
884 : : }
885 : :
886 : : // Fill new item...
887 : :
888 : : // Set Values
889 : 0 : OUString aKey = aOldValuesKey;
890 [ # # ]: 0 : aKey += makeHierarchalNameSegment( rPropName );
891 : :
892 : : // ... handle
893 : 0 : OUString aNewKey1 = aKey;
894 : 0 : aNewKey1 += aHandleKey;
895 : : Any aAny =
896 [ # # ]: 0 : xRootHierNameAccess->getByHierarchicalName(
897 [ # # ]: 0 : aNewKey1 );
898 [ # # ]: 0 : xNewPropNameReplace->replaceByName(
899 : : OUString("Handle"),
900 [ # # ]: 0 : aAny );
901 : :
902 : : // ... value
903 : 0 : aNewKey1 = aKey;
904 : 0 : aNewKey1 += aValueKey;
905 : : aAny =
906 [ # # ]: 0 : xRootHierNameAccess->getByHierarchicalName(
907 [ # # ]: 0 : aNewKey1 );
908 [ # # ]: 0 : xNewPropNameReplace->replaceByName(
909 : : OUString("Value"),
910 [ # # ]: 0 : aAny );
911 : :
912 : : // ... state
913 : 0 : aNewKey1 = aKey;
914 : 0 : aNewKey1 += aStateKey;
915 : : aAny =
916 [ # # ]: 0 : xRootHierNameAccess->getByHierarchicalName(
917 [ # # ]: 0 : aNewKey1 );
918 [ # # ]: 0 : xNewPropNameReplace->replaceByName(
919 : : OUString("State"),
920 [ # # ]: 0 : aAny );
921 : :
922 : : // ... attributes
923 : 0 : aNewKey1 = aKey;
924 : 0 : aNewKey1 += aAttrKey;
925 : : aAny =
926 [ # # ]: 0 : xRootHierNameAccess->getByHierarchicalName(
927 [ # # ]: 0 : aNewKey1 );
928 [ # # ]: 0 : xNewPropNameReplace->replaceByName(
929 : : OUString("Attributes"),
930 [ # # ]: 0 : aAny );
931 : :
932 : : // Insert new item.
933 [ # # ]: 0 : xNewContainer->insertByName(
934 [ # # ][ # # ]: 0 : rPropName, makeAny( xNewPropNameReplace ) );
935 : :
936 : : // Commit changes.
937 [ # # ][ # # ]: 0 : xBatch->commitChanges();
938 [ # # ][ # # ]: 0 : }
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
939 [ # # ][ # # ]: 0 : }
[ # # ][ # #
# # # # #
# # ]
940 : : }
941 [ # # ]: 0 : catch (const IllegalArgumentException&)
942 : : {
943 : : // insertByName, replaceByName
944 : :
945 : : OSL_FAIL( "PropertySetRegistry::renamePropertySet - "
946 : : "caught IllegalArgumentException!" );
947 : : return;
948 : : }
949 [ # # ]: 0 : catch (const ElementExistException&)
950 : : {
951 : : // insertByName
952 : :
953 : : OSL_FAIL( "PropertySetRegistry::renamePropertySet - "
954 : : "caught ElementExistException!" );
955 : : return;
956 : : }
957 [ # # ]: 0 : catch (const WrappedTargetException&)
958 : : {
959 : : // insertByName, replaceByName, commitChanges
960 : :
961 : : OSL_FAIL( "PropertySetRegistry::renamePropertySet - "
962 : : "caught WrappedTargetException!" );
963 : : return;
964 : : }
965 [ # # ]: 0 : catch (const NoSuchElementException&)
966 : : {
967 : : // getByHierarchicalName, replaceByName
968 : :
969 : : OSL_FAIL( "PropertySetRegistry::renamePropertySet - "
970 : : "caught NoSuchElementException!" );
971 : : return;
972 : : }
973 [ # # ]: 0 : catch (const RuntimeException&)
974 : : {
975 : : OSL_FAIL( "PropertySetRegistry::renamePropertySet - "
976 : : "caught RuntimeException!" );
977 : : return;
978 : : }
979 [ # # # # : 0 : catch (const Exception&)
# ]
980 : : {
981 : : // createInstance
982 : :
983 : : OSL_FAIL( "PropertySetRegistry::renamePropertySet - "
984 : : "caught Exception!" );
985 : : return;
986 : : }
987 : :
988 : : //////////////////////////////////////////////////////
989 : : // Remove old entry...
990 : : //////////////////////////////////////////////////////
991 : :
992 : : try
993 : : {
994 : : // Remove item.
995 [ # # ][ # # ]: 0 : xContainer->removeByName( rOldKey );
996 : : // Commit changes.
997 [ # # ][ # # ]: 0 : xBatch->commitChanges();
998 : :
999 : : // Success.
1000 : : return;
1001 : : }
1002 [ # # ]: 0 : catch (const NoSuchElementException&)
1003 : : {
1004 : : // removeByName
1005 : :
1006 : : OSL_FAIL( "PropertySetRegistry::renamePropertySet - "
1007 : : "caught NoSuchElementException!" );
1008 : : return;
1009 : : }
1010 [ # # ]: 0 : catch (const WrappedTargetException&)
1011 : : {
1012 : : // commitChanges
1013 : :
1014 : : OSL_FAIL( "PropertySetRegistry::renamePropertySet - "
1015 : : "caught WrappedTargetException!" );
1016 : : return;
1017 : 0 : }
1018 [ # # ][ # # ]: 0 : }
[ # # ]
1019 : : }
1020 : : }
1021 : :
1022 [ # # ]: 0 : OSL_FAIL( "PropertySetRegistry::renamePropertySet - Error!" );
1023 : : }
1024 : :
1025 : : //=========================================================================
1026 : 238 : Reference< XMultiServiceFactory > PropertySetRegistry::getConfigProvider()
1027 : : {
1028 [ + + ]: 238 : if ( !m_pImpl->m_xConfigProvider.is() )
1029 : : {
1030 [ + - ]: 236 : osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
1031 [ + - ]: 236 : if ( !m_pImpl->m_xConfigProvider.is() )
1032 : : {
1033 : 236 : const Sequence< Any >& rInitArgs = m_pImpl->m_aInitArgs;
1034 : :
1035 [ - + ]: 236 : if ( rInitArgs.getLength() > 0 )
1036 : : {
1037 : : // Extract config provider from service init args.
1038 [ # # ]: 0 : rInitArgs[ 0 ] >>= m_pImpl->m_xConfigProvider;
1039 : :
1040 : : OSL_ENSURE( m_pImpl->m_xConfigProvider.is(),
1041 : : "PropertySetRegistry::getConfigProvider - "
1042 : : "No config provider!" );
1043 : : }
1044 : : else
1045 : : {
1046 : : try
1047 : : {
1048 : : m_pImpl->m_xConfigProvider
1049 : : = Reference< XMultiServiceFactory >(
1050 [ + - ]: 236 : m_xSMgr->createInstance(
1051 : : OUString(
1052 : : "com.sun.star.configuration."
1053 : 236 : "ConfigurationProvider" ) ),
1054 [ + - ][ + - ]: 236 : UNO_QUERY_THROW );
[ + - ][ # # ]
1055 : : }
1056 [ # # ]: 0 : catch (const Exception&)
1057 : : {
1058 : : OSL_TRACE( "PropertySetRegistry::getConfigProvider - "
1059 : : "caught exception!" );
1060 : : }
1061 : : }
1062 [ + - ]: 236 : }
1063 : : }
1064 : :
1065 : 238 : return m_pImpl->m_xConfigProvider;
1066 : : }
1067 : :
1068 : : //=========================================================================
1069 : 111636 : Reference< XInterface > PropertySetRegistry::getRootConfigReadAccess()
1070 : : {
1071 : : try
1072 : : {
1073 [ + - ]: 111636 : osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
1074 : :
1075 [ + + ]: 111636 : if ( !m_pImpl->m_xRootReadAccess.is() )
1076 : : {
1077 [ - + ]: 236 : if ( m_pImpl->m_bTriedToGetRootReadAccess ) // #82494#
1078 : : {
1079 : : OSL_FAIL( "PropertySetRegistry::getRootConfigReadAccess - "
1080 : : "Unable to read any config data! -> #82494#" );
1081 : 0 : return Reference< XInterface >();
1082 : : }
1083 : :
1084 [ + - ]: 236 : getConfigProvider();
1085 : :
1086 [ + - ]: 236 : if ( m_pImpl->m_xConfigProvider.is() )
1087 : : {
1088 [ + - ]: 236 : Sequence< Any > aArguments( 1 );
1089 : 236 : PropertyValue aProperty;
1090 : : aProperty.Name
1091 : 236 : = OUString( CFGPROPERTY_NODEPATH );
1092 : : aProperty.Value
1093 [ + - ]: 236 : <<= OUString( STORE_CONTENTPROPERTIES_KEY );
1094 [ + - ][ + - ]: 236 : aArguments[ 0 ] <<= aProperty;
1095 : :
1096 : 236 : m_pImpl->m_bTriedToGetRootReadAccess = sal_True;
1097 : :
1098 : : m_pImpl->m_xRootReadAccess =
1099 [ + - ]: 236 : m_pImpl->m_xConfigProvider->createInstanceWithArguments(
1100 : : OUString( "com.sun.star.configuration.ConfigurationAccess" ),
1101 [ + - ][ + - ]: 236 : aArguments );
1102 : :
1103 [ + - ]: 236 : if ( m_pImpl->m_xRootReadAccess.is() )
1104 [ + - ][ + - ]: 236 : return m_pImpl->m_xRootReadAccess;
[ - + ]
1105 : : }
1106 : : }
1107 : : else
1108 [ + - ][ - + ]: 111636 : return m_pImpl->m_xRootReadAccess;
1109 : : }
1110 [ # # # ]: 0 : catch (const RuntimeException&)
1111 : : {
1112 : 0 : throw;
1113 : : }
1114 : 0 : catch (const Exception&)
1115 : : {
1116 : : // createInstance, createInstanceWithArguments
1117 : :
1118 : : OSL_FAIL( "PropertySetRegistry::getRootConfigReadAccess - caught Exception!" );
1119 : 0 : return Reference< XInterface >();
1120 : : }
1121 : :
1122 : : OSL_TRACE( "PropertySetRegistry::getRootConfigReadAccess - Error!" );
1123 : 111636 : return Reference< XInterface >();
1124 : : }
1125 : :
1126 : : //=========================================================================
1127 : 104 : Reference< XInterface > PropertySetRegistry::getConfigWriteAccess(
1128 : : const OUString& rPath )
1129 : : {
1130 : : try
1131 : : {
1132 [ + - ]: 104 : osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
1133 : :
1134 [ + + ]: 104 : if ( !m_pImpl->m_xRootWriteAccess.is() )
1135 : : {
1136 [ - + ]: 2 : if ( m_pImpl->m_bTriedToGetRootWriteAccess ) // #82494#
1137 : : {
1138 : : OSL_FAIL( "PropertySetRegistry::getConfigWriteAccess - "
1139 : : "Unable to write any config data! -> #82494#" );
1140 : 0 : return Reference< XInterface >();
1141 : : }
1142 : :
1143 [ + - ]: 2 : getConfigProvider();
1144 : :
1145 [ + - ]: 2 : if ( m_pImpl->m_xConfigProvider.is() )
1146 : : {
1147 [ + - ]: 2 : Sequence< Any > aArguments( 2 );
1148 : 2 : PropertyValue aProperty;
1149 : :
1150 : 2 : aProperty.Name = OUString( CFGPROPERTY_NODEPATH );
1151 [ + - ]: 2 : aProperty.Value <<= OUString( STORE_CONTENTPROPERTIES_KEY );
1152 [ + - ][ + - ]: 2 : aArguments[ 0 ] <<= aProperty;
1153 : :
1154 : 2 : aProperty.Name = OUString( CFGPROPERTY_LAZYWRITE );
1155 [ + - ]: 2 : aProperty.Value <<= sal_True;
1156 [ + - ][ + - ]: 2 : aArguments[ 1 ] <<= aProperty;
1157 : :
1158 : 2 : m_pImpl->m_bTriedToGetRootWriteAccess = sal_True;
1159 : :
1160 : : m_pImpl->m_xRootWriteAccess =
1161 [ + - ]: 2 : m_pImpl->m_xConfigProvider->createInstanceWithArguments(
1162 : : OUString( "com.sun.star.configuration.ConfigurationUpdateAccess" ),
1163 [ + - ][ + - ]: 2 : aArguments );
1164 : :
1165 : : OSL_ENSURE( m_pImpl->m_xRootWriteAccess.is(),
1166 : : "PropertySetRegistry::getConfigWriteAccess - "
1167 [ + - ]: 2 : "No config update access!" );
1168 : : }
1169 : : }
1170 : :
1171 [ + - ]: 104 : if ( m_pImpl->m_xRootWriteAccess.is() )
1172 : : {
1173 [ + + ]: 104 : if ( !rPath.isEmpty() )
1174 : : {
1175 : : Reference< XHierarchicalNameAccess > xNA(
1176 [ + - ]: 38 : m_pImpl->m_xRootWriteAccess, UNO_QUERY );
1177 [ + - ]: 38 : if ( xNA.is() )
1178 : : {
1179 : 38 : Reference< XInterface > xInterface;
1180 [ + - ][ + - ]: 38 : xNA->getByHierarchicalName( rPath ) >>= xInterface;
[ + - ]
1181 : :
1182 [ + - ]: 38 : if ( xInterface.is() )
1183 [ - + ]: 38 : return xInterface;
1184 [ - + ]: 38 : }
1185 : : }
1186 : : else
1187 : 66 : return m_pImpl->m_xRootWriteAccess;
1188 [ + - ][ - + ]: 104 : }
1189 : : }
1190 [ # # # # ]: 0 : catch (const RuntimeException&)
1191 : : {
1192 : 0 : throw;
1193 : : }
1194 : 0 : catch (const NoSuchElementException&)
1195 : : {
1196 : : // getByHierarchicalName
1197 : :
1198 : : OSL_FAIL( "PropertySetRegistry::getConfigWriteAccess - "
1199 : : "caught NoSuchElementException!" );
1200 : 0 : return Reference< XInterface >();
1201 : : }
1202 : 0 : catch (const Exception&)
1203 : : {
1204 : : // createInstance, createInstanceWithArguments
1205 : :
1206 : : OSL_FAIL( "PropertySetRegistry::getConfigWriteAccess - "
1207 : : "caught Exception!" );
1208 : 0 : return Reference< XInterface >();
1209 : : }
1210 : :
1211 : : OSL_FAIL( "PropertySetRegistry::getConfigWriteAccess - Error!" );
1212 : 104 : return Reference< XInterface >();
1213 : : }
1214 : :
1215 : : //=========================================================================
1216 : : //
1217 : : // PropertyListeners_Impl.
1218 : : //
1219 : : //=========================================================================
1220 : :
1221 : : typedef OMultiTypeInterfaceContainerHelperVar
1222 : : <
1223 : : OUString,
1224 : : hashString_Impl,
1225 : : equalString_Impl
1226 : : > PropertyListeners_Impl;
1227 : :
1228 : : //=========================================================================
1229 : : //
1230 : : // PersistentPropertySet_Impl.
1231 : : //
1232 : : //=========================================================================
1233 : :
1234 : : struct PersistentPropertySet_Impl
1235 : : {
1236 : : PropertySetRegistry* m_pCreator;
1237 : : PropertySetInfo_Impl* m_pInfo;
1238 : : OUString m_aKey;
1239 : : OUString m_aFullKey;
1240 : : osl::Mutex m_aMutex;
1241 : : OInterfaceContainerHelper* m_pDisposeEventListeners;
1242 : : OInterfaceContainerHelper* m_pPropSetChangeListeners;
1243 : : PropertyListeners_Impl* m_pPropertyChangeListeners;
1244 : :
1245 : 72 : PersistentPropertySet_Impl( PropertySetRegistry& rCreator,
1246 : : const OUString& rKey )
1247 : : : m_pCreator( &rCreator ), m_pInfo( NULL ), m_aKey( rKey ),
1248 : : m_pDisposeEventListeners( NULL ), m_pPropSetChangeListeners( NULL ),
1249 [ + - ]: 72 : m_pPropertyChangeListeners( NULL )
1250 : : {
1251 : 72 : m_pCreator->acquire();
1252 : 72 : }
1253 : :
1254 : 72 : ~PersistentPropertySet_Impl()
1255 [ + - ]: 72 : {
1256 : 72 : m_pCreator->release();
1257 : :
1258 [ + + ]: 72 : if ( m_pInfo )
1259 : 6 : m_pInfo->release();
1260 : :
1261 [ - + ][ # # ]: 72 : delete m_pDisposeEventListeners;
1262 [ - + ][ # # ]: 72 : delete m_pPropSetChangeListeners;
1263 [ - + ][ # # ]: 72 : delete m_pPropertyChangeListeners;
1264 : 72 : }
1265 : : };
1266 : :
1267 : : //=========================================================================
1268 : : //=========================================================================
1269 : : //=========================================================================
1270 : : //
1271 : : // PersistentPropertySet Implementation.
1272 : : //
1273 : : //=========================================================================
1274 : : //=========================================================================
1275 : : //=========================================================================
1276 : :
1277 : 72 : PersistentPropertySet::PersistentPropertySet(
1278 : : const Reference< XMultiServiceFactory >& rXSMgr,
1279 : : PropertySetRegistry& rCreator,
1280 : : const OUString& rKey )
1281 : : : m_xSMgr( rXSMgr ),
1282 [ + - ][ + - ]: 72 : m_pImpl( new PersistentPropertySet_Impl( rCreator, rKey ) )
1283 : : {
1284 : : // register at creator.
1285 [ + - ]: 72 : rCreator.add( this );
1286 : 72 : }
1287 : :
1288 : : //=========================================================================
1289 : : // virtual
1290 : 72 : PersistentPropertySet::~PersistentPropertySet()
1291 : : {
1292 : : // deregister at creator.
1293 [ + - ]: 72 : m_pImpl->m_pCreator->remove( this );
1294 : :
1295 [ + - ][ + - ]: 72 : delete m_pImpl;
1296 [ - + ]: 144 : }
1297 : :
1298 : : //=========================================================================
1299 : : //
1300 : : // XInterface methods.
1301 : : //
1302 : : //=========================================================================
1303 : :
1304 [ + - ][ + - ]: 372 : XINTERFACE_IMPL_9( PersistentPropertySet,
[ # # ]
1305 : : XTypeProvider,
1306 : : XServiceInfo,
1307 : : XComponent,
1308 : : XPropertySet, /* base of XPersistentPropertySet */
1309 : : XNamed,
1310 : : XPersistentPropertySet,
1311 : : XPropertyContainer,
1312 : : XPropertySetInfoChangeNotifier,
1313 : : XPropertyAccess );
1314 : :
1315 : : //=========================================================================
1316 : : //
1317 : : // XTypeProvider methods.
1318 : : //
1319 : : //=========================================================================
1320 : :
1321 [ # # ][ # # ]: 0 : XTYPEPROVIDER_IMPL_8( PersistentPropertySet,
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
1322 : : XTypeProvider,
1323 : : XServiceInfo,
1324 : : XComponent,
1325 : : XPersistentPropertySet,
1326 : : XNamed,
1327 : : XPropertyContainer,
1328 : : XPropertySetInfoChangeNotifier,
1329 : : XPropertyAccess );
1330 : :
1331 : : //=========================================================================
1332 : : //
1333 : : // XServiceInfo methods.
1334 : : //
1335 : : //=========================================================================
1336 : :
1337 [ # # ][ # # ]: 0 : XSERVICEINFO_NOFACTORY_IMPL_1( PersistentPropertySet,
[ # # ][ # # ]
[ # # ][ # # ]
1338 : : OUString( "com.sun.star.comp.ucb.PersistentPropertySet" ),
1339 : : OUString( PERS_PROPSET_SERVICE_NAME ) );
1340 : :
1341 : : //=========================================================================
1342 : : //
1343 : : // XComponent methods.
1344 : : //
1345 : : //=========================================================================
1346 : :
1347 : : // virtual
1348 : 0 : void SAL_CALL PersistentPropertySet::dispose()
1349 : : throw( RuntimeException )
1350 : : {
1351 [ # # # # ]: 0 : if ( m_pImpl->m_pDisposeEventListeners &&
[ # # ]
1352 : 0 : m_pImpl->m_pDisposeEventListeners->getLength() )
1353 : : {
1354 [ # # ]: 0 : EventObject aEvt;
1355 [ # # ]: 0 : aEvt.Source = static_cast< XComponent * >( this );
1356 [ # # ][ # # ]: 0 : m_pImpl->m_pDisposeEventListeners->disposeAndClear( aEvt );
1357 : : }
1358 : :
1359 [ # # # # ]: 0 : if ( m_pImpl->m_pPropSetChangeListeners &&
[ # # ]
1360 : 0 : m_pImpl->m_pPropSetChangeListeners->getLength() )
1361 : : {
1362 [ # # ]: 0 : EventObject aEvt;
1363 [ # # ]: 0 : aEvt.Source = static_cast< XPropertySetInfoChangeNotifier * >( this );
1364 [ # # ][ # # ]: 0 : m_pImpl->m_pPropSetChangeListeners->disposeAndClear( aEvt );
1365 : : }
1366 : :
1367 [ # # ]: 0 : if ( m_pImpl->m_pPropertyChangeListeners )
1368 : : {
1369 [ # # ]: 0 : EventObject aEvt;
1370 [ # # ]: 0 : aEvt.Source = static_cast< XPropertySet * >( this );
1371 [ # # ][ # # ]: 0 : m_pImpl->m_pPropertyChangeListeners->disposeAndClear( aEvt );
1372 : : }
1373 : 0 : }
1374 : :
1375 : : //=========================================================================
1376 : : // virtual
1377 : 0 : void SAL_CALL PersistentPropertySet::addEventListener(
1378 : : const Reference< XEventListener >& Listener )
1379 : : throw( RuntimeException )
1380 : : {
1381 [ # # ]: 0 : if ( !m_pImpl->m_pDisposeEventListeners )
1382 : : m_pImpl->m_pDisposeEventListeners =
1383 [ # # ]: 0 : new OInterfaceContainerHelper( m_pImpl->m_aMutex );
1384 : :
1385 : 0 : m_pImpl->m_pDisposeEventListeners->addInterface( Listener );
1386 : 0 : }
1387 : :
1388 : : //=========================================================================
1389 : : // virtual
1390 : 0 : void SAL_CALL PersistentPropertySet::removeEventListener(
1391 : : const Reference< XEventListener >& Listener )
1392 : : throw( RuntimeException )
1393 : : {
1394 [ # # ]: 0 : if ( m_pImpl->m_pDisposeEventListeners )
1395 : 0 : m_pImpl->m_pDisposeEventListeners->removeInterface( Listener );
1396 : :
1397 : : // Note: Don't want to delete empty container here -> performance.
1398 : 0 : }
1399 : :
1400 : : //=========================================================================
1401 : : //
1402 : : // XPropertySet methods.
1403 : : //
1404 : : //=========================================================================
1405 : :
1406 : : // virtual
1407 : : Reference< XPropertySetInfo > SAL_CALL
1408 : 6 : PersistentPropertySet::getPropertySetInfo()
1409 : : throw( RuntimeException )
1410 : : {
1411 [ + - ]: 6 : osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
1412 : :
1413 : 6 : PropertySetInfo_Impl*& rpInfo = m_pImpl->m_pInfo;
1414 [ + - ]: 6 : if ( !rpInfo )
1415 : : {
1416 [ + - ]: 6 : rpInfo = new PropertySetInfo_Impl( m_xSMgr, this );
1417 : 6 : rpInfo->acquire();
1418 : : }
1419 [ + - ][ + - ]: 6 : return Reference< XPropertySetInfo >( rpInfo );
[ + - ]
1420 : : }
1421 : :
1422 : : //=========================================================================
1423 : : // virtual
1424 : 6 : void SAL_CALL PersistentPropertySet::setPropertyValue(
1425 : : const OUString& aPropertyName, const Any& aValue )
1426 : : throw( UnknownPropertyException,
1427 : : PropertyVetoException,
1428 : : IllegalArgumentException,
1429 : : WrappedTargetException,
1430 : : RuntimeException )
1431 : : {
1432 [ - + ]: 6 : if ( aPropertyName.isEmpty() )
1433 [ # # ]: 0 : throw UnknownPropertyException();
1434 : :
1435 [ + - ]: 6 : osl::ClearableGuard< osl::Mutex > aCGuard( m_pImpl->m_aMutex );
1436 : :
1437 : : Reference< XHierarchicalNameAccess > xRootHierNameAccess(
1438 [ + - ][ + - ]: 6 : m_pImpl->m_pCreator->getRootConfigReadAccess(), UNO_QUERY );
1439 [ + - ]: 6 : if ( xRootHierNameAccess.is() )
1440 : : {
1441 [ + - ]: 6 : OUString aFullPropName( getFullKey() );
1442 : 6 : aFullPropName += OUString("/");
1443 [ + - ]: 6 : aFullPropName += makeHierarchalNameSegment( aPropertyName );
1444 : :
1445 : : // Does property exist?
1446 [ + - ][ + - ]: 6 : if ( xRootHierNameAccess->hasByHierarchicalName( aFullPropName ) )
[ + - ]
1447 : : {
1448 : : Reference< XNameReplace > xNameReplace(
1449 : : m_pImpl->m_pCreator->getConfigWriteAccess(
1450 [ + - ][ + - ]: 6 : aFullPropName ), UNO_QUERY );
1451 : : Reference< XChangesBatch > xBatch(
1452 : : m_pImpl->m_pCreator->getConfigWriteAccess(
1453 [ + - ][ + - ]: 6 : OUString() ), UNO_QUERY );
1454 : :
1455 [ + - ][ + - ]: 6 : if ( xNameReplace.is() && xBatch.is() )
[ + - ]
1456 : : {
1457 : : try
1458 : : {
1459 : : // Obtain old value
1460 : 6 : OUString aValueName = aFullPropName;
1461 : 6 : aValueName += OUString("/Value");
1462 : : Any aOldValue
1463 [ + - ]: 6 : = xRootHierNameAccess->getByHierarchicalName(
1464 [ + - ]: 6 : aValueName );
1465 : : // Check value type.
1466 [ - + ]: 6 : if ( aOldValue.getValueType() != aValue.getValueType() )
1467 : : {
1468 [ # # ]: 0 : aCGuard.clear();
1469 [ # # ]: 0 : throw IllegalArgumentException();
1470 : : }
1471 : :
1472 : : // Write value
1473 [ + - ]: 6 : xNameReplace->replaceByName(
1474 : : OUString("Value"),
1475 [ + - ]: 6 : aValue );
1476 : :
1477 : : // Write state ( Now it is a directly set value )
1478 [ + - ]: 6 : xNameReplace->replaceByName(
1479 : : OUString("State"),
1480 : : makeAny(
1481 : : sal_Int32(
1482 [ + - ][ + - ]: 6 : PropertyState_DIRECT_VALUE ) ) );
1483 : :
1484 : : // Commit changes.
1485 [ + - ][ + - ]: 6 : xBatch->commitChanges();
1486 : :
1487 [ + - ]: 6 : PropertyChangeEvent aEvt;
1488 [ - + ]: 6 : if ( m_pImpl->m_pPropertyChangeListeners )
1489 : : {
1490 : : // Obtain handle
1491 : 0 : aValueName = aFullPropName;
1492 : 0 : aValueName += OUString("/Handle");
1493 : 0 : sal_Int32 nHandle = -1;
1494 [ # # ]: 0 : xRootHierNameAccess->getByHierarchicalName( aValueName )
1495 [ # # ]: 0 : >>= nHandle;
1496 : :
1497 [ # # ]: 0 : aEvt.Source = (OWeakObject*)this;
1498 : 0 : aEvt.PropertyName = aPropertyName;
1499 : 0 : aEvt.PropertyHandle = nHandle;
1500 : 0 : aEvt.Further = sal_False;
1501 : 0 : aEvt.OldValue = aOldValue;
1502 : 0 : aEvt.NewValue = aValue;
1503 : :
1504 : : // Callback follows!
1505 [ # # ]: 0 : aCGuard.clear();
1506 : :
1507 [ # # ]: 0 : notifyPropertyChangeEvent( aEvt );
1508 : : }
1509 [ + - ]: 12 : return;
[ # # # # ]
1510 : : }
1511 [ # # ]: 0 : catch (const IllegalArgumentException&)
1512 : : {
1513 : : // replaceByName
1514 : : }
1515 [ # # ]: 0 : catch (const NoSuchElementException&)
1516 : : {
1517 : : // getByHierarchicalName, replaceByName
1518 : : }
1519 [ # # ]: 0 : catch (const WrappedTargetException&)
1520 : : {
1521 : : // replaceByName, commitChanges
1522 : : }
1523 [ + - ][ - + ]: 6 : }
1524 [ - + ]: 6 : }
1525 : : }
1526 : :
1527 [ + - ][ # # ]: 6 : throw UnknownPropertyException();
1528 : : }
1529 : :
1530 : : //=========================================================================
1531 : : // virtual
1532 : 34 : Any SAL_CALL PersistentPropertySet::getPropertyValue(
1533 : : const OUString& PropertyName )
1534 : : throw( UnknownPropertyException,
1535 : : WrappedTargetException,
1536 : : RuntimeException )
1537 : : {
1538 [ - + ]: 34 : if ( PropertyName.isEmpty() )
1539 [ # # ]: 0 : throw UnknownPropertyException();
1540 : :
1541 [ + - ]: 34 : osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
1542 : :
1543 : : Reference< XHierarchicalNameAccess > xNameAccess(
1544 [ + - ][ + - ]: 34 : m_pImpl->m_pCreator->getRootConfigReadAccess(), UNO_QUERY );
1545 [ + - ]: 34 : if ( xNameAccess.is() )
1546 : : {
1547 [ + - ]: 34 : OUString aFullPropName( getFullKey() );
1548 : 34 : aFullPropName += OUString("/");
1549 [ + - ]: 34 : aFullPropName += makeHierarchalNameSegment( PropertyName );
1550 : 34 : aFullPropName += OUString("/Value");
1551 : : try
1552 : : {
1553 [ + - ][ + - ]: 68 : return xNameAccess->getByHierarchicalName( aFullPropName );
1554 : : }
1555 [ # # ]: 0 : catch (const NoSuchElementException&)
1556 : : {
1557 [ # # ]: 0 : throw UnknownPropertyException();
1558 : 34 : }
1559 : : }
1560 : :
1561 [ # # ][ + - ]: 34 : throw UnknownPropertyException();
1562 : : }
1563 : :
1564 : : //=========================================================================
1565 : : // virtual
1566 : 0 : void SAL_CALL PersistentPropertySet::addPropertyChangeListener(
1567 : : const OUString& aPropertyName,
1568 : : const Reference< XPropertyChangeListener >& xListener )
1569 : : throw( UnknownPropertyException,
1570 : : WrappedTargetException,
1571 : : RuntimeException )
1572 : : {
1573 : : // load();
1574 : :
1575 [ # # ]: 0 : if ( !m_pImpl->m_pPropertyChangeListeners )
1576 : : m_pImpl->m_pPropertyChangeListeners =
1577 [ # # ]: 0 : new PropertyListeners_Impl( m_pImpl->m_aMutex );
1578 : :
1579 : : m_pImpl->m_pPropertyChangeListeners->addInterface(
1580 : 0 : aPropertyName, xListener );
1581 : 0 : }
1582 : :
1583 : : //=========================================================================
1584 : : // virtual
1585 : 0 : void SAL_CALL PersistentPropertySet::removePropertyChangeListener(
1586 : : const OUString& aPropertyName,
1587 : : const Reference< XPropertyChangeListener >& aListener )
1588 : : throw( UnknownPropertyException,
1589 : : WrappedTargetException,
1590 : : RuntimeException )
1591 : : {
1592 : : // load();
1593 : :
1594 [ # # ]: 0 : if ( m_pImpl->m_pPropertyChangeListeners )
1595 : : m_pImpl->m_pPropertyChangeListeners->removeInterface(
1596 : 0 : aPropertyName, aListener );
1597 : :
1598 : : // Note: Don't want to delete empty container here -> performance.
1599 : 0 : }
1600 : :
1601 : : //=========================================================================
1602 : : // virtual
1603 : 0 : void SAL_CALL PersistentPropertySet::addVetoableChangeListener(
1604 : : const OUString&,
1605 : : const Reference< XVetoableChangeListener >& )
1606 : : throw( UnknownPropertyException,
1607 : : WrappedTargetException,
1608 : : RuntimeException )
1609 : : {
1610 : : // load();
1611 : : // OSL_FAIL( // "PersistentPropertySet::addVetoableChangeListener - N.Y.I." );
1612 : 0 : }
1613 : :
1614 : : //=========================================================================
1615 : : // virtual
1616 : 0 : void SAL_CALL PersistentPropertySet::removeVetoableChangeListener(
1617 : : const OUString&,
1618 : : const Reference< XVetoableChangeListener >& )
1619 : : throw( UnknownPropertyException,
1620 : : WrappedTargetException,
1621 : : RuntimeException )
1622 : : {
1623 : : // load();
1624 : : // OSL_FAIL( // "PersistentPropertySet::removeVetoableChangeListener - N.Y.I." );
1625 : 0 : }
1626 : :
1627 : : //=========================================================================
1628 : : //
1629 : : // XPersistentPropertySet methods.
1630 : : //
1631 : : //=========================================================================
1632 : :
1633 : : // virtual
1634 : 0 : Reference< XPropertySetRegistry > SAL_CALL PersistentPropertySet::getRegistry()
1635 : : throw( RuntimeException )
1636 : : {
1637 [ # # ]: 0 : return Reference< XPropertySetRegistry >( m_pImpl->m_pCreator );
1638 : : }
1639 : :
1640 : : //=========================================================================
1641 : : // virtual
1642 : 144 : OUString SAL_CALL PersistentPropertySet::getKey()
1643 : : throw( RuntimeException )
1644 : : {
1645 : 144 : return m_pImpl->m_aKey;
1646 : : }
1647 : :
1648 : : //=========================================================================
1649 : : //
1650 : : // XNamed methods.
1651 : : //
1652 : : //=========================================================================
1653 : :
1654 : : // virtual
1655 : 0 : OUString SAL_CALL PersistentPropertySet::getName()
1656 : : throw( RuntimeException )
1657 : : {
1658 : : // same as getKey()
1659 : 0 : return m_pImpl->m_aKey;
1660 : : }
1661 : :
1662 : : //=========================================================================
1663 : : // virtual
1664 : 0 : void SAL_CALL PersistentPropertySet::setName( const OUString& aName )
1665 : : throw( RuntimeException )
1666 : : {
1667 [ # # ]: 0 : if ( aName != m_pImpl->m_aKey )
1668 : 0 : m_pImpl->m_pCreator->renamePropertySet( m_pImpl->m_aKey, aName );
1669 : 0 : }
1670 : :
1671 : : //=========================================================================
1672 : : //
1673 : : // XPropertyContainer methods.
1674 : : //
1675 : : //=========================================================================
1676 : :
1677 : : // virtual
1678 : 32 : void SAL_CALL PersistentPropertySet::addProperty(
1679 : : const OUString& Name, sal_Int16 Attributes, const Any& DefaultValue )
1680 : : throw( PropertyExistException,
1681 : : IllegalTypeException,
1682 : : IllegalArgumentException,
1683 : : RuntimeException )
1684 : : {
1685 [ - + ]: 32 : if ( Name.isEmpty() )
1686 [ # # ]: 0 : throw IllegalArgumentException();
1687 : :
1688 : : // @@@ What other types can't be written to config server?
1689 : :
1690 : : // Check type class ( Not all types can be written to storage )
1691 : 32 : TypeClass eTypeClass = DefaultValue.getValueTypeClass();
1692 [ - + ]: 32 : if ( eTypeClass == TypeClass_INTERFACE )
1693 [ # # ]: 0 : throw IllegalTypeException();
1694 : :
1695 [ + - ]: 32 : osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
1696 : :
1697 : : // Property already in set?
1698 : :
1699 : 32 : OUString aFullValuesName;
1700 : :
1701 : : Reference< XHierarchicalNameAccess > xRootHierNameAccess(
1702 [ + - ][ + - ]: 32 : m_pImpl->m_pCreator->getRootConfigReadAccess(), UNO_QUERY );
1703 [ + - ]: 32 : if ( xRootHierNameAccess.is() )
1704 : : {
1705 [ + - ]: 32 : aFullValuesName = getFullKey();
1706 : 32 : OUString aFullPropName = aFullValuesName;
1707 : 32 : aFullPropName += OUString("/");
1708 [ + - ]: 32 : aFullPropName += makeHierarchalNameSegment( Name );
1709 : :
1710 [ + - ][ - + ]: 32 : if ( xRootHierNameAccess->hasByHierarchicalName( aFullPropName ) )
[ + - ]
1711 : : {
1712 : : // Already in set.
1713 [ # # ]: 0 : throw PropertyExistException();
1714 : 32 : }
1715 : : }
1716 : :
1717 : : // Property is always removeable.
1718 : 32 : Attributes |= PropertyAttribute::REMOVEABLE;
1719 : :
1720 : : // Add property.
1721 : :
1722 : : Reference< XSingleServiceFactory > xFac(
1723 : : m_pImpl->m_pCreator->getConfigWriteAccess( aFullValuesName ),
1724 [ + - ][ + - ]: 32 : UNO_QUERY );
1725 [ + - ]: 32 : Reference< XNameContainer > xContainer( xFac, UNO_QUERY );
1726 : : Reference< XChangesBatch > xBatch(
1727 : : m_pImpl->m_pCreator->getConfigWriteAccess( OUString() ),
1728 [ + - ][ + - ]: 32 : UNO_QUERY );
1729 : :
1730 : : OSL_ENSURE( xFac.is(),
1731 : : "PersistentPropertySet::addProperty - No factory!" );
1732 : :
1733 : : OSL_ENSURE( xBatch.is(),
1734 : : "PersistentPropertySet::addProperty - No batch!" );
1735 : :
1736 : : OSL_ENSURE( xContainer.is(),
1737 : : "PersistentPropertySet::addProperty - No container!" );
1738 : :
1739 [ + - ][ + - ]: 32 : if ( xFac.is() && xBatch.is() && xContainer.is() )
[ + - ][ + - ]
1740 : : {
1741 : : try
1742 : : {
1743 : : // Create new "PropertyValue" config item.
1744 : : Reference< XNameReplace > xNameReplace(
1745 [ + - ][ + - ]: 32 : xFac->createInstance(), UNO_QUERY );
[ + - ]
1746 : :
1747 [ + - ]: 32 : if ( xNameReplace.is() )
1748 : : {
1749 : : // Fill new item...
1750 : :
1751 : : // Set handle
1752 [ + - ]: 32 : xNameReplace->replaceByName(
1753 : : OUString("Handle"),
1754 [ + - ][ + - ]: 32 : makeAny( sal_Int32( -1 ) ) );
1755 : :
1756 : : // Set default value
1757 [ + - ]: 32 : xNameReplace->replaceByName(
1758 : : OUString("Value"),
1759 [ + - ]: 32 : DefaultValue );
1760 : :
1761 : : // Set state ( always "default" )
1762 [ + - ]: 32 : xNameReplace->replaceByName(
1763 : : OUString("State"),
1764 : : makeAny(
1765 : : sal_Int32(
1766 [ + - ][ + - ]: 32 : PropertyState_DEFAULT_VALUE ) ) );
1767 : :
1768 : : // Set attributes
1769 [ + - ]: 32 : xNameReplace->replaceByName(
1770 : : OUString("Attributes"),
1771 [ + - ][ + - ]: 32 : makeAny( sal_Int32( Attributes ) ) );
1772 : :
1773 : : // Insert new item.
1774 [ + - ][ + - ]: 32 : xContainer->insertByName( Name, makeAny( xNameReplace ) );
[ + - ]
1775 : :
1776 : : // Commit changes.
1777 [ + - ][ + - ]: 32 : xBatch->commitChanges();
1778 : :
1779 : : // Property set info is invalid.
1780 [ - + ]: 32 : if ( m_pImpl->m_pInfo )
1781 [ # # ]: 0 : m_pImpl->m_pInfo->reset();
1782 : :
1783 : : // Notify propertyset info change listeners.
1784 [ - + ][ # # ]: 32 : if ( m_pImpl->m_pPropSetChangeListeners &&
[ - + ]
1785 [ # # ]: 0 : m_pImpl->m_pPropSetChangeListeners->getLength() )
1786 : : {
1787 : : PropertySetInfoChangeEvent evt(
1788 : : static_cast< OWeakObject * >( this ),
1789 : : Name,
1790 : : -1,
1791 [ # # ][ # # ]: 0 : PropertySetInfoChange::PROPERTY_INSERTED );
1792 [ # # ][ # # ]: 32 : notifyPropertySetInfoChange( evt );
1793 : : }
1794 : :
1795 : : // Success.
1796 : : return;
1797 [ - + ]: 32 : }
1798 : : }
1799 [ # # ]: 0 : catch (const IllegalArgumentException&)
1800 : : {
1801 : : // insertByName
1802 : :
1803 : : OSL_FAIL( "PersistentPropertySet::addProperty - "
1804 : : "caught IllegalArgumentException!" );
1805 : : return;
1806 : : }
1807 [ # # ]: 0 : catch (const ElementExistException&)
1808 : : {
1809 : : // insertByName
1810 : :
1811 : : OSL_FAIL( "PersistentPropertySet::addProperty - "
1812 : : "caught ElementExistException!" );
1813 : : return;
1814 : : }
1815 [ # # ]: 0 : catch (const WrappedTargetException&)
1816 : : {
1817 : : // replaceByName, insertByName, commitChanges
1818 : :
1819 : : OSL_FAIL( "PersistentPropertySet::addProperty - "
1820 : : "caught WrappedTargetException!" );
1821 : : return;
1822 : : }
1823 [ # # # # : 0 : catch (const RuntimeException&)
# # ]
1824 : : {
1825 : 0 : throw;
1826 : : }
1827 [ # # ]: 0 : catch (const Exception&)
1828 : : {
1829 : : // createInstance
1830 : :
1831 : : OSL_FAIL( "PersistentPropertySet::addProperty - "
1832 : : "caught Exception!" );
1833 : : return;
1834 : : }
1835 : : }
1836 : :
1837 [ + - ][ + - ]: 32 : OSL_FAIL( "PersistentPropertySet::addProperty - Error!" );
[ + - ][ + - ]
[ + - ][ + - ]
[ - + ]
1838 : : }
1839 : :
1840 : : //=========================================================================
1841 : : // virtual
1842 : 0 : void SAL_CALL PersistentPropertySet::removeProperty( const OUString& Name )
1843 : : throw( UnknownPropertyException,
1844 : : NotRemoveableException,
1845 : : RuntimeException )
1846 : : {
1847 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
1848 : :
1849 : 0 : OUString aFullValuesName;
1850 : 0 : OUString aFullPropName;
1851 : :
1852 : : Reference< XHierarchicalNameAccess > xRootHierNameAccess(
1853 [ # # ][ # # ]: 0 : m_pImpl->m_pCreator->getRootConfigReadAccess(), UNO_QUERY );
1854 [ # # ]: 0 : if ( xRootHierNameAccess.is() )
1855 : : {
1856 [ # # ]: 0 : aFullValuesName = getFullKey();
1857 : 0 : aFullPropName = aFullValuesName;
1858 : 0 : aFullPropName += OUString("/");
1859 [ # # ]: 0 : aFullPropName += makeHierarchalNameSegment( Name );
1860 : :
1861 : : // Property in set?
1862 [ # # ][ # # ]: 0 : if ( !xRootHierNameAccess->hasByHierarchicalName( aFullPropName ) )
[ # # ]
1863 [ # # ]: 0 : throw UnknownPropertyException();
1864 : :
1865 : : // Property removeable?
1866 : : try
1867 : : {
1868 : 0 : OUString aFullAttrName = aFullPropName;
1869 : 0 : aFullAttrName += OUString("/Attributes");
1870 : :
1871 : 0 : sal_Int32 nAttribs = 0;
1872 [ # # # # ]: 0 : if ( xRootHierNameAccess->getByHierarchicalName( aFullAttrName )
1873 [ # # ]: 0 : >>= nAttribs )
1874 : : {
1875 [ # # ]: 0 : if ( !( nAttribs & PropertyAttribute::REMOVEABLE ) )
1876 : : {
1877 : : // Not removeable!
1878 [ # # ]: 0 : throw NotRemoveableException();
1879 : : }
1880 : : }
1881 : : else
1882 : : {
1883 : : OSL_FAIL( "PersistentPropertySet::removeProperty - "
1884 : : "No attributes!" );
1885 : : return;
1886 [ # # ][ # # ]: 0 : }
1887 : : }
1888 [ # # ]: 0 : catch (const NoSuchElementException&)
1889 : : {
1890 : : // getByHierarchicalName
1891 : :
1892 : : OSL_FAIL( "PersistentPropertySet::removeProperty - "
1893 : : "caught NoSuchElementException!" );
1894 : : }
1895 : :
1896 : : // Remove property...
1897 : :
1898 : : Reference< XNameContainer > xContainer(
1899 : : m_pImpl->m_pCreator->getConfigWriteAccess( aFullValuesName ),
1900 [ # # ][ # # ]: 0 : UNO_QUERY );
1901 : : Reference< XChangesBatch > xBatch(
1902 : : m_pImpl->m_pCreator->getConfigWriteAccess( OUString() ),
1903 [ # # ][ # # ]: 0 : UNO_QUERY );
1904 : :
1905 : : OSL_ENSURE( xBatch.is(),
1906 : : "PersistentPropertySet::removeProperty - No batch!" );
1907 : :
1908 : : OSL_ENSURE( xContainer.is(),
1909 : : "PersistentPropertySet::removeProperty - No container!" );
1910 : :
1911 [ # # ][ # # ]: 0 : if ( xBatch.is() && xContainer.is() )
[ # # ]
1912 : : {
1913 : : try
1914 : : {
1915 : 0 : sal_Int32 nHandle = -1;
1916 : :
1917 [ # # ][ # # ]: 0 : if ( m_pImpl->m_pPropSetChangeListeners &&
[ # # ]
1918 [ # # ]: 0 : m_pImpl->m_pPropSetChangeListeners->getLength() )
1919 : : {
1920 : : // Obtain property handle ( needed for propertysetinfo
1921 : : // change event )...
1922 : :
1923 : : try
1924 : : {
1925 : 0 : OUString aFullHandleName = aFullPropName;
1926 : : aFullHandleName
1927 : 0 : += OUString("/Handle");
1928 : :
1929 [ # # # # ]: 0 : if ( ! ( xRootHierNameAccess->getByHierarchicalName(
1930 [ # # ]: 0 : aFullHandleName ) >>= nHandle ) )
1931 [ # # ]: 0 : nHandle = -1;
1932 : :
1933 : : }
1934 [ # # ]: 0 : catch (const NoSuchElementException&)
1935 : : {
1936 : : // getByHierarchicalName
1937 : :
1938 : : OSL_FAIL( "PersistentPropertySet::removeProperty - "
1939 : : "caught NoSuchElementException!" );
1940 : 0 : nHandle = -1;
1941 : : }
1942 : : }
1943 : :
1944 [ # # ][ # # ]: 0 : xContainer->removeByName( Name );
1945 [ # # ][ # # ]: 0 : xBatch->commitChanges();
1946 : :
1947 : : // Property set info is invalid.
1948 [ # # ]: 0 : if ( m_pImpl->m_pInfo )
1949 [ # # ]: 0 : m_pImpl->m_pInfo->reset();
1950 : :
1951 : : // Notify propertyset info change listeners.
1952 [ # # ][ # # ]: 0 : if ( m_pImpl->m_pPropSetChangeListeners &&
[ # # ]
1953 [ # # ]: 0 : m_pImpl->m_pPropSetChangeListeners->getLength() )
1954 : : {
1955 : : PropertySetInfoChangeEvent evt(
1956 : : static_cast< OWeakObject * >( this ),
1957 : : Name,
1958 : : nHandle,
1959 [ # # ][ # # ]: 0 : PropertySetInfoChange::PROPERTY_REMOVED );
1960 [ # # ]: 0 : notifyPropertySetInfoChange( evt );
[ # # # ]
[ # # ]
1961 : : }
1962 : :
1963 : : // Success.
1964 : : return;
1965 : : }
1966 [ # # ]: 0 : catch (const NoSuchElementException&)
1967 : : {
1968 : : // removeByName
1969 : :
1970 : : OSL_FAIL( "PersistentPropertySet::removeProperty - "
1971 : : "caught NoSuchElementException!" );
1972 : : return;
1973 : : }
1974 [ # # ]: 0 : catch (const WrappedTargetException&)
1975 : : {
1976 : : // commitChanges
1977 : :
1978 : : OSL_FAIL( "PersistentPropertySet::removeProperty - "
1979 : : "caught WrappedTargetException!" );
1980 : : return;
1981 : : }
1982 [ # # ][ # # ]: 0 : }
1983 : : }
1984 : :
1985 [ # # ][ # # ]: 0 : OSL_FAIL( "PersistentPropertySet::removeProperty - Error!" );
[ # # ][ # # ]
[ # # ]
1986 : : }
1987 : :
1988 : : //=========================================================================
1989 : : //
1990 : : // XPropertySetInfoChangeNotifier methods.
1991 : : //
1992 : : //=========================================================================
1993 : :
1994 : : // virtual
1995 : 0 : void SAL_CALL PersistentPropertySet::addPropertySetInfoChangeListener(
1996 : : const Reference< XPropertySetInfoChangeListener >& Listener )
1997 : : throw( RuntimeException )
1998 : : {
1999 [ # # ]: 0 : if ( !m_pImpl->m_pPropSetChangeListeners )
2000 : : m_pImpl->m_pPropSetChangeListeners =
2001 [ # # ]: 0 : new OInterfaceContainerHelper( m_pImpl->m_aMutex );
2002 : :
2003 : 0 : m_pImpl->m_pPropSetChangeListeners->addInterface( Listener );
2004 : 0 : }
2005 : :
2006 : : //=========================================================================
2007 : : // virtual
2008 : 0 : void SAL_CALL PersistentPropertySet::removePropertySetInfoChangeListener(
2009 : : const Reference< XPropertySetInfoChangeListener >& Listener )
2010 : : throw( RuntimeException )
2011 : : {
2012 [ # # ]: 0 : if ( m_pImpl->m_pPropSetChangeListeners )
2013 : 0 : m_pImpl->m_pPropSetChangeListeners->removeInterface( Listener );
2014 : 0 : }
2015 : :
2016 : : //=========================================================================
2017 : : //
2018 : : // XPropertyAccess methods.
2019 : : //
2020 : : //=========================================================================
2021 : :
2022 : : // virtual
2023 : 0 : Sequence< PropertyValue > SAL_CALL PersistentPropertySet::getPropertyValues()
2024 : : throw( RuntimeException )
2025 : : {
2026 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
2027 : :
2028 : : Reference< XHierarchicalNameAccess > xRootHierNameAccess(
2029 [ # # ][ # # ]: 0 : m_pImpl->m_pCreator->getRootConfigReadAccess(), UNO_QUERY );
2030 [ # # ]: 0 : if ( xRootHierNameAccess.is() )
2031 : : {
2032 : : try
2033 : : {
2034 : 0 : Reference< XNameAccess > xNameAccess;
2035 [ # # ][ # # ]: 0 : xRootHierNameAccess->getByHierarchicalName(getFullKey())
2036 [ # # ][ # # ]: 0 : >>= xNameAccess;
2037 [ # # ]: 0 : if ( xNameAccess.is() )
2038 : : {
2039 : : // Obtain property names.
2040 : :
2041 [ # # ][ # # ]: 0 : Sequence< OUString > aElems = xNameAccess->getElementNames();
2042 : :
2043 : 0 : sal_Int32 nCount = aElems.getLength();
2044 [ # # ]: 0 : if ( nCount )
2045 : : {
2046 : : Reference< XHierarchicalNameAccess > xHierNameAccess(
2047 [ # # ]: 0 : xNameAccess, UNO_QUERY );
2048 : :
2049 : : OSL_ENSURE( xHierNameAccess.is(),
2050 : : "PersistentPropertySet::getPropertyValues - "
2051 : : "No hierarchical name access!" );
2052 : :
2053 [ # # ]: 0 : if ( xHierNameAccess.is() )
2054 : : {
2055 [ # # ]: 0 : Sequence< PropertyValue > aValues( nCount );
2056 : :
2057 : 0 : const OUString aHandleName("/Handle");
2058 : 0 : const OUString aValueName("/Value");
2059 : 0 : const OUString aStateName("/State");
2060 : :
2061 [ # # ]: 0 : for ( sal_Int32 n = 0; n < nCount; ++n )
2062 : : {
2063 [ # # ]: 0 : PropertyValue& rValue = aValues[ n ];
2064 [ # # ]: 0 : OUString rName = aElems[ n ];
2065 : : OUString aXMLName
2066 [ # # ]: 0 : = makeHierarchalNameSegment( rName );
2067 : :
2068 : : // Set property name.
2069 : :
2070 : 0 : rValue.Name = rName;
2071 : :
2072 : : try
2073 : : {
2074 : : // Obtain and set property handle
2075 : 0 : OUString aHierName = aXMLName;
2076 : 0 : aHierName += aHandleName;
2077 : : Any aKeyValue
2078 [ # # ]: 0 : = xHierNameAccess->getByHierarchicalName(
2079 [ # # ]: 0 : aHierName );
2080 : :
2081 : 0 : if ( !( aKeyValue >>= rValue.Handle ) )
2082 : : OSL_FAIL( "PersistentPropertySet::getPropertyValues - "
2083 [ # # ]: 0 : "Error getting property handle!" );
2084 : : }
2085 [ # # ]: 0 : catch (const NoSuchElementException&)
2086 : : {
2087 : : // getByHierarchicalName
2088 : :
2089 : : OSL_FAIL( "PersistentPropertySet::getPropertyValues - "
2090 : : "NoSuchElementException!" );
2091 : : }
2092 : :
2093 : : try
2094 : : {
2095 : : // Obtain and set property value
2096 : 0 : OUString aHierName = aXMLName;
2097 : 0 : aHierName += aValueName;
2098 : : rValue.Value
2099 [ # # ]: 0 : = xHierNameAccess->getByHierarchicalName(
2100 [ # # ][ # # ]: 0 : aHierName );
2101 : :
2102 : : // Note: The value may be void if addProperty
2103 : : // was called with a default value
2104 : : // of type void.
2105 : : }
2106 [ # # ]: 0 : catch (const NoSuchElementException&)
2107 : : {
2108 : : // getByHierarchicalName
2109 : :
2110 : : OSL_FAIL( "PersistentPropertySet::getPropertyValues - "
2111 : : "NoSuchElementException!" );
2112 : : }
2113 : :
2114 : : try
2115 : : {
2116 : : // Obtain and set property state
2117 : 0 : OUString aHierName = aXMLName;
2118 : 0 : aHierName += aStateName;
2119 : : Any aKeyValue
2120 [ # # ]: 0 : = xHierNameAccess->getByHierarchicalName(
2121 [ # # ]: 0 : aHierName );
2122 : :
2123 : 0 : sal_Int32 nState = 0;
2124 [ # # ]: 0 : if ( !( aKeyValue >>= nState ) )
2125 : : OSL_FAIL( "PersistentPropertySet::getPropertyValues - "
2126 : : "Error getting property state!" );
2127 : : else
2128 [ # # ]: 0 : rValue.State = PropertyState( nState );
2129 : : }
2130 [ # # ]: 0 : catch (const NoSuchElementException&)
2131 : : {
2132 : : // getByHierarchicalName
2133 : :
2134 : : OSL_FAIL( "PersistentPropertySet::getPropertyValues - "
2135 : : "NoSuchElementException!" );
2136 : : }
2137 : 0 : }
2138 : :
2139 [ # # ][ # # ]: 0 : return aValues;
2140 [ # # ]: 0 : }
2141 [ # # ][ # # ]: 0 : }
2142 [ # # ][ # # ]: 0 : }
2143 : : }
2144 [ # # ]: 0 : catch (const NoSuchElementException&)
2145 : : {
2146 : : // getByHierarchicalName
2147 : : }
2148 : : }
2149 : :
2150 [ # # ][ # # ]: 0 : return Sequence< PropertyValue >( 0 );
2151 : : }
2152 : :
2153 : : //=========================================================================
2154 : : // virtual
2155 : 0 : void SAL_CALL PersistentPropertySet::setPropertyValues(
2156 : : const Sequence< PropertyValue >& aProps )
2157 : : throw( UnknownPropertyException,
2158 : : PropertyVetoException,
2159 : : IllegalArgumentException,
2160 : : WrappedTargetException,
2161 : : RuntimeException )
2162 : : {
2163 : 0 : sal_Int32 nCount = aProps.getLength();
2164 [ # # ]: 0 : if ( !nCount )
2165 : : return;
2166 : :
2167 [ # # ]: 0 : osl::ClearableGuard< osl::Mutex > aCGuard( m_pImpl->m_aMutex );
2168 : :
2169 : : Reference< XHierarchicalNameAccess > xRootHierNameAccess(
2170 [ # # ][ # # ]: 0 : m_pImpl->m_pCreator->getRootConfigReadAccess(), UNO_QUERY );
2171 [ # # ]: 0 : if ( xRootHierNameAccess.is() )
2172 : : {
2173 : 0 : const PropertyValue* pNewValues = aProps.getConstArray();
2174 : :
2175 : : typedef std::list< PropertyChangeEvent > Events;
2176 [ # # ]: 0 : Events aEvents;
2177 : :
2178 [ # # ]: 0 : OUString aFullPropNamePrefix( getFullKey() );
2179 : 0 : aFullPropNamePrefix += OUString("/");
2180 : :
2181 : : // Iterate over given property value sequence.
2182 [ # # ]: 0 : for ( sal_Int32 n = 0; n < nCount; ++n )
2183 : : {
2184 : 0 : const PropertyValue& rNewValue = pNewValues[ n ];
2185 : 0 : const OUString& rName = rNewValue.Name;
2186 : :
2187 : 0 : OUString aFullPropName = aFullPropNamePrefix;
2188 [ # # ]: 0 : aFullPropName += makeHierarchalNameSegment( rName );
2189 : :
2190 : : // Does property exist?
2191 [ # # ][ # # ]: 0 : if ( xRootHierNameAccess->hasByHierarchicalName( aFullPropName ) )
[ # # ]
2192 : : {
2193 : : Reference< XNameReplace > xNameReplace(
2194 : : m_pImpl->m_pCreator->getConfigWriteAccess(
2195 [ # # ][ # # ]: 0 : aFullPropName ), UNO_QUERY );
2196 : : Reference< XChangesBatch > xBatch(
2197 : : m_pImpl->m_pCreator->getConfigWriteAccess(
2198 [ # # ][ # # ]: 0 : OUString() ), UNO_QUERY );
2199 : :
2200 [ # # ][ # # ]: 0 : if ( xNameReplace.is() && xBatch.is() )
[ # # ]
2201 : : {
2202 : : try
2203 : : {
2204 : : // Write handle
2205 [ # # ]: 0 : xNameReplace->replaceByName(
2206 : : OUString("Handle"),
2207 [ # # ][ # # ]: 0 : makeAny( rNewValue.Handle ) );
2208 : :
2209 : : // Save old value
2210 : 0 : OUString aValueName = aFullPropName;
2211 : 0 : aValueName += OUString("/Value");
2212 : : Any aOldValue
2213 [ # # ]: 0 : = xRootHierNameAccess->getByHierarchicalName(
2214 [ # # ]: 0 : aValueName );
2215 : : // Write value
2216 [ # # ]: 0 : xNameReplace->replaceByName(
2217 : : OUString("Value"),
2218 [ # # ]: 0 : rNewValue.Value );
2219 : :
2220 : : // Write state ( Now it is a directly set value )
2221 [ # # ]: 0 : xNameReplace->replaceByName(
2222 : : OUString("State"),
2223 : : makeAny(
2224 : : sal_Int32(
2225 [ # # ][ # # ]: 0 : PropertyState_DIRECT_VALUE ) ) );
2226 : :
2227 : : // Commit changes.
2228 [ # # ][ # # ]: 0 : xBatch->commitChanges();
2229 : :
2230 [ # # ]: 0 : if ( m_pImpl->m_pPropertyChangeListeners )
2231 : : {
2232 [ # # ]: 0 : PropertyChangeEvent aEvt;
2233 [ # # ]: 0 : aEvt.Source = (OWeakObject*)this;
2234 : 0 : aEvt.PropertyName = rNewValue.Name;
2235 : 0 : aEvt.PropertyHandle = rNewValue.Handle;
2236 : 0 : aEvt.Further = sal_False;
2237 : 0 : aEvt.OldValue = aOldValue;
2238 : 0 : aEvt.NewValue = rNewValue.Value;
2239 : :
2240 [ # # ][ # # ]: 0 : aEvents.push_back( aEvt );
2241 [ # # # # ]: 0 : }
2242 : : }
2243 [ # # ]: 0 : catch (const IllegalArgumentException&)
2244 : : {
2245 : : // replaceByName
2246 : : }
2247 [ # # ]: 0 : catch (const NoSuchElementException&)
2248 : : {
2249 : : // getByHierarchicalName, replaceByName
2250 : : }
2251 [ # # ]: 0 : catch (const WrappedTargetException&)
2252 : : {
2253 : : // replaceByName, commitChanges
2254 : : }
2255 : 0 : }
2256 : : }
2257 : 0 : }
2258 : :
2259 : : // Callback follows!
2260 [ # # ]: 0 : aCGuard.clear();
2261 : :
2262 [ # # ]: 0 : if ( m_pImpl->m_pPropertyChangeListeners )
2263 : : {
2264 : : // Notify property changes.
2265 : 0 : Events::const_iterator it = aEvents.begin();
2266 : 0 : Events::const_iterator end = aEvents.end();
2267 : :
2268 [ # # ]: 0 : while ( it != end )
2269 : : {
2270 [ # # ]: 0 : notifyPropertyChangeEvent( (*it) );
2271 : 0 : ++it;
2272 : : }
2273 : : }
2274 : :
2275 : 0 : return;
2276 : : }
2277 : :
2278 [ # # ][ # # ]: 0 : OSL_FAIL( "PersistentPropertySet::setPropertyValues - Nothing set!" );
[ # # ]
2279 : : }
2280 : :
2281 : : //=========================================================================
2282 : : //
2283 : : // Non-interface methods
2284 : : //
2285 : : //=========================================================================
2286 : :
2287 : 0 : void PersistentPropertySet::notifyPropertyChangeEvent(
2288 : : const PropertyChangeEvent& rEvent ) const
2289 : : {
2290 : : // Get "normal" listeners for the property.
2291 : : OInterfaceContainerHelper* pContainer =
2292 : : m_pImpl->m_pPropertyChangeListeners->getContainer(
2293 : 0 : rEvent.PropertyName );
2294 [ # # ][ # # ]: 0 : if ( pContainer && pContainer->getLength() )
[ # # ]
2295 : : {
2296 [ # # ]: 0 : OInterfaceIteratorHelper aIter( *pContainer );
2297 [ # # ]: 0 : while ( aIter.hasMoreElements() )
2298 : : {
2299 : : // Propagate event.
2300 : : Reference< XPropertyChangeListener > xListener(
2301 [ # # ][ # # ]: 0 : aIter.next(), UNO_QUERY );
2302 [ # # ]: 0 : if ( xListener.is() )
2303 [ # # ][ # # ]: 0 : xListener->propertyChange( rEvent );
2304 [ # # ]: 0 : }
2305 : : }
2306 : :
2307 : : // Get "normal" listeners for all properties.
2308 : : OInterfaceContainerHelper* pNoNameContainer =
2309 [ # # ]: 0 : m_pImpl->m_pPropertyChangeListeners->getContainer( OUString() );
2310 [ # # ][ # # ]: 0 : if ( pNoNameContainer && pNoNameContainer->getLength() )
[ # # ]
2311 : : {
2312 [ # # ]: 0 : OInterfaceIteratorHelper aIter( *pNoNameContainer );
2313 [ # # ]: 0 : while ( aIter.hasMoreElements() )
2314 : : {
2315 : : // Propagate event.
2316 : : Reference< XPropertyChangeListener > xListener(
2317 [ # # ][ # # ]: 0 : aIter.next(), UNO_QUERY );
2318 [ # # ]: 0 : if ( xListener.is() )
2319 [ # # ][ # # ]: 0 : xListener->propertyChange( rEvent );
2320 [ # # ]: 0 : }
2321 : : }
2322 : 0 : }
2323 : :
2324 : : //=========================================================================
2325 : 0 : void PersistentPropertySet::notifyPropertySetInfoChange(
2326 : : const PropertySetInfoChangeEvent& evt ) const
2327 : : {
2328 [ # # ]: 0 : if ( !m_pImpl->m_pPropSetChangeListeners )
2329 : 0 : return;
2330 : :
2331 : : // Notify event listeners.
2332 [ # # ]: 0 : OInterfaceIteratorHelper aIter( *( m_pImpl->m_pPropSetChangeListeners ) );
2333 [ # # ]: 0 : while ( aIter.hasMoreElements() )
2334 : : {
2335 : : // Propagate event.
2336 : : Reference< XPropertySetInfoChangeListener >
2337 [ # # ][ # # ]: 0 : xListener( aIter.next(), UNO_QUERY );
2338 [ # # ]: 0 : if ( xListener.is() )
2339 [ # # ][ # # ]: 0 : xListener->propertySetInfoChange( evt );
2340 [ # # ]: 0 : }
2341 : : }
2342 : :
2343 : : //=========================================================================
2344 : 78 : const OUString& PersistentPropertySet::getFullKey()
2345 : : {
2346 [ + + ]: 78 : if ( m_pImpl->m_aFullKey.isEmpty() )
2347 : : {
2348 [ + - ]: 72 : osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
2349 [ + - ]: 72 : if ( m_pImpl->m_aFullKey.isEmpty() )
2350 : : {
2351 : : m_pImpl->m_aFullKey
2352 [ + - ]: 72 : = makeHierarchalNameSegment( m_pImpl->m_aKey );
2353 : : m_pImpl->m_aFullKey
2354 : 72 : += OUString( "/Values" );
2355 [ + - ]: 72 : }
2356 : : }
2357 : :
2358 : 78 : return m_pImpl->m_aFullKey;
2359 : : }
2360 : :
2361 : : //=========================================================================
2362 : 6 : PropertySetRegistry& PersistentPropertySet::getPropertySetRegistry()
2363 : : {
2364 : 6 : return *m_pImpl->m_pCreator;
2365 : : }
2366 : :
2367 : : //=========================================================================
2368 : : //=========================================================================
2369 : : //
2370 : : // PropertySetInfo_Impl Implementation.
2371 : : //
2372 : : //=========================================================================
2373 : : //=========================================================================
2374 : :
2375 : 6 : PropertySetInfo_Impl::PropertySetInfo_Impl(
2376 : : const Reference< XMultiServiceFactory >& rxSMgr,
2377 : : PersistentPropertySet* pOwner )
2378 : : : m_xSMgr( rxSMgr ),
2379 : : m_pProps( NULL ),
2380 : 6 : m_pOwner( pOwner )
2381 : : {
2382 : 6 : }
2383 : :
2384 : : //=========================================================================
2385 : : // virtual
2386 : 6 : PropertySetInfo_Impl::~PropertySetInfo_Impl()
2387 : : {
2388 [ + - ][ + - ]: 6 : delete m_pProps;
2389 : :
2390 : : // !!! Do not delete m_pOwner !!!
2391 [ - + ]: 12 : }
2392 : :
2393 : : //=========================================================================
2394 : : //
2395 : : // XInterface methods.
2396 : : //
2397 : : //=========================================================================
2398 : :
2399 [ # # ][ # # ]: 24 : XINTERFACE_IMPL_2( PropertySetInfo_Impl,
[ # # ]
2400 : : XTypeProvider,
2401 : : XPropertySetInfo );
2402 : :
2403 : : //=========================================================================
2404 : : //
2405 : : // XTypeProvider methods.
2406 : : //
2407 : : //=========================================================================
2408 : :
2409 [ # # ][ # # ]: 0 : XTYPEPROVIDER_IMPL_2( PropertySetInfo_Impl,
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
2410 : : XTypeProvider,
2411 : : XPropertySetInfo );
2412 : :
2413 : : //=========================================================================
2414 : : //
2415 : : // XPropertySetInfo methods.
2416 : : //
2417 : : //=========================================================================
2418 : :
2419 : : // virtual
2420 : 6 : Sequence< Property > SAL_CALL PropertySetInfo_Impl::getProperties()
2421 : : throw( RuntimeException )
2422 : : {
2423 [ + - ]: 6 : if ( !m_pProps )
2424 : : {
2425 : : Reference< XHierarchicalNameAccess > xRootHierNameAccess(
2426 : 6 : m_pOwner->getPropertySetRegistry().getRootConfigReadAccess(),
2427 [ + - ][ + - ]: 6 : UNO_QUERY );
2428 [ + - ]: 6 : if ( xRootHierNameAccess.is() )
2429 : : {
2430 : : try
2431 : : {
2432 : 6 : Reference< XNameAccess > xNameAccess;
2433 [ + - ]: 6 : xRootHierNameAccess->getByHierarchicalName(
2434 [ + - ]: 6 : m_pOwner->getFullKey() )
2435 [ + - ][ + - ]: 6 : >>= xNameAccess;
2436 [ + - ]: 6 : if ( xNameAccess.is() )
2437 : : {
2438 : : // Obtain property names.
2439 : :
2440 : : Sequence< OUString > aElems
2441 [ + - ][ + - ]: 6 : = xNameAccess->getElementNames();
2442 : :
2443 : 6 : sal_uInt32 nCount = aElems.getLength();
2444 : : Sequence< Property >* pPropSeq
2445 [ + - ]: 6 : = new Sequence< Property >( nCount );
2446 : :
2447 [ + - ]: 6 : if ( nCount )
2448 : : {
2449 : : Reference< XHierarchicalNameAccess > xHierNameAccess(
2450 [ + - ]: 6 : xNameAccess, UNO_QUERY );
2451 : :
2452 : : OSL_ENSURE( xHierNameAccess.is(),
2453 : : "PropertySetInfo_Impl::getProperties - "
2454 : : "No hierarchical name access!" );
2455 : :
2456 [ + - ]: 6 : if ( xHierNameAccess.is() )
2457 : : {
2458 : 6 : const OUString aHandleName("/Handle");
2459 : 6 : const OUString aValueName("/Value");
2460 : 6 : const OUString aAttrName("/Attributes");
2461 : :
2462 [ + - ]: 6 : Property* pProps = pPropSeq->getArray();
2463 : :
2464 [ + + ]: 18 : for ( sal_uInt32 n = 0; n < nCount; ++n )
2465 : : {
2466 : 12 : Property& rProp = pProps[ n ];
2467 [ + - ]: 12 : OUString rName = aElems[ n ];
2468 : : OUString aXMLName
2469 [ + - ]: 12 : = makeHierarchalNameSegment( rName );
2470 : :
2471 : : // Set property name.
2472 : :
2473 : 12 : rProp.Name = rName;
2474 : :
2475 : : try
2476 : : {
2477 : : // Obtain and set property handle
2478 : 12 : OUString aHierName = aXMLName;
2479 : 12 : aHierName += aHandleName;
2480 : : Any aKeyValue
2481 [ + - ]: 12 : = xHierNameAccess->getByHierarchicalName(
2482 [ + - ]: 12 : aHierName );
2483 : :
2484 : 12 : if ( !( aKeyValue >>= rProp.Handle ) )
2485 : : OSL_FAIL( "PropertySetInfo_Impl::getProperties - "
2486 [ # # ]: 12 : "Error getting property handle!" );
2487 : : }
2488 [ # # ]: 0 : catch (const NoSuchElementException&)
2489 : : {
2490 : : // getByHierarchicalName
2491 : :
2492 : : OSL_FAIL( "PropertySetInfo_Impl::getProperties - "
2493 : : "NoSuchElementException!" );
2494 : : }
2495 : :
2496 : : try
2497 : : {
2498 : : // Obtain and set property type
2499 : 12 : OUString aHierName = aXMLName;
2500 : 12 : aHierName += aValueName;
2501 : : Any aKeyValue
2502 [ + - ]: 12 : = xHierNameAccess->getByHierarchicalName(
2503 [ + - ]: 12 : aHierName );
2504 : :
2505 : : // Note: The type may be void if addProperty
2506 : : // was called with a default value
2507 : : // of type void.
2508 : :
2509 [ # # ]: 12 : rProp.Type = aKeyValue.getValueType();
2510 : : }
2511 [ # # ]: 0 : catch (const NoSuchElementException&)
2512 : : {
2513 : : // getByHierarchicalName
2514 : :
2515 : : OSL_FAIL( "PropertySetInfo_Impl::getProperties - "
2516 : : "NoSuchElementException!" );
2517 : : }
2518 : :
2519 : : try
2520 : : {
2521 : : // Obtain and set property attributes
2522 : 12 : OUString aHierName = aXMLName;
2523 : 12 : aHierName += aAttrName;
2524 : : Any aKeyValue
2525 [ + - ]: 12 : = xHierNameAccess->getByHierarchicalName(
2526 [ + - ]: 12 : aHierName );
2527 : :
2528 : 12 : sal_Int32 nAttribs = 0;
2529 [ + - ]: 12 : if ( aKeyValue >>= nAttribs )
2530 : : rProp.Attributes
2531 : 12 : = sal_Int16( nAttribs );
2532 : : else
2533 : : OSL_FAIL( "PropertySetInfo_Impl::getProperties - "
2534 [ # # ]: 12 : "Error getting property attributes!" );
2535 : : }
2536 [ # # ]: 0 : catch (const NoSuchElementException&)
2537 : : {
2538 : : // getByHierarchicalName
2539 : :
2540 : : OSL_FAIL( "PropertySetInfo_Impl::getProperties - "
2541 : : "NoSuchElementException!" );
2542 : : }
2543 : 18 : }
2544 : 6 : }
2545 : : }
2546 : :
2547 : : // Success.
2548 : 6 : m_pProps = pPropSeq;
2549 [ + - ][ + - ]: 6 : return *m_pProps;
2550 [ - + ][ # # ]: 6 : }
2551 : : }
2552 [ # # ]: 0 : catch (const NoSuchElementException&)
2553 : : {
2554 : : // getByHierarchicalName
2555 : : }
2556 : : }
2557 : :
2558 : : OSL_FAIL( "PropertySetInfo_Impl::getProperties - Error!" );
2559 [ # # ][ - + ]: 6 : m_pProps = new Sequence< Property >( 0 );
2560 : : }
2561 : :
2562 : 6 : return *m_pProps;
2563 : : }
2564 : :
2565 : : //=========================================================================
2566 : : // virtual
2567 : 0 : Property SAL_CALL PropertySetInfo_Impl::getPropertyByName(
2568 : : const OUString& aName )
2569 : : throw( UnknownPropertyException, RuntimeException )
2570 : : {
2571 : : Reference< XHierarchicalNameAccess > xRootHierNameAccess(
2572 : 0 : m_pOwner->getPropertySetRegistry().getRootConfigReadAccess(),
2573 [ # # ][ # # ]: 0 : UNO_QUERY );
2574 [ # # ]: 0 : if ( xRootHierNameAccess.is() )
2575 : : {
2576 [ # # ]: 0 : OUString aFullPropName( m_pOwner->getFullKey() );
2577 : 0 : aFullPropName += OUString("/");
2578 [ # # ]: 0 : aFullPropName += makeHierarchalNameSegment( aName );
2579 : :
2580 : : // Does property exist?
2581 [ # # ][ # # ]: 0 : if ( !xRootHierNameAccess->hasByHierarchicalName( aFullPropName ) )
[ # # ]
2582 [ # # ]: 0 : throw UnknownPropertyException();
2583 : :
2584 : : try
2585 : : {
2586 : 0 : Property aProp;
2587 : :
2588 : : // Obtain handle.
2589 : 0 : OUString aKey = aFullPropName;
2590 : 0 : aKey += OUString("/Handle");
2591 : :
2592 [ # # # # ]: 0 : if ( !( xRootHierNameAccess->getByHierarchicalName( aKey )
2593 [ # # ]: 0 : >>= aProp.Handle ) )
2594 : : {
2595 : : OSL_FAIL( "PropertySetInfo_Impl::getPropertyByName - "
2596 : : "No handle!" );
2597 : 0 : return Property();
2598 : : }
2599 : :
2600 : : // Obtain Value and extract type.
2601 : 0 : aKey = aFullPropName;
2602 : 0 : aKey += OUString("/Value");
2603 : :
2604 [ # # ][ # # ]: 0 : Any aValue = xRootHierNameAccess->getByHierarchicalName( aKey );
2605 [ # # ]: 0 : if ( !aValue.hasValue() )
2606 : : {
2607 : : OSL_FAIL( "PropertySetInfo_Impl::getPropertyByName - "
2608 : : "No Value!" );
2609 : 0 : return Property();
2610 : : }
2611 : :
2612 : 0 : aProp.Type = aValue.getValueType();
2613 : :
2614 : : // Obtain Attributes.
2615 : 0 : aKey = aFullPropName;
2616 : 0 : aKey += OUString("/Attributes");
2617 : :
2618 : 0 : sal_Int32 nAttribs = 0;
2619 [ # # # # ]: 0 : if ( xRootHierNameAccess->getByHierarchicalName( aKey )
2620 [ # # ]: 0 : >>= nAttribs )
2621 : 0 : aProp.Attributes = sal_Int16( nAttribs );
2622 : : else
2623 : : {
2624 : : OSL_FAIL( "PropertySetInfo_Impl::getPropertyByName - "
2625 : : "No attributes!" );
2626 : 0 : return Property();
2627 : : }
2628 : :
2629 : : // set name.
2630 : 0 : aProp.Name = aName;
2631 : :
2632 : : // Success.
2633 [ # # ]: 0 : return aProp;
2634 : : }
2635 [ # # ]: 0 : catch (const NoSuchElementException&)
2636 : : {
2637 : : // getByHierarchicalName
2638 : :
2639 : : OSL_FAIL( "PropertySetInfo_Impl::getPropertyByName - "
2640 : : "caught NoSuchElementException!" );
2641 [ # # ]: 0 : }
2642 : :
2643 : : }
2644 : :
2645 : : OSL_FAIL( "PropertySetInfo_Impl::getPropertyByName - Error!" );
2646 : 0 : return Property();
2647 : : }
2648 : :
2649 : : //=========================================================================
2650 : : // virtual
2651 : 0 : sal_Bool SAL_CALL PropertySetInfo_Impl::hasPropertyByName(
2652 : : const OUString& Name )
2653 : : throw( RuntimeException )
2654 : : {
2655 : : Reference< XHierarchicalNameAccess > xRootHierNameAccess(
2656 : 0 : m_pOwner->getPropertySetRegistry().getRootConfigReadAccess(),
2657 [ # # ][ # # ]: 0 : UNO_QUERY );
2658 [ # # ]: 0 : if ( xRootHierNameAccess.is() )
2659 : : {
2660 [ # # ]: 0 : OUString aFullPropName( m_pOwner->getFullKey() );
2661 : 0 : aFullPropName += OUString("/");
2662 [ # # ]: 0 : aFullPropName += makeHierarchalNameSegment( Name );
2663 : :
2664 [ # # ][ # # ]: 0 : return xRootHierNameAccess->hasByHierarchicalName( aFullPropName );
2665 : : }
2666 : :
2667 : 0 : return sal_False;
2668 : : }
2669 : :
2670 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|