1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #ifndef _CPPUHELPER_BOOTSTRAP_HXX_
28 #define _CPPUHELPER_BOOTSTRAP_HXX_
29 
30 #include "sal/config.h"
31 #include "com/sun/star/uno/Exception.hpp"
32 #include "com/sun/star/uno/Reference.hxx"
33 #include "rtl/ustring.hxx"
34 #include "sal/types.h"
35 
36 namespace com { namespace sun { namespace star {
37     namespace container { class XHierarchicalNameAccess; }
38     namespace registry { class XSimpleRegistry; }
39     namespace uno { class XComponentContext; }
40 } } }
41 
42 namespace cppu
43 {
44 
45 /** Creates a simple registry service instance.
46 
47     @rBootstrapPath optional bootstrap path for initial components
48     @return simple registry service instance
49 */
50 ::com::sun::star::uno::Reference< ::com::sun::star::registry::XSimpleRegistry >
51 SAL_CALL createSimpleRegistry(
52 	const ::rtl::OUString & rBootstrapPath = ::rtl::OUString() )
53     SAL_THROW( () );
54 
55 /** Creates a nested registry service instance.
56 
57     @rBootstrapPath optional bootstrap path for initial components
58     @return nested registry service instance
59 */
60 ::com::sun::star::uno::Reference< ::com::sun::star::registry::XSimpleRegistry >
61 SAL_CALL createNestedRegistry(
62 	const ::rtl::OUString & rBootstrapPath = ::rtl::OUString() )
63     SAL_THROW( () );
64 
65 /** Installs type description manager instance, i.e. registers a callback at cppu core.
66 
67     @param xTDMgr manager instance
68     @return true, if successfully registered
69 */
70 sal_Bool SAL_CALL installTypeDescriptionManager(
71     ::com::sun::star::uno::Reference< ::com::sun::star::container::XHierarchicalNameAccess > const & xTDMgr )
72     SAL_THROW( () );
73 
74 /** Bootstraps an initial component context with service manager upon a given registry.
75     This includes insertion of initial services:
76       - (registry) service manager, shared lib loader,
77       - simple registry, nested registry,
78       - implementation registration
79       - registry typedescription provider, typedescription manager (also installs it into cppu core)
80 
81     @param xRegistry registry for service manager and singleton objects of context (may be null)
82     @param rBootstrapPath optional bootstrap path for initial components
83     @return component context
84 */
85 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > SAL_CALL
86 bootstrap_InitialComponentContext(
87     ::com::sun::star::uno::Reference< ::com::sun::star::registry::XSimpleRegistry > const & xRegistry,
88     ::rtl::OUString const & rBootstrapPath = ::rtl::OUString() )
89 	SAL_THROW( (::com::sun::star::uno::Exception) );
90 
91 
92 /** Bootstraps an initial component context with service manager upon default types and
93     services registry.
94     This includes insertion of initial services:
95       - (registry) service manager, shared lib loader,
96       - simple registry, nested registry,
97       - implementation registration
98       - registry typedescription provider, typedescription manager (also installs it into cppu core)
99 
100     This function tries to find its parameters via these bootstrap variables:
101 
102       - UNO_TYPES         -- a space separated list of file urls of type rdbs
103       - UNO_SERVICES      -- a space separated list of file urls of service rdbs
104       - UNO_WRITERDB      -- a file url of a write rdb (e.g. user.rdb)
105 
106     Please look at http://udk.openoffice.org/common/man/concept/uno_default_bootstrapping.html
107 	for further info.
108 
109     @return component context
110 */
111 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > SAL_CALL
112 defaultBootstrap_InitialComponentContext() SAL_THROW( (::com::sun::star::uno::Exception) );
113 
114 
115 /** Bootstraps an initial component context with service manager upon default types and
116     services registry.
117     This includes insertion of initial services:
118       - (registry) service manager, shared lib loader,
119       - simple registry, nested registry,
120       - implementation registration
121       - registry typedescription provider, typedescription manager (also installs it into cppu core)
122 
123     This function tries to find its parameters via these bootstrap variables:
124 
125       - UNO_TYPES         -- a space separated list of file urls of type rdbs
126       - UNO_SERVICES      -- a space separated list of file urls of service rdbs
127       - UNO_WRITERDB      -- a file url of a write rdb (e.g. user.rdb)
128 
129     Please look at http://udk.openoffice.org/common/man/concept/uno_default_bootstrapping.html
130 	for further info.
131 
132     @param iniFile ini filename to get bootstrap variables
133     @return component context
134 */
135 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > SAL_CALL
136 defaultBootstrap_InitialComponentContext(const ::rtl::OUString & iniFile) SAL_THROW( (::com::sun::star::uno::Exception) );
137 
138 /**
139  * An exception indicating a bootstrap error.
140  *
141  * @since UDK 3.2.0
142  */
143 class BootstrapException
144 {
145 public:
146     /**
147      * Constructs a BootstrapException.
148      */
149     BootstrapException();
150 
151     /**
152      * Constructs a BootstrapException with the specified detail message.
153      *
154      * @param rMessage
155      * A message containing any details about the exception.
156      */
157     BootstrapException( const ::rtl::OUString & rMessage );
158 
159     /**
160      * Copy constructs a BootstrapException.
161      */
162     BootstrapException( const BootstrapException & e );
163 
164     /**
165      * Destructs a BootstrapException.
166      */
167     virtual ~BootstrapException();
168 
169     /**
170      * Assigns a BootstrapException.
171      */
172     BootstrapException & operator=( const BootstrapException & e );
173 
174     /** Gets the message.
175 
176         @return
177         A reference to the message. The reference is valid for the lifetime of
178         this BootstrapException.
179      */
180     const ::rtl::OUString & getMessage() const;
181 
182 private:
183     ::rtl::OUString m_aMessage;
184 };
185 
186 /**
187  * Bootstraps the component context from a UNO installation.
188  *
189  * @return a bootstrapped component context
190  * @exception BootstrapException
191  * Thrown in case bootstrap() signals an exception due to a
192  * bootstrap error.
193  *
194  * @since UDK 3.2.0
195  */
196 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >
197 SAL_CALL bootstrap();
198 
199 /**
200  * Helper function to expand vnd.sun.star.expand URLs in contexts where no
201  * properly bootstrapped UNO is (yet) available.
202  *
203  * @internal
204  *
205  * @param uri
206  * Some URI (but not a URI reference).
207  *
208  * @return
209  * If uri is a vnd.sun.star.expand URL, then the expansion of that URL is
210  * returned; expansion may lead to a string that is not a legal URI. Otherwise,
211  * the uri is returned unchanged.
212  *
213  * @exception com::sun::star::lang::IllegalArgumentException
214  * If uri is a vnd.sun.star.expand URL that contains unknown macros.
215  *
216  * @since UDK 3.2.8
217  */
218 ::rtl::OUString
219 SAL_CALL bootstrap_expandUri(::rtl::OUString const & uri);
220 
221 } // end namespace cppu
222 
223 #endif
224