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 "boost/noncopyable.hpp"
13 #include "com/sun/star/configuration/XReadWriteAccess.hpp"
14 #include "com/sun/star/container/NoSuchElementException.hpp"
15 #include "com/sun/star/lang/IllegalArgumentException.hpp"
16 #include "com/sun/star/lang/NotInitializedException.hpp"
17 #include "com/sun/star/lang/WrappedTargetException.hpp"
18 #include "com/sun/star/lang/XInitialization.hpp"
19 #include "com/sun/star/lang/XServiceInfo.hpp"
20 #include "com/sun/star/uno/Any.hxx"
21 #include "com/sun/star/uno/Exception.hpp"
22 #include "com/sun/star/uno/Reference.hxx"
23 #include "com/sun/star/uno/RuntimeException.hpp"
24 #include "com/sun/star/uno/Sequence.hxx"
25 #include "com/sun/star/uno/XComponentContext.hpp"
26 #include "com/sun/star/uno/XInterface.hpp"
27 #include "com/sun/star/util/ChangesSet.hpp"
28 #include "cppuhelper/implbase3.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::WeakImplHelper3
<
47 css::lang::XServiceInfo
, css::lang::XInitialization
,
48 css::configuration::XReadWriteAccess
>,
49 private boost::noncopyable
53 css::uno::Reference
< css::uno::XComponentContext
> const & context
):
59 virtual OUString SAL_CALL
getImplementationName()
60 throw (css::uno::RuntimeException
)
61 { return read_write_access::getImplementationName(); }
63 virtual sal_Bool SAL_CALL
supportsService(OUString
const &)
64 throw (css::uno::RuntimeException
)
67 virtual css::uno::Sequence
< OUString
> SAL_CALL
68 getSupportedServiceNames() throw (css::uno::RuntimeException
)
69 { return read_write_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
);
75 virtual css::uno::Any SAL_CALL
getByHierarchicalName(
76 OUString
const & aName
)
78 css::container::NoSuchElementException
, css::uno::RuntimeException
)
79 { return getRoot()->getByHierarchicalName(aName
); }
81 virtual sal_Bool SAL_CALL
hasByHierarchicalName(OUString
const & aName
)
82 throw (css::uno::RuntimeException
)
83 { return getRoot()->hasByHierarchicalName(aName
); }
85 virtual void SAL_CALL
replaceByHierarchicalName(
86 OUString
const & aName
, css::uno::Any
const & aElement
)
88 css::lang::IllegalArgumentException
,
89 css::container::NoSuchElementException
,
90 css::lang::WrappedTargetException
, css::uno::RuntimeException
)
91 { getRoot()->replaceByHierarchicalName(aName
, aElement
); }
93 virtual void SAL_CALL
commitChanges()
94 throw (css::lang::WrappedTargetException
, css::uno::RuntimeException
)
95 { getRoot()->commitChanges(); }
97 virtual sal_Bool SAL_CALL
hasPendingChanges()
98 throw (css::uno::RuntimeException
)
99 { return getRoot()->hasPendingChanges(); }
101 virtual css::util::ChangesSet SAL_CALL
getPendingChanges()
102 throw (css::uno::RuntimeException
)
103 { return getRoot()->getPendingChanges(); }
105 rtl::Reference
< RootAccess
> getRoot();
107 css::uno::Reference
< css::uno::XComponentContext
> context_
;
110 rtl::Reference
< RootAccess
> root_
;
113 void Service::initialize(css::uno::Sequence
< css::uno::Any
> const & aArguments
)
114 throw (css::uno::Exception
, css::uno::RuntimeException
)
117 if (aArguments
.getLength() != 1 || !(aArguments
[0] >>= locale
)) {
118 throw css::lang::IllegalArgumentException(
119 "not exactly one string argument",
120 static_cast< cppu::OWeakObject
* >(this), -1);
122 osl::MutexGuard
g1(mutex_
);
124 throw css::uno::RuntimeException(
125 "already initialized", static_cast< cppu::OWeakObject
* >(this));
127 osl::MutexGuard
g2(*lock());
128 Components
& components
= Components::getSingleton(context_
);
129 root_
= new RootAccess(components
, "/", locale
, true);
130 components
.addRootAccess(root_
);
133 rtl::Reference
< RootAccess
> Service::getRoot() {
134 osl::MutexGuard
g(mutex_
);
136 throw css::lang::NotInitializedException(
137 "not initialized", static_cast< cppu::OWeakObject
* >(this));
144 css::uno::Reference
< css::uno::XInterface
> create(
145 css::uno::Reference
< css::uno::XComponentContext
> const & context
)
147 return static_cast< cppu::OWeakObject
* >(new Service(context
));
150 OUString
getImplementationName() {
151 return OUString("com.sun.star.comp.configuration.ReadWriteAccess");
154 css::uno::Sequence
< OUString
> getSupportedServiceNames() {
155 OUString
name("com.sun.star.configuration.ReadWriteAccess");
156 return css::uno::Sequence
< OUString
>(&name
, 1);
161 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */