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 <cassert>
13 : #include <vector>
14 :
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"
24 :
25 : using rtl::OUString;
26 :
27 : #include "macro_expander.hxx"
28 : #include "paths.hxx"
29 : #include "servicemanager.hxx"
30 : #include "typemanager.hxx"
31 :
32 : namespace {
33 :
34 782 : rtl::OUString getBootstrapVariable(
35 : rtl::Bootstrap const & bootstrap, rtl::OUString const & name)
36 : {
37 782 : rtl::OUString v;
38 782 : if (!bootstrap.getFrom(name, v)) {
39 : throw css::uno::DeploymentException(
40 0 : "Cannot obtain " + name + " from uno ini",
41 0 : css::uno::Reference< css::uno::XInterface >());
42 : }
43 782 : return v;
44 : }
45 :
46 : }
47 :
48 : css::uno::Reference< css::uno::XComponentContext >
49 391 : cppu::defaultBootstrap_InitialComponentContext(rtl::OUString const & iniUri)
50 : SAL_THROW((css::uno::Exception))
51 : {
52 391 : rtl::Bootstrap bs(iniUri);
53 391 : if (bs.getHandle() == 0) {
54 : throw css::uno::DeploymentException(
55 0 : "Cannot open uno ini " + iniUri,
56 0 : css::uno::Reference< css::uno::XInterface >());
57 : }
58 : rtl::Reference< cppuhelper::ServiceManager > smgr(
59 782 : new cppuhelper::ServiceManager);
60 391 : smgr->init(getBootstrapVariable(bs, "UNO_SERVICES"));
61 782 : rtl::Reference< cppuhelper::TypeManager > tmgr(new cppuhelper::TypeManager);
62 391 : tmgr->init(getBootstrapVariable(bs, "UNO_TYPES"));
63 782 : cppu::ContextEntry_Init entry;
64 782 : 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 391 : static_cast< cppu::OWeakObject * >(smgr.get()))),
71 391 : 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 391 : static_cast< cppu::OWeakObject * >(tmgr.get()))),
78 391 : 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 391 : true));
85 391 : smgr->addSingletonContextEntries(&context_values);
86 : context_values.push_back(
87 : cppu::ContextEntry_Init(
88 : "/services/com.sun.star.security.AccessController/mode",
89 391 : 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 391 : true));
96 : assert(!context_values.empty());
97 : css::uno::Reference< css::uno::XComponentContext > context(
98 : createComponentContext(
99 782 : &context_values[0], context_values.size(),
100 1173 : css::uno::Reference< css::uno::XComponentContext >()));
101 391 : smgr->setContext(context);
102 391 : cppu::installTypeDescriptionManager(tmgr.get());
103 782 : return context;
104 : }
105 :
106 : css::uno::Reference< css::uno::XComponentContext >
107 391 : cppu::defaultBootstrap_InitialComponentContext()
108 : SAL_THROW((css::uno::Exception))
109 : {
110 391 : return defaultBootstrap_InitialComponentContext(getUnoIniUri());
111 : }
112 :
113 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|