update credits
[LibreOffice.git] / cppuhelper / source / defaultbootstrap.cxx
blobff83389641327dff23aee5e76b504c0e4a3ca6cd
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
10 #include "sal/config.h"
12 #include <cassert>
13 #include <vector>
15 #include "com/sun/star/uno/DeploymentException.hpp"
16 #include "com/sun/star/uno/Any.hxx"
17 #include "com/sun/star/uno/Reference.hxx"
18 #include "com/sun/star/uno/XComponentContext.hpp"
19 #include "cppuhelper/bootstrap.hxx"
20 #include "cppuhelper/component_context.hxx"
21 #include "rtl/bootstrap.hxx"
22 #include "rtl/ref.hxx"
23 #include "rtl/ustring.hxx"
25 using rtl::OUString;
27 #include "macro_expander.hxx"
28 #include "paths.hxx"
29 #include "servicemanager.hxx"
30 #include "typemanager.hxx"
32 namespace {
34 rtl::OUString getBootstrapVariable(
35 rtl::Bootstrap const & bootstrap, rtl::OUString const & name)
37 rtl::OUString v;
38 if (!bootstrap.getFrom(name, v)) {
39 throw css::uno::DeploymentException(
40 "Cannot obtain " + name + " from uno ini",
41 css::uno::Reference< css::uno::XInterface >());
43 return v;
48 css::uno::Reference< css::uno::XComponentContext >
49 cppu::defaultBootstrap_InitialComponentContext(rtl::OUString const & iniUri)
50 SAL_THROW((css::uno::Exception))
52 rtl::Bootstrap bs(iniUri);
53 if (bs.getHandle() == 0) {
54 throw css::uno::DeploymentException(
55 "Cannot open uno ini " + iniUri,
56 css::uno::Reference< css::uno::XInterface >());
58 rtl::Reference< cppuhelper::ServiceManager > smgr(
59 new cppuhelper::ServiceManager);
60 smgr->init(getBootstrapVariable(bs, "UNO_SERVICES"));
61 rtl::Reference< cppuhelper::TypeManager > tmgr(new cppuhelper::TypeManager);
62 tmgr->init(getBootstrapVariable(bs, "UNO_TYPES"));
63 cppu::ContextEntry_Init entry;
64 std::vector< cppu::ContextEntry_Init > context_values;
65 context_values.push_back(
66 cppu::ContextEntry_Init(
67 "/singletons/com.sun.star.lang.theServiceManager",
68 css::uno::makeAny(
69 css::uno::Reference< css::uno::XInterface >(
70 static_cast< cppu::OWeakObject * >(smgr.get()))),
71 false));
72 context_values.push_back(
73 cppu::ContextEntry_Init(
74 "/singletons/com.sun.star.reflection.theTypeDescriptionManager",
75 css::uno::makeAny(
76 css::uno::Reference< css::uno::XInterface >(
77 static_cast< cppu::OWeakObject * >(tmgr.get()))),
78 false));
79 context_values.push_back( //TODO: from services.rdb?
80 cppu::ContextEntry_Init(
81 "/singletons/com.sun.star.util.theMacroExpander",
82 css::uno::makeAny(
83 cppuhelper::detail::create_bootstrap_macro_expander_factory()),
84 true));
85 smgr->addSingletonContextEntries(&context_values);
86 context_values.push_back(
87 cppu::ContextEntry_Init(
88 "/services/com.sun.star.security.AccessController/mode",
89 css::uno::makeAny(rtl::OUString("off")), false));
90 context_values.push_back(
91 cppu::ContextEntry_Init(
92 "/singletons/com.sun.star.security.theAccessController",
93 css::uno::makeAny(
94 rtl::OUString("com.sun.star.security.AccessController")),
95 true));
96 assert(!context_values.empty());
97 css::uno::Reference< css::uno::XComponentContext > context(
98 createComponentContext(
99 &context_values[0], context_values.size(),
100 css::uno::Reference< css::uno::XComponentContext >()));
101 smgr->setContext(context);
102 cppu::installTypeDescriptionManager(tmgr.get());
103 return context;
106 css::uno::Reference< css::uno::XComponentContext >
107 cppu::defaultBootstrap_InitialComponentContext()
108 SAL_THROW((css::uno::Exception))
110 return defaultBootstrap_InitialComponentContext(getUnoIniUri());
113 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */