merge the formfield patch from ooo-build
[ooovba.git] / ucb / source / core / ucbstore.cxx
blobe0abbba396ebd6230329bbcb95e784f4b79028e2
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ucbstore.cxx,v $
10 * $Revision: 1.17 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_ucb.hxx"
34 /**************************************************************************
35 TODO
36 **************************************************************************
38 *************************************************************************/
40 #include <list>
41 #include <hash_map>
42 #include <osl/diagnose.h>
43 #include <rtl/ustrbuf.hxx>
44 #include <cppuhelper/interfacecontainer.hxx>
45 #include <com/sun/star/beans/PropertyAttribute.hpp>
46 #include <com/sun/star/beans/PropertySetInfoChange.hpp>
47 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
48 #include <com/sun/star/container/XNameContainer.hpp>
49 #include <com/sun/star/container/XNameReplace.hpp>
50 #include <com/sun/star/util/XChangesBatch.hpp>
51 #include "ucbstore.hxx"
53 using namespace com::sun::star::beans;
54 using namespace com::sun::star::container;
55 using namespace com::sun::star::lang;
56 using namespace com::sun::star::ucb;
57 using namespace com::sun::star::uno;
58 using namespace com::sun::star::util;
59 using namespace cppu;
60 using namespace rtl;
62 //=========================================================================
63 rtl::OUString makeHierarchalNameSegment( const rtl::OUString & rIn )
65 rtl::OUStringBuffer aBuffer;
66 aBuffer.appendAscii( "['" );
68 sal_Int32 nCount = rIn.getLength();
69 for ( sal_Int32 n = 0; n < nCount; ++n )
71 const sal_Unicode c = rIn.getStr()[ n ];
72 switch ( c )
74 case '&':
75 aBuffer.appendAscii( "&amp;" );
76 break;
78 case '"':
79 aBuffer.appendAscii( "&quot;" );
80 break;
82 case '\'':
83 aBuffer.appendAscii( "&apos;" );
84 break;
86 case '<':
87 aBuffer.appendAscii( "&lt;" );
88 break;
90 case '>':
91 aBuffer.appendAscii( "&gt;" );
92 break;
94 default:
95 aBuffer.append( c );
96 break;
100 aBuffer.appendAscii( "']" );
101 return rtl::OUString( aBuffer.makeStringAndClear() );
104 //=========================================================================
106 #define STORE_CONTENTPROPERTIES_KEY "/org.openoffice.ucb.Store/ContentProperties"
108 // describe path of cfg entry
109 #define CFGPROPERTY_NODEPATH "nodepath"
110 // true->async. update; false->sync. update
111 #define CFGPROPERTY_LAZYWRITE "lazywrite"
113 //=========================================================================
115 struct equalString_Impl
117 bool operator()( const OUString& s1, const OUString& s2 ) const
119 return !!( s1 == s2 );
123 struct hashString_Impl
125 size_t operator()( const OUString & rName ) const
127 return rName.hashCode();
131 //=========================================================================
133 // PropertySetMap_Impl.
135 //=========================================================================
137 typedef std::hash_map
139 OUString,
140 PersistentPropertySet*,
141 hashString_Impl,
142 equalString_Impl
144 PropertySetMap_Impl;
146 //=========================================================================
148 // class PropertySetInfo_Impl
150 //=========================================================================
152 class PropertySetInfo_Impl :
153 public OWeakObject, public XTypeProvider, public XPropertySetInfo
155 Reference< XMultiServiceFactory > m_xSMgr;
156 Sequence< Property >* m_pProps;
157 PersistentPropertySet* m_pOwner;
159 public:
160 PropertySetInfo_Impl( const Reference< XMultiServiceFactory >& rxSMgr,
161 PersistentPropertySet* pOwner );
162 virtual ~PropertySetInfo_Impl();
164 // XInterface
165 XINTERFACE_DECL()
167 // XTypeProvider
168 XTYPEPROVIDER_DECL()
170 // XPropertySetInfo
171 virtual Sequence< Property > SAL_CALL getProperties()
172 throw( RuntimeException );
173 virtual Property SAL_CALL getPropertyByName( const OUString& aName )
174 throw( UnknownPropertyException, RuntimeException );
175 virtual sal_Bool SAL_CALL hasPropertyByName( const OUString& Name )
176 throw( RuntimeException );
178 // Non-interface methods.
179 void reset() { delete m_pProps; m_pProps = 0; }
182 //=========================================================================
184 // UcbStore_Impl.
186 //=========================================================================
188 struct UcbStore_Impl
190 osl::Mutex m_aMutex;
191 Sequence< Any > m_aInitArgs;
192 Reference< XPropertySetRegistry > m_xTheRegistry;
195 //=========================================================================
196 //=========================================================================
197 //=========================================================================
199 // UcbStore Implementation.
201 //=========================================================================
202 //=========================================================================
203 //=========================================================================
205 UcbStore::UcbStore( const Reference< XMultiServiceFactory >& rXSMgr )
206 : m_xSMgr( rXSMgr ),
207 m_pImpl( new UcbStore_Impl() )
211 //=========================================================================
212 // virtual
213 UcbStore::~UcbStore()
215 delete m_pImpl;
218 //=========================================================================
220 // XInterface methods.
222 //=========================================================================
224 XINTERFACE_IMPL_4( UcbStore,
225 XTypeProvider,
226 XServiceInfo,
227 XPropertySetRegistryFactory,
228 XInitialization );
230 //=========================================================================
232 // XTypeProvider methods.
234 //=========================================================================
236 XTYPEPROVIDER_IMPL_4( UcbStore,
237 XTypeProvider,
238 XServiceInfo,
239 XPropertySetRegistryFactory,
240 XInitialization );
242 //=========================================================================
244 // XServiceInfo methods.
246 //=========================================================================
248 XSERVICEINFO_IMPL_1( UcbStore,
249 OUString::createFromAscii(
250 "com.sun.star.comp.ucb.UcbStore" ),
251 OUString::createFromAscii(
252 STORE_SERVICE_NAME ) );
254 //=========================================================================
256 // Service factory implementation.
258 //=========================================================================
260 ONE_INSTANCE_SERVICE_FACTORY_IMPL( UcbStore );
262 //=========================================================================
264 // XPropertySetRegistryFactory methods.
266 //=========================================================================
268 // virtual
269 Reference< XPropertySetRegistry > SAL_CALL
270 UcbStore::createPropertySetRegistry( const OUString& )
271 throw( RuntimeException )
273 // The URL parameter is ignored by this interface implementation. It always
274 // uses the configuration server as storage medium.
276 if ( !m_pImpl->m_xTheRegistry.is() )
278 osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
279 if ( !m_pImpl->m_xTheRegistry.is() )
280 m_pImpl->m_xTheRegistry = new PropertySetRegistry( m_xSMgr, *this );
282 return m_pImpl->m_xTheRegistry;
285 //=========================================================================
287 // XInitialization methods.
289 //=========================================================================
291 // virtual
292 void SAL_CALL UcbStore::initialize( const Sequence< Any >& aArguments )
293 throw( Exception, RuntimeException )
295 osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
296 m_pImpl->m_aInitArgs = aArguments;
299 //=========================================================================
301 // New methods.
303 //=========================================================================
305 void UcbStore::removeRegistry()
307 if ( m_pImpl->m_xTheRegistry.is() )
309 osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
310 if ( m_pImpl->m_xTheRegistry.is() )
311 m_pImpl->m_xTheRegistry = 0;
315 //=========================================================================
316 const Sequence< Any >& UcbStore::getInitArgs() const
318 return m_pImpl->m_aInitArgs;
321 //=========================================================================
323 // PropertySetRegistry_Impl.
325 //=========================================================================
327 struct PropertySetRegistry_Impl
329 UcbStore* m_pCreator;
330 PropertySetMap_Impl m_aPropSets;
331 Reference< XMultiServiceFactory > m_xConfigProvider;
332 Reference< XInterface > m_xRootReadAccess;
333 Reference< XInterface > m_xRootWriteAccess;
334 osl::Mutex m_aMutex;
335 sal_Bool m_bTriedToGetRootReadAccess; // #82494#
336 sal_Bool m_bTriedToGetRootWriteAccess; // #82494#
338 PropertySetRegistry_Impl( UcbStore& rCreator )
339 : m_pCreator( &rCreator ),
340 m_bTriedToGetRootReadAccess( sal_False ),
341 m_bTriedToGetRootWriteAccess( sal_False )
343 m_pCreator->acquire();
346 ~PropertySetRegistry_Impl()
348 m_pCreator->removeRegistry();
349 m_pCreator->release();
353 //=========================================================================
354 //=========================================================================
355 //=========================================================================
357 // PropertySetRegistry Implementation.
359 //=========================================================================
360 //=========================================================================
361 //=========================================================================
363 PropertySetRegistry::PropertySetRegistry(
364 const Reference< XMultiServiceFactory >& rXSMgr,
365 UcbStore& rCreator )
366 : m_xSMgr( rXSMgr ),
367 m_pImpl( new PropertySetRegistry_Impl( rCreator ) )
371 //=========================================================================
372 // virtual
373 PropertySetRegistry::~PropertySetRegistry()
375 delete m_pImpl;
378 //=========================================================================
380 // XInterface methods.
382 //=========================================================================
384 XINTERFACE_IMPL_5( PropertySetRegistry,
385 XTypeProvider,
386 XServiceInfo,
387 XPropertySetRegistry,
388 XElementAccess, /* base of XNameAccess */
389 XNameAccess );
391 //=========================================================================
393 // XTypeProvider methods.
395 //=========================================================================
397 XTYPEPROVIDER_IMPL_4( PropertySetRegistry,
398 XTypeProvider,
399 XServiceInfo,
400 XPropertySetRegistry,
401 XNameAccess );
403 //=========================================================================
405 // XServiceInfo methods.
407 //=========================================================================
409 XSERVICEINFO_NOFACTORY_IMPL_1( PropertySetRegistry,
410 OUString::createFromAscii(
411 "com.sun.star.comp.ucb.PropertySetRegistry" ),
412 OUString::createFromAscii(
413 PROPSET_REG_SERVICE_NAME ) );
415 //=========================================================================
417 // XPropertySetRegistry methods.
419 //=========================================================================
421 // virtual
422 Reference< XPersistentPropertySet > SAL_CALL
423 PropertySetRegistry::openPropertySet( const OUString& key, sal_Bool create )
424 throw( RuntimeException )
426 if ( key.getLength() )
428 osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
430 PropertySetMap_Impl& rSets = m_pImpl->m_aPropSets;
432 PropertySetMap_Impl::const_iterator it = rSets.find( key );
433 if ( it != rSets.end() )
435 // Already instanciated.
436 return Reference< XPersistentPropertySet >( (*it).second );
438 else
440 // Create new instance.
441 Reference< XNameAccess > xRootNameAccess(
442 getRootConfigReadAccess(), UNO_QUERY );
443 if ( xRootNameAccess.is() )
445 // Propertyset in registry?
446 if ( xRootNameAccess->hasByName( key ) )
448 // Yep!
449 return Reference< XPersistentPropertySet >(
450 new PersistentPropertySet(
451 m_xSMgr, *this, key ) );
453 else if ( create )
455 // No. Create entry for propertyset.
457 Reference< XSingleServiceFactory > xFac(
458 getConfigWriteAccess( OUString() ), UNO_QUERY );
459 Reference< XChangesBatch > xBatch( xFac, UNO_QUERY );
460 Reference< XNameContainer > xContainer( xFac, UNO_QUERY );
462 OSL_ENSURE( xFac.is(),
463 "PropertySetRegistry::openPropertySet - "
464 "No factory!" );
466 OSL_ENSURE( xBatch.is(),
467 "PropertySetRegistry::openPropertySet - "
468 "No batch!" );
470 OSL_ENSURE( xContainer.is(),
471 "PropertySetRegistry::openPropertySet - "
472 "No conteiner!" );
474 if ( xFac.is() && xBatch.is() && xContainer.is() )
478 // Create new "Properties" config item.
479 Reference< XNameReplace > xNameReplace(
480 xFac->createInstance(), UNO_QUERY );
482 if ( xNameReplace.is() )
484 // Fill new item...
486 // // Set Values
487 // xNameReplace->replaceByName(
488 // OUString::createFromAscii( "Values" ),
489 // makeAny( ... ) );
491 // Insert new item.
492 xContainer->insertByName(
493 key, makeAny( xNameReplace ) );
494 // Commit changes.
495 xBatch->commitChanges();
497 return Reference< XPersistentPropertySet >(
498 new PersistentPropertySet(
499 m_xSMgr, *this, key ) );
502 catch ( IllegalArgumentException& )
504 // insertByName
506 OSL_ENSURE( sal_False,
507 "PropertySetRegistry::openPropertySet - "
508 "caught IllegalArgumentException!" );
510 catch ( ElementExistException& )
512 // insertByName
514 OSL_ENSURE( sal_False,
515 "PropertySetRegistry::openPropertySet - "
516 "caught ElementExistException!" );
518 catch ( WrappedTargetException& )
520 // insertByName, commitChanges
522 OSL_ENSURE( sal_False,
523 "PropertySetRegistry::openPropertySet - "
524 "caught WrappedTargetException!" );
526 catch ( RuntimeException& )
528 OSL_ENSURE( sal_False,
529 "PropertySetRegistry::openPropertySet - "
530 "caught RuntimeException!" );
532 catch ( Exception& )
534 // createInstance
536 OSL_ENSURE( sal_False,
537 "PropertySetRegistry::openPropertySet - "
538 "caught Exception!" );
542 else
544 // No entry. Fail, but no error.
545 return Reference< XPersistentPropertySet >();
549 OSL_ENSURE( sal_False,
550 "PropertySetRegistry::openPropertySet - Error!" );
554 return Reference< XPersistentPropertySet >();
557 //=========================================================================
558 // virtual
559 void SAL_CALL PropertySetRegistry::removePropertySet( const OUString& key )
560 throw( RuntimeException )
562 if ( !key.getLength() )
563 return;
565 osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
567 Reference< XNameAccess > xRootNameAccess(
568 getRootConfigReadAccess(), UNO_QUERY );
569 if ( xRootNameAccess.is() )
571 // Propertyset in registry?
572 if ( !xRootNameAccess->hasByName( key ) )
573 return;
574 Reference< XChangesBatch > xBatch(
575 getConfigWriteAccess( OUString() ), UNO_QUERY );
576 Reference< XNameContainer > xContainer( xBatch, UNO_QUERY );
578 OSL_ENSURE( xBatch.is(),
579 "PropertySetRegistry::removePropertySet - "
580 "No batch!" );
582 OSL_ENSURE( xContainer.is(),
583 "PropertySetRegistry::removePropertySet - "
584 "No conteiner!" );
586 if ( xBatch.is() && xContainer.is() )
590 // Remove item.
591 xContainer->removeByName( key );
592 // Commit changes.
593 xBatch->commitChanges();
595 // Success.
596 return;
598 catch ( NoSuchElementException& )
600 // removeByName
602 OSL_ENSURE( sal_False,
603 "PropertySetRegistry::removePropertySet - "
604 "caught NoSuchElementException!" );
605 return;
607 catch ( WrappedTargetException& )
609 // commitChanges
611 OSL_ENSURE( sal_False,
612 "PropertySetRegistry::removePropertySet - "
613 "caught WrappedTargetException!" );
614 return;
618 return;
621 OSL_ENSURE( sal_False, "PropertySetRegistry::removePropertySet - Error!" );
624 //=========================================================================
626 // XElementAccess methods.
628 //=========================================================================
630 // virtual
631 com::sun::star::uno::Type SAL_CALL PropertySetRegistry::getElementType()
632 throw( RuntimeException )
634 return getCppuType( ( Reference< XPersistentPropertySet > * ) 0 );
637 //=========================================================================
638 // virtual
639 sal_Bool SAL_CALL PropertySetRegistry::hasElements()
640 throw( RuntimeException )
642 osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
644 Reference< XElementAccess > xElemAccess(
645 getRootConfigReadAccess(), UNO_QUERY );
646 if ( xElemAccess.is() )
647 return xElemAccess->hasElements();
649 return sal_False;
652 //=========================================================================
654 // XNameAccess methods.
656 //=========================================================================
658 // virtual
659 Any SAL_CALL PropertySetRegistry::getByName( const OUString& aName )
660 throw( NoSuchElementException, WrappedTargetException, RuntimeException )
662 osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
664 Reference< XNameAccess > xNameAccess(
665 getRootConfigReadAccess(), UNO_QUERY );
666 if ( xNameAccess.is() )
671 return xNameAccess->getByName( aName );
673 catch ( NoSuchElementException& )
675 // getByName
677 catch ( WrappedTargetException& )
679 // getByName
683 return Any();
686 //=========================================================================
687 // virtual
688 Sequence< OUString > SAL_CALL PropertySetRegistry::getElementNames()
689 throw( RuntimeException )
691 osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
693 Reference< XNameAccess > xNameAccess(
694 getRootConfigReadAccess(), UNO_QUERY );
695 if ( xNameAccess.is() )
697 return xNameAccess->getElementNames();
699 return Sequence< OUString >( 0 );
702 //=========================================================================
703 // virtual
704 sal_Bool SAL_CALL PropertySetRegistry::hasByName( const OUString& aName )
705 throw( RuntimeException )
707 osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
709 Reference< XNameAccess > xNameAccess(
710 getRootConfigReadAccess(), UNO_QUERY );
711 if ( xNameAccess.is() )
713 return xNameAccess->hasByName( aName );
716 return sal_False;
719 //=========================================================================
720 void PropertySetRegistry::add( PersistentPropertySet* pSet )
722 OUString key( pSet->getKey() );
724 if ( key.getLength() )
726 osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
727 m_pImpl->m_aPropSets[ key ] = pSet;
731 //=========================================================================
732 void PropertySetRegistry::remove( PersistentPropertySet* pSet )
734 OUString key( pSet->getKey() );
736 if ( key.getLength() )
738 osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
740 PropertySetMap_Impl& rSets = m_pImpl->m_aPropSets;
742 PropertySetMap_Impl::iterator it = rSets.find( key );
743 if ( it != rSets.end() )
745 // Found.
746 rSets.erase( it );
751 //=========================================================================
752 void PropertySetRegistry::renamePropertySet( const OUString& rOldKey,
753 const OUString& rNewKey )
755 if ( rOldKey == rNewKey )
756 return;
758 Reference< XNameAccess > xRootNameAccess(
759 getConfigWriteAccess( OUString() ), UNO_QUERY );
760 if ( xRootNameAccess.is() )
762 // Old key present?
763 if ( xRootNameAccess->hasByName( rOldKey ) )
765 // New key not present?
766 if ( xRootNameAccess->hasByName( rNewKey ) )
768 OSL_ENSURE( sal_False,
769 "PropertySetRegistry::renamePropertySet - "
770 "New key exists!" );
771 return;
773 Reference< XSingleServiceFactory > xFac(
774 xRootNameAccess, UNO_QUERY );
775 Reference< XChangesBatch > xBatch( xFac, UNO_QUERY );
776 Reference< XNameContainer > xContainer( xFac, UNO_QUERY );
778 OSL_ENSURE( xFac.is(),
779 "PropertySetRegistry::renamePropertySet - "
780 "No factory!" );
782 OSL_ENSURE( xBatch.is(),
783 "PropertySetRegistry::renamePropertySet - "
784 "No batch!" );
786 OSL_ENSURE( xContainer.is(),
787 "PropertySetRegistry::renamePropertySet - "
788 "No container!" );
790 if ( xFac.is() && xBatch.is() && xContainer.is() )
792 //////////////////////////////////////////////////////
793 // Create new "Properties" config item.
794 //////////////////////////////////////////////////////
798 Reference< XNameReplace > xNameReplace(
799 xFac->createInstance(), UNO_QUERY );
801 if ( xNameReplace.is() )
803 // Insert new item.
804 xContainer->insertByName(
805 rNewKey, makeAny( xNameReplace ) );
806 // Commit changes.
807 xBatch->commitChanges();
810 catch ( IllegalArgumentException& )
812 // insertByName
814 OSL_ENSURE( sal_False,
815 "PropertySetRegistry::renamePropertySet - "
816 "caught IllegalArgumentException!" );
817 return;
819 catch ( ElementExistException& )
821 // insertByName
823 OSL_ENSURE( sal_False,
824 "PropertySetRegistry::renamePropertySet - "
825 "caught ElementExistException!" );
826 return;
828 catch ( WrappedTargetException& )
830 // insertByName, commitChanges
832 OSL_ENSURE( sal_False,
833 "PropertySetRegistry::renamePropertySet - "
834 "caught WrappedTargetException!" );
835 return;
837 catch ( RuntimeException& )
839 OSL_ENSURE( sal_False,
840 "PropertySetRegistry::renamePropertySet - "
841 "caught RuntimeException!" );
842 return;
844 catch ( Exception& )
846 // createInstance
848 OSL_ENSURE( sal_False,
849 "PropertySetRegistry::renamePropertySet - "
850 "caught Exception!" );
851 return;
854 //////////////////////////////////////////////////////
855 // Copy data...
856 //////////////////////////////////////////////////////
858 Reference< XHierarchicalNameAccess > xRootHierNameAccess(
859 xRootNameAccess, UNO_QUERY );
860 if ( !xRootHierNameAccess.is() )
862 OSL_ENSURE( sal_False,
863 "PropertySetRegistry::renamePropertySet - "
864 "No hierarchical name access!" );
865 return;
870 rtl::OUString aOldValuesKey
871 = makeHierarchalNameSegment( rOldKey );
872 aOldValuesKey += OUString::createFromAscii( "/Values" );
874 Reference< XNameAccess > xOldNameAccess;
875 xRootHierNameAccess->getByHierarchicalName(
876 aOldValuesKey )
877 >>= xOldNameAccess;
878 if ( !xOldNameAccess.is() )
880 OSL_ENSURE( sal_False,
881 "PersistentPropertySet::renamePropertySet - "
882 "No old name access!" );
883 return;
886 // Obtain property names.
887 Sequence< OUString > aElems
888 = xOldNameAccess->getElementNames();
889 sal_Int32 nCount = aElems.getLength();
890 if ( nCount )
892 rtl::OUString aNewValuesKey
893 = makeHierarchalNameSegment( rNewKey );
894 aNewValuesKey += OUString::createFromAscii( "/Values" );
896 Reference< XSingleServiceFactory > xNewFac;
897 xRootHierNameAccess->getByHierarchicalName(
898 aNewValuesKey )
899 >>= xNewFac;
900 if ( !xNewFac.is() )
902 OSL_ENSURE( sal_False,
903 "PersistentPropertySet::renamePropertySet - "
904 "No new factory!" );
905 return;
908 Reference< XNameContainer > xNewContainer(
909 xNewFac, UNO_QUERY );
910 if ( !xNewContainer.is() )
912 OSL_ENSURE( sal_False,
913 "PersistentPropertySet::renamePropertySet - "
914 "No new container!" );
915 return;
918 aOldValuesKey += OUString::createFromAscii( "/" );
920 OUString aHandleKey
921 = OUString::createFromAscii( "/Handle" );
922 OUString aValueKey
923 = OUString::createFromAscii( "/Value" );
924 OUString aStateKey
925 = OUString::createFromAscii( "/State" );
926 OUString aAttrKey
927 = OUString::createFromAscii( "/Attributes" );
929 for ( sal_Int32 n = 0; n < nCount; ++n )
931 const OUString& rPropName = aElems[ n ];
933 // Create new item.
934 Reference< XNameReplace > xNewPropNameReplace(
935 xNewFac->createInstance(), UNO_QUERY );
937 if ( !xNewPropNameReplace.is() )
939 OSL_ENSURE( sal_False,
940 "PersistentPropertySet::renamePropertySet - "
941 "No new prop name replace!" );
942 return;
945 // Fill new item...
947 // Set Values
948 OUString aKey = aOldValuesKey;
949 aKey += makeHierarchalNameSegment( rPropName );
951 // ... handle
952 OUString aNewKey1 = aKey;
953 aNewKey1 += aHandleKey;
954 Any aAny =
955 xRootHierNameAccess->getByHierarchicalName(
956 aNewKey1 );
957 xNewPropNameReplace->replaceByName(
958 OUString::createFromAscii( "Handle" ),
959 aAny );
961 // ... value
962 aNewKey1 = aKey;
963 aNewKey1 += aValueKey;
964 aAny =
965 xRootHierNameAccess->getByHierarchicalName(
966 aNewKey1 );
967 xNewPropNameReplace->replaceByName(
968 OUString::createFromAscii( "Value" ),
969 aAny );
971 // ... state
972 aNewKey1 = aKey;
973 aNewKey1 += aStateKey;
974 aAny =
975 xRootHierNameAccess->getByHierarchicalName(
976 aNewKey1 );
977 xNewPropNameReplace->replaceByName(
978 OUString::createFromAscii( "State" ),
979 aAny );
981 // ... attributes
982 aNewKey1 = aKey;
983 aNewKey1 += aAttrKey;
984 aAny =
985 xRootHierNameAccess->getByHierarchicalName(
986 aNewKey1 );
987 xNewPropNameReplace->replaceByName(
988 OUString::createFromAscii( "Attributes" ),
989 aAny );
991 // Insert new item.
992 xNewContainer->insertByName(
993 rPropName, makeAny( xNewPropNameReplace ) );
995 // Commit changes.
996 xBatch->commitChanges();
1000 catch ( IllegalArgumentException& )
1002 // insertByName, replaceByName
1004 OSL_ENSURE( sal_False,
1005 "PropertySetRegistry::renamePropertySet - "
1006 "caught IllegalArgumentException!" );
1007 return;
1009 catch ( ElementExistException& )
1011 // insertByName
1013 OSL_ENSURE( sal_False,
1014 "PropertySetRegistry::renamePropertySet - "
1015 "caught ElementExistException!" );
1016 return;
1018 catch ( WrappedTargetException& )
1020 // insertByName, replaceByName, commitChanges
1022 OSL_ENSURE( sal_False,
1023 "PropertySetRegistry::renamePropertySet - "
1024 "caught WrappedTargetException!" );
1025 return;
1027 catch ( NoSuchElementException& )
1029 // getByHierarchicalName, replaceByName
1031 OSL_ENSURE( sal_False,
1032 "PropertySetRegistry::renamePropertySet - "
1033 "caught NoSuchElementException!" );
1034 return;
1036 catch ( RuntimeException& )
1038 OSL_ENSURE( sal_False,
1039 "PropertySetRegistry::renamePropertySet - "
1040 "caught RuntimeException!" );
1041 return;
1043 catch ( Exception& )
1045 // createInstance
1047 OSL_ENSURE( sal_False,
1048 "PropertySetRegistry::renamePropertySet - "
1049 "caught Exception!" );
1050 return;
1053 //////////////////////////////////////////////////////
1054 // Remove old entry...
1055 //////////////////////////////////////////////////////
1059 // Remove item.
1060 xContainer->removeByName( rOldKey );
1061 // Commit changes.
1062 xBatch->commitChanges();
1064 // Success.
1065 return;
1067 catch ( NoSuchElementException& )
1069 // removeByName
1071 OSL_ENSURE( sal_False,
1072 "PropertySetRegistry::renamePropertySet - "
1073 "caught NoSuchElementException!" );
1074 return;
1076 catch ( WrappedTargetException& )
1078 // commitChanges
1080 OSL_ENSURE( sal_False,
1081 "PropertySetRegistry::renamePropertySet - "
1082 "caught WrappedTargetException!" );
1083 return;
1089 OSL_ENSURE( sal_False, "PropertySetRegistry::renamePropertySet - Error!" );
1092 //=========================================================================
1093 Reference< XMultiServiceFactory > PropertySetRegistry::getConfigProvider()
1095 if ( !m_pImpl->m_xConfigProvider.is() )
1097 osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
1098 if ( !m_pImpl->m_xConfigProvider.is() )
1100 const Sequence< Any >& rInitArgs
1101 = m_pImpl->m_pCreator->getInitArgs();
1103 if ( rInitArgs.getLength() > 0 )
1105 // Extract config provider from service init args.
1106 rInitArgs[ 0 ] >>= m_pImpl->m_xConfigProvider;
1108 OSL_ENSURE( m_pImpl->m_xConfigProvider.is(),
1109 "PropertySetRegistry::getConfigProvider - "
1110 "No config provider!" );
1112 else
1116 m_pImpl->m_xConfigProvider
1117 = Reference< XMultiServiceFactory >(
1118 m_xSMgr->createInstance(
1119 OUString::createFromAscii(
1120 "com.sun.star.configuration."
1121 "ConfigurationProvider" ) ),
1122 UNO_QUERY );
1124 OSL_ENSURE( m_pImpl->m_xConfigProvider.is(),
1125 "PropertySetRegistry::getConfigProvider - "
1126 "No config provider!" );
1129 catch ( Exception& )
1131 OSL_ENSURE( sal_False,
1132 "PropertySetRegistry::getConfigProvider - "
1133 "caught exception!" );
1139 return m_pImpl->m_xConfigProvider;
1142 //=========================================================================
1143 Reference< XInterface > PropertySetRegistry::getRootConfigReadAccess()
1147 osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
1149 if ( !m_pImpl->m_xRootReadAccess.is() )
1151 if ( m_pImpl->m_bTriedToGetRootReadAccess ) // #82494#
1153 OSL_ENSURE( sal_False,
1154 "PropertySetRegistry::getRootConfigReadAccess - "
1155 "Unable to read any config data! -> #82494#" );
1156 return Reference< XInterface >();
1159 getConfigProvider();
1161 if ( m_pImpl->m_xConfigProvider.is() )
1163 Sequence< Any > aArguments( 1 );
1164 PropertyValue aProperty;
1165 aProperty.Name
1166 = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
1167 CFGPROPERTY_NODEPATH ) );
1168 aProperty.Value
1169 <<= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
1170 STORE_CONTENTPROPERTIES_KEY ) );
1171 aArguments[ 0 ] <<= aProperty;
1173 m_pImpl->m_bTriedToGetRootReadAccess = sal_True;
1175 m_pImpl->m_xRootReadAccess =
1176 m_pImpl->m_xConfigProvider->createInstanceWithArguments(
1177 OUString::createFromAscii(
1178 "com.sun.star.configuration.ConfigurationAccess" ),
1179 aArguments );
1181 if ( m_pImpl->m_xRootReadAccess.is() )
1182 return m_pImpl->m_xRootReadAccess;
1185 else
1186 return m_pImpl->m_xRootReadAccess;
1188 catch ( RuntimeException& )
1190 throw;
1192 catch ( Exception& )
1194 // createInstance, createInstanceWithArguments
1196 OSL_ENSURE( sal_False,
1197 "PropertySetRegistry::getRootConfigReadAccess - caught Exception!" );
1198 return Reference< XInterface >();
1201 OSL_ENSURE( sal_False,
1202 "PropertySetRegistry::getRootConfigReadAccess - Error!" );
1203 return Reference< XInterface >();
1206 //=========================================================================
1207 Reference< XInterface > PropertySetRegistry::getConfigWriteAccess(
1208 const OUString& rPath )
1212 osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
1214 if ( !m_pImpl->m_xRootWriteAccess.is() )
1216 if ( m_pImpl->m_bTriedToGetRootWriteAccess ) // #82494#
1218 OSL_ENSURE( sal_False,
1219 "PropertySetRegistry::getConfigWriteAccess - "
1220 "Unable to write any config data! -> #82494#" );
1221 return Reference< XInterface >();
1224 getConfigProvider();
1226 if ( m_pImpl->m_xConfigProvider.is() )
1228 Sequence< Any > aArguments( 2 );
1229 PropertyValue aProperty;
1231 aProperty.Name
1232 = OUString( RTL_CONSTASCII_USTRINGPARAM(
1233 CFGPROPERTY_NODEPATH ) );
1234 aProperty.Value
1235 <<= OUString( RTL_CONSTASCII_USTRINGPARAM(
1236 STORE_CONTENTPROPERTIES_KEY ) );
1237 aArguments[ 0 ] <<= aProperty;
1239 aProperty.Name
1240 = OUString( RTL_CONSTASCII_USTRINGPARAM(
1241 CFGPROPERTY_LAZYWRITE ) );
1242 aProperty.Value <<= sal_True;
1243 aArguments[ 1 ] <<= aProperty;
1245 m_pImpl->m_bTriedToGetRootWriteAccess = sal_True;
1247 m_pImpl->m_xRootWriteAccess =
1248 m_pImpl->m_xConfigProvider->createInstanceWithArguments(
1249 OUString::createFromAscii(
1250 "com.sun.star.configuration.ConfigurationUpdateAccess" ),
1251 aArguments );
1253 OSL_ENSURE( m_pImpl->m_xRootWriteAccess.is(),
1254 "PropertySetRegistry::getConfigWriteAccess - "
1255 "No config update access!" );
1259 if ( m_pImpl->m_xRootWriteAccess.is() )
1261 if ( rPath.getLength() )
1263 Reference< XHierarchicalNameAccess > xNA(
1264 m_pImpl->m_xRootWriteAccess, UNO_QUERY );
1265 if ( xNA.is() )
1267 Reference< XInterface > xInterface;
1268 xNA->getByHierarchicalName( rPath ) >>= xInterface;
1270 if ( xInterface.is() )
1271 return xInterface;
1274 else
1275 return m_pImpl->m_xRootWriteAccess;
1278 catch ( RuntimeException& )
1280 throw;
1282 catch ( NoSuchElementException& )
1284 // getByHierarchicalName
1286 OSL_ENSURE( sal_False,
1287 "PropertySetRegistry::getConfigWriteAccess - "
1288 "caught NoSuchElementException!" );
1289 return Reference< XInterface >();
1291 catch ( Exception& )
1293 // createInstance, createInstanceWithArguments
1295 OSL_ENSURE( sal_False,
1296 "PropertySetRegistry::getConfigWriteAccess - "
1297 "caught Exception!" );
1298 return Reference< XInterface >();
1301 OSL_ENSURE( sal_False,
1302 "PropertySetRegistry::getConfigWriteAccess - Error!" );
1303 return Reference< XInterface >();
1306 //=========================================================================
1308 // PropertyListeners_Impl.
1310 //=========================================================================
1312 typedef OMultiTypeInterfaceContainerHelperVar
1314 OUString,
1315 hashString_Impl,
1316 equalString_Impl
1317 > PropertyListeners_Impl;
1319 //=========================================================================
1321 // PersistentPropertySet_Impl.
1323 //=========================================================================
1325 struct PersistentPropertySet_Impl
1327 PropertySetRegistry* m_pCreator;
1328 PropertySetInfo_Impl* m_pInfo;
1329 OUString m_aKey;
1330 OUString m_aFullKey;
1331 osl::Mutex m_aMutex;
1332 OInterfaceContainerHelper* m_pDisposeEventListeners;
1333 OInterfaceContainerHelper* m_pPropSetChangeListeners;
1334 PropertyListeners_Impl* m_pPropertyChangeListeners;
1336 PersistentPropertySet_Impl( PropertySetRegistry& rCreator,
1337 const OUString& rKey )
1338 : m_pCreator( &rCreator ), m_pInfo( NULL ), m_aKey( rKey ),
1339 m_pDisposeEventListeners( NULL ), m_pPropSetChangeListeners( NULL ),
1340 m_pPropertyChangeListeners( NULL )
1342 m_pCreator->acquire();
1345 ~PersistentPropertySet_Impl()
1347 m_pCreator->release();
1349 if ( m_pInfo )
1350 m_pInfo->release();
1352 delete m_pDisposeEventListeners;
1353 delete m_pPropSetChangeListeners;
1354 delete m_pPropertyChangeListeners;
1358 //=========================================================================
1359 //=========================================================================
1360 //=========================================================================
1362 // PersistentPropertySet Implementation.
1364 //=========================================================================
1365 //=========================================================================
1366 //=========================================================================
1368 PersistentPropertySet::PersistentPropertySet(
1369 const Reference< XMultiServiceFactory >& rXSMgr,
1370 PropertySetRegistry& rCreator,
1371 const OUString& rKey )
1372 : m_xSMgr( rXSMgr ),
1373 m_pImpl( new PersistentPropertySet_Impl( rCreator, rKey ) )
1375 // register at creator.
1376 rCreator.add( this );
1379 //=========================================================================
1380 // virtual
1381 PersistentPropertySet::~PersistentPropertySet()
1383 // deregister at creator.
1384 m_pImpl->m_pCreator->remove( this );
1386 delete m_pImpl;
1389 //=========================================================================
1391 // XInterface methods.
1393 //=========================================================================
1395 XINTERFACE_IMPL_9( PersistentPropertySet,
1396 XTypeProvider,
1397 XServiceInfo,
1398 XComponent,
1399 XPropertySet, /* base of XPersistentPropertySet */
1400 XNamed,
1401 XPersistentPropertySet,
1402 XPropertyContainer,
1403 XPropertySetInfoChangeNotifier,
1404 XPropertyAccess );
1406 //=========================================================================
1408 // XTypeProvider methods.
1410 //=========================================================================
1412 XTYPEPROVIDER_IMPL_8( PersistentPropertySet,
1413 XTypeProvider,
1414 XServiceInfo,
1415 XComponent,
1416 XPersistentPropertySet,
1417 XNamed,
1418 XPropertyContainer,
1419 XPropertySetInfoChangeNotifier,
1420 XPropertyAccess );
1422 //=========================================================================
1424 // XServiceInfo methods.
1426 //=========================================================================
1428 XSERVICEINFO_NOFACTORY_IMPL_1( PersistentPropertySet,
1429 OUString::createFromAscii(
1430 "com.sun.star.comp.ucb.PersistentPropertySet" ),
1431 OUString::createFromAscii(
1432 PERS_PROPSET_SERVICE_NAME ) );
1434 //=========================================================================
1436 // XComponent methods.
1438 //=========================================================================
1440 // virtual
1441 void SAL_CALL PersistentPropertySet::dispose()
1442 throw( RuntimeException )
1444 if ( m_pImpl->m_pDisposeEventListeners &&
1445 m_pImpl->m_pDisposeEventListeners->getLength() )
1447 EventObject aEvt;
1448 aEvt.Source = static_cast< XComponent * >( this );
1449 m_pImpl->m_pDisposeEventListeners->disposeAndClear( aEvt );
1452 if ( m_pImpl->m_pPropSetChangeListeners &&
1453 m_pImpl->m_pPropSetChangeListeners->getLength() )
1455 EventObject aEvt;
1456 aEvt.Source = static_cast< XPropertySetInfoChangeNotifier * >( this );
1457 m_pImpl->m_pPropSetChangeListeners->disposeAndClear( aEvt );
1460 if ( m_pImpl->m_pPropertyChangeListeners )
1462 EventObject aEvt;
1463 aEvt.Source = static_cast< XPropertySet * >( this );
1464 m_pImpl->m_pPropertyChangeListeners->disposeAndClear( aEvt );
1468 //=========================================================================
1469 // virtual
1470 void SAL_CALL PersistentPropertySet::addEventListener(
1471 const Reference< XEventListener >& Listener )
1472 throw( RuntimeException )
1474 if ( !m_pImpl->m_pDisposeEventListeners )
1475 m_pImpl->m_pDisposeEventListeners =
1476 new OInterfaceContainerHelper( m_pImpl->m_aMutex );
1478 m_pImpl->m_pDisposeEventListeners->addInterface( Listener );
1481 //=========================================================================
1482 // virtual
1483 void SAL_CALL PersistentPropertySet::removeEventListener(
1484 const Reference< XEventListener >& Listener )
1485 throw( RuntimeException )
1487 if ( m_pImpl->m_pDisposeEventListeners )
1488 m_pImpl->m_pDisposeEventListeners->removeInterface( Listener );
1490 // Note: Don't want to delete empty container here -> performance.
1493 //=========================================================================
1495 // XPropertySet methods.
1497 //=========================================================================
1499 // virtual
1500 Reference< XPropertySetInfo > SAL_CALL
1501 PersistentPropertySet::getPropertySetInfo()
1502 throw( RuntimeException )
1504 osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
1506 PropertySetInfo_Impl*& rpInfo = m_pImpl->m_pInfo;
1507 if ( !rpInfo )
1509 rpInfo = new PropertySetInfo_Impl( m_xSMgr, this );
1510 rpInfo->acquire();
1512 return Reference< XPropertySetInfo >( rpInfo );
1515 //=========================================================================
1516 // virtual
1517 void SAL_CALL PersistentPropertySet::setPropertyValue(
1518 const OUString& aPropertyName, const Any& aValue )
1519 throw( UnknownPropertyException,
1520 PropertyVetoException,
1521 IllegalArgumentException,
1522 WrappedTargetException,
1523 RuntimeException )
1525 if ( !aPropertyName.getLength() )
1526 throw UnknownPropertyException();
1528 osl::ClearableGuard< osl::Mutex > aCGuard( m_pImpl->m_aMutex );
1530 Reference< XHierarchicalNameAccess > xRootHierNameAccess(
1531 m_pImpl->m_pCreator->getRootConfigReadAccess(), UNO_QUERY );
1532 if ( xRootHierNameAccess.is() )
1534 OUString aFullPropName( getFullKey() );
1535 aFullPropName += OUString::createFromAscii( "/" );
1536 aFullPropName += makeHierarchalNameSegment( aPropertyName );
1538 // Does property exist?
1539 if ( xRootHierNameAccess->hasByHierarchicalName( aFullPropName ) )
1541 Reference< XNameReplace > xNameReplace(
1542 m_pImpl->m_pCreator->getConfigWriteAccess(
1543 aFullPropName ), UNO_QUERY );
1544 Reference< XChangesBatch > xBatch(
1545 m_pImpl->m_pCreator->getConfigWriteAccess(
1546 OUString() ), UNO_QUERY );
1548 if ( xNameReplace.is() && xBatch.is() )
1552 // Obtain old value
1553 OUString aValueName = aFullPropName;
1554 aValueName += OUString::createFromAscii( "/Value" );
1555 Any aOldValue
1556 = xRootHierNameAccess->getByHierarchicalName(
1557 aValueName );
1558 // Check value type.
1559 if ( aOldValue.getValueType() != aValue.getValueType() )
1561 aCGuard.clear();
1562 throw IllegalArgumentException();
1565 // Write value
1566 xNameReplace->replaceByName(
1567 OUString::createFromAscii( "Value" ),
1568 aValue );
1570 // Write state ( Now it is a directly set value )
1571 xNameReplace->replaceByName(
1572 OUString::createFromAscii( "State" ),
1573 makeAny( PropertyState_DIRECT_VALUE ) );
1575 // Commit changes.
1576 xBatch->commitChanges();
1578 PropertyChangeEvent aEvt;
1579 if ( m_pImpl->m_pPropertyChangeListeners )
1581 // Obtain handle
1582 aValueName = aFullPropName;
1583 aValueName += OUString::createFromAscii( "/Handle" );
1584 sal_Int32 nHandle = -1;
1585 xRootHierNameAccess->getByHierarchicalName( aValueName )
1586 >>= nHandle;
1588 aEvt.Source = (OWeakObject*)this;
1589 aEvt.PropertyName = aPropertyName;
1590 aEvt.PropertyHandle = nHandle;
1591 aEvt.Further = sal_False;
1592 aEvt.OldValue = aOldValue;
1593 aEvt.NewValue = aValue;
1595 // Callback follows!
1596 aCGuard.clear();
1598 notifyPropertyChangeEvent( aEvt );
1600 return;
1602 catch ( IllegalArgumentException& )
1604 // replaceByName
1606 catch ( NoSuchElementException& )
1608 // getByHierarchicalName, replaceByName
1610 catch ( WrappedTargetException& )
1612 // replaceByName, commitChanges
1618 throw UnknownPropertyException();
1621 //=========================================================================
1622 // virtual
1623 Any SAL_CALL PersistentPropertySet::getPropertyValue(
1624 const OUString& PropertyName )
1625 throw( UnknownPropertyException,
1626 WrappedTargetException,
1627 RuntimeException )
1629 if ( !PropertyName.getLength() )
1630 throw UnknownPropertyException();
1632 osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
1634 Reference< XHierarchicalNameAccess > xNameAccess(
1635 m_pImpl->m_pCreator->getRootConfigReadAccess(), UNO_QUERY );
1636 if ( xNameAccess.is() )
1638 OUString aFullPropName( getFullKey() );
1639 aFullPropName += OUString::createFromAscii( "/" );
1640 aFullPropName += makeHierarchalNameSegment( PropertyName );
1641 aFullPropName += OUString::createFromAscii( "/Value" );
1644 return xNameAccess->getByHierarchicalName( aFullPropName );
1646 catch ( NoSuchElementException& )
1648 throw UnknownPropertyException();
1652 throw UnknownPropertyException();
1655 //=========================================================================
1656 // virtual
1657 void SAL_CALL PersistentPropertySet::addPropertyChangeListener(
1658 const OUString& aPropertyName,
1659 const Reference< XPropertyChangeListener >& xListener )
1660 throw( UnknownPropertyException,
1661 WrappedTargetException,
1662 RuntimeException )
1664 // load();
1666 if ( !m_pImpl->m_pPropertyChangeListeners )
1667 m_pImpl->m_pPropertyChangeListeners =
1668 new PropertyListeners_Impl( m_pImpl->m_aMutex );
1670 m_pImpl->m_pPropertyChangeListeners->addInterface(
1671 aPropertyName, xListener );
1674 //=========================================================================
1675 // virtual
1676 void SAL_CALL PersistentPropertySet::removePropertyChangeListener(
1677 const OUString& aPropertyName,
1678 const Reference< XPropertyChangeListener >& aListener )
1679 throw( UnknownPropertyException,
1680 WrappedTargetException,
1681 RuntimeException )
1683 // load();
1685 if ( m_pImpl->m_pPropertyChangeListeners )
1686 m_pImpl->m_pPropertyChangeListeners->removeInterface(
1687 aPropertyName, aListener );
1689 // Note: Don't want to delete empty container here -> performance.
1692 //=========================================================================
1693 // virtual
1694 void SAL_CALL PersistentPropertySet::addVetoableChangeListener(
1695 const OUString&,
1696 const Reference< XVetoableChangeListener >& )
1697 throw( UnknownPropertyException,
1698 WrappedTargetException,
1699 RuntimeException )
1701 // load();
1702 // OSL_ENSURE( sal_False,
1703 // "PersistentPropertySet::addVetoableChangeListener - N.Y.I." );
1706 //=========================================================================
1707 // virtual
1708 void SAL_CALL PersistentPropertySet::removeVetoableChangeListener(
1709 const OUString&,
1710 const Reference< XVetoableChangeListener >& )
1711 throw( UnknownPropertyException,
1712 WrappedTargetException,
1713 RuntimeException )
1715 // load();
1716 // OSL_ENSURE( sal_False,
1717 // "PersistentPropertySet::removeVetoableChangeListener - N.Y.I." );
1720 //=========================================================================
1722 // XPersistentPropertySet methods.
1724 //=========================================================================
1726 // virtual
1727 Reference< XPropertySetRegistry > SAL_CALL PersistentPropertySet::getRegistry()
1728 throw( RuntimeException )
1730 return Reference< XPropertySetRegistry >( m_pImpl->m_pCreator );
1733 //=========================================================================
1734 // virtual
1735 OUString SAL_CALL PersistentPropertySet::getKey()
1736 throw( RuntimeException )
1738 return m_pImpl->m_aKey;
1741 //=========================================================================
1743 // XNamed methods.
1745 //=========================================================================
1747 // virtual
1748 rtl::OUString SAL_CALL PersistentPropertySet::getName()
1749 throw( RuntimeException )
1751 // same as getKey()
1752 return m_pImpl->m_aKey;
1755 //=========================================================================
1756 // virtual
1757 void SAL_CALL PersistentPropertySet::setName( const OUString& aName )
1758 throw( RuntimeException )
1760 if ( aName != m_pImpl->m_aKey )
1761 m_pImpl->m_pCreator->renamePropertySet( m_pImpl->m_aKey, aName );
1764 //=========================================================================
1766 // XPropertyContainer methods.
1768 //=========================================================================
1770 // virtual
1771 void SAL_CALL PersistentPropertySet::addProperty(
1772 const OUString& Name, sal_Int16 Attributes, const Any& DefaultValue )
1773 throw( PropertyExistException,
1774 IllegalTypeException,
1775 IllegalArgumentException,
1776 RuntimeException )
1778 if ( !Name.getLength() )
1779 throw IllegalArgumentException();
1781 // @@@ What other types can't be written to config server?
1783 // Check type class ( Not all types can be written to storage )
1784 TypeClass eTypeClass = DefaultValue.getValueTypeClass();
1785 if ( eTypeClass == TypeClass_INTERFACE )
1786 throw IllegalTypeException();
1788 osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
1790 // Property already in set?
1792 OUString aFullValuesName;
1794 Reference< XHierarchicalNameAccess > xRootHierNameAccess(
1795 m_pImpl->m_pCreator->getRootConfigReadAccess(), UNO_QUERY );
1796 if ( xRootHierNameAccess.is() )
1798 aFullValuesName = getFullKey();
1799 OUString aFullPropName = aFullValuesName;
1800 aFullPropName += OUString::createFromAscii( "/" );
1801 aFullPropName += makeHierarchalNameSegment( Name );
1803 if ( xRootHierNameAccess->hasByHierarchicalName( aFullPropName ) )
1805 // Already in set.
1806 throw PropertyExistException();
1810 // Property is always removeable.
1811 Attributes |= PropertyAttribute::REMOVEABLE;
1813 // Add property.
1815 Reference< XSingleServiceFactory > xFac(
1816 m_pImpl->m_pCreator->getConfigWriteAccess( aFullValuesName ),
1817 UNO_QUERY );
1818 Reference< XNameContainer > xContainer( xFac, UNO_QUERY );
1819 Reference< XChangesBatch > xBatch(
1820 m_pImpl->m_pCreator->getConfigWriteAccess( OUString() ),
1821 UNO_QUERY );
1823 OSL_ENSURE( xFac.is(),
1824 "PersistentPropertySet::addProperty - No factory!" );
1826 OSL_ENSURE( xBatch.is(),
1827 "PersistentPropertySet::addProperty - No batch!" );
1829 OSL_ENSURE( xContainer.is(),
1830 "PersistentPropertySet::addProperty - No container!" );
1832 if ( xFac.is() && xBatch.is() && xContainer.is() )
1836 // Create new "PropertyValue" config item.
1837 Reference< XNameReplace > xNameReplace(
1838 xFac->createInstance(), UNO_QUERY );
1840 if ( xNameReplace.is() )
1842 // Fill new item...
1844 // Set handle
1845 xNameReplace->replaceByName(
1846 OUString::createFromAscii( "Handle" ),
1847 makeAny( sal_Int32( -1 ) ) );
1849 // Set default value
1850 xNameReplace->replaceByName(
1851 OUString::createFromAscii( "Value" ),
1852 DefaultValue );
1854 // Set state ( always "default" )
1855 xNameReplace->replaceByName(
1856 OUString::createFromAscii( "State" ),
1857 makeAny( PropertyState_DEFAULT_VALUE ) );
1859 // Set attributes
1860 xNameReplace->replaceByName(
1861 OUString::createFromAscii( "Attributes" ),
1862 makeAny( sal_Int32( Attributes ) ) );
1864 // Insert new item.
1865 xContainer->insertByName( Name, makeAny( xNameReplace ) );
1867 // Commit changes.
1868 xBatch->commitChanges();
1870 // Property set info is invalid.
1871 if ( m_pImpl->m_pInfo )
1872 m_pImpl->m_pInfo->reset();
1874 // Notify propertyset info change listeners.
1875 if ( m_pImpl->m_pPropSetChangeListeners &&
1876 m_pImpl->m_pPropSetChangeListeners->getLength() )
1878 PropertySetInfoChangeEvent evt(
1879 static_cast< OWeakObject * >( this ),
1880 Name,
1882 PropertySetInfoChange::PROPERTY_INSERTED );
1883 notifyPropertySetInfoChange( evt );
1886 // Success.
1887 return;
1890 catch ( IllegalArgumentException& )
1892 // insertByName
1894 OSL_ENSURE( sal_False,
1895 "PersistentPropertySet::addProperty - "
1896 "caught IllegalArgumentException!" );
1897 return;
1899 catch ( ElementExistException& )
1901 // insertByName
1903 OSL_ENSURE( sal_False,
1904 "PersistentPropertySet::addProperty - "
1905 "caught ElementExistException!" );
1906 return;
1908 catch ( WrappedTargetException& )
1910 // replaceByName, insertByName, commitChanges
1912 OSL_ENSURE( sal_False,
1913 "PersistentPropertySet::addProperty - "
1914 "caught WrappedTargetException!" );
1915 return;
1917 catch ( RuntimeException& )
1919 throw;
1921 catch ( Exception& )
1923 // createInstance
1925 OSL_ENSURE( sal_False,
1926 "PersistentPropertySet::addProperty - "
1927 "caught Exception!" );
1928 return;
1932 OSL_ENSURE( sal_False,
1933 "PersistentPropertySet::addProperty - Error!" );
1936 //=========================================================================
1937 // virtual
1938 void SAL_CALL PersistentPropertySet::removeProperty( const OUString& Name )
1939 throw( UnknownPropertyException,
1940 NotRemoveableException,
1941 RuntimeException )
1943 osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
1945 OUString aFullValuesName;
1946 OUString aFullPropName;
1948 Reference< XHierarchicalNameAccess > xRootHierNameAccess(
1949 m_pImpl->m_pCreator->getRootConfigReadAccess(), UNO_QUERY );
1950 if ( xRootHierNameAccess.is() )
1952 aFullValuesName = getFullKey();
1953 aFullPropName = aFullValuesName;
1954 aFullPropName += OUString::createFromAscii( "/" );
1955 aFullPropName += makeHierarchalNameSegment( Name );
1957 // Property in set?
1958 if ( !xRootHierNameAccess->hasByHierarchicalName( aFullPropName ) )
1959 throw UnknownPropertyException();
1961 // Property removeable?
1964 OUString aFullAttrName = aFullPropName;
1965 aFullAttrName += OUString::createFromAscii( "/Attributes" );
1967 sal_Int32 nAttribs = 0;
1968 if ( xRootHierNameAccess->getByHierarchicalName( aFullAttrName )
1969 >>= nAttribs )
1971 if ( !( nAttribs & PropertyAttribute::REMOVEABLE ) )
1973 // Not removeable!
1974 throw NotRemoveableException();
1977 else
1979 OSL_ENSURE( sal_False,
1980 "PersistentPropertySet::removeProperty - "
1981 "No attributes!" );
1982 return;
1985 catch ( NoSuchElementException& )
1987 // getByHierarchicalName
1989 OSL_ENSURE( sal_False,
1990 "PersistentPropertySet::removeProperty - "
1991 "caught NoSuchElementException!" );
1994 // Remove property...
1996 Reference< XNameContainer > xContainer(
1997 m_pImpl->m_pCreator->getConfigWriteAccess( aFullValuesName ),
1998 UNO_QUERY );
1999 Reference< XChangesBatch > xBatch(
2000 m_pImpl->m_pCreator->getConfigWriteAccess( OUString() ),
2001 UNO_QUERY );
2003 OSL_ENSURE( xBatch.is(),
2004 "PersistentPropertySet::removeProperty - No batch!" );
2006 OSL_ENSURE( xContainer.is(),
2007 "PersistentPropertySet::removeProperty - No container!" );
2009 if ( xBatch.is() && xContainer.is() )
2013 sal_Int32 nHandle = -1;
2015 if ( m_pImpl->m_pPropSetChangeListeners &&
2016 m_pImpl->m_pPropSetChangeListeners->getLength() )
2018 // Obtain property handle ( needed for propertysetinfo
2019 // change event )...
2023 OUString aFullHandleName = aFullPropName;
2024 aFullHandleName
2025 += OUString::createFromAscii( "/Handle" );
2027 if ( ! ( xRootHierNameAccess->getByHierarchicalName(
2028 aFullHandleName ) >>= nHandle ) )
2029 nHandle = -1;
2032 catch ( NoSuchElementException& )
2034 // getByHierarchicalName
2036 OSL_ENSURE( sal_False,
2037 "PersistentPropertySet::removeProperty - "
2038 "caught NoSuchElementException!" );
2039 nHandle = -1;
2043 xContainer->removeByName( Name );
2044 xBatch->commitChanges();
2046 // Property set info is invalid.
2047 if ( m_pImpl->m_pInfo )
2048 m_pImpl->m_pInfo->reset();
2050 // Notify propertyset info change listeners.
2051 if ( m_pImpl->m_pPropSetChangeListeners &&
2052 m_pImpl->m_pPropSetChangeListeners->getLength() )
2054 PropertySetInfoChangeEvent evt(
2055 static_cast< OWeakObject * >( this ),
2056 Name,
2057 nHandle,
2058 PropertySetInfoChange::PROPERTY_REMOVED );
2059 notifyPropertySetInfoChange( evt );
2062 // Success.
2063 return;
2065 catch ( NoSuchElementException& )
2067 // removeByName
2069 OSL_ENSURE( sal_False,
2070 "PersistentPropertySet::removeProperty - "
2071 "caught NoSuchElementException!" );
2072 return;
2074 catch ( WrappedTargetException& )
2076 // commitChanges
2078 OSL_ENSURE( sal_False,
2079 "PersistentPropertySet::removeProperty - "
2080 "caught WrappedTargetException!" );
2081 return;
2086 OSL_ENSURE( sal_False,
2087 "PersistentPropertySet::removeProperty - Error!" );
2090 //=========================================================================
2092 // XPropertySetInfoChangeNotifier methods.
2094 //=========================================================================
2096 // virtual
2097 void SAL_CALL PersistentPropertySet::addPropertySetInfoChangeListener(
2098 const Reference< XPropertySetInfoChangeListener >& Listener )
2099 throw( RuntimeException )
2101 if ( !m_pImpl->m_pPropSetChangeListeners )
2102 m_pImpl->m_pPropSetChangeListeners =
2103 new OInterfaceContainerHelper( m_pImpl->m_aMutex );
2105 m_pImpl->m_pPropSetChangeListeners->addInterface( Listener );
2108 //=========================================================================
2109 // virtual
2110 void SAL_CALL PersistentPropertySet::removePropertySetInfoChangeListener(
2111 const Reference< XPropertySetInfoChangeListener >& Listener )
2112 throw( RuntimeException )
2114 if ( m_pImpl->m_pPropSetChangeListeners )
2115 m_pImpl->m_pPropSetChangeListeners->removeInterface( Listener );
2118 //=========================================================================
2120 // XPropertyAccess methods.
2122 //=========================================================================
2124 // virtual
2125 Sequence< PropertyValue > SAL_CALL PersistentPropertySet::getPropertyValues()
2126 throw( RuntimeException )
2128 osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
2130 Reference< XHierarchicalNameAccess > xRootHierNameAccess(
2131 m_pImpl->m_pCreator->getRootConfigReadAccess(), UNO_QUERY );
2132 if ( xRootHierNameAccess.is() )
2136 Reference< XNameAccess > xNameAccess;
2137 xRootHierNameAccess->getByHierarchicalName(getFullKey())
2138 >>= xNameAccess;
2139 if ( xNameAccess.is() )
2141 // Obtain property names.
2143 Sequence< OUString > aElems = xNameAccess->getElementNames();
2145 sal_Int32 nCount = aElems.getLength();
2146 if ( nCount )
2148 Reference< XHierarchicalNameAccess > xHierNameAccess(
2149 xNameAccess, UNO_QUERY );
2151 OSL_ENSURE( xHierNameAccess.is(),
2152 "PersistentPropertySet::getPropertyValues - "
2153 "No hierarchical name access!" );
2155 if ( xHierNameAccess.is() )
2157 Sequence< PropertyValue > aValues( nCount );
2159 const OUString aHandleName
2160 = OUString::createFromAscii( "/Handle" );
2161 const OUString aValueName
2162 = OUString::createFromAscii( "/Value" );
2163 const OUString aStateName
2164 = OUString::createFromAscii( "/State" );
2166 for ( sal_Int32 n = 0; n < nCount; ++n )
2168 PropertyValue& rValue = aValues[ n ];
2169 OUString rName = aElems[ n ];
2170 OUString aXMLName
2171 = makeHierarchalNameSegment( rName );
2173 // Set property name.
2175 rValue.Name = rName;
2179 // Obtain and set property handle
2180 OUString aHierName = aXMLName;
2181 aHierName += aHandleName;
2182 Any aKeyValue
2183 = xHierNameAccess->getByHierarchicalName(
2184 aHierName );
2186 if ( !( aKeyValue >>= rValue.Handle ) )
2187 OSL_ENSURE( sal_False,
2188 "PersistentPropertySet::getPropertyValues - "
2189 "Error getting property handle!" );
2191 catch ( NoSuchElementException& )
2193 // getByHierarchicalName
2195 OSL_ENSURE( sal_False,
2196 "PersistentPropertySet::getPropertyValues - "
2197 "NoSuchElementException!" );
2202 // Obtain and set property value
2203 OUString aHierName = aXMLName;
2204 aHierName += aValueName;
2205 rValue.Value
2206 = xHierNameAccess->getByHierarchicalName(
2207 aHierName );
2209 // Note: The value may be void if addProperty
2210 // was called with a default value
2211 // of type void.
2213 catch ( NoSuchElementException& )
2215 // getByHierarchicalName
2217 OSL_ENSURE( sal_False,
2218 "PersistentPropertySet::getPropertyValues - "
2219 "NoSuchElementException!" );
2224 // Obtain and set property state
2225 OUString aHierName = aXMLName;
2226 aHierName += aStateName;
2227 Any aKeyValue
2228 = xHierNameAccess->getByHierarchicalName(
2229 aHierName );
2231 sal_Int32 nState = 0;
2232 if ( !( aKeyValue >>= nState ) )
2233 OSL_ENSURE( sal_False,
2234 "PersistentPropertySet::getPropertyValues - "
2235 "Error getting property state!" );
2236 else
2237 rValue.State = PropertyState( nState );
2239 catch ( NoSuchElementException& )
2241 // getByHierarchicalName
2243 OSL_ENSURE( sal_False,
2244 "PersistentPropertySet::getPropertyValues - "
2245 "NoSuchElementException!" );
2249 return aValues;
2254 catch ( NoSuchElementException& )
2256 // getByHierarchicalName
2260 return Sequence< PropertyValue >( 0 );
2263 //=========================================================================
2264 // virtual
2265 void SAL_CALL PersistentPropertySet::setPropertyValues(
2266 const Sequence< PropertyValue >& aProps )
2267 throw( UnknownPropertyException,
2268 PropertyVetoException,
2269 IllegalArgumentException,
2270 WrappedTargetException,
2271 RuntimeException )
2273 sal_Int32 nCount = aProps.getLength();
2274 if ( !nCount )
2275 return;
2277 osl::ClearableGuard< osl::Mutex > aCGuard( m_pImpl->m_aMutex );
2279 Reference< XHierarchicalNameAccess > xRootHierNameAccess(
2280 m_pImpl->m_pCreator->getRootConfigReadAccess(), UNO_QUERY );
2281 if ( xRootHierNameAccess.is() )
2283 const PropertyValue* pNewValues = aProps.getConstArray();
2285 typedef std::list< PropertyChangeEvent > Events;
2286 Events aEvents;
2288 OUString aFullPropNamePrefix( getFullKey() );
2289 aFullPropNamePrefix += OUString::createFromAscii( "/" );
2291 // Iterate over given property value sequence.
2292 for ( sal_Int32 n = 0; n < nCount; ++n )
2294 const PropertyValue& rNewValue = pNewValues[ n ];
2295 const OUString& rName = rNewValue.Name;
2297 OUString aFullPropName = aFullPropNamePrefix;
2298 aFullPropName += makeHierarchalNameSegment( rName );
2300 // Does property exist?
2301 if ( xRootHierNameAccess->hasByHierarchicalName( aFullPropName ) )
2303 Reference< XNameReplace > xNameReplace(
2304 m_pImpl->m_pCreator->getConfigWriteAccess(
2305 aFullPropName ), UNO_QUERY );
2306 Reference< XChangesBatch > xBatch(
2307 m_pImpl->m_pCreator->getConfigWriteAccess(
2308 OUString() ), UNO_QUERY );
2310 if ( xNameReplace.is() && xBatch.is() )
2314 // Write handle
2315 xNameReplace->replaceByName(
2316 OUString::createFromAscii( "Handle" ),
2317 makeAny( rNewValue.Handle ) );
2319 // Save old value
2320 OUString aValueName = aFullPropName;
2321 aValueName += OUString::createFromAscii( "/Value" );
2322 Any aOldValue
2323 = xRootHierNameAccess->getByHierarchicalName(
2324 aValueName );
2325 // Write value
2326 xNameReplace->replaceByName(
2327 OUString::createFromAscii( "Value" ),
2328 rNewValue.Value );
2330 // Write state ( Now it is a directly set value )
2331 xNameReplace->replaceByName(
2332 OUString::createFromAscii( "State" ),
2333 makeAny( PropertyState_DIRECT_VALUE ) );
2335 // Commit changes.
2336 xBatch->commitChanges();
2338 if ( m_pImpl->m_pPropertyChangeListeners )
2340 PropertyChangeEvent aEvt;
2341 aEvt.Source = (OWeakObject*)this;
2342 aEvt.PropertyName = rNewValue.Name;
2343 aEvt.PropertyHandle = rNewValue.Handle;
2344 aEvt.Further = sal_False;
2345 aEvt.OldValue = aOldValue;
2346 aEvt.NewValue = rNewValue.Value;
2348 aEvents.push_back( aEvt );
2351 catch ( IllegalArgumentException& )
2353 // replaceByName
2355 catch ( NoSuchElementException& )
2357 // getByHierarchicalName, replaceByName
2359 catch ( WrappedTargetException& )
2361 // replaceByName, commitChanges
2367 // Callback follows!
2368 aCGuard.clear();
2370 if ( m_pImpl->m_pPropertyChangeListeners )
2372 // Notify property changes.
2373 Events::const_iterator it = aEvents.begin();
2374 Events::const_iterator end = aEvents.end();
2376 while ( it != end )
2378 notifyPropertyChangeEvent( (*it) );
2379 it++;
2383 return;
2386 OSL_ENSURE( sal_False,
2387 "PersistentPropertySet::setPropertyValues - Nothing set!" );
2390 //=========================================================================
2392 // Non-interface methods
2394 //=========================================================================
2396 void PersistentPropertySet::notifyPropertyChangeEvent(
2397 const PropertyChangeEvent& rEvent ) const
2399 // Get "normal" listeners for the property.
2400 OInterfaceContainerHelper* pContainer =
2401 m_pImpl->m_pPropertyChangeListeners->getContainer(
2402 rEvent.PropertyName );
2403 if ( pContainer && pContainer->getLength() )
2405 OInterfaceIteratorHelper aIter( *pContainer );
2406 while ( aIter.hasMoreElements() )
2408 // Propagate event.
2409 Reference< XPropertyChangeListener > xListener(
2410 aIter.next(), UNO_QUERY );
2411 if ( xListener.is() )
2412 xListener->propertyChange( rEvent );
2416 // Get "normal" listeners for all properties.
2417 OInterfaceContainerHelper* pNoNameContainer =
2418 m_pImpl->m_pPropertyChangeListeners->getContainer( OUString() );
2419 if ( pNoNameContainer && pNoNameContainer->getLength() )
2421 OInterfaceIteratorHelper aIter( *pNoNameContainer );
2422 while ( aIter.hasMoreElements() )
2424 // Propagate event.
2425 Reference< XPropertyChangeListener > xListener(
2426 aIter.next(), UNO_QUERY );
2427 if ( xListener.is() )
2428 xListener->propertyChange( rEvent );
2433 //=========================================================================
2434 void PersistentPropertySet::notifyPropertySetInfoChange(
2435 const PropertySetInfoChangeEvent& evt ) const
2437 if ( !m_pImpl->m_pPropSetChangeListeners )
2438 return;
2440 // Notify event listeners.
2441 OInterfaceIteratorHelper aIter( *( m_pImpl->m_pPropSetChangeListeners ) );
2442 while ( aIter.hasMoreElements() )
2444 // Propagate event.
2445 Reference< XPropertySetInfoChangeListener >
2446 xListener( aIter.next(), UNO_QUERY );
2447 if ( xListener.is() )
2448 xListener->propertySetInfoChange( evt );
2452 //=========================================================================
2453 const OUString& PersistentPropertySet::getFullKey()
2455 if ( !m_pImpl->m_aFullKey.getLength() )
2457 osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
2458 if ( !m_pImpl->m_aFullKey.getLength() )
2460 m_pImpl->m_aFullKey
2461 = makeHierarchalNameSegment( m_pImpl->m_aKey );
2462 m_pImpl->m_aFullKey
2463 += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/Values" ) );
2467 return m_pImpl->m_aFullKey;
2470 //=========================================================================
2471 PropertySetRegistry& PersistentPropertySet::getPropertySetRegistry()
2473 return *m_pImpl->m_pCreator;
2476 //=========================================================================
2477 //=========================================================================
2479 // PropertySetInfo_Impl Implementation.
2481 //=========================================================================
2482 //=========================================================================
2484 PropertySetInfo_Impl::PropertySetInfo_Impl(
2485 const Reference< XMultiServiceFactory >& rxSMgr,
2486 PersistentPropertySet* pOwner )
2487 : m_xSMgr( rxSMgr ),
2488 m_pProps( NULL ),
2489 m_pOwner( pOwner )
2493 //=========================================================================
2494 // virtual
2495 PropertySetInfo_Impl::~PropertySetInfo_Impl()
2497 delete m_pProps;
2499 // !!! Do not delete m_pOwner !!!
2502 //=========================================================================
2504 // XInterface methods.
2506 //=========================================================================
2508 XINTERFACE_IMPL_2( PropertySetInfo_Impl,
2509 XTypeProvider,
2510 XPropertySetInfo );
2512 //=========================================================================
2514 // XTypeProvider methods.
2516 //=========================================================================
2518 XTYPEPROVIDER_IMPL_2( PropertySetInfo_Impl,
2519 XTypeProvider,
2520 XPropertySetInfo );
2522 //=========================================================================
2524 // XPropertySetInfo methods.
2526 //=========================================================================
2528 // virtual
2529 Sequence< Property > SAL_CALL PropertySetInfo_Impl::getProperties()
2530 throw( RuntimeException )
2532 if ( !m_pProps )
2534 Reference< XHierarchicalNameAccess > xRootHierNameAccess(
2535 m_pOwner->getPropertySetRegistry().getRootConfigReadAccess(),
2536 UNO_QUERY );
2537 if ( xRootHierNameAccess.is() )
2541 Reference< XNameAccess > xNameAccess;
2542 xRootHierNameAccess->getByHierarchicalName(
2543 m_pOwner->getFullKey() )
2544 >>= xNameAccess;
2545 if ( xNameAccess.is() )
2547 // Obtain property names.
2549 Sequence< OUString > aElems
2550 = xNameAccess->getElementNames();
2552 sal_uInt32 nCount = aElems.getLength();
2553 Sequence< Property >* pPropSeq
2554 = new Sequence< Property >( nCount );
2556 if ( nCount )
2558 Reference< XHierarchicalNameAccess > xHierNameAccess(
2559 xNameAccess, UNO_QUERY );
2561 OSL_ENSURE( xHierNameAccess.is(),
2562 "PropertySetInfo_Impl::getProperties - "
2563 "No hierarchical name access!" );
2565 if ( xHierNameAccess.is() )
2567 const OUString aHandleName
2568 = OUString::createFromAscii( "/Handle" );
2569 const OUString aValueName
2570 = OUString::createFromAscii( "/Value" );
2571 const OUString aAttrName
2572 = OUString::createFromAscii( "/Attributes" );
2574 Property* pProps = pPropSeq->getArray();
2576 for ( sal_uInt32 n = 0; n < nCount; ++n )
2578 Property& rProp = pProps[ n ];
2579 OUString rName = aElems[ n ];
2580 OUString aXMLName
2581 = makeHierarchalNameSegment( rName );
2583 // Set property name.
2585 rProp.Name = rName;
2589 // Obtain and set property handle
2590 rtl::OUString aHierName = aXMLName;
2591 aHierName += aHandleName;
2592 Any aKeyValue
2593 = xHierNameAccess->getByHierarchicalName(
2594 aHierName );
2596 if ( !( aKeyValue >>= rProp.Handle ) )
2597 OSL_ENSURE( sal_False,
2598 "PropertySetInfo_Impl::getProperties - "
2599 "Error getting property handle!" );
2601 catch ( NoSuchElementException& )
2603 // getByHierarchicalName
2605 OSL_ENSURE( sal_False,
2606 "PropertySetInfo_Impl::getProperties - "
2607 "NoSuchElementException!" );
2612 // Obtain and set property type
2613 rtl::OUString aHierName = aXMLName;
2614 aHierName += aValueName;
2615 Any aKeyValue
2616 = xHierNameAccess->getByHierarchicalName(
2617 aHierName );
2619 // Note: The type may be void if addProperty
2620 // was called with a default value
2621 // of type void.
2623 rProp.Type = aKeyValue.getValueType();
2625 catch ( NoSuchElementException& )
2627 // getByHierarchicalName
2629 OSL_ENSURE( sal_False,
2630 "PropertySetInfo_Impl::getProperties - "
2631 "NoSuchElementException!" );
2636 // Obtain and set property attributes
2637 rtl::OUString aHierName = aXMLName;
2638 aHierName += aAttrName;
2639 Any aKeyValue
2640 = xHierNameAccess->getByHierarchicalName(
2641 aHierName );
2643 sal_Int32 nAttribs = 0;
2644 if ( aKeyValue >>= nAttribs )
2645 rProp.Attributes
2646 = sal_Int16( nAttribs );
2647 else
2648 OSL_ENSURE( sal_False,
2649 "PropertySetInfo_Impl::getProperties - "
2650 "Error getting property attributes!" );
2652 catch ( NoSuchElementException& )
2654 // getByHierarchicalName
2656 OSL_ENSURE( sal_False,
2657 "PropertySetInfo_Impl::getProperties - "
2658 "NoSuchElementException!" );
2664 // Success.
2665 m_pProps = pPropSeq;
2666 return *m_pProps;
2669 catch ( NoSuchElementException& )
2671 // getByHierarchicalName
2675 OSL_ENSURE( sal_False, "PropertySetInfo_Impl::getProperties - Error!" );
2676 m_pProps = new Sequence< Property >( 0 );
2679 return *m_pProps;
2682 //=========================================================================
2683 // virtual
2684 Property SAL_CALL PropertySetInfo_Impl::getPropertyByName(
2685 const OUString& aName )
2686 throw( UnknownPropertyException, RuntimeException )
2688 Reference< XHierarchicalNameAccess > xRootHierNameAccess(
2689 m_pOwner->getPropertySetRegistry().getRootConfigReadAccess(),
2690 UNO_QUERY );
2691 if ( xRootHierNameAccess.is() )
2693 OUString aFullPropName( m_pOwner->getFullKey() );
2694 aFullPropName += OUString::createFromAscii( "/" );
2695 aFullPropName += makeHierarchalNameSegment( aName );
2697 // Does property exist?
2698 if ( !xRootHierNameAccess->hasByHierarchicalName( aFullPropName ) )
2699 throw UnknownPropertyException();
2703 Property aProp;
2705 // Obtain handle.
2706 OUString aKey = aFullPropName;
2707 aKey += OUString::createFromAscii( "/Handle" );
2709 if ( !( xRootHierNameAccess->getByHierarchicalName( aKey )
2710 >>= aProp.Handle ) )
2712 OSL_ENSURE( sal_False,
2713 "PropertySetInfo_Impl::getPropertyByName - "
2714 "No handle!" );
2715 return Property();
2718 // Obtain Value and extract type.
2719 aKey = aFullPropName;
2720 aKey += OUString::createFromAscii( "/Value" );
2722 Any aValue = xRootHierNameAccess->getByHierarchicalName( aKey );
2723 if ( !aValue.hasValue() )
2725 OSL_ENSURE( sal_False,
2726 "PropertySetInfo_Impl::getPropertyByName - "
2727 "No Value!" );
2728 return Property();
2731 aProp.Type = aValue.getValueType();
2733 // Obtain Attributes.
2734 aKey = aFullPropName;
2735 aKey += OUString::createFromAscii( "/Attributes" );
2737 sal_Int32 nAttribs = 0;
2738 if ( xRootHierNameAccess->getByHierarchicalName( aKey )
2739 >>= nAttribs )
2740 aProp.Attributes = sal_Int16( nAttribs );
2741 else
2743 OSL_ENSURE( sal_False,
2744 "PropertySetInfo_Impl::getPropertyByName - "
2745 "No attributes!" );
2746 return Property();
2749 // set name.
2750 aProp.Name = aName;
2752 // Success.
2753 return aProp;
2755 catch ( NoSuchElementException& )
2757 // getByHierarchicalName
2759 OSL_ENSURE( sal_False,
2760 "PropertySetInfo_Impl::getPropertyByName - "
2761 "caught NoSuchElementException!" );
2766 OSL_ENSURE( sal_False, "PropertySetInfo_Impl::getPropertyByName - Error!" );
2767 return Property();
2770 //=========================================================================
2771 // virtual
2772 sal_Bool SAL_CALL PropertySetInfo_Impl::hasPropertyByName(
2773 const OUString& Name )
2774 throw( RuntimeException )
2776 Reference< XHierarchicalNameAccess > xRootHierNameAccess(
2777 m_pOwner->getPropertySetRegistry().getRootConfigReadAccess(),
2778 UNO_QUERY );
2779 if ( xRootHierNameAccess.is() )
2781 OUString aFullPropName( m_pOwner->getFullKey() );
2782 aFullPropName += OUString::createFromAscii( "/" );
2783 aFullPropName += makeHierarchalNameSegment( Name );
2785 return xRootHierNameAccess->hasByHierarchicalName( aFullPropName );
2788 return sal_False;