bump product version to 5.0.4.1
[LibreOffice.git] / ucb / source / ucp / hierarchy / hierarchydatasource.cxx
blob36a714815b7117fa73be766770c665b36d5df9e1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 /**************************************************************************
22 TODO
23 **************************************************************************
25 Note: Configuration Management classes do not support XAggregation.
26 So I have to wrap the interesting interfaces manually.
28 *************************************************************************/
29 #include "hierarchydatasource.hxx"
30 #include <osl/diagnose.h>
32 #include "osl/doublecheckedlocking.h"
33 #include <comphelper/processfactory.hxx>
34 #include <cppuhelper/interfacecontainer.hxx>
35 #include <com/sun/star/beans/PropertyValue.hpp>
36 #include <com/sun/star/configuration/theDefaultProvider.hpp>
37 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
38 #include <com/sun/star/container/XNameContainer.hpp>
39 #include <com/sun/star/util/XChangesBatch.hpp>
40 #include <com/sun/star/util/XChangesNotifier.hpp>
42 using namespace com::sun::star;
43 using namespace hierarchy_ucp;
47 // describe path of cfg entry
48 #define CFGPROPERTY_NODEPATH "nodepath"
49 // true->async. update; false->sync. update
50 #define CFGPROPERTY_LAZYWRITE "lazywrite"
52 #define READ_SERVICE_NAME "com.sun.star.ucb.HierarchyDataReadAccess"
53 #define READWRITE_SERVICE_NAME "com.sun.star.ucb.HierarchyDataReadWriteAccess"
55 #define CONFIG_READ_SERVICE_NAME \
56 "com.sun.star.configuration.ConfigurationAccess"
57 #define CONFIG_READWRITE_SERVICE_NAME \
58 "com.sun.star.configuration.ConfigurationUpdateAccess"
59 #define CONFIG_DATA_ROOT_KEY \
60 "/org.openoffice.ucb.Hierarchy/Root"
64 namespace hcp_impl
69 // HierarchyDataReadAccess Implementation.
73 class HierarchyDataAccess : public cppu::OWeakObject,
74 public lang::XServiceInfo,
75 public lang::XTypeProvider,
76 public lang::XComponent,
77 public lang::XSingleServiceFactory,
78 public container::XHierarchicalNameAccess,
79 public container::XNameContainer,
80 public util::XChangesNotifier,
81 public util::XChangesBatch
83 osl::Mutex m_aMutex;
84 uno::Reference< uno::XInterface > m_xConfigAccess;
85 uno::Reference< lang::XComponent > m_xCfgC;
86 uno::Reference< lang::XSingleServiceFactory > m_xCfgSSF;
87 uno::Reference< container::XHierarchicalNameAccess > m_xCfgHNA;
88 uno::Reference< container::XNameContainer > m_xCfgNC;
89 uno::Reference< container::XNameReplace > m_xCfgNR;
90 uno::Reference< container::XNameAccess > m_xCfgNA;
91 uno::Reference< container::XElementAccess > m_xCfgEA;
92 uno::Reference< util::XChangesNotifier > m_xCfgCN;
93 uno::Reference< util::XChangesBatch > m_xCfgCB;
94 bool m_bReadOnly;
96 public:
97 HierarchyDataAccess( const uno::Reference<
98 uno::XInterface > & xConfigAccess,
99 bool bReadOnly );
100 virtual ~HierarchyDataAccess();
102 // XInterface
103 virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType )
104 throw( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
105 virtual void SAL_CALL acquire()
106 throw() SAL_OVERRIDE;
107 virtual void SAL_CALL release()
108 throw() SAL_OVERRIDE;
110 // XServiceInfo
111 virtual OUString SAL_CALL getImplementationName()
112 throw( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
113 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName )
114 throw( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
115 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames()
116 throw( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
118 static OUString getImplementationName_Static();
119 static css::uno::Sequence< OUString > getSupportedServiceNames_Static();
121 // XTypeProvider
122 virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId()
123 throw( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
124 virtual css::uno::Sequence< com::sun::star::uno::Type > SAL_CALL getTypes()
125 throw( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
127 // XComponent
128 virtual void SAL_CALL
129 dispose()
130 throw ( uno::RuntimeException, std::exception ) SAL_OVERRIDE;
131 virtual void SAL_CALL
132 addEventListener( const uno::Reference< lang::XEventListener > & xListener )
133 throw ( uno::RuntimeException, std::exception ) SAL_OVERRIDE;
134 virtual void SAL_CALL
135 removeEventListener( const uno::Reference<
136 lang::XEventListener > & aListener )
137 throw ( uno::RuntimeException, std::exception ) SAL_OVERRIDE;
139 // XSingleServiceFactory
140 virtual uno::Reference< uno::XInterface > SAL_CALL
141 createInstance()
142 throw ( uno::Exception, uno::RuntimeException, std::exception ) SAL_OVERRIDE;
143 virtual uno::Reference< uno::XInterface > SAL_CALL
144 createInstanceWithArguments( const uno::Sequence< uno::Any > & aArguments )
145 throw ( uno::Exception, uno::RuntimeException, std::exception ) SAL_OVERRIDE;
147 // XHierarchicalNameAccess
148 virtual uno::Any SAL_CALL
149 getByHierarchicalName( const OUString & aName )
150 throw ( container::NoSuchElementException, uno::RuntimeException, std::exception ) SAL_OVERRIDE;
151 virtual sal_Bool SAL_CALL
152 hasByHierarchicalName( const OUString & aName )
153 throw ( uno::RuntimeException, std::exception ) SAL_OVERRIDE;
155 // XNameContainer
156 virtual void SAL_CALL
157 insertByName( const OUString & aName, const uno::Any & aElement )
158 throw ( lang::IllegalArgumentException,
159 container::ElementExistException,
160 lang::WrappedTargetException,
161 uno::RuntimeException, std::exception ) SAL_OVERRIDE;
162 virtual void SAL_CALL
163 removeByName( const OUString & Name )
164 throw ( container::NoSuchElementException,
165 lang::WrappedTargetException,
166 uno::RuntimeException, std::exception ) SAL_OVERRIDE;
168 // XNameReplace ( base of XNameContainer )
169 virtual void SAL_CALL
170 replaceByName( const OUString & aName, const uno::Any & aElement )
171 throw ( lang::IllegalArgumentException,
172 container::NoSuchElementException,
173 lang::WrappedTargetException,
174 uno::RuntimeException, std::exception ) SAL_OVERRIDE;
176 // XNameAccess ( base of XNameReplace )
177 virtual uno::Any SAL_CALL
178 getByName( const OUString & aName )
179 throw ( container::NoSuchElementException,
180 lang::WrappedTargetException,
181 uno::RuntimeException, std::exception ) SAL_OVERRIDE;
182 virtual uno::Sequence< OUString > SAL_CALL
183 getElementNames()
184 throw ( uno::RuntimeException, std::exception ) SAL_OVERRIDE;
185 virtual sal_Bool SAL_CALL
186 hasByName( const OUString & aName )
187 throw ( uno::RuntimeException, std::exception ) SAL_OVERRIDE;
189 // XElementAccess ( base of XNameAccess )
190 virtual uno::Type SAL_CALL
191 getElementType()
192 throw ( uno::RuntimeException, std::exception ) SAL_OVERRIDE;
193 virtual sal_Bool SAL_CALL
194 hasElements()
195 throw ( uno::RuntimeException, std::exception ) SAL_OVERRIDE;
197 // XChangesNotifier
198 virtual void SAL_CALL
199 addChangesListener( const uno::Reference<
200 util::XChangesListener > & aListener )
201 throw ( uno::RuntimeException, std::exception ) SAL_OVERRIDE;
202 virtual void SAL_CALL
203 removeChangesListener( const uno::Reference<
204 util::XChangesListener > & aListener )
205 throw ( uno::RuntimeException, std::exception ) SAL_OVERRIDE;
207 // XChangesBatch
208 virtual void SAL_CALL
209 commitChanges()
210 throw ( lang::WrappedTargetException, uno::RuntimeException, std::exception ) SAL_OVERRIDE;
211 virtual sal_Bool SAL_CALL
212 hasPendingChanges()
213 throw ( uno::RuntimeException, std::exception ) SAL_OVERRIDE;
214 virtual uno::Sequence< util::ElementChange > SAL_CALL
215 getPendingChanges()
216 throw ( uno::RuntimeException, std::exception ) SAL_OVERRIDE;
219 } // namespace hcp_impl
221 using namespace hcp_impl;
226 // HierarchyDataSource Implementation.
231 HierarchyDataSource::HierarchyDataSource(
232 const uno::Reference< uno::XComponentContext > & rxContext )
233 : m_xContext( rxContext ),
234 m_pDisposeEventListeners( 0 )
239 // virtual
240 HierarchyDataSource::~HierarchyDataSource()
242 delete m_pDisposeEventListeners;
247 // XInterface methods.
248 void SAL_CALL HierarchyDataSource::acquire()
249 throw()
251 OWeakObject::acquire();
254 void SAL_CALL HierarchyDataSource::release()
255 throw()
257 OWeakObject::release();
260 css::uno::Any SAL_CALL HierarchyDataSource::queryInterface( const css::uno::Type & rType )
261 throw( css::uno::RuntimeException, std::exception )
263 css::uno::Any aRet = cppu::queryInterface( rType,
264 (static_cast< lang::XTypeProvider* >(this)),
265 (static_cast< lang::XServiceInfo* >(this)),
266 (static_cast< lang::XComponent* >(this)),
267 (static_cast< lang::XMultiServiceFactory* >(this))
269 return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
272 // XTypeProvider methods.
276 XTYPEPROVIDER_IMPL_4( HierarchyDataSource,
277 lang::XTypeProvider,
278 lang::XServiceInfo,
279 lang::XComponent,
280 lang::XMultiServiceFactory );
284 // XServiceInfo methods.
288 XSERVICEINFO_IMPL_0_CTX( HierarchyDataSource,
289 OUString( "com.sun.star.comp.ucb.HierarchyDataSource" ) )
291 uno::Sequence< OUString > aSNS( 2 );
292 aSNS[ 0 ] = "com.sun.star.ucb.DefaultHierarchyDataSource";
293 aSNS[ 1 ] = "com.sun.star.ucb.HierarchyDataSource";
294 return aSNS;
297 ONE_INSTANCE_SERVICE_FACTORY_IMPL( HierarchyDataSource );
301 // XComponent methods.
305 // virtual
306 void SAL_CALL HierarchyDataSource::dispose()
307 throw( uno::RuntimeException, std::exception )
309 osl::Guard< osl::Mutex > aGuard( m_aMutex );
311 if ( m_pDisposeEventListeners && m_pDisposeEventListeners->getLength() )
313 lang::EventObject aEvt;
314 aEvt.Source = static_cast< lang::XComponent * >( this );
315 m_pDisposeEventListeners->disposeAndClear( aEvt );
320 // virtual
321 void SAL_CALL HierarchyDataSource::addEventListener(
322 const uno::Reference< lang::XEventListener > & Listener )
323 throw( uno::RuntimeException, std::exception )
325 osl::Guard< osl::Mutex > aGuard( m_aMutex );
327 if ( !m_pDisposeEventListeners )
328 m_pDisposeEventListeners
329 = new cppu::OInterfaceContainerHelper( m_aMutex );
331 m_pDisposeEventListeners->addInterface( Listener );
335 // virtual
336 void SAL_CALL HierarchyDataSource::removeEventListener(
337 const uno::Reference< lang::XEventListener > & Listener )
338 throw( uno::RuntimeException, std::exception )
340 osl::Guard< osl::Mutex > aGuard( m_aMutex );
342 if ( m_pDisposeEventListeners )
343 m_pDisposeEventListeners->removeInterface( Listener );
348 // XMultiServiceFactory methods.
352 // virtual
353 uno::Reference< uno::XInterface > SAL_CALL
354 HierarchyDataSource::createInstance( const OUString & aServiceSpecifier )
355 throw ( uno::Exception, uno::RuntimeException, std::exception )
357 // Create view to root node.
359 beans::PropertyValue aProp;
360 aProp.Name = CFGPROPERTY_NODEPATH;
361 aProp.Value <<= OUString( CONFIG_DATA_ROOT_KEY );
363 uno::Sequence< uno::Any > aArguments( 1 );
364 aArguments[ 0 ] <<= aProp;
366 return createInstanceWithArguments( aServiceSpecifier, aArguments, false );
370 // virtual
371 uno::Reference< uno::XInterface > SAL_CALL
372 HierarchyDataSource::createInstanceWithArguments(
373 const OUString & ServiceSpecifier,
374 const uno::Sequence< uno::Any > & Arguments )
375 throw ( uno::Exception, uno::RuntimeException, std::exception )
377 return createInstanceWithArguments( ServiceSpecifier, Arguments, true );
381 // virtual
382 uno::Sequence< OUString > SAL_CALL
383 HierarchyDataSource::getAvailableServiceNames()
384 throw ( uno::RuntimeException, std::exception )
386 uno::Sequence< OUString > aNames( 2 );
387 aNames[ 0 ] = READ_SERVICE_NAME;
388 aNames[ 1 ] = READWRITE_SERVICE_NAME;
389 return aNames;
394 // Non-interface methods
398 uno::Reference< uno::XInterface > SAL_CALL
399 HierarchyDataSource::createInstanceWithArguments(
400 const OUString & ServiceSpecifier,
401 const uno::Sequence< uno::Any > & Arguments,
402 bool bCheckArgs )
403 throw ( uno::Exception, uno::RuntimeException )
405 osl::Guard< osl::Mutex > aGuard( m_aMutex );
407 // Check service specifier.
408 bool bReadOnly = ServiceSpecifier == READ_SERVICE_NAME;
409 bool bReadWrite = !bReadOnly && ServiceSpecifier == READWRITE_SERVICE_NAME;
411 if ( !bReadOnly && !bReadWrite )
413 OSL_FAIL( "HierarchyDataSource::createInstanceWithArguments - "
414 "Unsupported service specifier!" );
415 return uno::Reference< uno::XInterface >();
418 uno::Sequence< uno::Any > aNewArgs( Arguments );
420 bool bHasLazyWriteProp = bReadOnly; // property must be added only if
421 // a writable view is requested.
422 if ( bCheckArgs )
424 // Check arguments.
425 bool bHasNodePath = false;
426 sal_Int32 nCount = Arguments.getLength();
427 for ( sal_Int32 n = 0; n < nCount; ++n )
429 beans::PropertyValue aProp;
430 if ( Arguments[ n ] >>= aProp )
432 if ( aProp.Name == CFGPROPERTY_NODEPATH )
434 OUString aPath;
435 if ( aProp.Value >>= aPath )
437 bHasNodePath = true;
439 // Create path to data inside the configuration.
440 OUString aConfigPath;
441 if ( !createConfigPath( aPath, aConfigPath ) )
443 OSL_FAIL( "HierarchyDataSource::"
444 "createInstanceWithArguments - "
445 "Invalid node path!" );
446 return uno::Reference< uno::XInterface >();
449 aProp.Value <<= aConfigPath;
451 // Set new path in arguments.
452 aNewArgs[ n ] <<= aProp;
454 if ( bHasLazyWriteProp )
455 break;
457 else
459 OSL_FAIL( "HierarchyDataSource::createInstanceWithArguments - "
460 "Invalid type for property 'nodepath'!" );
461 return uno::Reference< uno::XInterface >();
464 else if ( aProp.Name == CFGPROPERTY_LAZYWRITE )
466 if ( aProp.Value.getValueType() == cppu::UnoType<bool>::get() )
468 bHasLazyWriteProp = true;
470 if ( bHasNodePath )
471 break;
473 else
475 OSL_FAIL( "HierarchyDataSource::createInstanceWithArguments - "
476 "Invalid type for property 'lazywrite'!" );
477 return uno::Reference< uno::XInterface >();
483 if ( !bHasNodePath )
485 OSL_FAIL( "HierarchyDataSource::createInstanceWithArguments - "
486 "No 'nodepath' property!" );
487 return uno::Reference< uno::XInterface >();
491 // Create Configuration Provider.
492 uno::Reference< lang::XMultiServiceFactory > xProv = getConfigProvider();
493 if ( !xProv.is() )
494 return uno::Reference< uno::XInterface >();
496 uno::Reference< uno::XInterface > xConfigAccess;
499 if ( bReadOnly )
501 // Create configuration read-only access object.
502 xConfigAccess = xProv->createInstanceWithArguments(
503 OUString( CONFIG_READ_SERVICE_NAME ),
504 aNewArgs );
506 else
508 // Append 'lazywrite' property value, if not already present.
509 if ( !bHasLazyWriteProp )
511 sal_Int32 nLen = aNewArgs.getLength();
512 aNewArgs.realloc( nLen + 1 );
514 beans::PropertyValue aProp;
515 aProp.Name = CFGPROPERTY_LAZYWRITE;
516 aProp.Value <<= sal_True;
517 aNewArgs[ nLen ] <<= aProp;
520 // Create configuration read-write access object.
521 xConfigAccess = xProv->createInstanceWithArguments(
522 OUString( CONFIG_READWRITE_SERVICE_NAME ),
523 aNewArgs );
526 catch ( uno::Exception const & )
528 OSL_FAIL( "HierarchyDataSource::createInstanceWithArguments - "
529 "Cannot instanciate configuration access!" );
530 throw;
533 if ( !xConfigAccess.is() )
535 OSL_FAIL( "HierarchyDataSource::createInstanceWithArguments - "
536 "Cannot instanciate configuration access!" );
537 return xConfigAccess;
540 return uno::Reference< uno::XInterface >(
541 static_cast< cppu::OWeakObject * >(
542 new HierarchyDataAccess( xConfigAccess, bReadOnly ) ) );
546 uno::Reference< lang::XMultiServiceFactory >
547 HierarchyDataSource::getConfigProvider()
549 if ( !m_xConfigProvider.is() )
551 osl::Guard< osl::Mutex > aGuard( m_aMutex );
552 if ( !m_xConfigProvider.is() )
556 m_xConfigProvider = configuration::theDefaultProvider::get( m_xContext );
558 catch ( uno::Exception const & )
560 OSL_FAIL( "HierarchyDataSource::getConfigProvider - "
561 "caught exception!" );
566 return m_xConfigProvider;
570 bool HierarchyDataSource::createConfigPath(
571 const OUString & rInPath, OUString & rOutPath )
573 if ( !rInPath.isEmpty() )
575 if ( rInPath.startsWith( "/" ) )
577 OSL_FAIL( "HierarchyDataSource::createConfigPath - "
578 "Leading slash in node path!" );
579 return false;
582 if ( rInPath.endsWith( "/" ) )
584 OSL_FAIL( "HierarchyDataSource::createConfigPath - "
585 "Trailing slash in node path!" );
586 return false;
589 rOutPath = CONFIG_DATA_ROOT_KEY "/" + rInPath;
591 else
593 rOutPath = CONFIG_DATA_ROOT_KEY;
596 return true;
602 // HierarchyDataAccess Implementation.
607 #define ENSURE_ORIG_INTERFACE( interface_name, member_name ) \
608 m_xCfg##member_name; \
609 if ( !m_xCfg##member_name.is() ) \
611 osl::Guard< osl::Mutex > aGuard( m_aMutex ); \
612 if ( !m_xCfg##member_name.is() ) \
613 m_xCfg##member_name \
614 = uno::Reference< interface_name >( \
615 m_xConfigAccess, uno::UNO_QUERY ); \
616 xOrig = m_xCfg##member_name; \
620 HierarchyDataAccess::HierarchyDataAccess( const uno::Reference<
621 uno::XInterface > & xConfigAccess,
622 bool bReadOnly )
623 : m_xConfigAccess( xConfigAccess ),
624 m_bReadOnly( bReadOnly )
629 // virtual
630 HierarchyDataAccess::~HierarchyDataAccess()
636 // XInterface methods.
637 void SAL_CALL HierarchyDataAccess::acquire()
638 throw()
640 OWeakObject::acquire();
643 void SAL_CALL HierarchyDataAccess::release()
644 throw()
646 OWeakObject::release();
649 // virtual
650 uno::Any SAL_CALL HierarchyDataAccess::queryInterface( const uno::Type & aType )
651 throw ( uno::RuntimeException, std::exception )
653 // Interfaces supported in read-only and read-write mode.
654 uno::Any aRet = cppu::queryInterface( aType,
655 static_cast< lang::XTypeProvider * >( this ),
656 static_cast< lang::XServiceInfo * >( this ),
657 static_cast< lang::XComponent * >( this ),
658 static_cast< container::XHierarchicalNameAccess * >( this ),
659 static_cast< container::XNameAccess * >( this ),
660 static_cast< container::XElementAccess * >( this ),
661 static_cast< util::XChangesNotifier * >( this ) );
663 // Interfaces supported only in read-write mode.
664 if ( !aRet.hasValue() && !m_bReadOnly )
666 aRet = cppu::queryInterface( aType,
667 static_cast< lang::XSingleServiceFactory * >( this ),
668 static_cast< container::XNameContainer * >( this ),
669 static_cast< container::XNameReplace * >( this ),
670 static_cast< util::XChangesBatch * >( this ) );
673 return aRet.hasValue() ? aRet : OWeakObject::queryInterface( aType );
678 // XTypeProvider methods.
682 XTYPEPROVIDER_COMMON_IMPL( HierarchyDataAccess );
685 // virtual
686 uno::Sequence< uno::Type > SAL_CALL HierarchyDataAccess::getTypes()
687 throw( uno::RuntimeException, std::exception )
689 cppu::OTypeCollection * pCollection = 0;
691 if ( m_bReadOnly )
693 static cppu::OTypeCollection* pReadOnlyTypes = 0;
695 pCollection = pReadOnlyTypes;
696 if ( !pCollection )
698 osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
700 pCollection = pReadOnlyTypes;
701 if ( !pCollection )
703 static cppu::OTypeCollection aCollection(
704 CPPU_TYPE_REF( lang::XTypeProvider ),
705 CPPU_TYPE_REF( lang::XServiceInfo ),
706 CPPU_TYPE_REF( lang::XComponent ),
707 CPPU_TYPE_REF( container::XHierarchicalNameAccess ),
708 CPPU_TYPE_REF( container::XNameAccess ),
709 CPPU_TYPE_REF( util::XChangesNotifier ) );
710 pCollection = &aCollection;
711 OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
712 pReadOnlyTypes = pCollection;
715 else {
716 OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
719 else
721 static cppu::OTypeCollection* pReadWriteTypes = 0;
723 pCollection = pReadWriteTypes;
724 if ( !pCollection )
726 osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
728 pCollection = pReadWriteTypes;
729 if ( !pCollection )
731 static cppu::OTypeCollection aCollection(
732 CPPU_TYPE_REF( lang::XTypeProvider ),
733 CPPU_TYPE_REF( lang::XServiceInfo ),
734 CPPU_TYPE_REF( lang::XComponent ),
735 CPPU_TYPE_REF( lang::XSingleServiceFactory ),
736 CPPU_TYPE_REF( container::XHierarchicalNameAccess ),
737 CPPU_TYPE_REF( container::XNameContainer ),
738 CPPU_TYPE_REF( util::XChangesBatch ),
739 CPPU_TYPE_REF( util::XChangesNotifier ) );
740 pCollection = &aCollection;
741 OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
742 pReadWriteTypes = pCollection;
745 else {
746 OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
750 return (*pCollection).getTypes();
755 // XServiceInfo methods.
759 XSERVICEINFO_NOFACTORY_IMPL_0(
760 HierarchyDataAccess,
761 OUString( "com.sun.star.comp.ucb.HierarchyDataAccess" ) )
763 uno::Sequence< OUString > aSNS( 2 );
764 aSNS[ 0 ] = READ_SERVICE_NAME;
765 aSNS[ 1 ] = READWRITE_SERVICE_NAME;
766 return aSNS;
771 // XComponent methods.
775 // virtual
776 void SAL_CALL HierarchyDataAccess::dispose()
777 throw ( uno::RuntimeException, std::exception )
779 uno::Reference< lang::XComponent > xOrig
780 = ENSURE_ORIG_INTERFACE( lang::XComponent, C );
782 OSL_ENSURE( xOrig.is(),
783 "HierarchyDataAccess : Data source is not an XComponent!" );
784 xOrig->dispose();
788 // virtual
789 void SAL_CALL HierarchyDataAccess::addEventListener(
790 const uno::Reference< lang::XEventListener > & xListener )
791 throw ( uno::RuntimeException, std::exception )
793 uno::Reference< lang::XComponent > xOrig
794 = ENSURE_ORIG_INTERFACE( lang::XComponent, C );
796 OSL_ENSURE( xOrig.is(),
797 "HierarchyDataAccess : Data source is not an XComponent!" );
798 xOrig->addEventListener( xListener );
802 // virtual
803 void SAL_CALL HierarchyDataAccess::removeEventListener(
804 const uno::Reference< lang::XEventListener > & aListener )
805 throw ( uno::RuntimeException, std::exception )
807 uno::Reference< lang::XComponent > xOrig
808 = ENSURE_ORIG_INTERFACE( lang::XComponent, C );
810 OSL_ENSURE( xOrig.is(),
811 "HierarchyDataAccess : Data source is not an XComponent!" );
812 xOrig->removeEventListener( aListener );
817 // XHierarchicalNameAccess methods.
821 // virtual
822 uno::Any SAL_CALL HierarchyDataAccess::getByHierarchicalName(
823 const OUString & aName )
824 throw ( container::NoSuchElementException, uno::RuntimeException, std::exception )
826 uno::Reference< container::XHierarchicalNameAccess > xOrig
827 = ENSURE_ORIG_INTERFACE( container::XHierarchicalNameAccess, HNA );
829 OSL_ENSURE( xOrig.is(),
830 "HierarchyDataAccess : "
831 "Data source is not an XHierarchicalNameAccess!" );
832 return xOrig->getByHierarchicalName( aName );
836 // virtual
837 sal_Bool SAL_CALL HierarchyDataAccess::hasByHierarchicalName(
838 const OUString & aName )
839 throw ( uno::RuntimeException, std::exception )
841 uno::Reference< container::XHierarchicalNameAccess > xOrig
842 = ENSURE_ORIG_INTERFACE( container::XHierarchicalNameAccess, HNA );
844 OSL_ENSURE( xOrig.is(),
845 "HierarchyDataAccess : "
846 "Data source is not an XHierarchicalNameAccess!" );
847 return xOrig->hasByHierarchicalName( aName );
852 // XNameAccess methods.
856 // virtual
857 uno::Any SAL_CALL HierarchyDataAccess::getByName( const OUString & aName )
858 throw ( container::NoSuchElementException,
859 lang::WrappedTargetException,
860 uno::RuntimeException, std::exception )
862 uno::Reference< container::XNameAccess > xOrig
863 = ENSURE_ORIG_INTERFACE( container::XNameAccess, NA );
865 OSL_ENSURE( xOrig.is(),
866 "HierarchyDataAccess : Data source is not an XNameAccess!" );
867 return xOrig->getByName( aName );
871 // virtual
872 uno::Sequence< OUString > SAL_CALL HierarchyDataAccess::getElementNames()
873 throw ( uno::RuntimeException, std::exception )
875 uno::Reference< container::XNameAccess > xOrig
876 = ENSURE_ORIG_INTERFACE( container::XNameAccess, NA );
878 OSL_ENSURE( xOrig.is(),
879 "HierarchyDataAccess : Data source is not an XNameAccess!" );
880 return xOrig->getElementNames();
884 // virtual
885 sal_Bool SAL_CALL HierarchyDataAccess::hasByName( const OUString & aName )
886 throw ( uno::RuntimeException, std::exception )
888 uno::Reference< container::XNameAccess > xOrig
889 = ENSURE_ORIG_INTERFACE( container::XNameAccess, NA );
891 OSL_ENSURE( xOrig.is(),
892 "HierarchyDataAccess : Data source is not an XNameAccess!" );
893 return xOrig->hasByName( aName );
898 // XElementAccess methods.
902 // virtual
903 uno::Type SAL_CALL HierarchyDataAccess::getElementType()
904 throw ( uno::RuntimeException, std::exception )
906 uno::Reference< container::XElementAccess > xOrig
907 = ENSURE_ORIG_INTERFACE( container::XElementAccess, EA );
909 OSL_ENSURE( xOrig.is(),
910 "HierarchyDataAccess : Data source is not an XElementAccess!" );
911 return xOrig->getElementType();
915 // virtual
916 sal_Bool SAL_CALL HierarchyDataAccess::hasElements()
917 throw ( uno::RuntimeException, std::exception )
919 uno::Reference< container::XElementAccess > xOrig
920 = ENSURE_ORIG_INTERFACE( container::XElementAccess, EA );
922 OSL_ENSURE( xOrig.is(),
923 "HierarchyDataAccess : Data source is not an XElementAccess!" );
924 return xOrig->hasElements();
929 // XChangesNotifier methods.
933 // virtual
934 void SAL_CALL HierarchyDataAccess::addChangesListener(
935 const uno::Reference< util::XChangesListener > & aListener )
936 throw ( uno::RuntimeException, std::exception )
938 uno::Reference< util::XChangesNotifier > xOrig
939 = ENSURE_ORIG_INTERFACE( util::XChangesNotifier, CN );
941 OSL_ENSURE( xOrig.is(),
942 "HierarchyDataAccess : Data source is not an XChangesNotifier!" );
943 xOrig->addChangesListener( aListener );
947 // virtual
948 void SAL_CALL HierarchyDataAccess::removeChangesListener(
949 const uno::Reference< util::XChangesListener > & aListener )
950 throw ( uno::RuntimeException, std::exception )
952 uno::Reference< util::XChangesNotifier > xOrig
953 = ENSURE_ORIG_INTERFACE( util::XChangesNotifier, CN );
955 OSL_ENSURE( xOrig.is(),
956 "HierarchyDataAccess : Data source is not an XChangesNotifier!" );
957 xOrig->removeChangesListener( aListener );
962 // XSingleServiceFactory methods.
966 // virtual
967 uno::Reference< uno::XInterface > SAL_CALL HierarchyDataAccess::createInstance()
968 throw ( uno::Exception, uno::RuntimeException, std::exception )
970 uno::Reference< lang::XSingleServiceFactory > xOrig
971 = ENSURE_ORIG_INTERFACE( lang::XSingleServiceFactory, SSF );
973 OSL_ENSURE( xOrig.is(),
974 "HierarchyDataAccess : Data source is not an XSingleServiceFactory!" );
975 return xOrig->createInstance();
979 // virtual
980 uno::Reference< uno::XInterface > SAL_CALL
981 HierarchyDataAccess::createInstanceWithArguments(
982 const uno::Sequence< uno::Any > & aArguments )
983 throw ( uno::Exception, uno::RuntimeException, std::exception )
985 uno::Reference< lang::XSingleServiceFactory > xOrig
986 = ENSURE_ORIG_INTERFACE( lang::XSingleServiceFactory, SSF );
988 OSL_ENSURE( xOrig.is(),
989 "HierarchyDataAccess : Data source is not an XSingleServiceFactory!" );
990 return xOrig->createInstanceWithArguments( aArguments );
995 // XNameContainer methods.
999 // virtual
1000 void SAL_CALL
1001 HierarchyDataAccess::insertByName( const OUString & aName,
1002 const uno::Any & aElement )
1003 throw ( lang::IllegalArgumentException,
1004 container::ElementExistException,
1005 lang::WrappedTargetException,
1006 uno::RuntimeException, std::exception )
1008 uno::Reference< container::XNameContainer > xOrig
1009 = ENSURE_ORIG_INTERFACE( container::XNameContainer, NC );
1011 OSL_ENSURE( xOrig.is(),
1012 "HierarchyDataAccess : Data source is not an XNameContainer!" );
1013 xOrig->insertByName( aName, aElement );
1017 // virtual
1018 void SAL_CALL
1019 HierarchyDataAccess::removeByName( const OUString & Name )
1020 throw ( container::NoSuchElementException,
1021 lang::WrappedTargetException,
1022 uno::RuntimeException, std::exception )
1024 uno::Reference< container::XNameContainer > xOrig
1025 = ENSURE_ORIG_INTERFACE( container::XNameContainer, NC );
1027 OSL_ENSURE( xOrig.is(),
1028 "HierarchyDataAccess : Data source is not an XNameContainer!" );
1029 xOrig->removeByName( Name );
1034 // XNameReplace methods.
1038 // virtual
1039 void SAL_CALL HierarchyDataAccess::replaceByName( const OUString & aName,
1040 const uno::Any & aElement )
1041 throw ( lang::IllegalArgumentException,
1042 container::NoSuchElementException,
1043 lang::WrappedTargetException,
1044 uno::RuntimeException, std::exception )
1046 uno::Reference< container::XNameReplace > xOrig
1047 = ENSURE_ORIG_INTERFACE( container::XNameReplace, NR );
1049 OSL_ENSURE( xOrig.is(),
1050 "HierarchyDataAccess : Data source is not an XNameReplace!" );
1051 xOrig->replaceByName( aName, aElement );
1056 // XChangesBatch methods.
1060 // virtual
1061 void SAL_CALL HierarchyDataAccess::commitChanges()
1062 throw ( lang::WrappedTargetException, uno::RuntimeException, std::exception )
1064 uno::Reference< util::XChangesBatch > xOrig
1065 = ENSURE_ORIG_INTERFACE( util::XChangesBatch, CB );
1067 OSL_ENSURE( xOrig.is(),
1068 "HierarchyDataAccess : Data source is not an XChangesBatch!" );
1069 xOrig->commitChanges();
1073 // virtual
1074 sal_Bool SAL_CALL HierarchyDataAccess::hasPendingChanges()
1075 throw ( uno::RuntimeException, std::exception )
1077 uno::Reference< util::XChangesBatch > xOrig
1078 = ENSURE_ORIG_INTERFACE( util::XChangesBatch, CB );
1080 OSL_ENSURE( xOrig.is(),
1081 "HierarchyDataAccess : Data source is not an XChangesBatch!" );
1082 return xOrig->hasPendingChanges();
1086 // virtual
1087 uno::Sequence< util::ElementChange > SAL_CALL
1088 HierarchyDataAccess::getPendingChanges()
1089 throw ( uno::RuntimeException, std::exception )
1091 uno::Reference< util::XChangesBatch > xOrig
1092 = ENSURE_ORIG_INTERFACE( util::XChangesBatch, CB );
1094 OSL_ENSURE( xOrig.is(),
1095 "HierarchyDataAccess : Data source is not an XChangesBatch!" );
1096 return xOrig->getPendingChanges();
1099 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */