bump product version to 4.1.6.2
[LibreOffice.git] / configmgr / source / readonlyaccess.cxx
blob974bedee0e2df429b54b204e357177ed5c62d198
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 "boost/noncopyable.hpp"
13 #include "com/sun/star/container/NoSuchElementException.hpp"
14 #include "com/sun/star/container/XHierarchicalNameAccess.hpp"
15 #include "com/sun/star/lang/IllegalArgumentException.hpp"
16 #include "com/sun/star/lang/NotInitializedException.hpp"
17 #include "com/sun/star/lang/XInitialization.hpp"
18 #include "com/sun/star/lang/XServiceInfo.hpp"
19 #include "com/sun/star/uno/Any.hxx"
20 #include "com/sun/star/uno/Exception.hpp"
21 #include "com/sun/star/uno/Reference.hxx"
22 #include "com/sun/star/uno/RuntimeException.hpp"
23 #include "com/sun/star/uno/Sequence.hxx"
24 #include "com/sun/star/uno/XComponentContext.hpp"
25 #include "com/sun/star/uno/XInterface.hpp"
26 #include "cppuhelper/implbase3.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 >,
47 private boost::noncopyable
49 public:
50 explicit Service(
51 css::uno::Reference< css::uno::XComponentContext > const & context):
52 context_(context) {}
54 private:
55 virtual ~Service() {}
57 virtual OUString SAL_CALL getImplementationName()
58 throw (css::uno::RuntimeException)
59 { return read_only_access::getImplementationName(); }
61 virtual sal_Bool SAL_CALL supportsService(OUString const &)
62 throw (css::uno::RuntimeException)
63 { return false; }
65 virtual css::uno::Sequence< OUString > SAL_CALL
66 getSupportedServiceNames() throw (css::uno::RuntimeException)
67 { return read_only_access::getSupportedServiceNames(); }
69 virtual void SAL_CALL initialize(
70 css::uno::Sequence< css::uno::Any > const & aArguments)
71 throw (css::uno::Exception, css::uno::RuntimeException);
73 virtual css::uno::Any SAL_CALL getByHierarchicalName(
74 OUString const & aName)
75 throw (
76 css::container::NoSuchElementException, css::uno::RuntimeException)
77 { return getRoot()->getByHierarchicalName(aName); }
79 virtual sal_Bool SAL_CALL hasByHierarchicalName(OUString const & aName)
80 throw (css::uno::RuntimeException)
81 { return getRoot()->hasByHierarchicalName(aName); }
83 rtl::Reference< RootAccess > getRoot();
85 css::uno::Reference< css::uno::XComponentContext > context_;
87 osl::Mutex mutex_;
88 rtl::Reference< RootAccess > root_;
91 void Service::initialize(css::uno::Sequence< css::uno::Any > const & aArguments)
92 throw (css::uno::Exception, css::uno::RuntimeException)
94 OUString locale;
95 if (aArguments.getLength() != 1 || !(aArguments[0] >>= locale)) {
96 throw css::lang::IllegalArgumentException(
97 "not exactly one string argument",
98 static_cast< cppu::OWeakObject * >(this), -1);
100 osl::MutexGuard g1(mutex_);
101 if (root_.is()) {
102 throw css::uno::RuntimeException(
103 "already initialized", static_cast< cppu::OWeakObject * >(this));
105 osl::MutexGuard g2(*lock());
106 Components & components = Components::getSingleton(context_);
107 root_ = new RootAccess(components, "/", locale, false);
108 components.addRootAccess(root_);
111 rtl::Reference< RootAccess > Service::getRoot() {
112 osl::MutexGuard g(mutex_);
113 if (!root_.is()) {
114 throw css::lang::NotInitializedException(
115 "not initialized", static_cast< cppu::OWeakObject * >(this));
117 return root_;
122 css::uno::Reference< css::uno::XInterface > create(
123 css::uno::Reference< css::uno::XComponentContext > const & context)
125 return static_cast< cppu::OWeakObject * >(new Service(context));
128 OUString getImplementationName() {
129 return OUString("com.sun.star.comp.configuration.ReadOnlyAccess");
132 css::uno::Sequence< OUString > getSupportedServiceNames() {
133 return css::uno::Sequence< OUString >();
138 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */