1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
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/implbase.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"
38 #include "readwriteaccess.hxx"
39 #include "rootaccess.hxx"
41 namespace configmgr
{ namespace read_write_access
{
46 public cppu::WeakImplHelper
<
47 css::lang::XServiceInfo
, css::lang::XInitialization
,
48 css::configuration::XReadWriteAccess
>
52 css::uno::Reference
< css::uno::XComponentContext
> const & context
):
56 Service(const Service
&) = delete;
57 Service
& operator=(const Service
&) = delete;
59 virtual ~Service() override
{}
61 virtual OUString SAL_CALL
getImplementationName() override
62 { return read_write_access::getImplementationName(); }
64 virtual sal_Bool SAL_CALL
supportsService(OUString
const & ServiceName
) override
65 { return cppu::supportsService(this, ServiceName
); }
67 virtual css::uno::Sequence
< OUString
> SAL_CALL
68 getSupportedServiceNames() override
69 { return read_write_access::getSupportedServiceNames(); }
71 virtual void SAL_CALL
initialize(
72 css::uno::Sequence
< css::uno::Any
> const & aArguments
) override
;
74 virtual css::uno::Any SAL_CALL
getByHierarchicalName(
75 OUString
const & aName
) override
76 { return getRoot()->getByHierarchicalName(aName
); }
78 virtual sal_Bool SAL_CALL
hasByHierarchicalName(OUString
const & aName
) override
79 { return getRoot()->hasByHierarchicalName(aName
); }
81 virtual void SAL_CALL
replaceByHierarchicalName(
82 OUString
const & aName
, css::uno::Any
const & aElement
) override
83 { getRoot()->replaceByHierarchicalName(aName
, aElement
); }
85 virtual void SAL_CALL
commitChanges() override
86 { getRoot()->commitChanges(); }
88 virtual sal_Bool SAL_CALL
hasPendingChanges() override
89 { return getRoot()->hasPendingChanges(); }
91 virtual css::uno::Sequence
< ::css::util::ElementChange
> SAL_CALL
getPendingChanges() override
92 { return getRoot()->getPendingChanges(); }
94 css::beans::Property SAL_CALL
getPropertyByHierarchicalName(
95 OUString
const & aHierarchicalName
)
97 { return getRoot()->getPropertyByHierarchicalName(aHierarchicalName
); }
99 sal_Bool SAL_CALL
hasPropertyByHierarchicalName(
100 OUString
const & aHierarchicalName
) override
101 { return getRoot()->hasPropertyByHierarchicalName(aHierarchicalName
); }
103 rtl::Reference
< RootAccess
> getRoot();
105 css::uno::Reference
< css::uno::XComponentContext
> context_
;
108 rtl::Reference
< RootAccess
> root_
;
111 void Service::initialize(css::uno::Sequence
< css::uno::Any
> const & aArguments
)
114 if (aArguments
.getLength() != 1 || !(aArguments
[0] >>= locale
)) {
115 throw css::lang::IllegalArgumentException(
116 "not exactly one string argument",
117 static_cast< cppu::OWeakObject
* >(this), -1);
119 osl::MutexGuard
g1(mutex_
);
121 throw css::uno::RuntimeException(
122 "already initialized", static_cast< cppu::OWeakObject
* >(this));
124 osl::MutexGuard
g2(*lock());
125 Components
& components
= Components::getSingleton(context_
);
126 root_
= new RootAccess(components
, "/", locale
, true);
127 components
.addRootAccess(root_
);
130 rtl::Reference
< RootAccess
> Service::getRoot() {
131 osl::MutexGuard
g(mutex_
);
133 throw css::lang::NotInitializedException(
134 "not initialized", static_cast< cppu::OWeakObject
* >(this));
141 css::uno::Reference
< css::uno::XInterface
> create(
142 css::uno::Reference
< css::uno::XComponentContext
> const & context
)
144 return static_cast< cppu::OWeakObject
* >(new Service(context
));
147 OUString
getImplementationName() {
148 return OUString("com.sun.star.comp.configuration.ReadWriteAccess");
151 css::uno::Sequence
< OUString
> getSupportedServiceNames() {
152 return css::uno::Sequence
< OUString
> { "com.sun.star.configuration.ReadWriteAccess" };
157 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */