Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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 : */
9 :
10 : #include <sal/config.h>
11 :
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>
35 :
36 : #include "components.hxx"
37 : #include "lock.hxx"
38 : #include "readwriteaccess.hxx"
39 : #include "rootaccess.hxx"
40 :
41 : namespace configmgr { namespace read_write_access {
42 :
43 : namespace {
44 :
45 : class Service:
46 : public cppu::WeakImplHelper3<
47 : css::lang::XServiceInfo, css::lang::XInitialization,
48 : css::configuration::XReadWriteAccess >
49 : {
50 : public:
51 4624 : explicit Service(
52 : css::uno::Reference< css::uno::XComponentContext > const & context):
53 4624 : context_(context) {}
54 :
55 : private:
56 : Service(const Service&) SAL_DELETED_FUNCTION;
57 : Service& operator=(const Service&) SAL_DELETED_FUNCTION;
58 :
59 9248 : virtual ~Service() {}
60 :
61 0 : virtual OUString SAL_CALL getImplementationName()
62 : throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
63 0 : { return read_write_access::getImplementationName(); }
64 :
65 0 : virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName)
66 : throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
67 0 : { return cppu::supportsService(this, ServiceName); }
68 :
69 : virtual css::uno::Sequence< OUString > SAL_CALL
70 0 : getSupportedServiceNames() throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
71 0 : { return read_write_access::getSupportedServiceNames(); }
72 :
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;
76 :
77 193736 : 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 193736 : { return getRoot()->getByHierarchicalName(aName); }
82 :
83 0 : virtual sal_Bool SAL_CALL hasByHierarchicalName(OUString const & aName)
84 : throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
85 0 : { return getRoot()->hasByHierarchicalName(aName); }
86 :
87 517 : 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 517 : { getRoot()->replaceByHierarchicalName(aName, aElement); }
94 :
95 511 : virtual void SAL_CALL commitChanges()
96 : throw (css::lang::WrappedTargetException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE
97 511 : { getRoot()->commitChanges(); }
98 :
99 0 : virtual sal_Bool SAL_CALL hasPendingChanges()
100 : throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
101 0 : { return getRoot()->hasPendingChanges(); }
102 :
103 0 : virtual css::util::ChangesSet SAL_CALL getPendingChanges()
104 : throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
105 0 : { return getRoot()->getPendingChanges(); }
106 :
107 0 : 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 0 : { return getRoot()->getPropertyByHierarchicalName(aHierarchicalName); }
114 :
115 0 : sal_Bool SAL_CALL hasPropertyByHierarchicalName(
116 : OUString const & aHierarchicalName)
117 : throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
118 0 : { return getRoot()->hasPropertyByHierarchicalName(aHierarchicalName); }
119 :
120 : rtl::Reference< RootAccess > getRoot();
121 :
122 : css::uno::Reference< css::uno::XComponentContext > context_;
123 :
124 : osl::Mutex mutex_;
125 : rtl::Reference< RootAccess > root_;
126 : };
127 :
128 4624 : void Service::initialize(css::uno::Sequence< css::uno::Any > const & aArguments)
129 : throw (css::uno::Exception, css::uno::RuntimeException, std::exception)
130 : {
131 4624 : OUString locale;
132 4624 : if (aArguments.getLength() != 1 || !(aArguments[0] >>= locale)) {
133 : throw css::lang::IllegalArgumentException(
134 : "not exactly one string argument",
135 0 : static_cast< cppu::OWeakObject * >(this), -1);
136 : }
137 9248 : osl::MutexGuard g1(mutex_);
138 4624 : if (root_.is()) {
139 : throw css::uno::RuntimeException(
140 0 : "already initialized", static_cast< cppu::OWeakObject * >(this));
141 : }
142 9248 : osl::MutexGuard g2(*lock());
143 4624 : Components & components = Components::getSingleton(context_);
144 4624 : root_ = new RootAccess(components, "/", locale, true);
145 9248 : components.addRootAccess(root_);
146 4624 : }
147 :
148 194764 : rtl::Reference< RootAccess > Service::getRoot() {
149 194764 : osl::MutexGuard g(mutex_);
150 194764 : if (!root_.is()) {
151 : throw css::lang::NotInitializedException(
152 0 : "not initialized", static_cast< cppu::OWeakObject * >(this));
153 : }
154 194764 : return root_;
155 : }
156 :
157 : }
158 :
159 4624 : css::uno::Reference< css::uno::XInterface > create(
160 : css::uno::Reference< css::uno::XComponentContext > const & context)
161 : {
162 4624 : return static_cast< cppu::OWeakObject * >(new Service(context));
163 : }
164 :
165 686 : OUString getImplementationName() {
166 686 : return OUString("com.sun.star.comp.configuration.ReadWriteAccess");
167 : }
168 :
169 213 : css::uno::Sequence< OUString > getSupportedServiceNames() {
170 213 : OUString name("com.sun.star.configuration.ReadWriteAccess");
171 213 : return css::uno::Sequence< OUString >(&name, 1);
172 : }
173 :
174 : } }
175 :
176 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|