Bump version to 5.0-43
[LibreOffice.git] / cppuhelper / source / defaultbootstrap.cxx
blob602fdfbcb081c44be1866009efb9c81188b7481b
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 <com/sun/star/lang/XSingleComponentFactory.hpp>
20 #include <cppuhelper/bootstrap.hxx>
21 #include <cppuhelper/component_context.hxx>
22 #include <rtl/bootstrap.hxx>
23 #include <rtl/ref.hxx>
24 #include <rtl/ustring.hxx>
26 using rtl::OUString;
28 #include "macro_expander.hxx"
29 #include "paths.hxx"
30 #include "servicemanager.hxx"
31 #include "typemanager.hxx"
33 namespace {
35 rtl::OUString getBootstrapVariable(
36 rtl::Bootstrap const & bootstrap, rtl::OUString const & name)
38 rtl::OUString v;
39 if (!bootstrap.getFrom(name, v)) {
40 throw css::uno::DeploymentException(
41 "Cannot obtain " + name + " from uno ini");
43 return v;
47 css::uno::Reference< css::uno::XComponentContext >
48 cppu::defaultBootstrap_InitialComponentContext(rtl::OUString const & iniUri)
50 rtl::Bootstrap bs(iniUri);
51 if (bs.getHandle() == 0) {
52 throw css::uno::DeploymentException(
53 "Cannot open uno ini " + iniUri);
55 rtl::Reference< cppuhelper::ServiceManager > smgr(
56 new cppuhelper::ServiceManager);
57 smgr->init(getBootstrapVariable(bs, "UNO_SERVICES"));
58 rtl::Reference< cppuhelper::TypeManager > tmgr(new cppuhelper::TypeManager);
59 tmgr->init(getBootstrapVariable(bs, "UNO_TYPES"));
60 cppu::ContextEntry_Init entry;
61 std::vector< cppu::ContextEntry_Init > context_values;
62 context_values.push_back(
63 cppu::ContextEntry_Init(
64 "/singletons/com.sun.star.lang.theServiceManager",
65 css::uno::makeAny(
66 css::uno::Reference< css::uno::XInterface >(
67 static_cast< cppu::OWeakObject * >(smgr.get()))),
68 false));
69 context_values.push_back(
70 cppu::ContextEntry_Init(
71 "/singletons/com.sun.star.reflection.theTypeDescriptionManager",
72 css::uno::makeAny(
73 css::uno::Reference< css::uno::XInterface >(
74 static_cast< cppu::OWeakObject * >(tmgr.get()))),
75 false));
76 context_values.push_back( //TODO: from services.rdb?
77 cppu::ContextEntry_Init(
78 "/singletons/com.sun.star.util.theMacroExpander",
79 css::uno::makeAny(
80 cppuhelper::detail::create_bootstrap_macro_expander_factory()),
81 true));
82 smgr->addSingletonContextEntries(&context_values);
83 context_values.push_back(
84 cppu::ContextEntry_Init(
85 "/services/com.sun.star.security.AccessController/mode",
86 css::uno::makeAny(rtl::OUString("off")), false));
87 context_values.push_back(
88 cppu::ContextEntry_Init(
89 "/singletons/com.sun.star.security.theAccessController",
90 css::uno::makeAny(
91 rtl::OUString("com.sun.star.security.AccessController")),
92 true));
93 assert(!context_values.empty());
94 css::uno::Reference< css::uno::XComponentContext > context(
95 createComponentContext(
96 &context_values[0], context_values.size(),
97 css::uno::Reference< css::uno::XComponentContext >()));
98 smgr->setContext(context);
99 cppu::installTypeDescriptionManager(tmgr.get());
100 return context;
103 css::uno::Reference< css::uno::XComponentContext >
104 cppu::defaultBootstrap_InitialComponentContext()
106 return defaultBootstrap_InitialComponentContext(getUnoIniUri());
109 void
110 cppu::preInitBootstrap(css::uno::Reference< css::uno::XComponentContext > const & xContext)
112 if (!xContext.is())
113 throw css::uno::DeploymentException("preInit: XComponentContext is not created");
115 css::uno::Reference< css::uno::XInterface > xService;
116 xContext->getValueByName("/singletons/com.sun.star.lang.theServiceManager") >>= xService;
117 if (!xService.is())
118 throw css::uno::DeploymentException("preInit: XMultiComponentFactory is not created");
120 rtl::Reference<cppuhelper::ServiceManager> aService(reinterpret_cast<cppuhelper::ServiceManager*>(xService.get()));
122 // pre-requisites:
123 // In order to load implementations and invoke
124 // component factory it is required:
125 // 1) defaultBootstrap_InitialComponentContext()
126 // 2) comphelper::setProcessServiceFactory(xSFactory);
127 // 3) InitVCL()
128 aService->loadImplementations();
130 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */