Impress Remote 1.0.5, tag sdremote-1.0.5
[LibreOffice.git] / configmgr / source / readonlyaccess.cxx
blobaee12125942f5642df00076a71ef47d1cd844695
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * Version: MPL 1.1 / GPLv3+ / LGPLv3+
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License or as specified alternatively below. You may obtain a copy of
8 * the License at http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * Major Contributor(s):
16 * Copyright (C) 2011 Red Hat, Inc., Stephan Bergmann <sbergman@redhat.com>
17 * (initial developer)
19 * All Rights Reserved.
21 * For minor contributions see the git repository.
23 * Alternatively, the contents of this file may be used under the terms of
24 * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
25 * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
26 * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
27 * instead of those above.
30 #include "sal/config.h"
32 #include "boost/noncopyable.hpp"
33 #include "com/sun/star/container/NoSuchElementException.hpp"
34 #include "com/sun/star/container/XHierarchicalNameAccess.hpp"
35 #include "com/sun/star/lang/IllegalArgumentException.hpp"
36 #include "com/sun/star/lang/NotInitializedException.hpp"
37 #include "com/sun/star/lang/XInitialization.hpp"
38 #include "com/sun/star/lang/XServiceInfo.hpp"
39 #include "com/sun/star/uno/Any.hxx"
40 #include "com/sun/star/uno/Exception.hpp"
41 #include "com/sun/star/uno/Reference.hxx"
42 #include "com/sun/star/uno/RuntimeException.hpp"
43 #include "com/sun/star/uno/Sequence.hxx"
44 #include "com/sun/star/uno/XComponentContext.hpp"
45 #include "com/sun/star/uno/XInterface.hpp"
46 #include "cppuhelper/implbase3.hxx"
47 #include "cppuhelper/weak.hxx"
48 #include "osl/mutex.hxx"
49 #include "rtl/ref.hxx"
50 #include "rtl/ustring.h"
51 #include "rtl/ustring.hxx"
52 #include "sal/types.h"
54 #include "components.hxx"
55 #include "lock.hxx"
56 #include "readonlyaccess.hxx"
57 #include "rootaccess.hxx"
59 namespace configmgr { namespace read_only_access {
61 namespace {
63 class Service:
64 public cppu::WeakImplHelper3<
65 css::lang::XServiceInfo, css::lang::XInitialization,
66 css::container::XHierarchicalNameAccess >,
67 private boost::noncopyable
69 public:
70 explicit Service(
71 css::uno::Reference< css::uno::XComponentContext > const & context):
72 context_(context) {}
74 private:
75 virtual ~Service() {}
77 virtual rtl::OUString SAL_CALL getImplementationName()
78 throw (css::uno::RuntimeException)
79 { return read_only_access::getImplementationName(); }
81 virtual sal_Bool SAL_CALL supportsService(rtl::OUString const &)
82 throw (css::uno::RuntimeException)
83 { return false; }
85 virtual css::uno::Sequence< rtl::OUString > SAL_CALL
86 getSupportedServiceNames() throw (css::uno::RuntimeException)
87 { return read_only_access::getSupportedServiceNames(); }
89 virtual void SAL_CALL initialize(
90 css::uno::Sequence< css::uno::Any > const & aArguments)
91 throw (css::uno::Exception, css::uno::RuntimeException);
93 virtual css::uno::Any SAL_CALL getByHierarchicalName(
94 rtl::OUString const & aName)
95 throw (
96 css::container::NoSuchElementException, css::uno::RuntimeException)
97 { return getRoot()->getByHierarchicalName(aName); }
99 virtual sal_Bool SAL_CALL hasByHierarchicalName(rtl::OUString const & aName)
100 throw (css::uno::RuntimeException)
101 { return getRoot()->hasByHierarchicalName(aName); }
103 rtl::Reference< RootAccess > getRoot();
105 css::uno::Reference< css::uno::XComponentContext > context_;
107 osl::Mutex mutex_;
108 rtl::Reference< RootAccess > root_;
111 void Service::initialize(css::uno::Sequence< css::uno::Any > const & aArguments)
112 throw (css::uno::Exception, css::uno::RuntimeException)
114 OUString locale;
115 if (aArguments.getLength() != 1 || !(aArguments[0] >>= locale)) {
116 throw css::lang::IllegalArgumentException(
117 "not exactly one string argument",
118 static_cast< cppu::OWeakObject * >(this), -1);
120 osl::MutexGuard g1(mutex_);
121 if (root_.is()) {
122 throw css::uno::RuntimeException(
123 "already initialized", static_cast< cppu::OWeakObject * >(this));
125 osl::MutexGuard g2(*lock());
126 Components & components = Components::getSingleton(context_);
127 root_ = new RootAccess(components, "/", locale, false);
128 components.addRootAccess(root_);
131 rtl::Reference< RootAccess > Service::getRoot() {
132 osl::MutexGuard g(mutex_);
133 if (!root_.is()) {
134 throw css::lang::NotInitializedException(
135 "not initialized", static_cast< cppu::OWeakObject * >(this));
137 return root_;
142 css::uno::Reference< css::uno::XInterface > create(
143 css::uno::Reference< css::uno::XComponentContext > const & context)
145 return static_cast< cppu::OWeakObject * >(new Service(context));
148 rtl::OUString getImplementationName() {
149 return rtl::OUString(
150 RTL_CONSTASCII_USTRINGPARAM(
151 "com.sun.star.comp.configuration.ReadOnlyAccess"));
154 css::uno::Sequence< rtl::OUString > getSupportedServiceNames() {
155 return css::uno::Sequence< rtl::OUString >();
160 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */