1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 /**************************************************************************
32 **************************************************************************
34 Note: Configuration Management classes do not support XAggregation.
35 So I have to wrap the interesting interfaces manually.
37 *************************************************************************/
38 #include "hierarchydatasource.hxx"
39 #include <osl/diagnose.h>
41 #include "osl/doublecheckedlocking.h"
42 #include <cppuhelper/interfacecontainer.hxx>
43 #include <com/sun/star/beans/PropertyValue.hpp>
44 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
45 #include <com/sun/star/container/XNameContainer.hpp>
46 #include <com/sun/star/util/XChangesBatch.hpp>
47 #include <com/sun/star/util/XChangesNotifier.hpp>
49 using namespace com::sun::star
;
50 using namespace hierarchy_ucp
;
52 //=========================================================================
54 // describe path of cfg entry
55 #define CFGPROPERTY_NODEPATH "nodepath"
56 // true->async. update; false->sync. update
57 #define CFGPROPERTY_LAZYWRITE "lazywrite"
59 #define READ_SERVICE_NAME "com.sun.star.ucb.HierarchyDataReadAccess"
60 #define READWRITE_SERVICE_NAME "com.sun.star.ucb.HierarchyDataReadWriteAccess"
62 #define CONFIG_PROVIDER_SERVICE_NAME \
63 "com.sun.star.configuration.ConfigurationProvider"
64 #define CONFIG_READ_SERVICE_NAME \
65 "com.sun.star.configuration.ConfigurationAccess"
66 #define CONFIG_READWRITE_SERVICE_NAME \
67 "com.sun.star.configuration.ConfigurationUpdateAccess"
68 #define CONFIG_DATA_ROOT_KEY \
69 "/org.openoffice.ucb.Hierarchy/Root"
71 //=========================================================================
76 //=========================================================================
78 // HierarchyDataReadAccess Implementation.
80 //=========================================================================
82 class HierarchyDataAccess
: public cppu::OWeakObject
,
83 public lang::XServiceInfo
,
84 public lang::XTypeProvider
,
85 public lang::XComponent
,
86 public lang::XSingleServiceFactory
,
87 public container::XHierarchicalNameAccess
,
88 public container::XNameContainer
,
89 public util::XChangesNotifier
,
90 public util::XChangesBatch
93 uno::Reference
< uno::XInterface
> m_xConfigAccess
;
94 uno::Reference
< lang::XComponent
> m_xCfgC
;
95 uno::Reference
< lang::XSingleServiceFactory
> m_xCfgSSF
;
96 uno::Reference
< container::XHierarchicalNameAccess
> m_xCfgHNA
;
97 uno::Reference
< container::XNameContainer
> m_xCfgNC
;
98 uno::Reference
< container::XNameReplace
> m_xCfgNR
;
99 uno::Reference
< container::XNameAccess
> m_xCfgNA
;
100 uno::Reference
< container::XElementAccess
> m_xCfgEA
;
101 uno::Reference
< util::XChangesNotifier
> m_xCfgCN
;
102 uno::Reference
< util::XChangesBatch
> m_xCfgCB
;
106 HierarchyDataAccess( const uno::Reference
<
107 uno::XInterface
> & xConfigAccess
,
109 virtual ~HierarchyDataAccess();
121 virtual void SAL_CALL
123 throw ( uno::RuntimeException
);
124 virtual void SAL_CALL
125 addEventListener( const uno::Reference
< lang::XEventListener
> & xListener
)
126 throw ( uno::RuntimeException
);
127 virtual void SAL_CALL
128 removeEventListener( const uno::Reference
<
129 lang::XEventListener
> & aListener
)
130 throw ( uno::RuntimeException
);
132 // XSingleServiceFactory
133 virtual uno::Reference
< uno::XInterface
> SAL_CALL
135 throw ( uno::Exception
, uno::RuntimeException
);
136 virtual uno::Reference
< uno::XInterface
> SAL_CALL
137 createInstanceWithArguments( const uno::Sequence
< uno::Any
> & aArguments
)
138 throw ( uno::Exception
, uno::RuntimeException
);
140 // XHierarchicalNameAccess
141 virtual uno::Any SAL_CALL
142 getByHierarchicalName( const rtl::OUString
& aName
)
143 throw ( container::NoSuchElementException
, uno::RuntimeException
);
144 virtual sal_Bool SAL_CALL
145 hasByHierarchicalName( const rtl::OUString
& aName
)
146 throw ( uno::RuntimeException
);
149 virtual void SAL_CALL
150 insertByName( const rtl::OUString
& aName
, const uno::Any
& aElement
)
151 throw ( lang::IllegalArgumentException
,
152 container::ElementExistException
,
153 lang::WrappedTargetException
,
154 uno::RuntimeException
);
155 virtual void SAL_CALL
156 removeByName( const rtl::OUString
& Name
)
157 throw ( container::NoSuchElementException
,
158 lang::WrappedTargetException
,
159 uno::RuntimeException
);
161 // XNameReplace ( base of XNameContainer )
162 virtual void SAL_CALL
163 replaceByName( const rtl::OUString
& aName
, const uno::Any
& aElement
)
164 throw ( lang::IllegalArgumentException
,
165 container::NoSuchElementException
,
166 lang::WrappedTargetException
,
167 uno::RuntimeException
);
169 // XNameAccess ( base of XNameReplace )
170 virtual uno::Any SAL_CALL
171 getByName( const rtl::OUString
& aName
)
172 throw ( container::NoSuchElementException
,
173 lang::WrappedTargetException
,
174 uno::RuntimeException
);
175 virtual uno::Sequence
< rtl::OUString
> SAL_CALL
177 throw ( uno::RuntimeException
);
178 virtual sal_Bool SAL_CALL
179 hasByName( const rtl::OUString
& aName
)
180 throw ( uno::RuntimeException
);
182 // XElementAccess ( base of XNameAccess )
183 virtual uno::Type SAL_CALL
185 throw ( uno::RuntimeException
);
186 virtual sal_Bool SAL_CALL
188 throw ( uno::RuntimeException
);
191 virtual void SAL_CALL
192 addChangesListener( const uno::Reference
<
193 util::XChangesListener
> & aListener
)
194 throw ( uno::RuntimeException
);
195 virtual void SAL_CALL
196 removeChangesListener( const uno::Reference
<
197 util::XChangesListener
> & aListener
)
198 throw ( uno::RuntimeException
);
201 virtual void SAL_CALL
203 throw ( lang::WrappedTargetException
, uno::RuntimeException
);
204 virtual sal_Bool SAL_CALL
206 throw ( uno::RuntimeException
);
207 virtual uno::Sequence
< util::ElementChange
> SAL_CALL
209 throw ( uno::RuntimeException
);
212 } // namespace hcp_impl
214 using namespace hcp_impl
;
216 //=========================================================================
217 //=========================================================================
219 // HierarchyDataSource Implementation.
221 //=========================================================================
222 //=========================================================================
224 HierarchyDataSource::HierarchyDataSource(
225 const uno::Reference
< lang::XMultiServiceFactory
> & rxServiceMgr
)
226 : m_xSMgr( rxServiceMgr
),
227 m_pDisposeEventListeners( 0 )
231 //=========================================================================
233 HierarchyDataSource::~HierarchyDataSource()
235 delete m_pDisposeEventListeners
;
238 //=========================================================================
240 // XInterface methods.
242 //=========================================================================
244 XINTERFACE_IMPL_4( HierarchyDataSource
,
248 lang::XMultiServiceFactory
);
250 //=========================================================================
252 // XTypeProvider methods.
254 //=========================================================================
256 XTYPEPROVIDER_IMPL_4( HierarchyDataSource
,
260 lang::XMultiServiceFactory
);
262 //=========================================================================
264 // XServiceInfo methods.
266 //=========================================================================
268 XSERVICEINFO_IMPL_0( HierarchyDataSource
,
269 rtl::OUString( "com.sun.star.comp.ucb.HierarchyDataSource" ) )
271 uno::Sequence
< rtl::OUString
> aSNS( 2 );
272 aSNS
[ 0 ] = rtl::OUString( "com.sun.star.ucb.DefaultHierarchyDataSource" );
273 aSNS
[ 1 ] = rtl::OUString( "com.sun.star.ucb.HierarchyDataSource" );
277 ONE_INSTANCE_SERVICE_FACTORY_IMPL( HierarchyDataSource
);
279 //=========================================================================
281 // XComponent methods.
283 //=========================================================================
286 void SAL_CALL
HierarchyDataSource::dispose()
287 throw( uno::RuntimeException
)
289 osl::Guard
< osl::Mutex
> aGuard( m_aMutex
);
291 if ( m_pDisposeEventListeners
&& m_pDisposeEventListeners
->getLength() )
293 lang::EventObject aEvt
;
294 aEvt
.Source
= static_cast< lang::XComponent
* >( this );
295 m_pDisposeEventListeners
->disposeAndClear( aEvt
);
299 //=========================================================================
301 void SAL_CALL
HierarchyDataSource::addEventListener(
302 const uno::Reference
< lang::XEventListener
> & Listener
)
303 throw( uno::RuntimeException
)
305 osl::Guard
< osl::Mutex
> aGuard( m_aMutex
);
307 if ( !m_pDisposeEventListeners
)
308 m_pDisposeEventListeners
309 = new cppu::OInterfaceContainerHelper( m_aMutex
);
311 m_pDisposeEventListeners
->addInterface( Listener
);
314 //=========================================================================
316 void SAL_CALL
HierarchyDataSource::removeEventListener(
317 const uno::Reference
< lang::XEventListener
> & Listener
)
318 throw( uno::RuntimeException
)
320 osl::Guard
< osl::Mutex
> aGuard( m_aMutex
);
322 if ( m_pDisposeEventListeners
)
323 m_pDisposeEventListeners
->removeInterface( Listener
);
326 //=========================================================================
328 // XMultiServiceFactory methods.
330 //=========================================================================
333 uno::Reference
< uno::XInterface
> SAL_CALL
334 HierarchyDataSource::createInstance( const rtl::OUString
& aServiceSpecifier
)
335 throw ( uno::Exception
, uno::RuntimeException
)
337 // Create view to root node.
339 beans::PropertyValue aProp
;
340 aProp
.Name
= rtl::OUString( CFGPROPERTY_NODEPATH
);
341 aProp
.Value
<<= rtl::OUString( CONFIG_DATA_ROOT_KEY
);
343 uno::Sequence
< uno::Any
> aArguments( 1 );
344 aArguments
[ 0 ] <<= aProp
;
346 return createInstanceWithArguments( aServiceSpecifier
, aArguments
, false );
349 //=========================================================================
351 uno::Reference
< uno::XInterface
> SAL_CALL
352 HierarchyDataSource::createInstanceWithArguments(
353 const rtl::OUString
& ServiceSpecifier
,
354 const uno::Sequence
< uno::Any
> & Arguments
)
355 throw ( uno::Exception
, uno::RuntimeException
)
357 return createInstanceWithArguments( ServiceSpecifier
, Arguments
, true );
360 //=========================================================================
362 uno::Sequence
< rtl::OUString
> SAL_CALL
363 HierarchyDataSource::getAvailableServiceNames()
364 throw ( uno::RuntimeException
)
366 uno::Sequence
< rtl::OUString
> aNames( 2 );
367 aNames
[ 0 ] = rtl::OUString( READ_SERVICE_NAME
);
368 aNames
[ 1 ] = rtl::OUString( READWRITE_SERVICE_NAME
);
372 //=========================================================================
374 // Non-interface methods
376 //=========================================================================
378 uno::Reference
< uno::XInterface
> SAL_CALL
379 HierarchyDataSource::createInstanceWithArguments(
380 const rtl::OUString
& ServiceSpecifier
,
381 const uno::Sequence
< uno::Any
> & Arguments
,
383 throw ( uno::Exception
, uno::RuntimeException
)
385 osl::Guard
< osl::Mutex
> aGuard( m_aMutex
);
387 // Check service specifier.
388 bool bReadOnly
= ServiceSpecifier
== READ_SERVICE_NAME
;
389 bool bReadWrite
= !bReadOnly
&& ServiceSpecifier
== READWRITE_SERVICE_NAME
;
391 if ( !bReadOnly
&& !bReadWrite
)
393 OSL_FAIL( "HierarchyDataSource::createInstanceWithArguments - "
394 "Unsupported service specifier!" );
395 return uno::Reference
< uno::XInterface
>();
398 uno::Sequence
< uno::Any
> aNewArgs( Arguments
);
400 bool bHasLazyWriteProp
= bReadOnly
; // property must be added only if
401 // a writable view is requested.
405 bool bHasNodePath
= false;
406 sal_Int32 nCount
= Arguments
.getLength();
407 for ( sal_Int32 n
= 0; n
< nCount
; ++n
)
409 beans::PropertyValue aProp
;
410 if ( Arguments
[ n
] >>= aProp
)
412 if ( aProp
.Name
== CFGPROPERTY_NODEPATH
)
415 if ( aProp
.Value
>>= aPath
)
419 // Create path to data inside the configuration.
420 rtl::OUString aConfigPath
;
421 if ( !createConfigPath( aPath
, aConfigPath
) )
423 OSL_FAIL( "HierarchyDataSource::"
424 "createInstanceWithArguments - "
425 "Invalid node path!" );
426 return uno::Reference
< uno::XInterface
>();
429 aProp
.Value
<<= aConfigPath
;
431 // Set new path in arguments.
432 aNewArgs
[ n
] <<= aProp
;
434 if ( bHasLazyWriteProp
)
439 OSL_FAIL( "HierarchyDataSource::createInstanceWithArguments - "
440 "Invalid type for property 'nodepath'!" );
441 return uno::Reference
< uno::XInterface
>();
444 else if ( aProp
.Name
== CFGPROPERTY_LAZYWRITE
)
446 if ( aProp
.Value
.getValueType() == getCppuBooleanType() )
448 bHasLazyWriteProp
= true;
455 OSL_FAIL( "HierarchyDataSource::createInstanceWithArguments - "
456 "Invalid type for property 'lazywrite'!" );
457 return uno::Reference
< uno::XInterface
>();
465 OSL_FAIL( "HierarchyDataSource::createInstanceWithArguments - "
466 "No 'nodepath' property!" );
467 return uno::Reference
< uno::XInterface
>();
471 // Create Configuration Provider.
472 uno::Reference
< lang::XMultiServiceFactory
> xProv
= getConfigProvider();
474 return uno::Reference
< uno::XInterface
>();
476 uno::Reference
< uno::XInterface
> xConfigAccess
;
481 // Create configuration read-only access object.
482 xConfigAccess
= xProv
->createInstanceWithArguments(
483 rtl::OUString( CONFIG_READ_SERVICE_NAME
),
488 // Append 'lazywrite' property value, if not already present.
489 if ( !bHasLazyWriteProp
)
491 sal_Int32 nLen
= aNewArgs
.getLength();
492 aNewArgs
.realloc( nLen
+ 1 );
494 beans::PropertyValue aProp
;
495 aProp
.Name
= rtl::OUString( CFGPROPERTY_LAZYWRITE
);
496 aProp
.Value
<<= sal_True
;
497 aNewArgs
[ nLen
] <<= aProp
;
500 // Create configuration read-write access object.
501 xConfigAccess
= xProv
->createInstanceWithArguments(
502 rtl::OUString( CONFIG_READWRITE_SERVICE_NAME
),
506 catch ( uno::Exception
const & )
508 OSL_FAIL( "HierarchyDataSource::createInstanceWithArguments - "
509 "Cannot instanciate configuration access!" );
513 if ( !xConfigAccess
.is() )
515 OSL_FAIL( "HierarchyDataSource::createInstanceWithArguments - "
516 "Cannot instanciate configuration access!" );
517 return xConfigAccess
;
520 return uno::Reference
< uno::XInterface
>(
521 static_cast< cppu::OWeakObject
* >(
522 new HierarchyDataAccess( xConfigAccess
, bReadOnly
) ) );
525 //=========================================================================
526 uno::Reference
< lang::XMultiServiceFactory
>
527 HierarchyDataSource::getConfigProvider()
529 if ( !m_xConfigProvider
.is() )
531 osl::Guard
< osl::Mutex
> aGuard( m_aMutex
);
532 if ( !m_xConfigProvider
.is() )
537 = uno::Reference
< lang::XMultiServiceFactory
>(
538 m_xSMgr
->createInstance(
539 rtl::OUString( CONFIG_PROVIDER_SERVICE_NAME
) ),
542 OSL_ENSURE( m_xConfigProvider
.is(),
543 "HierarchyDataSource::getConfigProvider - "
544 "No configuration provider!" );
546 catch ( uno::Exception
const & )
548 OSL_FAIL( "HierarchyDataSource::getConfigProvider - "
549 "caught exception!" );
554 return m_xConfigProvider
;
557 //=========================================================================
558 bool HierarchyDataSource::createConfigPath(
559 const rtl::OUString
& rInPath
, rtl::OUString
& rOutPath
)
561 if ( !rInPath
.isEmpty() )
563 if ( rInPath
.indexOf( '/' ) == 0 )
565 OSL_FAIL( "HierarchyDataSource::createConfigPath - "
566 "Leading slash in node path!" );
570 if ( rInPath
.lastIndexOf( '/' ) == rInPath
.getLength() - 1 )
572 OSL_FAIL( "HierarchyDataSource::createConfigPath - "
573 "Trailing slash in node path!" );
577 rtl::OUString
aOutPath(
578 CONFIG_DATA_ROOT_KEY
"/" );
584 rOutPath
= rtl::OUString( CONFIG_DATA_ROOT_KEY
);
590 //=========================================================================
591 //=========================================================================
593 // HierarchyDataAccess Implementation.
595 //=========================================================================
596 //=========================================================================
598 #define ENSURE_ORIG_INTERFACE( interface_name, member_name ) \
599 m_xCfg##member_name; \
600 if ( !m_xCfg##member_name.is() ) \
602 osl::Guard< osl::Mutex > aGuard( m_aMutex ); \
603 if ( !m_xCfg##member_name.is() ) \
604 m_xCfg##member_name \
605 = uno::Reference< interface_name >( \
606 m_xConfigAccess, uno::UNO_QUERY ); \
607 xOrig = m_xCfg##member_name; \
610 //=========================================================================
611 HierarchyDataAccess::HierarchyDataAccess( const uno::Reference
<
612 uno::XInterface
> & xConfigAccess
,
614 : m_xConfigAccess( xConfigAccess
),
615 m_bReadOnly( bReadOnly
)
619 //=========================================================================
621 HierarchyDataAccess::~HierarchyDataAccess()
625 //=========================================================================
627 // XInterface methods.
629 //=========================================================================
631 XINTERFACE_COMMON_IMPL( HierarchyDataAccess
);
633 //=========================================================================
635 uno::Any SAL_CALL
HierarchyDataAccess::queryInterface( const uno::Type
& aType
)
636 throw ( uno::RuntimeException
)
638 // Interfaces supported in read-only and read-write mode.
639 uno::Any aRet
= cppu::queryInterface( aType
,
640 static_cast< lang::XTypeProvider
* >( this ),
641 static_cast< lang::XServiceInfo
* >( this ),
642 static_cast< lang::XComponent
* >( this ),
643 static_cast< container::XHierarchicalNameAccess
* >( this ),
644 static_cast< container::XNameAccess
* >( this ),
645 static_cast< container::XElementAccess
* >( this ),
646 static_cast< util::XChangesNotifier
* >( this ) );
648 // Interfaces supported only in read-write mode.
649 if ( !aRet
.hasValue() && !m_bReadOnly
)
651 aRet
= cppu::queryInterface( aType
,
652 static_cast< lang::XSingleServiceFactory
* >( this ),
653 static_cast< container::XNameContainer
* >( this ),
654 static_cast< container::XNameReplace
* >( this ),
655 static_cast< util::XChangesBatch
* >( this ) );
658 return aRet
.hasValue() ? aRet
: OWeakObject::queryInterface( aType
);
661 //=========================================================================
663 // XTypeProvider methods.
665 //=========================================================================
667 XTYPEPROVIDER_COMMON_IMPL( HierarchyDataAccess
);
669 //=========================================================================
671 uno::Sequence
< uno::Type
> SAL_CALL
HierarchyDataAccess::getTypes()
672 throw( uno::RuntimeException
)
674 cppu::OTypeCollection
* pCollection
= 0;
678 static cppu::OTypeCollection
* pReadOnlyTypes
= 0;
680 pCollection
= pReadOnlyTypes
;
683 osl::Guard
< osl::Mutex
> aGuard( osl::Mutex::getGlobalMutex() );
685 pCollection
= pReadOnlyTypes
;
688 static cppu::OTypeCollection
aCollection(
689 CPPU_TYPE_REF( lang::XTypeProvider
),
690 CPPU_TYPE_REF( lang::XServiceInfo
),
691 CPPU_TYPE_REF( lang::XComponent
),
692 CPPU_TYPE_REF( container::XHierarchicalNameAccess
),
693 CPPU_TYPE_REF( container::XNameAccess
),
694 CPPU_TYPE_REF( util::XChangesNotifier
) );
695 pCollection
= &aCollection
;
696 OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
697 pReadOnlyTypes
= pCollection
;
701 OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
706 static cppu::OTypeCollection
* pReadWriteTypes
= 0;
708 pCollection
= pReadWriteTypes
;
711 osl::Guard
< osl::Mutex
> aGuard( osl::Mutex::getGlobalMutex() );
713 pCollection
= pReadWriteTypes
;
716 static cppu::OTypeCollection
aCollection(
717 CPPU_TYPE_REF( lang::XTypeProvider
),
718 CPPU_TYPE_REF( lang::XServiceInfo
),
719 CPPU_TYPE_REF( lang::XComponent
),
720 CPPU_TYPE_REF( lang::XSingleServiceFactory
),
721 CPPU_TYPE_REF( container::XHierarchicalNameAccess
),
722 CPPU_TYPE_REF( container::XNameContainer
),
723 CPPU_TYPE_REF( util::XChangesBatch
),
724 CPPU_TYPE_REF( util::XChangesNotifier
) );
725 pCollection
= &aCollection
;
726 OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
727 pReadWriteTypes
= pCollection
;
731 OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
735 return (*pCollection
).getTypes();
738 //=========================================================================
740 // XServiceInfo methods.
742 //=========================================================================
744 XSERVICEINFO_NOFACTORY_IMPL_0(
746 rtl::OUString( "com.sun.star.comp.ucb.HierarchyDataAccess" ) )
748 uno::Sequence
< rtl::OUString
> aSNS( 2 );
749 aSNS
[ 0 ] = rtl::OUString( READ_SERVICE_NAME
);
750 aSNS
[ 1 ] = rtl::OUString( READWRITE_SERVICE_NAME
);
754 //=========================================================================
756 // XComponent methods.
758 //=========================================================================
761 void SAL_CALL
HierarchyDataAccess::dispose()
762 throw ( uno::RuntimeException
)
764 uno::Reference
< lang::XComponent
> xOrig
765 = ENSURE_ORIG_INTERFACE( lang::XComponent
, C
);
767 OSL_ENSURE( xOrig
.is(),
768 "HierarchyDataAccess : Data source is not an XComponent!" );
772 //=========================================================================
774 void SAL_CALL
HierarchyDataAccess::addEventListener(
775 const uno::Reference
< lang::XEventListener
> & xListener
)
776 throw ( uno::RuntimeException
)
778 uno::Reference
< lang::XComponent
> xOrig
779 = ENSURE_ORIG_INTERFACE( lang::XComponent
, C
);
781 OSL_ENSURE( xOrig
.is(),
782 "HierarchyDataAccess : Data source is not an XComponent!" );
783 xOrig
->addEventListener( xListener
);
786 //=========================================================================
788 void SAL_CALL
HierarchyDataAccess::removeEventListener(
789 const uno::Reference
< lang::XEventListener
> & aListener
)
790 throw ( uno::RuntimeException
)
792 uno::Reference
< lang::XComponent
> xOrig
793 = ENSURE_ORIG_INTERFACE( lang::XComponent
, C
);
795 OSL_ENSURE( xOrig
.is(),
796 "HierarchyDataAccess : Data source is not an XComponent!" );
797 xOrig
->removeEventListener( aListener
);
800 //=========================================================================
802 // XHierarchicalNameAccess methods.
804 //=========================================================================
807 uno::Any SAL_CALL
HierarchyDataAccess::getByHierarchicalName(
808 const rtl::OUString
& aName
)
809 throw ( container::NoSuchElementException
, uno::RuntimeException
)
811 uno::Reference
< container::XHierarchicalNameAccess
> xOrig
812 = ENSURE_ORIG_INTERFACE( container::XHierarchicalNameAccess
, HNA
);
814 OSL_ENSURE( xOrig
.is(),
815 "HierarchyDataAccess : "
816 "Data source is not an XHierarchicalNameAccess!" );
817 return xOrig
->getByHierarchicalName( aName
);
820 //=========================================================================
822 sal_Bool SAL_CALL
HierarchyDataAccess::hasByHierarchicalName(
823 const rtl::OUString
& aName
)
824 throw ( uno::RuntimeException
)
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
->hasByHierarchicalName( aName
);
835 //=========================================================================
837 // XNameAccess methods.
839 //=========================================================================
842 uno::Any SAL_CALL
HierarchyDataAccess::getByName( const rtl::OUString
& aName
)
843 throw ( container::NoSuchElementException
,
844 lang::WrappedTargetException
,
845 uno::RuntimeException
)
847 uno::Reference
< container::XNameAccess
> xOrig
848 = ENSURE_ORIG_INTERFACE( container::XNameAccess
, NA
);
850 OSL_ENSURE( xOrig
.is(),
851 "HierarchyDataAccess : Data source is not an XNameAccess!" );
852 return xOrig
->getByName( aName
);
855 //=========================================================================
857 uno::Sequence
< rtl::OUString
> SAL_CALL
HierarchyDataAccess::getElementNames()
858 throw ( uno::RuntimeException
)
860 uno::Reference
< container::XNameAccess
> xOrig
861 = ENSURE_ORIG_INTERFACE( container::XNameAccess
, NA
);
863 OSL_ENSURE( xOrig
.is(),
864 "HierarchyDataAccess : Data source is not an XNameAccess!" );
865 return xOrig
->getElementNames();
868 //=========================================================================
870 sal_Bool SAL_CALL
HierarchyDataAccess::hasByName( const rtl::OUString
& aName
)
871 throw ( uno::RuntimeException
)
873 uno::Reference
< container::XNameAccess
> xOrig
874 = ENSURE_ORIG_INTERFACE( container::XNameAccess
, NA
);
876 OSL_ENSURE( xOrig
.is(),
877 "HierarchyDataAccess : Data source is not an XNameAccess!" );
878 return xOrig
->hasByName( aName
);
881 //=========================================================================
883 // XElementAccess methods.
885 //=========================================================================
888 uno::Type SAL_CALL
HierarchyDataAccess::getElementType()
889 throw ( uno::RuntimeException
)
891 uno::Reference
< container::XElementAccess
> xOrig
892 = ENSURE_ORIG_INTERFACE( container::XElementAccess
, EA
);
894 OSL_ENSURE( xOrig
.is(),
895 "HierarchyDataAccess : Data source is not an XElementAccess!" );
896 return xOrig
->getElementType();
899 //=========================================================================
901 sal_Bool SAL_CALL
HierarchyDataAccess::hasElements()
902 throw ( uno::RuntimeException
)
904 uno::Reference
< container::XElementAccess
> xOrig
905 = ENSURE_ORIG_INTERFACE( container::XElementAccess
, EA
);
907 OSL_ENSURE( xOrig
.is(),
908 "HierarchyDataAccess : Data source is not an XElementAccess!" );
909 return xOrig
->hasElements();
912 //=========================================================================
914 // XChangesNotifier methods.
916 //=========================================================================
919 void SAL_CALL
HierarchyDataAccess::addChangesListener(
920 const uno::Reference
< util::XChangesListener
> & aListener
)
921 throw ( uno::RuntimeException
)
923 uno::Reference
< util::XChangesNotifier
> xOrig
924 = ENSURE_ORIG_INTERFACE( util::XChangesNotifier
, CN
);
926 OSL_ENSURE( xOrig
.is(),
927 "HierarchyDataAccess : Data source is not an XChangesNotifier!" );
928 xOrig
->addChangesListener( aListener
);
931 //=========================================================================
933 void SAL_CALL
HierarchyDataAccess::removeChangesListener(
934 const uno::Reference
< util::XChangesListener
> & aListener
)
935 throw ( uno::RuntimeException
)
937 uno::Reference
< util::XChangesNotifier
> xOrig
938 = ENSURE_ORIG_INTERFACE( util::XChangesNotifier
, CN
);
940 OSL_ENSURE( xOrig
.is(),
941 "HierarchyDataAccess : Data source is not an XChangesNotifier!" );
942 xOrig
->removeChangesListener( aListener
);
945 //=========================================================================
947 // XSingleServiceFactory methods.
949 //=========================================================================
952 uno::Reference
< uno::XInterface
> SAL_CALL
HierarchyDataAccess::createInstance()
953 throw ( uno::Exception
, uno::RuntimeException
)
955 uno::Reference
< lang::XSingleServiceFactory
> xOrig
956 = ENSURE_ORIG_INTERFACE( lang::XSingleServiceFactory
, SSF
);
958 OSL_ENSURE( xOrig
.is(),
959 "HierarchyDataAccess : Data source is not an XSingleServiceFactory!" );
960 return xOrig
->createInstance();
963 //=========================================================================
965 uno::Reference
< uno::XInterface
> SAL_CALL
966 HierarchyDataAccess::createInstanceWithArguments(
967 const uno::Sequence
< uno::Any
> & aArguments
)
968 throw ( uno::Exception
, uno::RuntimeException
)
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
->createInstanceWithArguments( aArguments
);
978 //=========================================================================
980 // XNameContainer methods.
982 //=========================================================================
986 HierarchyDataAccess::insertByName( const rtl::OUString
& aName
,
987 const uno::Any
& aElement
)
988 throw ( lang::IllegalArgumentException
,
989 container::ElementExistException
,
990 lang::WrappedTargetException
,
991 uno::RuntimeException
)
993 uno::Reference
< container::XNameContainer
> xOrig
994 = ENSURE_ORIG_INTERFACE( container::XNameContainer
, NC
);
996 OSL_ENSURE( xOrig
.is(),
997 "HierarchyDataAccess : Data source is not an XNameContainer!" );
998 xOrig
->insertByName( aName
, aElement
);
1001 //=========================================================================
1004 HierarchyDataAccess::removeByName( const rtl::OUString
& Name
)
1005 throw ( container::NoSuchElementException
,
1006 lang::WrappedTargetException
,
1007 uno::RuntimeException
)
1009 uno::Reference
< container::XNameContainer
> xOrig
1010 = ENSURE_ORIG_INTERFACE( container::XNameContainer
, NC
);
1012 OSL_ENSURE( xOrig
.is(),
1013 "HierarchyDataAccess : Data source is not an XNameContainer!" );
1014 xOrig
->removeByName( Name
);
1017 //=========================================================================
1019 // XNameReplace methods.
1021 //=========================================================================
1024 void SAL_CALL
HierarchyDataAccess::replaceByName( const rtl::OUString
& aName
,
1025 const uno::Any
& aElement
)
1026 throw ( lang::IllegalArgumentException
,
1027 container::NoSuchElementException
,
1028 lang::WrappedTargetException
,
1029 uno::RuntimeException
)
1031 uno::Reference
< container::XNameReplace
> xOrig
1032 = ENSURE_ORIG_INTERFACE( container::XNameReplace
, NR
);
1034 OSL_ENSURE( xOrig
.is(),
1035 "HierarchyDataAccess : Data source is not an XNameReplace!" );
1036 xOrig
->replaceByName( aName
, aElement
);
1039 //=========================================================================
1041 // XChangesBatch methods.
1043 //=========================================================================
1046 void SAL_CALL
HierarchyDataAccess::commitChanges()
1047 throw ( lang::WrappedTargetException
, uno::RuntimeException
)
1049 uno::Reference
< util::XChangesBatch
> xOrig
1050 = ENSURE_ORIG_INTERFACE( util::XChangesBatch
, CB
);
1052 OSL_ENSURE( xOrig
.is(),
1053 "HierarchyDataAccess : Data source is not an XChangesBatch!" );
1054 xOrig
->commitChanges();
1057 //=========================================================================
1059 sal_Bool SAL_CALL
HierarchyDataAccess::hasPendingChanges()
1060 throw ( uno::RuntimeException
)
1062 uno::Reference
< util::XChangesBatch
> xOrig
1063 = ENSURE_ORIG_INTERFACE( util::XChangesBatch
, CB
);
1065 OSL_ENSURE( xOrig
.is(),
1066 "HierarchyDataAccess : Data source is not an XChangesBatch!" );
1067 return xOrig
->hasPendingChanges();
1070 //=========================================================================
1072 uno::Sequence
< util::ElementChange
> SAL_CALL
1073 HierarchyDataAccess::getPendingChanges()
1074 throw ( uno::RuntimeException
)
1076 uno::Reference
< util::XChangesBatch
> xOrig
1077 = ENSURE_ORIG_INTERFACE( util::XChangesBatch
, CB
);
1079 OSL_ENSURE( xOrig
.is(),
1080 "HierarchyDataAccess : Data source is not an XChangesBatch!" );
1081 return xOrig
->getPendingChanges();
1084 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */