bump product version to 5.0.4.1
[LibreOffice.git] / configmgr / source / readonlyaccess.cxx
blob9989eac30ab21095396986b28a8e3b38ea26fd37
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/implbase3.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::WeakImplHelper3<
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&) SAL_DELETED_FUNCTION;
55 Service& operator=(const Service&) SAL_DELETED_FUNCTION;
57 virtual ~Service() {}
59 virtual OUString SAL_CALL getImplementationName()
60 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
61 { return read_only_access::getImplementationName(); }
63 virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName)
64 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
65 { return cppu::supportsService(this, ServiceName); }
67 virtual css::uno::Sequence< OUString > SAL_CALL
68 getSupportedServiceNames() throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
69 { return read_only_access::getSupportedServiceNames(); }
71 virtual void SAL_CALL initialize(
72 css::uno::Sequence< css::uno::Any > const & aArguments)
73 throw (css::uno::Exception, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
75 virtual css::uno::Any SAL_CALL getByHierarchicalName(
76 OUString const & aName)
77 throw (
78 css::container::NoSuchElementException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE
79 { return getRoot()->getByHierarchicalName(aName); }
81 virtual sal_Bool SAL_CALL hasByHierarchicalName(OUString const & aName)
82 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
83 { return getRoot()->hasByHierarchicalName(aName); }
85 rtl::Reference< RootAccess > getRoot();
87 css::uno::Reference< css::uno::XComponentContext > context_;
89 osl::Mutex mutex_;
90 rtl::Reference< RootAccess > root_;
93 void Service::initialize(css::uno::Sequence< css::uno::Any > const & aArguments)
94 throw (css::uno::Exception, css::uno::RuntimeException, std::exception)
96 OUString locale;
97 if (aArguments.getLength() != 1 || !(aArguments[0] >>= locale)) {
98 throw css::lang::IllegalArgumentException(
99 "not exactly one string argument",
100 static_cast< cppu::OWeakObject * >(this), -1);
102 osl::MutexGuard g1(mutex_);
103 if (root_.is()) {
104 throw css::uno::RuntimeException(
105 "already initialized", static_cast< cppu::OWeakObject * >(this));
107 osl::MutexGuard g2(*lock());
108 Components & components = Components::getSingleton(context_);
109 root_ = new RootAccess(components, "/", locale, false);
110 components.addRootAccess(root_);
113 rtl::Reference< RootAccess > Service::getRoot() {
114 osl::MutexGuard g(mutex_);
115 if (!root_.is()) {
116 throw css::lang::NotInitializedException(
117 "not initialized", static_cast< cppu::OWeakObject * >(this));
119 return root_;
124 css::uno::Reference< css::uno::XInterface > create(
125 css::uno::Reference< css::uno::XComponentContext > const & context)
127 return static_cast< cppu::OWeakObject * >(new Service(context));
130 OUString getImplementationName() {
131 return OUString("com.sun.star.comp.configuration.ReadOnlyAccess");
134 css::uno::Sequence< OUString > getSupportedServiceNames() {
135 OUString name("com.sun.star.configuration.ReadOnlyAccess");
136 return css::uno::Sequence< OUString >(&name, 1);
141 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */