bump product version to 6.3.0.0.beta1
[LibreOffice.git] / configmgr / source / readonlyaccess.cxx
blobb14ad3dc59b87f9050bc3ba30b1e997384622bd8
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/NoSuchElementException.hpp>
13 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
14 #include <com/sun/star/lang/IllegalArgumentException.hpp>
15 #include <com/sun/star/lang/NotInitializedException.hpp>
16 #include <com/sun/star/lang/XInitialization.hpp>
17 #include <com/sun/star/lang/XServiceInfo.hpp>
18 #include <com/sun/star/uno/Any.hxx>
19 #include <com/sun/star/uno/Exception.hpp>
20 #include <com/sun/star/uno/Reference.hxx>
21 #include <com/sun/star/uno/RuntimeException.hpp>
22 #include <com/sun/star/uno/Sequence.hxx>
23 #include <com/sun/star/uno/XComponentContext.hpp>
24 #include <com/sun/star/uno/XInterface.hpp>
25 #include <cppuhelper/implbase.hxx>
26 #include <cppuhelper/supportsservice.hxx>
27 #include <cppuhelper/weak.hxx>
28 #include <osl/mutex.hxx>
29 #include <rtl/ref.hxx>
30 #include <rtl/ustring.h>
31 #include <rtl/ustring.hxx>
32 #include <sal/types.h>
34 #include "components.hxx"
35 #include "lock.hxx"
36 #include "readonlyaccess.hxx"
37 #include "rootaccess.hxx"
39 namespace configmgr { namespace read_only_access {
41 namespace {
43 class Service:
44 public cppu::WeakImplHelper<
45 css::lang::XServiceInfo, css::lang::XInitialization,
46 css::container::XHierarchicalNameAccess >
48 public:
49 explicit Service(
50 css::uno::Reference< css::uno::XComponentContext > const & context):
51 context_(context) {}
53 private:
54 Service(const Service&) = delete;
55 Service& operator=(const Service&) = delete;
57 virtual ~Service() override {}
59 virtual OUString SAL_CALL getImplementationName() override
60 { return read_only_access::getImplementationName(); }
62 virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override
63 { return cppu::supportsService(this, ServiceName); }
65 virtual css::uno::Sequence< OUString > SAL_CALL
66 getSupportedServiceNames() override
67 { return read_only_access::getSupportedServiceNames(); }
69 virtual void SAL_CALL initialize(
70 css::uno::Sequence< css::uno::Any > const & aArguments) override;
72 virtual css::uno::Any SAL_CALL getByHierarchicalName(
73 OUString const & aName) override
74 { return getRoot()->getByHierarchicalName(aName); }
76 virtual sal_Bool SAL_CALL hasByHierarchicalName(OUString const & aName) override
77 { return getRoot()->hasByHierarchicalName(aName); }
79 rtl::Reference< RootAccess > getRoot();
81 css::uno::Reference< css::uno::XComponentContext > context_;
83 osl::Mutex mutex_;
84 rtl::Reference< RootAccess > root_;
87 void Service::initialize(css::uno::Sequence< css::uno::Any > const & aArguments)
89 OUString locale;
90 if (aArguments.getLength() != 1 || !(aArguments[0] >>= locale)) {
91 throw css::lang::IllegalArgumentException(
92 "not exactly one string argument",
93 static_cast< cppu::OWeakObject * >(this), -1);
95 osl::MutexGuard g1(mutex_);
96 if (root_.is()) {
97 throw css::uno::RuntimeException(
98 "already initialized", static_cast< cppu::OWeakObject * >(this));
100 osl::MutexGuard g2(*lock());
101 Components & components = Components::getSingleton(context_);
102 root_ = new RootAccess(components, "/", locale, false);
103 components.addRootAccess(root_);
106 rtl::Reference< RootAccess > Service::getRoot() {
107 osl::MutexGuard g(mutex_);
108 if (!root_.is()) {
109 throw css::lang::NotInitializedException(
110 "not initialized", static_cast< cppu::OWeakObject * >(this));
112 return root_;
117 css::uno::Reference< css::uno::XInterface > create(
118 css::uno::Reference< css::uno::XComponentContext > const & context)
120 return static_cast< cppu::OWeakObject * >(new Service(context));
123 OUString getImplementationName() {
124 return OUString("com.sun.star.comp.configuration.ReadOnlyAccess");
127 css::uno::Sequence< OUString > getSupportedServiceNames() {
128 return css::uno::Sequence< OUString > { "com.sun.star.configuration.ReadOnlyAccess" };
133 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */