1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef _CPPUHELPER_BOOTSTRAP_HXX_
24 #define _CPPUHELPER_BOOTSTRAP_HXX_
25 
26 #include "sal/config.h"
27 #include "com/sun/star/uno/Exception.hpp"
28 #include "com/sun/star/uno/Reference.hxx"
29 #include "rtl/ustring.hxx"
30 #include "sal/types.h"
31 
32 #include "cppuhelper/cppuhelperdllapi.h"
33 
34 namespace com { namespace sun { namespace star {
35     namespace container { class XHierarchicalNameAccess; }
36     namespace registry { class XSimpleRegistry; }
37     namespace uno { class XComponentContext; }
38 } } }
39 
40 namespace cppu
41 {
42 
43 /** Creates a simple registry service instance.
44 
45     @rBootstrapPath optional bootstrap path for initial components
46     @return simple registry service instance
47 */
48 CPPUHELPER_DLLPUBLIC
49 ::com::sun::star::uno::Reference< ::com::sun::star::registry::XSimpleRegistry >
50 SAL_CALL createSimpleRegistry(
51 	const ::rtl::OUString & rBootstrapPath = ::rtl::OUString() )
52     SAL_THROW( () );
53 
54 /** Creates a nested registry service instance.
55 
56     @rBootstrapPath optional bootstrap path for initial components
57     @return nested registry service instance
58 */
59 CPPUHELPER_DLLPUBLIC
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 CPPUHELPER_DLLPUBLIC
71 sal_Bool SAL_CALL installTypeDescriptionManager(
72     ::com::sun::star::uno::Reference< ::com::sun::star::container::XHierarchicalNameAccess > const & xTDMgr )
73     SAL_THROW( () );
74 
75 /** Bootstraps an initial component context with service manager upon a given registry.
76     This includes insertion of initial services:
77       - (registry) service manager, shared lib loader,
78       - simple registry, nested registry,
79       - implementation registration
80       - registry typedescription provider, typedescription manager (also installs it into cppu core)
81 
82     @param xRegistry registry for service manager and singleton objects of context (may be null)
83     @param rBootstrapPath optional bootstrap path for initial components
84     @return component context
85 */
86 CPPUHELPER_DLLPUBLIC
87 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > SAL_CALL
88 bootstrap_InitialComponentContext(
89     ::com::sun::star::uno::Reference< ::com::sun::star::registry::XSimpleRegistry > const & xRegistry,
90     ::rtl::OUString const & rBootstrapPath = ::rtl::OUString() )
91 	SAL_THROW( (::com::sun::star::uno::Exception) );
92 
93 
94 /** Bootstraps an initial component context with service manager upon default types and
95     services registry.
96     This includes insertion of initial services:
97       - (registry) service manager, shared lib loader,
98       - simple registry, nested registry,
99       - implementation registration
100       - registry typedescription provider, typedescription manager (also installs it into cppu core)
101 
102     This function tries to find its parameters via these bootstrap variables:
103 
104       - UNO_TYPES         -- a space separated list of file urls of type rdbs
105       - UNO_SERVICES      -- a space separated list of file urls of service rdbs
106       - UNO_WRITERDB      -- a file url of a write rdb (e.g. user.rdb)
107 
108     Please look at http://udk.openoffice.org/common/man/concept/uno_default_bootstrapping.html
109 	for further info.
110 
111     @return component context
112 */
113 CPPUHELPER_DLLPUBLIC
114 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > SAL_CALL
115 defaultBootstrap_InitialComponentContext() SAL_THROW( (::com::sun::star::uno::Exception) );
116 
117 
118 /** Bootstraps an initial component context with service manager upon default types and
119     services registry.
120     This includes insertion of initial services:
121       - (registry) service manager, shared lib loader,
122       - simple registry, nested registry,
123       - implementation registration
124       - registry typedescription provider, typedescription manager (also installs it into cppu core)
125 
126     This function tries to find its parameters via these bootstrap variables:
127 
128       - UNO_TYPES         -- a space separated list of file urls of type rdbs
129       - UNO_SERVICES      -- a space separated list of file urls of service rdbs
130       - UNO_WRITERDB      -- a file url of a write rdb (e.g. user.rdb)
131 
132     Please look at http://udk.openoffice.org/common/man/concept/uno_default_bootstrapping.html
133 	for further info.
134 
135     @param iniFile ini filename to get bootstrap variables
136     @return component context
137 */
138 CPPUHELPER_DLLPUBLIC
139 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > SAL_CALL
140 defaultBootstrap_InitialComponentContext(const ::rtl::OUString & iniFile) SAL_THROW( (::com::sun::star::uno::Exception) );
141 
142 /**
143  * An exception indicating a bootstrap error.
144  *
145  * @since UDK 3.2.0
146  */
147 class CPPUHELPER_DLLPUBLIC BootstrapException
148 {
149 public:
150     /**
151      * Constructs a BootstrapException.
152      */
153     BootstrapException();
154 
155     /**
156      * Constructs a BootstrapException with the specified detail message.
157      *
158      * @param rMessage
159      * A message containing any details about the exception.
160      */
161     BootstrapException( const ::rtl::OUString & rMessage );
162 
163     /**
164      * Copy constructs a BootstrapException.
165      */
166     BootstrapException( const BootstrapException & e );
167 
168     /**
169      * Destructs a BootstrapException.
170      */
171     virtual ~BootstrapException();
172 
173     /**
174      * Assigns a BootstrapException.
175      */
176     BootstrapException & operator=( const BootstrapException & e );
177 
178     /** Gets the message.
179 
180         @return
181         A reference to the message. The reference is valid for the lifetime of
182         this BootstrapException.
183      */
184     const ::rtl::OUString & getMessage() const;
185 
186 private:
187     ::rtl::OUString m_aMessage;
188 };
189 
190 /**
191  * Bootstraps the component context from a UNO installation.
192  *
193  * @return a bootstrapped component context
194  * @exception BootstrapException
195  * Thrown in case bootstrap() signals an exception due to a
196  * bootstrap error.
197  *
198  * @since UDK 3.2.0
199  */
200 CPPUHELPER_DLLPUBLIC
201 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >
202 SAL_CALL bootstrap();
203 
204 /**
205  * Helper function to expand vnd.sun.star.expand URLs in contexts where no
206  * properly bootstrapped UNO is (yet) available.
207  *
208  * @internal
209  *
210  * @param uri
211  * Some URI (but not a URI reference).
212  *
213  * @return
214  * If uri is a vnd.sun.star.expand URL, then the expansion of that URL is
215  * returned; expansion may lead to a string that is not a legal URI. Otherwise,
216  * the uri is returned unchanged.
217  *
218  * @exception com::sun::star::lang::IllegalArgumentException
219  * If uri is a vnd.sun.star.expand URL that contains unknown macros.
220  *
221  * @since UDK 3.2.8
222  */
223 CPPUHELPER_DLLPUBLIC
224 ::rtl::OUString
225 SAL_CALL bootstrap_expandUri(::rtl::OUString const & uri);
226 
227 } // end namespace cppu
228 
229 #endif
230