Update ooo320-m1
[ooovba.git] / ucb / source / ucp / hierarchy / hierarchydatasource.cxx
blob933beec7f78f0b626bc363c0628d2e46a478b1ad
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: hierarchydatasource.cxx,v $
10 * $Revision: 1.11 $
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 Note: Configuration Management classes do not support XAggregation.
39 So I have to wrap the interesting interfaces manually.
41 *************************************************************************/
42 #include "hierarchydatasource.hxx"
43 #include <osl/diagnose.h>
45 #include "osl/doublecheckedlocking.h"
46 #include <cppuhelper/interfacecontainer.hxx>
47 #include <com/sun/star/beans/PropertyValue.hpp>
48 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
49 #include <com/sun/star/container/XNameContainer.hpp>
50 #include <com/sun/star/util/XChangesBatch.hpp>
51 #include <com/sun/star/util/XChangesNotifier.hpp>
53 using namespace com::sun::star;
54 using namespace hierarchy_ucp;
56 //=========================================================================
58 // describe path of cfg entry
59 #define CFGPROPERTY_NODEPATH "nodepath"
60 // true->async. update; false->sync. update
61 #define CFGPROPERTY_LAZYWRITE "lazywrite"
63 #define READ_SERVICE_NAME "com.sun.star.ucb.HierarchyDataReadAccess"
64 #define READWRITE_SERVICE_NAME "com.sun.star.ucb.HierarchyDataReadWriteAccess"
66 #define CONFIG_PROVIDER_SERVICE_NAME \
67 "com.sun.star.configuration.ConfigurationProvider"
68 #define CONFIG_READ_SERVICE_NAME \
69 "com.sun.star.configuration.ConfigurationAccess"
70 #define CONFIG_READWRITE_SERVICE_NAME \
71 "com.sun.star.configuration.ConfigurationUpdateAccess"
72 #define CONFIG_DATA_ROOT_KEY \
73 "/org.openoffice.ucb.Hierarchy/Root"
75 //=========================================================================
77 namespace hcp_impl
80 //=========================================================================
82 // HierarchyDataReadAccess Implementation.
84 //=========================================================================
86 class HierarchyDataAccess : public cppu::OWeakObject,
87 public lang::XServiceInfo,
88 public lang::XTypeProvider,
89 public lang::XComponent,
90 public lang::XSingleServiceFactory,
91 public container::XHierarchicalNameAccess,
92 public container::XNameContainer,
93 public util::XChangesNotifier,
94 public util::XChangesBatch
96 osl::Mutex m_aMutex;
97 uno::Reference< uno::XInterface > m_xConfigAccess;
98 uno::Reference< lang::XComponent > m_xCfgC;
99 uno::Reference< lang::XSingleServiceFactory > m_xCfgSSF;
100 uno::Reference< container::XHierarchicalNameAccess > m_xCfgHNA;
101 uno::Reference< container::XNameContainer > m_xCfgNC;
102 uno::Reference< container::XNameReplace > m_xCfgNR;
103 uno::Reference< container::XNameAccess > m_xCfgNA;
104 uno::Reference< container::XElementAccess > m_xCfgEA;
105 uno::Reference< util::XChangesNotifier > m_xCfgCN;
106 uno::Reference< util::XChangesBatch > m_xCfgCB;
107 bool m_bReadOnly;
109 public:
110 HierarchyDataAccess( const uno::Reference<
111 uno::XInterface > & xConfigAccess,
112 bool bReadOnly );
113 virtual ~HierarchyDataAccess();
115 // XInterface
116 XINTERFACE_DECL()
118 // XServiceInfo
119 XSERVICEINFO_DECL()
121 // XTypeProvider
122 XTYPEPROVIDER_DECL()
124 // XComponent
125 virtual void SAL_CALL
126 dispose()
127 throw ( uno::RuntimeException );
128 virtual void SAL_CALL
129 addEventListener( const uno::Reference< lang::XEventListener > & xListener )
130 throw ( uno::RuntimeException );
131 virtual void SAL_CALL
132 removeEventListener( const uno::Reference<
133 lang::XEventListener > & aListener )
134 throw ( uno::RuntimeException );
136 // XSingleServiceFactory
137 virtual uno::Reference< uno::XInterface > SAL_CALL
138 createInstance()
139 throw ( uno::Exception, uno::RuntimeException );
140 virtual uno::Reference< uno::XInterface > SAL_CALL
141 createInstanceWithArguments( const uno::Sequence< uno::Any > & aArguments )
142 throw ( uno::Exception, uno::RuntimeException );
144 // XHierarchicalNameAccess
145 virtual uno::Any SAL_CALL
146 getByHierarchicalName( const rtl::OUString & aName )
147 throw ( container::NoSuchElementException, uno::RuntimeException );
148 virtual sal_Bool SAL_CALL
149 hasByHierarchicalName( const rtl::OUString & aName )
150 throw ( uno::RuntimeException );
152 // XNameContainer
153 virtual void SAL_CALL
154 insertByName( const rtl::OUString & aName, const uno::Any & aElement )
155 throw ( lang::IllegalArgumentException,
156 container::ElementExistException,
157 lang::WrappedTargetException,
158 uno::RuntimeException );
159 virtual void SAL_CALL
160 removeByName( const rtl::OUString & Name )
161 throw ( container::NoSuchElementException,
162 lang::WrappedTargetException,
163 uno::RuntimeException );
165 // XNameReplace ( base of XNameContainer )
166 virtual void SAL_CALL
167 replaceByName( const rtl::OUString & aName, const uno::Any & aElement )
168 throw ( lang::IllegalArgumentException,
169 container::NoSuchElementException,
170 lang::WrappedTargetException,
171 uno::RuntimeException );
173 // XNameAccess ( base of XNameReplace )
174 virtual uno::Any SAL_CALL
175 getByName( const rtl::OUString & aName )
176 throw ( container::NoSuchElementException,
177 lang::WrappedTargetException,
178 uno::RuntimeException );
179 virtual uno::Sequence< rtl::OUString > SAL_CALL
180 getElementNames()
181 throw ( uno::RuntimeException );
182 virtual sal_Bool SAL_CALL
183 hasByName( const rtl::OUString & aName )
184 throw ( uno::RuntimeException );
186 // XElementAccess ( base of XNameAccess )
187 virtual uno::Type SAL_CALL
188 getElementType()
189 throw ( uno::RuntimeException );
190 virtual sal_Bool SAL_CALL
191 hasElements()
192 throw ( uno::RuntimeException );
194 // XChangesNotifier
195 virtual void SAL_CALL
196 addChangesListener( const uno::Reference<
197 util::XChangesListener > & aListener )
198 throw ( uno::RuntimeException );
199 virtual void SAL_CALL
200 removeChangesListener( const uno::Reference<
201 util::XChangesListener > & aListener )
202 throw ( uno::RuntimeException );
204 // XChangesBatch
205 virtual void SAL_CALL
206 commitChanges()
207 throw ( lang::WrappedTargetException, uno::RuntimeException );
208 virtual sal_Bool SAL_CALL
209 hasPendingChanges()
210 throw ( uno::RuntimeException );
211 virtual uno::Sequence< util::ElementChange > SAL_CALL
212 getPendingChanges()
213 throw ( uno::RuntimeException );
216 } // namespace hcp_impl
218 using namespace hcp_impl;
220 //=========================================================================
221 //=========================================================================
223 // HierarchyDataSource Implementation.
225 //=========================================================================
226 //=========================================================================
228 HierarchyDataSource::HierarchyDataSource(
229 const uno::Reference< lang::XMultiServiceFactory > & rxServiceMgr )
230 : m_xSMgr( rxServiceMgr ),
231 m_pDisposeEventListeners( 0 )
235 //=========================================================================
236 // virtual
237 HierarchyDataSource::~HierarchyDataSource()
239 delete m_pDisposeEventListeners;
242 //=========================================================================
244 // XInterface methods.
246 //=========================================================================
248 XINTERFACE_IMPL_4( HierarchyDataSource,
249 lang::XTypeProvider,
250 lang::XServiceInfo,
251 lang::XComponent,
252 lang::XMultiServiceFactory );
254 //=========================================================================
256 // XTypeProvider methods.
258 //=========================================================================
260 XTYPEPROVIDER_IMPL_4( HierarchyDataSource,
261 lang::XTypeProvider,
262 lang::XServiceInfo,
263 lang::XComponent,
264 lang::XMultiServiceFactory );
266 //=========================================================================
268 // XServiceInfo methods.
270 //=========================================================================
272 XSERVICEINFO_IMPL_0( HierarchyDataSource,
273 rtl::OUString::createFromAscii(
274 "com.sun.star.comp.ucb.HierarchyDataSource" ) )
276 uno::Sequence< rtl::OUString > aSNS( 2 );
277 aSNS[ 0 ] = rtl::OUString::createFromAscii(
278 "com.sun.star.ucb.DefaultHierarchyDataSource" );
279 aSNS[ 1 ] = rtl::OUString::createFromAscii(
280 "com.sun.star.ucb.HierarchyDataSource" );
281 return aSNS;
284 ONE_INSTANCE_SERVICE_FACTORY_IMPL( HierarchyDataSource );
286 //=========================================================================
288 // XComponent methods.
290 //=========================================================================
292 // virtual
293 void SAL_CALL HierarchyDataSource::dispose()
294 throw( uno::RuntimeException )
296 osl::Guard< osl::Mutex > aGuard( m_aMutex );
298 if ( m_pDisposeEventListeners && m_pDisposeEventListeners->getLength() )
300 lang::EventObject aEvt;
301 aEvt.Source = static_cast< lang::XComponent * >( this );
302 m_pDisposeEventListeners->disposeAndClear( aEvt );
306 //=========================================================================
307 // virtual
308 void SAL_CALL HierarchyDataSource::addEventListener(
309 const uno::Reference< lang::XEventListener > & Listener )
310 throw( uno::RuntimeException )
312 osl::Guard< osl::Mutex > aGuard( m_aMutex );
314 if ( !m_pDisposeEventListeners )
315 m_pDisposeEventListeners
316 = new cppu::OInterfaceContainerHelper( m_aMutex );
318 m_pDisposeEventListeners->addInterface( Listener );
321 //=========================================================================
322 // virtual
323 void SAL_CALL HierarchyDataSource::removeEventListener(
324 const uno::Reference< lang::XEventListener > & Listener )
325 throw( uno::RuntimeException )
327 osl::Guard< osl::Mutex > aGuard( m_aMutex );
329 if ( m_pDisposeEventListeners )
330 m_pDisposeEventListeners->removeInterface( Listener );
333 //=========================================================================
335 // XMultiServiceFactory methods.
337 //=========================================================================
339 // virtual
340 uno::Reference< uno::XInterface > SAL_CALL
341 HierarchyDataSource::createInstance( const rtl::OUString & aServiceSpecifier )
342 throw ( uno::Exception, uno::RuntimeException )
344 // Create view to root node.
346 beans::PropertyValue aProp;
347 aProp.Name = rtl::OUString(
348 RTL_CONSTASCII_USTRINGPARAM( CFGPROPERTY_NODEPATH ) );
349 aProp.Value <<=
350 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( CONFIG_DATA_ROOT_KEY ) );
352 uno::Sequence< uno::Any > aArguments( 1 );
353 aArguments[ 0 ] <<= aProp;
355 return createInstanceWithArguments( aServiceSpecifier, aArguments, false );
358 //=========================================================================
359 // virtual
360 uno::Reference< uno::XInterface > SAL_CALL
361 HierarchyDataSource::createInstanceWithArguments(
362 const rtl::OUString & ServiceSpecifier,
363 const uno::Sequence< uno::Any > & Arguments )
364 throw ( uno::Exception, uno::RuntimeException )
366 return createInstanceWithArguments( ServiceSpecifier, Arguments, true );
369 //=========================================================================
370 // virtual
371 uno::Sequence< rtl::OUString > SAL_CALL
372 HierarchyDataSource::getAvailableServiceNames()
373 throw ( uno::RuntimeException )
375 uno::Sequence< rtl::OUString > aNames( 2 );
376 aNames[ 0 ] = rtl::OUString(
377 RTL_CONSTASCII_USTRINGPARAM( READ_SERVICE_NAME ) );
378 aNames[ 1 ] = rtl::OUString(
379 RTL_CONSTASCII_USTRINGPARAM( READWRITE_SERVICE_NAME ) );
380 return aNames;
383 //=========================================================================
385 // Non-interface methods
387 //=========================================================================
389 uno::Reference< uno::XInterface > SAL_CALL
390 HierarchyDataSource::createInstanceWithArguments(
391 const rtl::OUString & ServiceSpecifier,
392 const uno::Sequence< uno::Any > & Arguments,
393 bool bCheckArgs )
394 throw ( uno::Exception, uno::RuntimeException )
396 osl::Guard< osl::Mutex > aGuard( m_aMutex );
398 // Check service specifier.
399 bool bReadOnly = !!ServiceSpecifier.equalsAsciiL(
400 RTL_CONSTASCII_STRINGPARAM( READ_SERVICE_NAME ) );
401 bool bReadWrite = !bReadOnly &&
402 ServiceSpecifier.equalsAsciiL(
403 RTL_CONSTASCII_STRINGPARAM( READWRITE_SERVICE_NAME ) );
405 if ( !bReadOnly && !bReadWrite )
407 OSL_ENSURE( false,
408 "HierarchyDataSource::createInstanceWithArguments - "
409 "Unsupported service specifier!" );
410 return uno::Reference< uno::XInterface >();
413 uno::Sequence< uno::Any > aNewArgs( Arguments );
415 bool bHasLazyWriteProp = bReadOnly; // property must be added only if
416 // a writable view is requested.
417 if ( bCheckArgs )
419 // Check arguments.
420 bool bHasNodePath = false;
421 sal_Int32 nCount = Arguments.getLength();
422 for ( sal_Int32 n = 0; n < nCount; ++n )
424 beans::PropertyValue aProp;
425 if ( Arguments[ n ] >>= aProp )
427 if ( aProp.Name.equalsAsciiL(
428 RTL_CONSTASCII_STRINGPARAM( CFGPROPERTY_NODEPATH ) ) )
430 rtl::OUString aPath;
431 if ( aProp.Value >>= aPath )
433 bHasNodePath = true;
435 // Create path to data inside the configuration.
436 rtl::OUString aConfigPath;
437 if ( !createConfigPath( aPath, aConfigPath ) )
439 OSL_ENSURE( false,
440 "HierarchyDataSource::"
441 "createInstanceWithArguments - "
442 "Invalid node path!" );
443 return uno::Reference< uno::XInterface >();
446 aProp.Value <<= aConfigPath;
448 // Set new path in arguments.
449 aNewArgs[ n ] <<= aProp;
451 if ( bHasLazyWriteProp )
452 break;
454 else
456 OSL_ENSURE( false,
457 "HierarchyDataSource::createInstanceWithArguments - "
458 "Invalid type for property 'nodepath'!" );
459 return uno::Reference< uno::XInterface >();
462 else if ( aProp.Name.equalsAsciiL(
463 RTL_CONSTASCII_STRINGPARAM(
464 CFGPROPERTY_LAZYWRITE ) ) )
466 if ( aProp.Value.getValueType() == getCppuBooleanType() )
468 bHasLazyWriteProp = true;
470 if ( bHasNodePath )
471 break;
473 else
475 OSL_ENSURE( false,
476 "HierarchyDataSource::createInstanceWithArguments - "
477 "Invalid type for property 'lazywrite'!" );
478 return uno::Reference< uno::XInterface >();
484 if ( !bHasNodePath )
486 OSL_ENSURE( false,
487 "HierarchyDataSource::createInstanceWithArguments - "
488 "No 'nodepath' property!" );
489 return uno::Reference< uno::XInterface >();
493 // Create Configuration Provider.
494 uno::Reference< lang::XMultiServiceFactory > xProv = getConfigProvider();
495 if ( !xProv.is() )
496 return uno::Reference< uno::XInterface >();
498 uno::Reference< uno::XInterface > xConfigAccess;
501 if ( bReadOnly )
503 // Create configuration read-only access object.
504 xConfigAccess = xProv->createInstanceWithArguments(
505 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
506 CONFIG_READ_SERVICE_NAME ) ),
507 aNewArgs );
509 else
511 // Append 'lazywrite' property value, if not already present.
512 if ( !bHasLazyWriteProp )
514 sal_Int32 nLen = aNewArgs.getLength();
515 aNewArgs.realloc( nLen + 1 );
517 beans::PropertyValue aProp;
518 aProp.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
519 CFGPROPERTY_LAZYWRITE ) );
520 aProp.Value <<= sal_True;
521 aNewArgs[ nLen ] <<= aProp;
524 // Create configuration read-write access object.
525 xConfigAccess = xProv->createInstanceWithArguments(
526 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
527 CONFIG_READWRITE_SERVICE_NAME ) ),
528 aNewArgs );
531 catch ( uno::Exception const & )
533 OSL_ENSURE( false,
534 "HierarchyDataSource::createInstanceWithArguments - "
535 "Cannot instanciate configuration access!" );
536 throw;
539 if ( !xConfigAccess.is() )
541 OSL_ENSURE( false,
542 "HierarchyDataSource::createInstanceWithArguments - "
543 "Cannot instanciate configuration access!" );
544 return xConfigAccess;
547 return uno::Reference< uno::XInterface >(
548 static_cast< cppu::OWeakObject * >(
549 new HierarchyDataAccess( xConfigAccess, bReadOnly ) ) );
552 //=========================================================================
553 uno::Reference< lang::XMultiServiceFactory >
554 HierarchyDataSource::getConfigProvider()
556 if ( !m_xConfigProvider.is() )
558 osl::Guard< osl::Mutex > aGuard( m_aMutex );
559 if ( !m_xConfigProvider.is() )
563 m_xConfigProvider
564 = uno::Reference< lang::XMultiServiceFactory >(
565 m_xSMgr->createInstance(
566 rtl::OUString(
567 RTL_CONSTASCII_USTRINGPARAM(
568 CONFIG_PROVIDER_SERVICE_NAME ) ) ),
569 uno::UNO_QUERY );
571 OSL_ENSURE( m_xConfigProvider.is(),
572 "HierarchyDataSource::getConfigProvider - "
573 "No configuration provider!" );
575 catch ( uno::Exception const & )
577 OSL_ENSURE( false,
578 "HierarchyDataSource::getConfigProvider - "
579 "caught exception!" );
584 return m_xConfigProvider;
587 //=========================================================================
588 bool HierarchyDataSource::createConfigPath(
589 const rtl::OUString & rInPath, rtl::OUString & rOutPath )
591 if ( rInPath.getLength() )
593 if ( rInPath.indexOf( '/' ) == 0 )
595 OSL_ENSURE( false,
596 "HierarchyDataSource::createConfigPath - "
597 "Leading slash in node path!" );
598 return false;
601 if ( rInPath.lastIndexOf( '/' ) == rInPath.getLength() - 1 )
603 OSL_ENSURE( false,
604 "HierarchyDataSource::createConfigPath - "
605 "Trailing slash in node path!" );
606 return false;
609 rtl::OUString aOutPath(
610 RTL_CONSTASCII_USTRINGPARAM( CONFIG_DATA_ROOT_KEY "/" ) );
611 aOutPath += rInPath;
612 rOutPath = aOutPath;
614 else
616 rOutPath = rtl::OUString(
617 RTL_CONSTASCII_USTRINGPARAM( CONFIG_DATA_ROOT_KEY ) );
620 return true;
623 //=========================================================================
624 //=========================================================================
626 // HierarchyDataAccess Implementation.
628 //=========================================================================
629 //=========================================================================
631 #define ENSURE_ORIG_INTERFACE( interface_name, member_name ) \
632 m_xCfg##member_name; \
633 if ( !m_xCfg##member_name.is() ) \
635 osl::Guard< osl::Mutex > aGuard( m_aMutex ); \
636 if ( !m_xCfg##member_name.is() ) \
637 m_xCfg##member_name \
638 = uno::Reference< interface_name >( \
639 m_xConfigAccess, uno::UNO_QUERY ); \
640 xOrig = m_xCfg##member_name; \
643 //=========================================================================
644 HierarchyDataAccess::HierarchyDataAccess( const uno::Reference<
645 uno::XInterface > & xConfigAccess,
646 bool bReadOnly )
647 : m_xConfigAccess( xConfigAccess ),
648 m_bReadOnly( bReadOnly )
652 //=========================================================================
653 // virtual
654 HierarchyDataAccess::~HierarchyDataAccess()
658 //=========================================================================
660 // XInterface methods.
662 //=========================================================================
664 XINTERFACE_COMMON_IMPL( HierarchyDataAccess );
666 //=========================================================================
667 // virtual
668 uno::Any SAL_CALL HierarchyDataAccess::queryInterface( const uno::Type & aType )
669 throw ( uno::RuntimeException )
671 // Interfaces supported in read-only and read-write mode.
672 uno::Any aRet = cppu::queryInterface( aType,
673 static_cast< lang::XTypeProvider * >( this ),
674 static_cast< lang::XServiceInfo * >( this ),
675 static_cast< lang::XComponent * >( this ),
676 static_cast< container::XHierarchicalNameAccess * >( this ),
677 static_cast< container::XNameAccess * >( this ),
678 static_cast< container::XElementAccess * >( this ),
679 static_cast< util::XChangesNotifier * >( this ) );
681 // Interfaces supported only in read-write mode.
682 if ( !aRet.hasValue() && !m_bReadOnly )
684 aRet = cppu::queryInterface( aType,
685 static_cast< lang::XSingleServiceFactory * >( this ),
686 static_cast< container::XNameContainer * >( this ),
687 static_cast< container::XNameReplace * >( this ),
688 static_cast< util::XChangesBatch * >( this ) );
691 return aRet.hasValue() ? aRet : OWeakObject::queryInterface( aType );
694 //=========================================================================
696 // XTypeProvider methods.
698 //=========================================================================
700 XTYPEPROVIDER_COMMON_IMPL( HierarchyDataAccess );
702 //=========================================================================
703 // virtual
704 uno::Sequence< uno::Type > SAL_CALL HierarchyDataAccess::getTypes()
705 throw( uno::RuntimeException )
707 cppu::OTypeCollection * pCollection = 0;
709 if ( m_bReadOnly )
711 static cppu::OTypeCollection* pReadOnlyTypes = 0;
713 pCollection = pReadOnlyTypes;
714 if ( !pCollection )
716 osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
718 pCollection = pReadOnlyTypes;
719 if ( !pCollection )
721 static cppu::OTypeCollection aCollection(
722 CPPU_TYPE_REF( lang::XTypeProvider ),
723 CPPU_TYPE_REF( lang::XServiceInfo ),
724 CPPU_TYPE_REF( lang::XComponent ),
725 CPPU_TYPE_REF( container::XHierarchicalNameAccess ),
726 CPPU_TYPE_REF( container::XNameAccess ),
727 CPPU_TYPE_REF( util::XChangesNotifier ) );
728 pCollection = &aCollection;
729 OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
730 pReadOnlyTypes = pCollection;
733 else {
734 OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
737 else
739 static cppu::OTypeCollection* pReadWriteTypes = 0;
741 pCollection = pReadWriteTypes;
742 if ( !pCollection )
744 osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
746 pCollection = pReadWriteTypes;
747 if ( !pCollection )
749 static cppu::OTypeCollection aCollection(
750 CPPU_TYPE_REF( lang::XTypeProvider ),
751 CPPU_TYPE_REF( lang::XServiceInfo ),
752 CPPU_TYPE_REF( lang::XComponent ),
753 CPPU_TYPE_REF( lang::XSingleServiceFactory ),
754 CPPU_TYPE_REF( container::XHierarchicalNameAccess ),
755 CPPU_TYPE_REF( container::XNameContainer ),
756 CPPU_TYPE_REF( util::XChangesBatch ),
757 CPPU_TYPE_REF( util::XChangesNotifier ) );
758 pCollection = &aCollection;
759 OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
760 pReadWriteTypes = pCollection;
763 else {
764 OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
768 return (*pCollection).getTypes();
771 //=========================================================================
773 // XServiceInfo methods.
775 //=========================================================================
777 XSERVICEINFO_NOFACTORY_IMPL_0(
778 HierarchyDataAccess,
779 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
780 "com.sun.star.comp.ucb.HierarchyDataAccess" ) ) )
782 uno::Sequence< rtl::OUString > aSNS( 2 );
783 aSNS[ 0 ] = rtl::OUString(
784 RTL_CONSTASCII_USTRINGPARAM( READ_SERVICE_NAME ) );
785 aSNS[ 1 ] = rtl::OUString(
786 RTL_CONSTASCII_USTRINGPARAM( READWRITE_SERVICE_NAME ) );
787 return aSNS;
790 //=========================================================================
792 // XComponent methods.
794 //=========================================================================
796 // virtual
797 void SAL_CALL HierarchyDataAccess::dispose()
798 throw ( uno::RuntimeException )
800 uno::Reference< lang::XComponent > xOrig
801 = ENSURE_ORIG_INTERFACE( lang::XComponent, C );
803 OSL_ENSURE( xOrig.is(),
804 "HierarchyDataAccess : Data source is not an XComponent!" );
805 xOrig->dispose();
808 //=========================================================================
809 // virtual
810 void SAL_CALL HierarchyDataAccess::addEventListener(
811 const uno::Reference< lang::XEventListener > & xListener )
812 throw ( uno::RuntimeException )
814 uno::Reference< lang::XComponent > xOrig
815 = ENSURE_ORIG_INTERFACE( lang::XComponent, C );
817 OSL_ENSURE( xOrig.is(),
818 "HierarchyDataAccess : Data source is not an XComponent!" );
819 xOrig->addEventListener( xListener );
822 //=========================================================================
823 // virtual
824 void SAL_CALL HierarchyDataAccess::removeEventListener(
825 const uno::Reference< lang::XEventListener > & aListener )
826 throw ( uno::RuntimeException )
828 uno::Reference< lang::XComponent > xOrig
829 = ENSURE_ORIG_INTERFACE( lang::XComponent, C );
831 OSL_ENSURE( xOrig.is(),
832 "HierarchyDataAccess : Data source is not an XComponent!" );
833 xOrig->removeEventListener( aListener );
836 //=========================================================================
838 // XHierarchicalNameAccess methods.
840 //=========================================================================
842 // virtual
843 uno::Any SAL_CALL HierarchyDataAccess::getByHierarchicalName(
844 const rtl::OUString & aName )
845 throw ( container::NoSuchElementException, uno::RuntimeException )
847 uno::Reference< container::XHierarchicalNameAccess > xOrig
848 = ENSURE_ORIG_INTERFACE( container::XHierarchicalNameAccess, HNA );
850 OSL_ENSURE( xOrig.is(),
851 "HierarchyDataAccess : "
852 "Data source is not an XHierarchicalNameAccess!" );
853 return xOrig->getByHierarchicalName( aName );
856 //=========================================================================
857 // virtual
858 sal_Bool SAL_CALL HierarchyDataAccess::hasByHierarchicalName(
859 const rtl::OUString & aName )
860 throw ( uno::RuntimeException )
862 uno::Reference< container::XHierarchicalNameAccess > xOrig
863 = ENSURE_ORIG_INTERFACE( container::XHierarchicalNameAccess, HNA );
865 OSL_ENSURE( xOrig.is(),
866 "HierarchyDataAccess : "
867 "Data source is not an XHierarchicalNameAccess!" );
868 return xOrig->hasByHierarchicalName( aName );
871 //=========================================================================
873 // XNameAccess methods.
875 //=========================================================================
877 // virtual
878 uno::Any SAL_CALL HierarchyDataAccess::getByName( const rtl::OUString & aName )
879 throw ( container::NoSuchElementException,
880 lang::WrappedTargetException,
881 uno::RuntimeException )
883 uno::Reference< container::XNameAccess > xOrig
884 = ENSURE_ORIG_INTERFACE( container::XNameAccess, NA );
886 OSL_ENSURE( xOrig.is(),
887 "HierarchyDataAccess : Data source is not an XNameAccess!" );
888 return xOrig->getByName( aName );
891 //=========================================================================
892 // virtual
893 uno::Sequence< rtl::OUString > SAL_CALL HierarchyDataAccess::getElementNames()
894 throw ( uno::RuntimeException )
896 uno::Reference< container::XNameAccess > xOrig
897 = ENSURE_ORIG_INTERFACE( container::XNameAccess, NA );
899 OSL_ENSURE( xOrig.is(),
900 "HierarchyDataAccess : Data source is not an XNameAccess!" );
901 return xOrig->getElementNames();
904 //=========================================================================
905 // virtual
906 sal_Bool SAL_CALL HierarchyDataAccess::hasByName( const rtl::OUString & aName )
907 throw ( uno::RuntimeException )
909 uno::Reference< container::XNameAccess > xOrig
910 = ENSURE_ORIG_INTERFACE( container::XNameAccess, NA );
912 OSL_ENSURE( xOrig.is(),
913 "HierarchyDataAccess : Data source is not an XNameAccess!" );
914 return xOrig->hasByName( aName );
917 //=========================================================================
919 // XElementAccess methods.
921 //=========================================================================
923 // virtual
924 uno::Type SAL_CALL HierarchyDataAccess::getElementType()
925 throw ( uno::RuntimeException )
927 uno::Reference< container::XElementAccess > xOrig
928 = ENSURE_ORIG_INTERFACE( container::XElementAccess, EA );
930 OSL_ENSURE( xOrig.is(),
931 "HierarchyDataAccess : Data source is not an XElementAccess!" );
932 return xOrig->getElementType();
935 //=========================================================================
936 // virtual
937 sal_Bool SAL_CALL HierarchyDataAccess::hasElements()
938 throw ( uno::RuntimeException )
940 uno::Reference< container::XElementAccess > xOrig
941 = ENSURE_ORIG_INTERFACE( container::XElementAccess, EA );
943 OSL_ENSURE( xOrig.is(),
944 "HierarchyDataAccess : Data source is not an XElementAccess!" );
945 return xOrig->hasElements();
948 //=========================================================================
950 // XChangesNotifier methods.
952 //=========================================================================
954 // virtual
955 void SAL_CALL HierarchyDataAccess::addChangesListener(
956 const uno::Reference< util::XChangesListener > & aListener )
957 throw ( uno::RuntimeException )
959 uno::Reference< util::XChangesNotifier > xOrig
960 = ENSURE_ORIG_INTERFACE( util::XChangesNotifier, CN );
962 OSL_ENSURE( xOrig.is(),
963 "HierarchyDataAccess : Data source is not an XChangesNotifier!" );
964 xOrig->addChangesListener( aListener );
967 //=========================================================================
968 // virtual
969 void SAL_CALL HierarchyDataAccess::removeChangesListener(
970 const uno::Reference< util::XChangesListener > & aListener )
971 throw ( uno::RuntimeException )
973 uno::Reference< util::XChangesNotifier > xOrig
974 = ENSURE_ORIG_INTERFACE( util::XChangesNotifier, CN );
976 OSL_ENSURE( xOrig.is(),
977 "HierarchyDataAccess : Data source is not an XChangesNotifier!" );
978 xOrig->removeChangesListener( aListener );
981 //=========================================================================
983 // XSingleServiceFactory methods.
985 //=========================================================================
987 // virtual
988 uno::Reference< uno::XInterface > SAL_CALL HierarchyDataAccess::createInstance()
989 throw ( uno::Exception, uno::RuntimeException )
991 uno::Reference< lang::XSingleServiceFactory > xOrig
992 = ENSURE_ORIG_INTERFACE( lang::XSingleServiceFactory, SSF );
994 OSL_ENSURE( xOrig.is(),
995 "HierarchyDataAccess : Data source is not an XSingleServiceFactory!" );
996 return xOrig->createInstance();
999 //=========================================================================
1000 // virtual
1001 uno::Reference< uno::XInterface > SAL_CALL
1002 HierarchyDataAccess::createInstanceWithArguments(
1003 const uno::Sequence< uno::Any > & aArguments )
1004 throw ( uno::Exception, uno::RuntimeException )
1006 uno::Reference< lang::XSingleServiceFactory > xOrig
1007 = ENSURE_ORIG_INTERFACE( lang::XSingleServiceFactory, SSF );
1009 OSL_ENSURE( xOrig.is(),
1010 "HierarchyDataAccess : Data source is not an XSingleServiceFactory!" );
1011 return xOrig->createInstanceWithArguments( aArguments );
1014 //=========================================================================
1016 // XNameContainer methods.
1018 //=========================================================================
1020 // virtual
1021 void SAL_CALL
1022 HierarchyDataAccess::insertByName( const rtl::OUString & aName,
1023 const uno::Any & aElement )
1024 throw ( lang::IllegalArgumentException,
1025 container::ElementExistException,
1026 lang::WrappedTargetException,
1027 uno::RuntimeException )
1029 uno::Reference< container::XNameContainer > xOrig
1030 = ENSURE_ORIG_INTERFACE( container::XNameContainer, NC );
1032 OSL_ENSURE( xOrig.is(),
1033 "HierarchyDataAccess : Data source is not an XNameContainer!" );
1034 xOrig->insertByName( aName, aElement );
1037 //=========================================================================
1038 // virtual
1039 void SAL_CALL
1040 HierarchyDataAccess::removeByName( const rtl::OUString & Name )
1041 throw ( container::NoSuchElementException,
1042 lang::WrappedTargetException,
1043 uno::RuntimeException )
1045 uno::Reference< container::XNameContainer > xOrig
1046 = ENSURE_ORIG_INTERFACE( container::XNameContainer, NC );
1048 OSL_ENSURE( xOrig.is(),
1049 "HierarchyDataAccess : Data source is not an XNameContainer!" );
1050 xOrig->removeByName( Name );
1053 //=========================================================================
1055 // XNameReplace methods.
1057 //=========================================================================
1059 // virtual
1060 void SAL_CALL HierarchyDataAccess::replaceByName( const rtl::OUString & aName,
1061 const uno::Any & aElement )
1062 throw ( lang::IllegalArgumentException,
1063 container::NoSuchElementException,
1064 lang::WrappedTargetException,
1065 uno::RuntimeException )
1067 uno::Reference< container::XNameReplace > xOrig
1068 = ENSURE_ORIG_INTERFACE( container::XNameReplace, NR );
1070 OSL_ENSURE( xOrig.is(),
1071 "HierarchyDataAccess : Data source is not an XNameReplace!" );
1072 xOrig->replaceByName( aName, aElement );
1075 //=========================================================================
1077 // XChangesBatch methods.
1079 //=========================================================================
1081 // virtual
1082 void SAL_CALL HierarchyDataAccess::commitChanges()
1083 throw ( lang::WrappedTargetException, uno::RuntimeException )
1085 uno::Reference< util::XChangesBatch > xOrig
1086 = ENSURE_ORIG_INTERFACE( util::XChangesBatch, CB );
1088 OSL_ENSURE( xOrig.is(),
1089 "HierarchyDataAccess : Data source is not an XChangesBatch!" );
1090 xOrig->commitChanges();
1093 //=========================================================================
1094 // virtual
1095 sal_Bool SAL_CALL HierarchyDataAccess::hasPendingChanges()
1096 throw ( uno::RuntimeException )
1098 uno::Reference< util::XChangesBatch > xOrig
1099 = ENSURE_ORIG_INTERFACE( util::XChangesBatch, CB );
1101 OSL_ENSURE( xOrig.is(),
1102 "HierarchyDataAccess : Data source is not an XChangesBatch!" );
1103 return xOrig->hasPendingChanges();
1106 //=========================================================================
1107 // virtual
1108 uno::Sequence< util::ElementChange > SAL_CALL
1109 HierarchyDataAccess::getPendingChanges()
1110 throw ( uno::RuntimeException )
1112 uno::Reference< util::XChangesBatch > xOrig
1113 = ENSURE_ORIG_INTERFACE( util::XChangesBatch, CB );
1115 OSL_ENSURE( xOrig.is(),
1116 "HierarchyDataAccess : Data source is not an XChangesBatch!" );
1117 return xOrig->getPendingChanges();