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 "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"
33 :
34 : #include "components.hxx"
35 : #include "lock.hxx"
36 : #include "readonlyaccess.hxx"
37 : #include "rootaccess.hxx"
38 :
39 : namespace configmgr { namespace read_only_access {
40 :
41 : namespace {
42 :
43 : class Service:
44 : public cppu::WeakImplHelper3<
45 : css::lang::XServiceInfo, css::lang::XInitialization,
46 : css::container::XHierarchicalNameAccess >,
47 : private boost::noncopyable
48 : {
49 : public:
50 1699 : explicit Service(
51 : css::uno::Reference< css::uno::XComponentContext > const & context):
52 1699 : context_(context) {}
53 :
54 : private:
55 3398 : virtual ~Service() {}
56 :
57 0 : virtual OUString SAL_CALL getImplementationName()
58 : throw (css::uno::RuntimeException)
59 0 : { return read_only_access::getImplementationName(); }
60 :
61 0 : virtual sal_Bool SAL_CALL supportsService(OUString const &)
62 : throw (css::uno::RuntimeException)
63 0 : { return false; }
64 :
65 : virtual css::uno::Sequence< OUString > SAL_CALL
66 0 : getSupportedServiceNames() throw (css::uno::RuntimeException)
67 0 : { return read_only_access::getSupportedServiceNames(); }
68 :
69 : virtual void SAL_CALL initialize(
70 : css::uno::Sequence< css::uno::Any > const & aArguments)
71 : throw (css::uno::Exception, css::uno::RuntimeException);
72 :
73 230848 : virtual css::uno::Any SAL_CALL getByHierarchicalName(
74 : OUString const & aName)
75 : throw (
76 : css::container::NoSuchElementException, css::uno::RuntimeException)
77 230848 : { return getRoot()->getByHierarchicalName(aName); }
78 :
79 0 : virtual sal_Bool SAL_CALL hasByHierarchicalName(OUString const & aName)
80 : throw (css::uno::RuntimeException)
81 0 : { return getRoot()->hasByHierarchicalName(aName); }
82 :
83 : rtl::Reference< RootAccess > getRoot();
84 :
85 : css::uno::Reference< css::uno::XComponentContext > context_;
86 :
87 : osl::Mutex mutex_;
88 : rtl::Reference< RootAccess > root_;
89 : };
90 :
91 1699 : void Service::initialize(css::uno::Sequence< css::uno::Any > const & aArguments)
92 : throw (css::uno::Exception, css::uno::RuntimeException)
93 : {
94 1699 : OUString locale;
95 1699 : if (aArguments.getLength() != 1 || !(aArguments[0] >>= locale)) {
96 : throw css::lang::IllegalArgumentException(
97 : "not exactly one string argument",
98 0 : static_cast< cppu::OWeakObject * >(this), -1);
99 : }
100 3398 : osl::MutexGuard g1(mutex_);
101 1699 : if (root_.is()) {
102 : throw css::uno::RuntimeException(
103 0 : "already initialized", static_cast< cppu::OWeakObject * >(this));
104 : }
105 3398 : osl::MutexGuard g2(*lock());
106 1699 : Components & components = Components::getSingleton(context_);
107 1699 : root_ = new RootAccess(components, "/", locale, false);
108 3398 : components.addRootAccess(root_);
109 1699 : }
110 :
111 230848 : rtl::Reference< RootAccess > Service::getRoot() {
112 230848 : osl::MutexGuard g(mutex_);
113 230848 : if (!root_.is()) {
114 : throw css::lang::NotInitializedException(
115 0 : "not initialized", static_cast< cppu::OWeakObject * >(this));
116 : }
117 230848 : return root_;
118 : }
119 :
120 : }
121 :
122 1699 : css::uno::Reference< css::uno::XInterface > create(
123 : css::uno::Reference< css::uno::XComponentContext > const & context)
124 : {
125 1699 : return static_cast< cppu::OWeakObject * >(new Service(context));
126 : }
127 :
128 436 : OUString getImplementationName() {
129 436 : return OUString("com.sun.star.comp.configuration.ReadOnlyAccess");
130 : }
131 :
132 135 : css::uno::Sequence< OUString > getSupportedServiceNames() {
133 135 : return css::uno::Sequence< OUString >();
134 : }
135 :
136 : } }
137 :
138 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|