bump product version to 5.0.4.1
[LibreOffice.git] / configmgr / source / readwriteaccess.cxx
blob19f0eb4a09b92fd8b2b0a575eb806eaca7ede9bf
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/configuration/XReadWriteAccess.hpp>
13 #include <com/sun/star/container/NoSuchElementException.hpp>
14 #include <com/sun/star/lang/IllegalArgumentException.hpp>
15 #include <com/sun/star/lang/NotInitializedException.hpp>
16 #include <com/sun/star/lang/WrappedTargetException.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 <com/sun/star/util/ChangesSet.hpp>
27 #include <cppuhelper/implbase3.hxx>
28 #include <cppuhelper/supportsservice.hxx>
29 #include <cppuhelper/weak.hxx>
30 #include <osl/mutex.hxx>
31 #include <rtl/ref.hxx>
32 #include <rtl/ustring.h>
33 #include <rtl/ustring.hxx>
34 #include <sal/types.h>
36 #include "components.hxx"
37 #include "lock.hxx"
38 #include "readwriteaccess.hxx"
39 #include "rootaccess.hxx"
41 namespace configmgr { namespace read_write_access {
43 namespace {
45 class Service:
46 public cppu::WeakImplHelper3<
47 css::lang::XServiceInfo, css::lang::XInitialization,
48 css::configuration::XReadWriteAccess >
50 public:
51 explicit Service(
52 css::uno::Reference< css::uno::XComponentContext > const & context):
53 context_(context) {}
55 private:
56 Service(const Service&) SAL_DELETED_FUNCTION;
57 Service& operator=(const Service&) SAL_DELETED_FUNCTION;
59 virtual ~Service() {}
61 virtual OUString SAL_CALL getImplementationName()
62 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
63 { return read_write_access::getImplementationName(); }
65 virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName)
66 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
67 { return cppu::supportsService(this, ServiceName); }
69 virtual css::uno::Sequence< OUString > SAL_CALL
70 getSupportedServiceNames() throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
71 { return read_write_access::getSupportedServiceNames(); }
73 virtual void SAL_CALL initialize(
74 css::uno::Sequence< css::uno::Any > const & aArguments)
75 throw (css::uno::Exception, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
77 virtual css::uno::Any SAL_CALL getByHierarchicalName(
78 OUString const & aName)
79 throw (
80 css::container::NoSuchElementException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE
81 { return getRoot()->getByHierarchicalName(aName); }
83 virtual sal_Bool SAL_CALL hasByHierarchicalName(OUString const & aName)
84 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
85 { return getRoot()->hasByHierarchicalName(aName); }
87 virtual void SAL_CALL replaceByHierarchicalName(
88 OUString const & aName, css::uno::Any const & aElement)
89 throw (
90 css::lang::IllegalArgumentException,
91 css::container::NoSuchElementException,
92 css::lang::WrappedTargetException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE
93 { getRoot()->replaceByHierarchicalName(aName, aElement); }
95 virtual void SAL_CALL commitChanges()
96 throw (css::lang::WrappedTargetException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE
97 { getRoot()->commitChanges(); }
99 virtual sal_Bool SAL_CALL hasPendingChanges()
100 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
101 { return getRoot()->hasPendingChanges(); }
103 virtual css::util::ChangesSet SAL_CALL getPendingChanges()
104 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
105 { return getRoot()->getPendingChanges(); }
107 css::beans::Property SAL_CALL getPropertyByHierarchicalName(
108 OUString const & aHierarchicalName)
109 throw (
110 css::beans::UnknownPropertyException, css::uno::RuntimeException,
111 std::exception)
112 SAL_OVERRIDE
113 { return getRoot()->getPropertyByHierarchicalName(aHierarchicalName); }
115 sal_Bool SAL_CALL hasPropertyByHierarchicalName(
116 OUString const & aHierarchicalName)
117 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
118 { return getRoot()->hasPropertyByHierarchicalName(aHierarchicalName); }
120 rtl::Reference< RootAccess > getRoot();
122 css::uno::Reference< css::uno::XComponentContext > context_;
124 osl::Mutex mutex_;
125 rtl::Reference< RootAccess > root_;
128 void Service::initialize(css::uno::Sequence< css::uno::Any > const & aArguments)
129 throw (css::uno::Exception, css::uno::RuntimeException, std::exception)
131 OUString locale;
132 if (aArguments.getLength() != 1 || !(aArguments[0] >>= locale)) {
133 throw css::lang::IllegalArgumentException(
134 "not exactly one string argument",
135 static_cast< cppu::OWeakObject * >(this), -1);
137 osl::MutexGuard g1(mutex_);
138 if (root_.is()) {
139 throw css::uno::RuntimeException(
140 "already initialized", static_cast< cppu::OWeakObject * >(this));
142 osl::MutexGuard g2(*lock());
143 Components & components = Components::getSingleton(context_);
144 root_ = new RootAccess(components, "/", locale, true);
145 components.addRootAccess(root_);
148 rtl::Reference< RootAccess > Service::getRoot() {
149 osl::MutexGuard g(mutex_);
150 if (!root_.is()) {
151 throw css::lang::NotInitializedException(
152 "not initialized", static_cast< cppu::OWeakObject * >(this));
154 return root_;
159 css::uno::Reference< css::uno::XInterface > create(
160 css::uno::Reference< css::uno::XComponentContext > const & context)
162 return static_cast< cppu::OWeakObject * >(new Service(context));
165 OUString getImplementationName() {
166 return OUString("com.sun.star.comp.configuration.ReadWriteAccess");
169 css::uno::Sequence< OUString > getSupportedServiceNames() {
170 OUString name("com.sun.star.configuration.ReadWriteAccess");
171 return css::uno::Sequence< OUString >(&name, 1);
176 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */