30#include <osl/diagnose.h>
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>
41#include <com/sun/star/lang/XSingleServiceFactory.hpp>
69 public lang::XServiceInfo,
70 public lang::XTypeProvider,
71 public lang::XComponent,
72 public lang::XSingleServiceFactory,
73 public container::XHierarchicalNameAccess,
74 public container::XNameContainer,
75 public util::XChangesNotifier,
76 public util::XChangesBatch
80 uno::Reference< lang::XComponent >
m_xCfgC;
81 uno::Reference< lang::XSingleServiceFactory >
m_xCfgSSF;
82 uno::Reference< container::XHierarchicalNameAccess >
m_xCfgHNA;
83 uno::Reference< container::XNameContainer >
m_xCfgNC;
84 uno::Reference< container::XNameReplace >
m_xCfgNR;
85 uno::Reference< container::XNameAccess >
m_xCfgNA;
86 uno::Reference< container::XElementAccess >
m_xCfgEA;
87 uno::Reference< util::XChangesNotifier >
m_xCfgCN;
88 uno::Reference< util::XChangesBatch >
m_xCfgCB;
92 HierarchyDataAccess( uno::Reference<
93 uno::XInterface > xConfigAccess,
97 virtual css::uno::Any SAL_CALL
queryInterface(
const css::uno::Type & rType )
override;
98 virtual void SAL_CALL acquire()
100 virtual
void SAL_CALL release()
104 virtual OUString SAL_CALL getImplementationName() override;
105 virtual
sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
106 virtual css::
uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
109 virtual css::
uno::Sequence<
sal_Int8 > SAL_CALL getImplementationId() override;
110 virtual css::
uno::Sequence< css::
uno::
Type > SAL_CALL getTypes() override;
113 virtual
void SAL_CALL
115 virtual
void SAL_CALL
116 addEventListener( const
uno::Reference< lang::XEventListener > & xListener ) override;
117 virtual
void SAL_CALL
118 removeEventListener( const
uno::Reference<
119 lang::XEventListener > & aListener ) override;
123 createInstance() override;
125 createInstanceWithArguments( const
uno::Sequence<
uno::Any > & aArguments ) override;
128 virtual
uno::Any SAL_CALL
129 getByHierarchicalName( const OUString & aName ) override;
131 hasByHierarchicalName( const OUString & aName ) override;
134 virtual
void SAL_CALL
135 insertByName( const OUString & aName, const
uno::Any & aElement ) override;
136 virtual
void SAL_CALL
137 removeByName( const OUString & Name ) override;
140 virtual
void SAL_CALL
141 replaceByName( const OUString & aName, const
uno::Any & aElement ) override;
144 virtual
uno::Any SAL_CALL
145 getByName( const OUString & aName ) override;
146 virtual
uno::Sequence< OUString > SAL_CALL
147 getElementNames() override;
149 hasByName( const OUString & aName ) override;
153 getElementType() override;
155 hasElements() override;
158 virtual
void SAL_CALL
159 addChangesListener( const
uno::Reference<
160 util::XChangesListener > & aListener ) override;
161 virtual
void SAL_CALL
162 removeChangesListener( const
uno::Reference<
163 util::XChangesListener > & aListener ) override;
166 virtual
void SAL_CALL
167 commitChanges() override;
169 hasPendingChanges() override;
170 virtual
uno::Sequence< util::ElementChange > SAL_CALL
171 getPendingChanges() override;
174 css::
uno::Reference<T> ensureOrigInterface(css::
uno::Reference<T>& x);
188 uno::Reference<
uno::XComponentContext > xContext )
189: m_xContext(
std::move( xContext ))
195HierarchyDataSource::~HierarchyDataSource()
200OUString SAL_CALL HierarchyDataSource::getImplementationName() \
202 return "com.sun.star.comp.ucb.HierarchyDataSource";
204sal_Bool SAL_CALL HierarchyDataSource::supportsService(
const OUString& ServiceName )
208css::uno::Sequence< OUString > HierarchyDataSource::getSupportedServiceNames()
210 return {
"com.sun.star.ucb.DefaultHierarchyDataSource",
"com.sun.star.ucb.HierarchyDataSource" };
213extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
215 css::uno::XComponentContext* context , css::uno::Sequence<css::uno::Any>
const&)
225void SAL_CALL HierarchyDataSource::dispose()
227 std::unique_lock aGuard(
m_aMutex );
229 if ( m_aDisposeEventListeners.getLength(aGuard) )
231 lang::EventObject aEvt;
232 aEvt.Source =
static_cast< lang::XComponent *
>( this );
233 m_aDisposeEventListeners.disposeAndClear( aGuard, aEvt );
239void SAL_CALL HierarchyDataSource::addEventListener(
240 const uno::Reference< lang::XEventListener > & Listener )
242 std::unique_lock aGuard(
m_aMutex );
244 m_aDisposeEventListeners.addInterface( aGuard, Listener );
249void SAL_CALL HierarchyDataSource::removeEventListener(
250 const uno::Reference< lang::XEventListener > & Listener )
252 std::unique_lock aGuard(
m_aMutex );
254 m_aDisposeEventListeners.removeInterface( aGuard, Listener );
262uno::Reference< uno::XInterface > SAL_CALL
263HierarchyDataSource::createInstance(
const OUString & aServiceSpecifier )
272 return createInstanceWithArguments( aServiceSpecifier,
aArguments,
false );
277uno::Reference< uno::XInterface > SAL_CALL
278HierarchyDataSource::createInstanceWithArguments(
279 const OUString & ServiceSpecifier,
280 const uno::Sequence< uno::Any > & Arguments )
282 return createInstanceWithArguments( ServiceSpecifier, Arguments,
true );
287uno::Sequence< OUString > SAL_CALL
288HierarchyDataSource::getAvailableServiceNames()
297uno::Reference< uno::XInterface >
298HierarchyDataSource::createInstanceWithArguments(
299 std::u16string_view ServiceSpecifier,
300 const uno::Sequence< uno::Any > & Arguments,
307 if ( !bReadOnly && !bReadWrite )
309 OSL_FAIL(
"HierarchyDataSource::createInstanceWithArguments - "
310 "Unsupported service specifier!" );
311 return uno::Reference< uno::XInterface >();
314 uno::Sequence< uno::Any > aNewArgs( Arguments );
315 auto aNewArgsRange = asNonConstRange(aNewArgs);
320 bool bHasNodePath =
false;
321 sal_Int32
nCount = Arguments.getLength();
322 for ( sal_Int32 n = 0;
n <
nCount; ++
n )
324 beans::PropertyValue aProp;
325 if ( Arguments[ n ] >>= aProp )
330 if ( aProp.Value >>= aPath )
335 OUString aConfigPath;
336 if ( !createConfigPath( aPath, aConfigPath ) )
338 OSL_FAIL(
"HierarchyDataSource::"
339 "createInstanceWithArguments - "
340 "Invalid node path!" );
341 return uno::Reference< uno::XInterface >();
344 aProp.Value <<= aConfigPath;
347 aNewArgsRange[
n ] <<= aProp;
353 OSL_FAIL(
"HierarchyDataSource::createInstanceWithArguments - "
354 "Invalid type for property 'nodepath'!" );
355 return uno::Reference< uno::XInterface >();
363 OSL_FAIL(
"HierarchyDataSource::createInstanceWithArguments - "
364 "No 'nodepath' property!" );
365 return uno::Reference< uno::XInterface >();
370 uno::Reference< lang::XMultiServiceFactory > xProv = getConfigProvider();
372 return uno::Reference< uno::XInterface >();
374 uno::Reference< uno::XInterface > xConfigAccess;
380 xConfigAccess = xProv->createInstanceWithArguments(
381 "com.sun.star.configuration.ConfigurationAccess",
387 xConfigAccess = xProv->createInstanceWithArguments(
388 "com.sun.star.configuration.ConfigurationUpdateAccess",
392 catch ( uno::Exception
const & )
394 OSL_FAIL(
"HierarchyDataSource::createInstanceWithArguments - "
395 "Cannot instantiate configuration access!" );
399 if ( !xConfigAccess.is() )
401 OSL_FAIL(
"HierarchyDataSource::createInstanceWithArguments - "
402 "Cannot instantiate configuration access!" );
403 return xConfigAccess;
406 return cppu::getXWeak(
new HierarchyDataAccess(xConfigAccess, bReadOnly));
410uno::Reference< lang::XMultiServiceFactory >
411HierarchyDataSource::getConfigProvider()
415 std::unique_lock aGuard(
m_aMutex );
422 catch ( uno::Exception
const & )
424 OSL_FAIL(
"HierarchyDataSource::getConfigProvider - "
425 "caught exception!" );
434bool HierarchyDataSource::createConfigPath(
435 std::u16string_view rInPath, OUString & rOutPath )
437 if ( !rInPath.empty() )
441 OSL_FAIL(
"HierarchyDataSource::createConfigPath - "
442 "Leading slash in node path!" );
448 OSL_FAIL(
"HierarchyDataSource::createConfigPath - "
449 "Trailing slash in node path!" );
467css::uno::Reference<T> HierarchyDataAccess::ensureOrigInterface(css::uno::Reference<T>& x)
471 std::scoped_lock aGuard(
m_aMutex );
478HierarchyDataAccess::HierarchyDataAccess( uno::Reference<
479 uno::XInterface > xConfigAccess,
487void SAL_CALL HierarchyDataAccess::acquire()
490 OWeakObject::acquire();
493void SAL_CALL HierarchyDataAccess::release()
496 OWeakObject::release();
504 static_cast< lang::XTypeProvider *
>(
this ),
505 static_cast< lang::XServiceInfo *
>(
this ),
506 static_cast< lang::XComponent *
>(
this ),
507 static_cast< container::XHierarchicalNameAccess *
>(
this ),
508 static_cast< container::XNameAccess *
>(
this ),
509 static_cast< container::XElementAccess *
>(
this ),
510 static_cast< util::XChangesNotifier *
>(
this ) );
516 static_cast< lang::XSingleServiceFactory *
>(
this ),
517 static_cast< container::XNameContainer *
>(
this ),
518 static_cast< container::XNameReplace *
>(
this ),
519 static_cast< util::XChangesBatch *
>(
this ) );
522 return aRet.
hasValue() ? aRet : OWeakObject::queryInterface( aType );
533uno::Sequence< uno::Type > SAL_CALL HierarchyDataAccess::getTypes()
545 return s_aReadOnlyTypes.getTypes();
559 return s_aReadWriteTypes.getTypes();
566OUString SAL_CALL HierarchyDataAccess::getImplementationName()
568 return "com.sun.star.comp.ucb.HierarchyDataAccess";
571sal_Bool SAL_CALL HierarchyDataAccess::supportsService(
const OUString& ServiceName )
576css::uno::Sequence< OUString > SAL_CALL HierarchyDataAccess::getSupportedServiceNames()
586void SAL_CALL HierarchyDataAccess::dispose()
588 uno::Reference< lang::XComponent > xOrig
589 = ensureOrigInterface(
m_xCfgC );
591 OSL_ENSURE( xOrig.is(),
592 "HierarchyDataAccess : Data source is not an XComponent!" );
598void SAL_CALL HierarchyDataAccess::addEventListener(
599 const uno::Reference< lang::XEventListener > & xListener )
601 uno::Reference< lang::XComponent > xOrig
602 = ensureOrigInterface(
m_xCfgC );
604 OSL_ENSURE( xOrig.is(),
605 "HierarchyDataAccess : Data source is not an XComponent!" );
606 xOrig->addEventListener( xListener );
611void SAL_CALL HierarchyDataAccess::removeEventListener(
612 const uno::Reference< lang::XEventListener > & aListener )
614 uno::Reference< lang::XComponent > xOrig
615 = ensureOrigInterface(
m_xCfgC );
617 OSL_ENSURE( xOrig.is(),
618 "HierarchyDataAccess : Data source is not an XComponent!" );
619 xOrig->removeEventListener( aListener );
627uno::Any SAL_CALL HierarchyDataAccess::getByHierarchicalName(
628 const OUString & aName )
630 uno::Reference< container::XHierarchicalNameAccess > xOrig
633 OSL_ENSURE( xOrig.is(),
634 "HierarchyDataAccess : "
635 "Data source is not an XHierarchicalNameAccess!" );
636 return xOrig->getByHierarchicalName( aName );
641sal_Bool SAL_CALL HierarchyDataAccess::hasByHierarchicalName(
642 const OUString & aName )
644 uno::Reference< container::XHierarchicalNameAccess > xOrig
647 OSL_ENSURE( xOrig.is(),
648 "HierarchyDataAccess : "
649 "Data source is not an XHierarchicalNameAccess!" );
650 return xOrig->hasByHierarchicalName( aName );
658uno::Any SAL_CALL HierarchyDataAccess::getByName(
const OUString & aName )
660 uno::Reference< container::XNameAccess > xOrig
663 OSL_ENSURE( xOrig.is(),
664 "HierarchyDataAccess : Data source is not an XNameAccess!" );
665 return xOrig->getByName( aName );
670uno::Sequence< OUString > SAL_CALL HierarchyDataAccess::getElementNames()
672 uno::Reference< container::XNameAccess > xOrig
675 OSL_ENSURE( xOrig.is(),
676 "HierarchyDataAccess : Data source is not an XNameAccess!" );
677 return xOrig->getElementNames();
682sal_Bool SAL_CALL HierarchyDataAccess::hasByName(
const OUString & aName )
684 uno::Reference< container::XNameAccess > xOrig
687 OSL_ENSURE( xOrig.is(),
688 "HierarchyDataAccess : Data source is not an XNameAccess!" );
689 return xOrig->hasByName( aName );
697uno::Type SAL_CALL HierarchyDataAccess::getElementType()
699 uno::Reference< container::XElementAccess > xOrig
702 OSL_ENSURE( xOrig.is(),
703 "HierarchyDataAccess : Data source is not an XElementAccess!" );
704 return xOrig->getElementType();
709sal_Bool SAL_CALL HierarchyDataAccess::hasElements()
711 uno::Reference< container::XElementAccess > xOrig
714 OSL_ENSURE( xOrig.is(),
715 "HierarchyDataAccess : Data source is not an XElementAccess!" );
716 return xOrig->hasElements();
724void SAL_CALL HierarchyDataAccess::addChangesListener(
725 const uno::Reference< util::XChangesListener > & aListener )
727 uno::Reference< util::XChangesNotifier > xOrig
730 OSL_ENSURE( xOrig.is(),
731 "HierarchyDataAccess : Data source is not an XChangesNotifier!" );
732 xOrig->addChangesListener( aListener );
737void SAL_CALL HierarchyDataAccess::removeChangesListener(
738 const uno::Reference< util::XChangesListener > & aListener )
740 uno::Reference< util::XChangesNotifier > xOrig
743 OSL_ENSURE( xOrig.is(),
744 "HierarchyDataAccess : Data source is not an XChangesNotifier!" );
745 xOrig->removeChangesListener( aListener );
753uno::Reference< uno::XInterface > SAL_CALL HierarchyDataAccess::createInstance()
755 uno::Reference< lang::XSingleServiceFactory > xOrig
758 OSL_ENSURE( xOrig.is(),
759 "HierarchyDataAccess : Data source is not an XSingleServiceFactory!" );
760 return xOrig->createInstance();
765uno::Reference< uno::XInterface > SAL_CALL
766HierarchyDataAccess::createInstanceWithArguments(
767 const uno::Sequence< uno::Any > & aArguments )
769 uno::Reference< lang::XSingleServiceFactory > xOrig
772 OSL_ENSURE( xOrig.is(),
773 "HierarchyDataAccess : Data source is not an XSingleServiceFactory!" );
774 return xOrig->createInstanceWithArguments( aArguments );
783HierarchyDataAccess::insertByName(
const OUString & aName,
786 uno::Reference< container::XNameContainer > xOrig
789 OSL_ENSURE( xOrig.is(),
790 "HierarchyDataAccess : Data source is not an XNameContainer!" );
791 xOrig->insertByName( aName, aElement );
797HierarchyDataAccess::removeByName(
const OUString & Name )
799 uno::Reference< container::XNameContainer > xOrig
802 OSL_ENSURE( xOrig.is(),
803 "HierarchyDataAccess : Data source is not an XNameContainer!" );
804 xOrig->removeByName( Name );
812void SAL_CALL HierarchyDataAccess::replaceByName(
const OUString & aName,
815 uno::Reference< container::XNameReplace > xOrig
818 OSL_ENSURE( xOrig.is(),
819 "HierarchyDataAccess : Data source is not an XNameReplace!" );
820 xOrig->replaceByName( aName, aElement );
828void SAL_CALL HierarchyDataAccess::commitChanges()
830 uno::Reference< util::XChangesBatch > xOrig
833 OSL_ENSURE( xOrig.is(),
834 "HierarchyDataAccess : Data source is not an XChangesBatch!" );
835 xOrig->commitChanges();
840sal_Bool SAL_CALL HierarchyDataAccess::hasPendingChanges()
842 uno::Reference< util::XChangesBatch > xOrig
845 OSL_ENSURE( xOrig.is(),
846 "HierarchyDataAccess : Data source is not an XChangesBatch!" );
847 return xOrig->hasPendingChanges();
852uno::Sequence< util::ElementChange > SAL_CALL
853HierarchyDataAccess::getPendingChanges()
855 uno::Reference< util::XChangesBatch > xOrig
858 OSL_ENSURE( xOrig.is(),
859 "HierarchyDataAccess : Data source is not an XChangesBatch!" );
860 return xOrig->getPendingChanges();
Reference< XComponentContext > m_xContext
uno::Reference< container::XNameContainer > m_xCfgNC
uno::Reference< lang::XComponent > m_xCfgC
uno::Reference< container::XNameAccess > m_xCfgNA
constexpr OUStringLiteral CFGPROPERTY_NODEPATH
uno::Reference< util::XChangesBatch > m_xCfgCB
XTYPEPROVIDER_COMMON_IMPL(HierarchyDataAccess)
uno::Reference< lang::XSingleServiceFactory > m_xCfgSSF
uno::Reference< container::XNameReplace > m_xCfgNR
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * ucb_HierarchyDataSource_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
constexpr OUStringLiteral READ_SERVICE_NAME
uno::Reference< uno::XInterface > m_xConfigAccess
constexpr OUStringLiteral CONFIG_DATA_ROOT_KEY
uno::Reference< util::XChangesNotifier > m_xCfgCN
uno::Reference< container::XHierarchicalNameAccess > m_xCfgHNA
uno::Reference< container::XElementAccess > m_xCfgEA
constexpr OUStringLiteral READWRITE_SERVICE_NAME
Sequence< PropertyValue > aArguments
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType, Interface1 *p1)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
constexpr OUStringLiteral READWRITE_SERVICE_NAME
constexpr OUStringLiteral READ_SERVICE_NAME
constexpr bool ends_with(std::basic_string_view< charT, traits > sv, std::basic_string_view< charT, traits > x) noexcept
constexpr bool starts_with(std::basic_string_view< charT, traits > sv, std::basic_string_view< charT, traits > x) noexcept
Reference< XMultiServiceFactory > m_xConfigProvider