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 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #include <vector>
22 :
23 : #include "rtl/string.hxx"
24 : #include "rtl/bootstrap.hxx"
25 : #include "rtl/strbuf.hxx"
26 : #include "osl/diagnose.h"
27 : #include "osl/file.h"
28 : #include "osl/module.h"
29 : #include "osl/process.h"
30 : #include "cppuhelper/shlib.hxx"
31 : #include "cppuhelper/factory.hxx"
32 : #include "cppuhelper/component_context.hxx"
33 : #include "cppuhelper/servicefactory.hxx"
34 : #include "cppuhelper/bootstrap.hxx"
35 :
36 : #include "com/sun/star/uno/DeploymentException.hpp"
37 : #include "com/sun/star/uno/XComponentContext.hpp"
38 : #include "com/sun/star/lang/XInitialization.hpp"
39 : #include <com/sun/star/lang/XServiceInfo.hpp>
40 : #include "com/sun/star/lang/XSingleServiceFactory.hpp"
41 : #include "com/sun/star/lang/XSingleComponentFactory.hpp"
42 : #include "com/sun/star/beans/XPropertySet.hpp"
43 : #include "com/sun/star/container/XSet.hpp"
44 : #include "com/sun/star/container/XHierarchicalNameAccess.hpp"
45 : #include "com/sun/star/registry/XSimpleRegistry.hpp"
46 : #include "com/sun/star/registry/XImplementationRegistration.hpp"
47 : #include "com/sun/star/security/XAccessController.hpp"
48 : #if OSL_DEBUG_LEVEL > 1
49 : #include <stdio.h>
50 : #endif
51 :
52 : #include "macro_expander.hxx"
53 : #include "paths.hxx"
54 : #include "servicefactory_detail.hxx"
55 :
56 : #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
57 :
58 :
59 : using namespace ::rtl;
60 : using namespace ::osl;
61 : using namespace ::com::sun::star;
62 : using namespace ::com::sun::star::uno;
63 :
64 : namespace cppu
65 : {
66 :
67 : Reference< security::XAccessController >
68 : createDefaultAccessController() SAL_THROW(());
69 :
70 132 : static Reference< XInterface > SAL_CALL createInstance(
71 : Reference< XInterface > const & xFactory,
72 : Reference< XComponentContext > const & xContext =
73 : Reference< XComponentContext >() )
74 : {
75 132 : Reference< lang::XSingleComponentFactory > xFac( xFactory, UNO_QUERY );
76 132 : if (xFac.is())
77 : {
78 132 : return xFac->createInstanceWithContext( xContext );
79 : }
80 : else
81 : {
82 0 : Reference< lang::XSingleServiceFactory > xFac2( xFactory, UNO_QUERY );
83 0 : if (xFac2.is())
84 : {
85 : OSL_ENSURE( !xContext.is(), "### ignoring context!" );
86 0 : return xFac2->createInstance();
87 0 : }
88 : }
89 : throw RuntimeException(
90 : OUSTR("no factory object given!"),
91 0 : Reference< XInterface >() );
92 : }
93 :
94 6 : Reference< registry::XSimpleRegistry > SAL_CALL createSimpleRegistry(
95 : OUString const & rBootstrapPath )
96 : SAL_THROW(())
97 : {
98 : try
99 : {
100 : return Reference< registry::XSimpleRegistry >(
101 : createInstance(
102 : loadSharedLibComponentFactory(
103 : OUSTR("bootstrap.uno" SAL_DLLEXTENSION),
104 6 : rBootstrapPath.isEmpty()
105 : ? get_this_libpath() : rBootstrapPath,
106 : OUSTR("com.sun.star.comp.stoc.SimpleRegistry"),
107 : Reference< lang::XMultiServiceFactory >(),
108 : Reference< registry::XRegistryKey >() ) ),
109 12 : UNO_QUERY );
110 : }
111 0 : catch (Exception & exc)
112 : {
113 : #if OSL_DEBUG_LEVEL > 0
114 : OString cstr_msg(
115 : OUStringToOString( exc.Message, RTL_TEXTENCODING_ASCII_US ) );
116 : OSL_ENSURE( !"### exception occurred:", cstr_msg.getStr() );
117 : #else
118 : (void) exc; // avoid warning about unused variable
119 : #endif
120 : }
121 :
122 0 : return Reference< registry::XSimpleRegistry >();
123 : }
124 :
125 4 : Reference< registry::XSimpleRegistry > SAL_CALL createNestedRegistry(
126 : OUString const & rBootstrapPath )
127 : SAL_THROW(())
128 : {
129 : try
130 : {
131 : return Reference< registry::XSimpleRegistry >(
132 : createInstance(
133 : loadSharedLibComponentFactory(
134 : OUSTR("bootstrap.uno" SAL_DLLEXTENSION),
135 4 : rBootstrapPath.isEmpty()
136 : ? get_this_libpath() : rBootstrapPath,
137 : OUSTR("com.sun.star.comp.stoc.NestedRegistry"),
138 : Reference< lang::XMultiServiceFactory >(),
139 : Reference< registry::XRegistryKey >() ) ),
140 8 : UNO_QUERY );
141 : }
142 0 : catch (Exception & exc)
143 : {
144 : #if OSL_DEBUG_LEVEL > 0
145 : OString cstr_msg(
146 : OUStringToOString( exc.Message, RTL_TEXTENCODING_ASCII_US ) );
147 : OSL_ENSURE( !"### exception occurred:", cstr_msg.getStr() );
148 : #else
149 : (void) exc; // avoid warning about unused variable
150 : #endif
151 : }
152 :
153 0 : return Reference< registry::XSimpleRegistry >();
154 : }
155 :
156 :
157 : /** bootstrap variables:
158 :
159 : UNO_AC=<mode> [mandatory]
160 : -- mode := { on, off, dynamic-only, single-user, single-default-user }
161 : UNO_AC_SERVICE=<service_name> [optional]
162 : -- override ac singleton service name
163 : UNO_AC_SINGLEUSER=<user-id|nothing> [optional]
164 : -- run with this user id or with default user policy (<nothing>)
165 : set UNO_AC=single-[default-]user
166 : UNO_AC_USERCACHE_SIZE=<cache_size>
167 : -- number of user permission sets to be cached
168 :
169 : UNO_AC_POLICYSERVICE=<service_name> [optional]
170 : -- override policy singleton service name
171 : UNO_AC_POLICYFILE=<file_url> [optional]
172 : -- read policy out of simple text file
173 : */
174 122 : void add_access_control_entries(
175 : ::std::vector< ContextEntry_Init > * values,
176 : Bootstrap const & bootstrap )
177 : SAL_THROW( (Exception) )
178 : {
179 122 : ContextEntry_Init entry;
180 122 : ::std::vector< ContextEntry_Init > & context_values = *values;
181 :
182 122 : OUString ac_policy;
183 122 : if (bootstrap.getFrom( OUSTR("UNO_AC_POLICYSERVICE"), ac_policy ))
184 : {
185 : // overridden service name
186 : // - policy singleton
187 0 : entry.bLateInitService = true;
188 0 : entry.name = OUSTR("/singletons/com.sun.star.security.thePolicy");
189 0 : entry.value <<= ac_policy;
190 0 : context_values.push_back( entry );
191 : }
192 122 : else if (bootstrap.getFrom( OUSTR("UNO_AC_POLICYFILE"), ac_policy ))
193 : {
194 : // check for file policy
195 : // - file policy prop: file-name
196 0 : if (0 != ac_policy.compareToAscii(
197 0 : RTL_CONSTASCII_STRINGPARAM("file:///") ))
198 : {
199 : // no file url
200 0 : OUString baseDir;
201 0 : if ( ::osl_getProcessWorkingDir( &baseDir.pData )
202 : != osl_Process_E_None )
203 : {
204 : OSL_ASSERT( false );
205 : }
206 0 : OUString fileURL;
207 0 : if ( ::osl_getAbsoluteFileURL(
208 0 : baseDir.pData, ac_policy.pData, &fileURL.pData )
209 : != osl_File_E_None )
210 : {
211 : OSL_ASSERT( false );
212 : }
213 0 : ac_policy = fileURL;
214 : }
215 :
216 0 : entry.bLateInitService = false;
217 : entry.name =
218 0 : OUSTR("/implementations/com.sun.star.security.comp.stoc.FilePolicy/"
219 0 : "file-name");
220 0 : entry.value <<= ac_policy;
221 0 : context_values.push_back( entry );
222 : // - policy singleton
223 0 : entry.bLateInitService = true;
224 0 : entry.name = OUSTR("/singletons/com.sun.star.security.thePolicy");
225 0 : entry.value <<= OUSTR("com.sun.star.security.comp.stoc.FilePolicy");
226 0 : context_values.push_back( entry );
227 : } // else policy singleton comes from storage
228 :
229 122 : OUString ac_mode;
230 122 : if (! bootstrap.getFrom( OUSTR("UNO_AC"), ac_mode ))
231 : {
232 122 : ac_mode = OUSTR("off"); // default
233 : }
234 122 : OUString ac_user;
235 122 : if (bootstrap.getFrom( OUSTR("UNO_AC_SINGLEUSER"), ac_user ))
236 : {
237 : // ac in single-user mode
238 0 : if (!ac_user.isEmpty())
239 : {
240 : // - ac prop: single-user-id
241 0 : entry.bLateInitService = false;
242 : entry.name =
243 0 : OUSTR("/services/com.sun.star.security.AccessController/"
244 0 : "single-user-id");
245 0 : entry.value <<= ac_user;
246 0 : context_values.push_back( entry );
247 0 : if ( ac_mode != "single-user" )
248 : {
249 : throw SecurityException(
250 : OUSTR("set UNO_AC=single-user "
251 : "if you set UNO_AC_SINGLEUSER=<user-id>!"),
252 0 : Reference< XInterface >() );
253 : }
254 : }
255 : else
256 : {
257 0 : if ( ac_mode != "single-default-user" )
258 : {
259 : throw SecurityException(
260 : OUSTR("set UNO_AC=single-default-user "
261 : "if you set UNO_AC_SINGLEUSER=<nothing>!"),
262 0 : Reference< XInterface >() );
263 : }
264 : }
265 : }
266 :
267 122 : OUString ac_service;
268 122 : if (! bootstrap.getFrom( OUSTR("UNO_AC_SERVICE"), ac_service ))
269 : {
270 : // override service name
271 122 : ac_service = OUSTR("com.sun.star.security.AccessController"); // default
272 : // ac = OUSTR("com.sun.star.security.comp.stoc.AccessController");
273 : }
274 :
275 : // - ac prop: user-cache-size
276 122 : OUString ac_cache;
277 122 : if (bootstrap.getFrom( OUSTR("UNO_AC_USERCACHE_SIZE"), ac_cache ))
278 : {
279 : // ac cache size
280 0 : sal_Int32 n = ac_cache.toInt32();
281 0 : if (0 < n)
282 : {
283 0 : entry.bLateInitService = false;
284 : entry.name =
285 0 : OUSTR("/services/com.sun.star.security.AccessController/"
286 0 : "user-cache-size");
287 0 : entry.value <<= n;
288 0 : context_values.push_back( entry );
289 : }
290 : }
291 :
292 : // - ac prop: mode
293 : // { "off", "on", "dynamic-only", "single-user", "single-default-user" }
294 122 : entry.bLateInitService = false;
295 122 : entry.name = OUSTR("/services/com.sun.star.security.AccessController/mode");
296 122 : entry.value <<= ac_mode;
297 122 : context_values.push_back( entry );
298 : // - ac singleton
299 122 : entry.bLateInitService = true;
300 122 : entry.name = OUSTR("/singletons/com.sun.star.security.theAccessController");
301 122 : entry.value <<= ac_service;
302 122 : context_values.push_back( entry );
303 122 : }
304 :
305 : namespace {
306 122 : void addFactories(
307 : char const * const * ppNames /* implname, ..., 0 */,
308 : OUString const & bootstrapPath,
309 : Reference< lang::XMultiComponentFactory > const & xMgr,
310 : Reference< registry::XRegistryKey > const & xKey )
311 : SAL_THROW( (Exception) )
312 : {
313 122 : Reference< container::XSet > xSet( xMgr, UNO_QUERY );
314 : OSL_ASSERT( xSet.is() );
315 122 : Reference< lang::XMultiServiceFactory > xSF( xMgr, UNO_QUERY );
316 :
317 1220 : while (*ppNames)
318 : {
319 976 : OUString implName( OUString::createFromAscii( *ppNames++ ) );
320 :
321 : Any aFac( makeAny( loadSharedLibComponentFactory(
322 : OUSTR("bootstrap.uno" SAL_DLLEXTENSION),
323 976 : bootstrapPath, implName, xSF, xKey ) ) );
324 976 : xSet->insert( aFac );
325 : #if OSL_DEBUG_LEVEL > 1
326 : if (xSet->has( aFac ))
327 : {
328 : Reference< lang::XServiceInfo > xInfo;
329 : if (aFac >>= xInfo)
330 : {
331 : ::fprintf(
332 : stderr, "> implementation %s supports: ", ppNames[ -1 ] );
333 : Sequence< OUString > supported(
334 : xInfo->getSupportedServiceNames() );
335 : for ( sal_Int32 nPos = supported.getLength(); nPos--; )
336 : {
337 : OString str( OUStringToOString(
338 : supported[ nPos ], RTL_TEXTENCODING_ASCII_US ) );
339 : ::fprintf( stderr, nPos ? "%s, " : "%s\n", str.getStr() );
340 : }
341 : }
342 : else
343 : {
344 : ::fprintf(
345 : stderr,
346 : "> implementation %s provides NO lang::XServiceInfo!!!\n",
347 : ppNames[ -1 ] );
348 : }
349 : }
350 : #endif
351 : #if OSL_DEBUG_LEVEL > 0
352 : if (! xSet->has( aFac ))
353 : {
354 : OStringBuffer buf( 64 );
355 : buf.append( "### failed inserting shared lib \"" );
356 : buf.append( "bootstrap.uno" SAL_DLLEXTENSION );
357 : buf.append( "\"!!!" );
358 : OString str( buf.makeStringAndClear() );
359 : OSL_FAIL( str.getStr() );
360 : }
361 : #endif
362 1098 : }
363 122 : }
364 :
365 : } // namespace
366 :
367 122 : Reference< lang::XMultiComponentFactory > bootstrapInitialSF(
368 : OUString const & rBootstrapPath )
369 : SAL_THROW( (Exception) )
370 : {
371 : OUString const & bootstrap_path =
372 122 : rBootstrapPath.isEmpty() ? get_this_libpath() : rBootstrapPath;
373 :
374 : Reference< lang::XMultiComponentFactory > xMgr(
375 : createInstance(
376 : loadSharedLibComponentFactory(
377 : OUSTR("bootstrap.uno" SAL_DLLEXTENSION), bootstrap_path,
378 : OUSTR("com.sun.star.comp.stoc.ORegistryServiceManager"),
379 : Reference< lang::XMultiServiceFactory >(),
380 : Reference< registry::XRegistryKey >() ) ),
381 122 : UNO_QUERY );
382 :
383 : // add initial bootstrap services
384 : static char const * ar[] = {
385 : "com.sun.star.comp.stoc.OServiceManagerWrapper",
386 : "com.sun.star.comp.stoc.DLLComponentLoader",
387 : "com.sun.star.comp.stoc.SimpleRegistry",
388 : "com.sun.star.comp.stoc.NestedRegistry",
389 : "com.sun.star.comp.stoc.TypeDescriptionManager",
390 : "com.sun.star.comp.stoc.ImplementationRegistration",
391 : "com.sun.star.security.comp.stoc.AccessController",
392 : "com.sun.star.security.comp.stoc.FilePolicy",
393 : 0
394 : };
395 : addFactories(
396 : ar, bootstrap_path,
397 122 : xMgr, Reference< registry::XRegistryKey >() );
398 :
399 122 : return xMgr;
400 : }
401 :
402 : // returns context with UNinitialized smgr
403 2 : Reference< XComponentContext > bootstrapInitialContext(
404 : Reference< lang::XMultiComponentFactory > const & xSF,
405 : Reference< registry::XSimpleRegistry > const & types_xRegistry,
406 : Reference< registry::XSimpleRegistry > const & services_xRegistry,
407 : OUString const & rBootstrapPath, Bootstrap const & bootstrap )
408 : SAL_THROW( (Exception) )
409 : {
410 2 : Reference< lang::XInitialization > xSFInit( xSF, UNO_QUERY );
411 2 : if (! xSFInit.is())
412 : {
413 : throw RuntimeException(
414 : OUSTR("servicemanager does not support XInitialization!"),
415 0 : Reference< XInterface >() );
416 : }
417 :
418 : // basic context values
419 2 : ContextEntry_Init entry;
420 2 : ::std::vector< ContextEntry_Init > context_values;
421 2 : context_values.reserve( 14 );
422 :
423 : // macro expander singleton for loader
424 2 : entry.bLateInitService = true;
425 2 : entry.name = OUSTR("/singletons/com.sun.star.util.theMacroExpander");
426 : entry.value
427 2 : <<= cppuhelper::detail::create_bootstrap_macro_expander_factory();
428 2 : context_values.push_back( entry );
429 :
430 : // tdmgr singleton
431 2 : entry.bLateInitService = true;
432 : entry.name =
433 2 : OUSTR("/singletons/com.sun.star.reflection.theTypeDescriptionManager");
434 2 : entry.value <<= OUSTR("com.sun.star.comp.stoc.TypeDescriptionManager");
435 2 : context_values.push_back( entry );
436 :
437 : // read out singleton infos from registry
438 2 : if (services_xRegistry.is())
439 : {
440 : Reference< registry::XRegistryKey > xKey(
441 2 : services_xRegistry->getRootKey() );
442 2 : if (xKey.is())
443 : {
444 2 : xKey = xKey->openKey( OUSTR("/SINGLETONS") );
445 2 : if (xKey.is())
446 : {
447 2 : entry.bLateInitService = true;
448 :
449 : Sequence< Reference< registry::XRegistryKey > > keys(
450 2 : xKey->openKeys() );
451 : Reference< registry::XRegistryKey > const * pKeys =
452 2 : keys.getConstArray();
453 4 : for ( sal_Int32 nPos = keys.getLength(); nPos--; )
454 : {
455 : css::uno::Sequence< rtl::OUString > impls(
456 : css::uno::Reference< css::registry::XRegistryKey >(
457 0 : pKeys[nPos]->openKey(
458 : rtl::OUString(
459 : RTL_CONSTASCII_USTRINGPARAM(
460 0 : "REGISTERED_BY"))),
461 0 : css::uno::UNO_SET_THROW)->getAsciiListValue());
462 0 : switch (impls.getLength()) {
463 : case 0:
464 : throw css::uno::DeploymentException(
465 0 : (pKeys[nPos]->getKeyName() +
466 : rtl::OUString(
467 : RTL_CONSTASCII_USTRINGPARAM(
468 0 : "/REGISTERED_BY is empty"))),
469 0 : css::uno::Reference< css::uno::XInterface >());
470 : case 1:
471 0 : break;
472 : default:
473 : OSL_TRACE(
474 : ("arbitrarily chosing \"%s\" among multiple"
475 : " implementations for \"%s\""),
476 : rtl::OUStringToOString(
477 : impls[0], RTL_TEXTENCODING_UTF8).getStr(),
478 : rtl::OUStringToOString(
479 : pKeys[nPos]->getKeyName(),
480 : RTL_TEXTENCODING_UTF8).getStr());
481 0 : break;
482 : }
483 : context_values.push_back(
484 : ContextEntry_Init(
485 : (rtl::OUString(
486 : RTL_CONSTASCII_USTRINGPARAM("/singletons/")) +
487 0 : pKeys[nPos]->getKeyName().copy(
488 0 : RTL_CONSTASCII_LENGTH("/SINGLETONS/"))),
489 0 : css::uno::makeAny(impls[0]),
490 0 : true));
491 2 : }
492 : }
493 2 : }
494 : }
495 :
496 : // ac, policy:
497 2 : add_access_control_entries( &context_values, bootstrap );
498 :
499 : // smgr singleton
500 2 : entry.bLateInitService = false;
501 2 : entry.name = OUSTR("/singletons/com.sun.star.lang.theServiceManager");
502 2 : entry.value <<= xSF;
503 2 : context_values.push_back( entry );
504 :
505 : Reference< XComponentContext > xContext(
506 : createComponentContext(
507 4 : &context_values[ 0 ], context_values.size(),
508 6 : Reference< XComponentContext >() ) );
509 : // set default context
510 2 : Reference< beans::XPropertySet > xProps( xSF, UNO_QUERY );
511 : OSL_ASSERT( xProps.is() );
512 2 : if (xProps.is())
513 : {
514 2 : xProps->setPropertyValue(
515 2 : OUSTR("DefaultContext"), makeAny( xContext ) );
516 : }
517 :
518 2 : Reference< container::XHierarchicalNameAccess > xTDMgr;
519 :
520 : // get tdmgr singleton
521 6 : if (xContext->getValueByName(
522 : OUSTR("/singletons/"
523 2 : "com.sun.star.reflection.theTypeDescriptionManager") )
524 4 : >>= xTDMgr)
525 : {
526 2 : if (types_xRegistry.is()) // insert rdb provider?
527 : {
528 : // add registry td provider factory to smgr and instance to tdmgr
529 : Reference< lang::XSingleComponentFactory > xFac(
530 : loadSharedLibComponentFactory(
531 : OUSTR("bootstrap.uno" SAL_DLLEXTENSION),
532 2 : rBootstrapPath.isEmpty()
533 : ? get_this_libpath() : rBootstrapPath,
534 : OUSTR("com.sun.star.comp.stoc.RegistryTypeDescriptionProvider"),
535 : Reference< lang::XMultiServiceFactory >( xSF, UNO_QUERY ),
536 4 : Reference< registry::XRegistryKey >() ), UNO_QUERY );
537 : OSL_ASSERT( xFac.is() );
538 :
539 : // smgr
540 2 : Reference< container::XSet > xSet( xSF, UNO_QUERY );
541 2 : xSet->insert( makeAny( xFac ) );
542 : OSL_ENSURE(
543 : xSet->has( makeAny( xFac ) ),
544 : "### failed registering registry td provider at smgr!" );
545 : // tdmgr
546 2 : xSet.set( xTDMgr, UNO_QUERY );
547 : OSL_ASSERT( xSet.is() );
548 2 : Any types_RDB( makeAny( types_xRegistry ) );
549 2 : Any rdbtdp( makeAny( xFac->createInstanceWithArgumentsAndContext(
550 2 : Sequence< Any >( &types_RDB, 1 ), xContext ) ) );
551 2 : xSet->insert( rdbtdp );
552 : OSL_ENSURE(
553 : xSet->has( rdbtdp ),
554 2 : "### failed inserting registry td provider to tdmgr!" );
555 : }
556 : // install callback
557 2 : installTypeDescriptionManager( xTDMgr );
558 : }
559 :
560 2 : return xContext;
561 : }
562 :
563 0 : static Reference< lang::XMultiComponentFactory > createImplServiceFactory(
564 : const OUString & rWriteRegistry,
565 : const OUString & rReadRegistry,
566 : sal_Bool bReadOnly,
567 : const OUString & rBootstrapPath )
568 : SAL_THROW( (Exception) )
569 : {
570 : Reference< lang::XMultiComponentFactory > xSF(
571 0 : bootstrapInitialSF( rBootstrapPath ) );
572 :
573 0 : Reference< registry::XSimpleRegistry > xRegistry;
574 :
575 : // open a registry
576 0 : sal_Bool bRegistryShouldBeValid = sal_False;
577 0 : if (!rWriteRegistry.isEmpty() && rReadRegistry.isEmpty())
578 : {
579 0 : bRegistryShouldBeValid = sal_True;
580 0 : xRegistry.set( createSimpleRegistry( rBootstrapPath ) );
581 0 : if (xRegistry.is())
582 : {
583 0 : if (bReadOnly)
584 : {
585 0 : xRegistry->open( rWriteRegistry, sal_True, sal_False );
586 : }
587 : else
588 : {
589 0 : xRegistry->open( rWriteRegistry, sal_False, sal_True );
590 : }
591 : }
592 : }
593 0 : else if (!rWriteRegistry.isEmpty() && !rReadRegistry.isEmpty())
594 : {
595 : // default registry
596 0 : bRegistryShouldBeValid = sal_True;
597 0 : xRegistry.set( createNestedRegistry( rBootstrapPath ) );
598 :
599 : Reference< registry::XSimpleRegistry > xWriteReg(
600 0 : createSimpleRegistry( rBootstrapPath ) );
601 0 : if (xWriteReg.is())
602 : {
603 0 : if (bReadOnly)
604 : {
605 : try
606 : {
607 0 : xWriteReg->open( rWriteRegistry, sal_True, sal_False );
608 : }
609 0 : catch (registry::InvalidRegistryException &)
610 : {
611 : }
612 :
613 0 : if (! xWriteReg->isValid())
614 : {
615 : throw RuntimeException(
616 : OUSTR("specified first registry "
617 : "could not be open readonly!"),
618 0 : Reference< XInterface >() );
619 : }
620 : }
621 : else
622 : {
623 0 : xWriteReg->open( rWriteRegistry, sal_False, sal_True );
624 : }
625 : }
626 :
627 : Reference< registry::XSimpleRegistry > xReadReg(
628 0 : createSimpleRegistry( rBootstrapPath ) );
629 0 : if (xReadReg.is())
630 : {
631 0 : xReadReg->open( rReadRegistry, sal_True, sal_False );
632 : }
633 :
634 0 : Reference< lang::XInitialization > xInit( xRegistry, UNO_QUERY );
635 0 : Sequence< Any > aInitSeq( 2 );
636 0 : aInitSeq[ 0 ] <<= xWriteReg;
637 0 : aInitSeq[ 1 ] <<= xReadReg;
638 0 : xInit->initialize( aInitSeq );
639 : }
640 :
641 0 : if (bRegistryShouldBeValid && (!xRegistry.is() || !xRegistry->isValid()))
642 : {
643 : throw RuntimeException(
644 : OUSTR("specified registry could not be initialized"),
645 0 : Reference< XInterface >() );
646 : }
647 :
648 0 : Bootstrap bootstrap;
649 : Reference< XComponentContext > xContext(
650 : bootstrapInitialContext(
651 0 : xSF, xRegistry, xRegistry, rBootstrapPath, bootstrap ) );
652 :
653 : // initialize sf
654 0 : Reference< lang::XInitialization > xInit( xSF, UNO_QUERY );
655 : OSL_ASSERT( xInit.is() );
656 0 : Sequence< Any > aSFInit( 1 );
657 0 : aSFInit[ 0 ] <<= xRegistry;
658 0 : xInit->initialize( aSFInit );
659 :
660 0 : return xSF;
661 : }
662 :
663 0 : Reference< lang::XMultiServiceFactory > SAL_CALL createRegistryServiceFactory(
664 : const OUString & rWriteRegistry,
665 : const OUString & rReadRegistry,
666 : sal_Bool bReadOnly,
667 : const OUString & rBootstrapPath )
668 : SAL_THROW( (Exception) )
669 : {
670 : return Reference< lang::XMultiServiceFactory >( createImplServiceFactory(
671 0 : rWriteRegistry, rReadRegistry, bReadOnly, rBootstrapPath ), UNO_QUERY );
672 : }
673 :
674 2 : Reference< XComponentContext > SAL_CALL bootstrap_InitialComponentContext(
675 : Reference< registry::XSimpleRegistry > const & xRegistry,
676 : OUString const & rBootstrapPath )
677 : SAL_THROW( (Exception) )
678 : {
679 2 : Bootstrap bootstrap;
680 :
681 : Reference< lang::XMultiComponentFactory > xSF(
682 2 : bootstrapInitialSF( rBootstrapPath ) );
683 : Reference< XComponentContext > xContext(
684 : bootstrapInitialContext(
685 2 : xSF, xRegistry, xRegistry, rBootstrapPath, bootstrap ) );
686 :
687 : // initialize sf
688 2 : Reference< lang::XInitialization > xInit( xSF, UNO_QUERY );
689 : OSL_ASSERT( xInit.is() );
690 2 : Sequence< Any > aSFInit( 2 );
691 2 : aSFInit[ 0 ] <<= xRegistry;
692 2 : aSFInit[ 1 ] <<= xContext; // default context
693 2 : xInit->initialize( aSFInit );
694 :
695 2 : return xContext;
696 : }
697 :
698 : }
699 :
700 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|