bump product version to 7.2.5.1
[LibreOffice.git] / configmgr / source / readonlyaccess.cxx
blob286963c783a2f247c30ed70e347b654a3850900f
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/.
8 */
10 #include <sal/config.h>
12 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
13 #include <com/sun/star/lang/IllegalArgumentException.hpp>
14 #include <com/sun/star/lang/NotInitializedException.hpp>
15 #include <com/sun/star/lang/XInitialization.hpp>
16 #include <com/sun/star/lang/XServiceInfo.hpp>
17 #include <com/sun/star/uno/Any.hxx>
18 #include <com/sun/star/uno/Reference.hxx>
19 #include <com/sun/star/uno/RuntimeException.hpp>
20 #include <com/sun/star/uno/Sequence.hxx>
21 #include <com/sun/star/uno/XInterface.hpp>
22 #include <cppuhelper/implbase.hxx>
23 #include <cppuhelper/supportsservice.hxx>
24 #include <cppuhelper/weak.hxx>
25 #include <osl/mutex.hxx>
26 #include <rtl/ref.hxx>
27 #include <rtl/ustring.hxx>
28 #include <sal/types.h>
30 #include "components.hxx"
31 #include "lock.hxx"
32 #include "rootaccess.hxx"
34 namespace configmgr::read_only_access {
36 namespace {
38 class Service:
39 public cppu::WeakImplHelper<
40 css::lang::XServiceInfo, css::lang::XInitialization,
41 css::container::XHierarchicalNameAccess >
43 public:
44 explicit Service(
45 css::uno::Reference< css::uno::XComponentContext > const & context):
46 context_(context) {}
48 private:
49 Service(const Service&) = delete;
50 Service& operator=(const Service&) = delete;
52 virtual ~Service() override {}
54 virtual OUString SAL_CALL getImplementationName() override
55 { return "com.sun.star.comp.configuration.ReadOnlyAccess"; }
57 virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override
58 { return cppu::supportsService(this, ServiceName); }
60 virtual css::uno::Sequence< OUString > SAL_CALL
61 getSupportedServiceNames() override
62 { return { "com.sun.star.configuration.ReadOnlyAccess" }; }
64 virtual void SAL_CALL initialize(
65 css::uno::Sequence< css::uno::Any > const & aArguments) override;
67 virtual css::uno::Any SAL_CALL getByHierarchicalName(
68 OUString const & aName) override
69 { return getRoot()->getByHierarchicalName(aName); }
71 virtual sal_Bool SAL_CALL hasByHierarchicalName(OUString const & aName) override
72 { return getRoot()->hasByHierarchicalName(aName); }
74 rtl::Reference< RootAccess > getRoot();
76 css::uno::Reference< css::uno::XComponentContext > context_;
78 osl::Mutex mutex_;
79 rtl::Reference< RootAccess > root_;
82 void Service::initialize(css::uno::Sequence< css::uno::Any > const & aArguments)
84 OUString locale;
85 if (aArguments.getLength() != 1 || !(aArguments[0] >>= locale)) {
86 throw css::lang::IllegalArgumentException(
87 "not exactly one string argument",
88 static_cast< cppu::OWeakObject * >(this), -1);
90 osl::MutexGuard g1(mutex_);
91 if (root_.is()) {
92 throw css::uno::RuntimeException(
93 "already initialized", static_cast< cppu::OWeakObject * >(this));
95 osl::MutexGuard g2(*lock());
96 Components & components = Components::getSingleton(context_);
97 root_ = new RootAccess(components, "/", locale, false);
98 components.addRootAccess(root_);
101 rtl::Reference< RootAccess > Service::getRoot() {
102 osl::MutexGuard g(mutex_);
103 if (!root_.is()) {
104 throw css::lang::NotInitializedException(
105 "not initialized", static_cast< cppu::OWeakObject * >(this));
107 return root_;
113 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
114 com_sun_star_comp_configuration_ReadOnlyAccess_get_implementation(
115 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&)
117 return cppu::acquire(new configmgr::read_only_access::Service(context));
120 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */