update dev300-m58
[ooovba.git] / configmgr / source / misc / bootstrap.cxx
blob714ed61ac2d3828497f34f5acae6597256eb1ae0
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: bootstrap.cxx,v $
10 * $Revision: 1.35 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_configmgr.hxx"
34 #include <stdio.h>
36 #include "bootstrap.hxx"
38 #ifndef CONFIGMGR_API_FACTORY_HXX_
39 #include "confapifactory.hxx"
40 #endif
41 #include "serviceinfohelper.hxx"
42 #include "matchlocale.hxx"
43 #include "tracer.hxx"
44 #include <cppuhelper/component_context.hxx>
45 #include <rtl/bootstrap.hxx>
46 #include <rtl/ustring.hxx>
47 #include <rtl/ustrbuf.hxx>
48 #include <osl/file.hxx>
49 #include <osl/process.h>
50 #include <osl/diagnose.h>
51 #include <com/sun/star/lang/DisposedException.hpp>
52 #include <com/sun/star/configuration/MissingBootstrapFileException.hpp>
53 #include <com/sun/star/configuration/InvalidBootstrapFileException.hpp>
54 #include <com/sun/star/configuration/InstallationIncompleteException.hpp>
55 #include <com/sun/star/beans/PropertyValue.hpp>
56 #include <com/sun/star/beans/XPropertySet.hpp>
58 // ---------------------------------------------------------------------------------------
59 // legacy argument names
60 #define ARGUMENT_LOCALE_COMPAT "locale"
61 #define ARGUMENT_ASYNC_COMPAT "lazywrite"
62 #define ARGUMENT_SERVERTYPE_COMPAT "servertype"
64 // legacy servertype setting
65 #define SETTING_SERVERTYPE_COMPAT "ServerType"
66 #define BOOTSTRAP_SERVERTYPE_COMPAT CONTEXT_ITEM_PREFIX_ SETTING_SERVERTYPE_COMPAT
68 #define SERVERTYPE_UNO_COMPAT "uno"
69 #define SERVERTYPE_PLUGIN_COMPAT "plugin"
70 // ---------------------------------------------------------------------------------------
72 #define NAME( N ) rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(N))
73 #define ITEM( N ) rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(N))
74 // ---------------------------------------------------------------------------------------
75 // -------------------------------------------------------------------------
77 // ---------------------------------------------------------------------------------------
78 namespace configmgr
80 // ---------------------------------------------------------------------------------------
81 // ---------------------------------------------------------------------------------------
82 static void convertToBool(const uno::Any& aValue, sal_Bool& bValue)
84 rtl::OUString aStrValue;
85 if (aValue >>= aStrValue)
87 if (aStrValue.equalsIgnoreAsciiCaseAscii("true"))
89 bValue = sal_True;
91 else if (aStrValue.equalsIgnoreAsciiCaseAscii("false"))
93 bValue = sal_False;
97 // ----------------------------------------------------------------------------------
98 const sal_Char k_BootstrapContextImplName[] = "com.sun.star.comp.configuration.bootstrap.BootstrapContext" ;
99 const sal_Char k_BootstrapContextServiceName[] = "com.sun.star.configuration.bootstrap.BootstrapContext" ;
101 // -------------------------------------------------------------------------
102 static sal_Char const * const k_BootstrapContextServiceNames [] =
104 k_BootstrapContextServiceName,
107 static const ServiceImplementationInfo k_BootstrapContextServiceInfo =
109 k_BootstrapContextImplName,
110 k_BootstrapContextServiceNames,
113 static const SingletonRegistrationInfo k_BootstrapContextSingletonInfo =
115 A_BootstrapContextSingletonName,
116 k_BootstrapContextImplName,
117 k_BootstrapContextServiceName,
120 // ---------------------------------------------------------------------------------------
121 // ---------------------------------------------------------------------------------------
122 uno::Reference<uno::XInterface> SAL_CALL
123 instantiateBootstrapContext( uno::Reference< uno::XComponentContext > const& xTargetContext )
125 uno::Reference< uno::XComponentContext > xContext = UnoContextTunnel::recoverContext(xTargetContext);
127 BootstrapContext * pContext = new BootstrapContext(xContext);
128 uno::Reference< uno::XComponentContext > xResult(pContext);
130 pContext->initialize();
132 return uno::Reference< uno::XInterface >( xResult, uno::UNO_QUERY );
135 const SingletonRegistrationInfo * getBootstrapContextSingletonInfo()
137 return &k_BootstrapContextSingletonInfo;
139 const ServiceRegistrationInfo * getBootstrapContextServiceInfo()
141 return getRegistrationInfo(&k_BootstrapContextServiceInfo);
143 // ---------------------------------------------------------------------------------------
144 // ---------------------------------------------------------------------------
146 static
147 inline
148 cppu::ContextEntry_Init makeEntry(beans::NamedValue const & aOverride)
150 return cppu::ContextEntry_Init(aOverride.Name,aOverride.Value);
152 // ---------------------------------------------------------------------------
154 static
155 cppu::ContextEntry_Init makeSingleton(SingletonRegistrationInfo const * pSingletonInfo)
157 OSL_ASSERT( pSingletonInfo &&
158 pSingletonInfo->singletonName &&
159 pSingletonInfo->instantiatedServiceName );
161 rtl::OUStringBuffer aSingletonName;
162 aSingletonName.appendAscii( RTL_CONSTASCII_STRINGPARAM(SINGLETON_) );
163 aSingletonName.appendAscii(pSingletonInfo->singletonName);
165 rtl::OUString const aServiceName = rtl::OUString::createFromAscii(pSingletonInfo->instantiatedServiceName);
167 return cppu::ContextEntry_Init(aSingletonName.makeStringAndClear(), uno::makeAny(aServiceName), true);
169 // ---------------------------------------------------------------------------
171 uno::Reference< uno::XComponentContext > BootstrapContext::createWrapper(uno::Reference< uno::XComponentContext > const & _xContext, uno::Sequence < beans::NamedValue > const & _aOverrides)
173 std::vector< cppu::ContextEntry_Init > aContextEntries;
174 aContextEntries.reserve(_aOverrides.getLength() + 5);
176 // marker + bootstrap context
177 aContextEntries.push_back( cppu::ContextEntry_Init(NAME(CONTEXT_ITEM_IS_WRAPPER_CONTEXT), uno::makeAny(sal_True)) );
178 aContextEntries.push_back( cppu::ContextEntry_Init(NAME(CONTEXT_ITEM_IS_BOOTSTRAP_CONTEXT), uno::makeAny(sal_False)) );
180 aContextEntries.push_back( makeSingleton(getBootstrapContextSingletonInfo()) );
182 // singletons except for passthrough
183 if (!isPassthrough(_xContext))
185 aContextEntries.push_back( makeSingleton(getDefaultProviderSingletonInfo()) );
186 aContextEntries.push_back( makeSingleton(backend::getDefaultBackendSingletonInfo()) );
189 for (sal_Int32 i = 0; i<_aOverrides.getLength(); ++i)
190 aContextEntries.push_back( makeEntry(_aOverrides[i]) );
192 return cppu::createComponentContext(&aContextEntries.front(),aContextEntries.size(),_xContext);
194 // ---------------------------------------------------------------------------
196 sal_Bool BootstrapContext::isWrapper(uno::Reference< uno::XComponentContext > const & _xContext)
198 OSL_ASSERT(_xContext.is());
199 if (!_xContext.is()) return false;
201 uno::Any aSetting = _xContext->getValueByName( NAME(CONTEXT_ITEM_IS_WRAPPER_CONTEXT) );
203 if (!aSetting.hasValue()) return false;
205 sal_Bool bValue = false;
206 OSL_VERIFY(aSetting >>= bValue);
208 return bValue;
210 // ---------------------------------------------------------------------------
211 // ---------------------------------------------------------------------------
213 BootstrapContext::BootstrapContext(uno::Reference< uno::XComponentContext > const & _xContext)
214 : ComponentContext(_xContext)
217 // ---------------------------------------------------------------------------
219 BootstrapContext::~BootstrapContext()
222 // ---------------------------------------------------------------------------
224 void BootstrapContext::initialize()
226 // get default Bootstrap URL
227 rtl::OUString sURL;
228 uno::Any aExplicitURL;
229 if ( this->lookupInContext(aExplicitURL,NAME(CONTEXT_ITEM_PREFIX_ SETTING_INIFILE)) )
231 OSL_VERIFY(aExplicitURL >>= sURL);
233 else if (!rtl::Bootstrap::get(NAME(BOOTSTRAP_ITEM_INIFILE),sURL))
235 sURL = getDefaultConfigurationBootstrapURL();
238 ComponentContext::initialize(sURL);
240 // ---------------------------------------------------------------------------------------
242 rtl::OUString BootstrapContext::getDefaultConfigurationBootstrapURL()
244 rtl::OUString url(
245 RTL_CONSTASCII_USTRINGPARAM(
246 "$OOO_BASE_DIR/program/" SAL_CONFIGFILE("configmgr")));
247 rtl::Bootstrap::expandMacros(url); //TODO: detect failure
248 return url;
250 // ---------------------------------------------------------------------------------------
252 rtl::OUString BootstrapContext::makeContextName(rtl::OUString const & _aName)
254 // check that it isn't long already
255 OSL_ENSURE(!_aName.matchIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM(CONTEXT_MODULE_PREFIX_) ),
256 "configmgr::BootstrapContext: passing argument in long context form won't work");
258 return NAME(CONTEXT_ITEM_PREFIX_).concat(_aName);
260 // ---------------------------------------------------------------------------
262 rtl::OUString BootstrapContext::makeBootstrapName(rtl::OUString const & _aName)
264 // check if already is short
265 if (!_aName.matchIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM(CONTEXT_ITEM_PREFIX_) ) )
267 OSL_TRACE( "configmgr: Cannot map name to bootstrap name: %s",
268 rtl::OUStringToOString(_aName,RTL_TEXTENCODING_ASCII_US).getStr() );
269 return _aName;
271 return NAME(BOOTSTRAP_ITEM_PREFIX_).concat(_aName.copy(RTL_CONSTASCII_LENGTH(CONTEXT_ITEM_PREFIX_)));
273 // ---------------------------------------------------------------------------
275 uno::Any SAL_CALL
276 BootstrapContext::getValueByName( const rtl::OUString& aName )
277 throw (uno::RuntimeException)
279 sal_Bool const bOurName = aName.matchIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM(CONTEXT_MODULE_PREFIX_) );
281 if (bOurName)
283 if (aName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(CONTEXT_ITEM_BOOTSTRAP_ERROR) ) )
284 return this->makeBootstrapException();
286 if (aName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(CONTEXT_ITEM_PREFIX_ SETTING_INIFILE) ) )
287 return uno::makeAny( this->getBootstrapURL() );
289 if (aName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(CONTEXT_ITEM_IS_BOOTSTRAP_CONTEXT) ) )
290 return uno::makeAny( sal_True );
292 else if (aName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(SINGLETON_ A_BootstrapContextSingletonName) ) )
294 return uno::makeAny( uno::Reference< uno::XComponentContext >(this) );
297 uno::Any aResult;
299 bool bFound = lookupInContext ( aResult, aName );
301 if (!bFound && bOurName) // requires: CONTEXT_ITEM_PREFIX_ starts with CONTEXT_MODULE_PREFIX_
303 if ( aName.matchIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM(CONTEXT_ITEM_PREFIX_) ) )
305 bFound = lookupInBootstrap( aResult, makeBootstrapName(aName) );
308 return aResult;
311 // ---------------------------------------------------------------------------
312 // class ContextReader
313 // ---------------------------------------------------------------------------
315 ContextReader::ContextReader(uno::Reference< uno::XComponentContext > const & context)
316 : m_basecontext(context)
317 , m_fullcontext()
319 OSL_ENSURE(context.is(), "ERROR: trying to create reader on NULL context\n");
320 if (context.is())
322 uno::Any aBootstrapContext = context->getValueByName( SINGLETON(A_BootstrapContextSingletonName) );
323 aBootstrapContext >>= m_fullcontext;
326 // ---------------------------------------------------------------------------
328 uno::Reference< lang::XMultiComponentFactory > ContextReader::getServiceManager() const
330 OSL_ASSERT(m_basecontext.is());
331 return m_basecontext->getServiceManager();
333 // ---------------------------------------------------------------------------
334 inline
335 uno::Any ContextReader::getSetting(rtl::OUString const & _aSetting) const
337 OSL_ASSERT(m_basecontext.is());
338 return getBestContext()->getValueByName(_aSetting);
341 inline
342 sal_Bool ContextReader::hasSetting(rtl::OUString const & _aSetting) const
344 return getSetting(_aSetting).hasValue();
347 inline
348 sal_Bool ContextReader::getBoolSetting(rtl::OUString const & _aSetting, sal_Bool bValue = false) const
350 uno::Any aValue = getSetting(_aSetting);
351 if (!(aValue >>= bValue))
352 convertToBool(aValue, bValue);
354 return bValue;
357 inline
358 rtl::OUString ContextReader::getStringSetting(rtl::OUString const & _aSetting, rtl::OUString aValue = rtl::OUString()) const
360 getSetting(_aSetting) >>= aValue;
361 return aValue;
363 // ---------------------------------------------------------------------------------------
365 sal_Bool ContextReader::isUnoBackend() const
367 rtl::OUString aSettingName = NAME(BOOTSTRAP_SERVERTYPE_COMPAT);
369 rtl::OUString aValue;
370 if (getSetting(aSettingName) >>= aValue)
372 return aValue.equalsAscii(SERVERTYPE_UNO_COMPAT);
374 else
376 return true;
379 // ---------------------------------------------------------------------------------------
381 sal_Bool ContextReader::hasUnoBackendService() const
383 return hasSetting( NAME(CONTEXT_ITEM_PREFIX_ SETTING_UNOSERVICE) );
385 sal_Bool ContextReader::hasUnoBackendWrapper() const
387 return hasSetting( NAME(CONTEXT_ITEM_PREFIX_ SETTING_UNOWRAPPER) );
390 sal_Bool ContextReader::hasLocale() const
392 return hasSetting( NAME(CONTEXT_ITEM_PREFIX_ SETTING_LOCALE_NEW) );
394 sal_Bool ContextReader::hasAsyncSetting() const
396 return hasSetting( NAME(CONTEXT_ITEM_PREFIX_ SETTING_ASYNC_NEW) );
398 sal_Bool ContextReader::hasOfflineSetting() const
400 return hasSetting( NAME(CONTEXT_ITEM_PREFIX_ SETTING_OFFLINE) );
402 // ---------------------------------------------------------------------------------------
404 rtl::OUString ContextReader::getUnoBackendService() const
406 return getStringSetting( NAME(CONTEXT_ITEM_PREFIX_ SETTING_UNOSERVICE) );
408 rtl::OUString ContextReader::getUnoBackendWrapper() const
410 return getStringSetting( NAME(CONTEXT_ITEM_PREFIX_ SETTING_UNOWRAPPER) );
413 rtl::OUString ContextReader::getLocale() const
415 return getStringSetting( NAME(CONTEXT_ITEM_PREFIX_ SETTING_LOCALE_NEW) );
417 sal_Bool ContextReader::getAsyncSetting() const
419 return getBoolSetting( NAME(CONTEXT_ITEM_PREFIX_ SETTING_ASYNC_NEW) );
421 sal_Bool ContextReader::getOfflineSetting() const
423 return getBoolSetting( NAME(CONTEXT_ITEM_PREFIX_ SETTING_OFFLINE) );
426 // get a special setting
427 sal_Bool ContextReader::isAdminService() const
429 return getBoolSetting( NAME(CONTEXT_ITEM_ADMINFLAG) );
432 sal_Bool ContextReader::isBootstrapValid() const
434 return this->isUnoBackend() &&
435 this->hasUnoBackendService() &&
436 (this->hasUnoBackendWrapper() || !this->getOfflineSetting());
439 uno::Any ContextReader::getBootstrapError() const
441 return getSetting( NAME(CONTEXT_ITEM_BOOTSTRAP_ERROR) );
443 // ---------------------------------------------------------------------------------------
445 bool ContextReader::testAdminService(uno::Reference< uno::XComponentContext > const & context, bool bAdmin)
447 OSL_ASSERT(context.is());
448 if (!context.is()) return false;
450 uno::Any aSetting = context->getValueByName( NAME(CONTEXT_ITEM_ADMINFLAG) );
452 sal_Bool bValue = false;
453 bool bTest = (aSetting >>= bValue) && bValue;
455 return bTest == bAdmin;
457 // ---------------------------------------------------------------------------
458 // ---------------------------------------------------------------------------------------
460 bool ArgumentHelper::extractArgument(beans::NamedValue & rValue, const uno::Any & aOverride)
462 if ( ! (aOverride >>= rValue) )
464 // it must be a PropertyValue, if it isn't a NamedValue
465 beans::PropertyValue aPV;
466 if ( !(aOverride >>= aPV) )
467 return false;
469 rValue.Name = aPV.Name;
470 rValue.Value = aPV.Value;
473 return true;
476 // ---------------------------------------------------------------------------------------
478 bool ArgumentHelper::checkBackendArgument(beans::NamedValue const & aAdjustedValue)
480 bool isWrappable =
481 aAdjustedValue.Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(CONTEXT_ITEM_PREFIX_ SETTING_ASYNC_NEW)) ||
482 aAdjustedValue.Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(CONTEXT_ITEM_PREFIX_ SETTING_LOCALE_NEW));
484 if (isWrappable) return false;
486 m_bHasBackendArguments = true;
487 return true;
489 // ---------------------------------------------------------------------------------------
491 bool ArgumentHelper::filterAndAdjustArgument(beans::NamedValue & rValue)
493 // handle old servertype argument and filter the 'plugin' value
494 if (rValue.Name.equalsAscii(ARGUMENT_SERVERTYPE_COMPAT))
496 rtl::OUString aServertype;
497 if (! (rValue.Value >>= aServertype))
498 return false;
500 if (aServertype.equalsAscii(SERVERTYPE_PLUGIN_COMPAT))
501 return false;
503 rValue.Name = NAME(BOOTSTRAP_SERVERTYPE_COMPAT);
504 // check, if it is already there
505 uno::Any const aExistingValue = m_context->getValueByName(rValue.Name);
507 if (aExistingValue.hasValue())
508 return !(aExistingValue == rValue.Value);
510 else
511 return !aServertype.equalsAscii(SERVERTYPE_UNO_COMPAT);
514 // map old argument names for comatibility
515 else if (rValue.Name.equalsAscii(ARGUMENT_LOCALE_COMPAT))
516 rValue.Name = NAME(SETTING_LOCALE_NEW);
518 else if (rValue.Name.equalsAscii(ARGUMENT_ASYNC_COMPAT))
519 rValue.Name = NAME(SETTING_ASYNC_NEW);
521 // give the item a long name
522 rValue.Name = BootstrapContext::makeContextName(rValue.Name);
524 // check, if it is already there
525 uno::Any const aExistingValue = m_context->getValueByName(rValue.Name);
527 return ! (aExistingValue == rValue.Value);
529 // ---------------------------------------------------------------------------------------
531 beans::NamedValue ArgumentHelper::makeAdminServiceOverride(sal_Bool bAdmin)
533 return beans::NamedValue( NAME(CONTEXT_ITEM_ADMINFLAG), uno::makeAny(bAdmin) );
535 // ---------------------------------------------------------------------------------------
536 // ---------------------------------------------------------------------------------------
537 // - bootstrapping error checking helper
538 // ---------------------------------------------------------------------------------------
539 namespace {
540 // ---------------------------------------------------------------------------------------
541 // error handling
542 // ---------------------------------------------------------------------------------------
543 enum BootstrapResult
545 BOOTSTRAP_DATA_OK,
546 INCOMPLETE_BOOTSTRAP_DATA,
547 INCOMPLETE_BOOTSTRAP_FILE,
548 MISSING_BOOTSTRAP_FILE,
549 BOOTSTRAP_FAILURE
551 // ---------------------------------------------------------------------------------------
552 static
553 rtl::OUString getFallbackErrorMessage( BootstrapResult _rc )
555 rtl::OUString sMessage(RTL_CONSTASCII_USTRINGPARAM("The program cannot start. "));
557 switch (_rc)
559 case MISSING_BOOTSTRAP_FILE:
560 sMessage = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("A main configuration file is missing"));
561 break;
563 case INCOMPLETE_BOOTSTRAP_FILE:
564 sMessage = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("A main configuration file is invalid"));
565 break;
567 case INCOMPLETE_BOOTSTRAP_DATA:
568 sMessage = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Required bootstrap data is not available"));
569 break;
571 default:
572 sMessage = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Unexpected bootstrap failure"));
573 break;
575 case BOOTSTRAP_DATA_OK:
576 break;
578 sMessage += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" (No detailed error message available.)"));
580 return sMessage;
582 // ---------------------------------------------------------------------------------------
584 static
585 uno::Any impl_makeBootstrapException( BootstrapResult _rc, rtl::OUString const& _sMessage, rtl::OUString const& _sURL, uno::Reference< uno::XInterface > _xContext )
587 rtl::OUString sMessage(_sMessage);
588 // ensure a message
589 if (sMessage.getLength()== 0)
591 OSL_ENSURE(false, "Bootstrap error message missing");
593 sMessage = getFallbackErrorMessage(_rc);
596 // raise the error
597 switch (_rc)
599 case MISSING_BOOTSTRAP_FILE:
600 return uno::makeAny( com::sun::star::configuration::MissingBootstrapFileException(sMessage, _xContext, _sURL) );
602 case INCOMPLETE_BOOTSTRAP_FILE:
603 return uno::makeAny( com::sun::star::configuration::InvalidBootstrapFileException(sMessage, _xContext, _sURL) );
605 default: OSL_ENSURE(false, "Undefined BootstrapResult code");
606 case INCOMPLETE_BOOTSTRAP_DATA:
607 case BOOTSTRAP_FAILURE:
608 return uno::makeAny( com::sun::star::configuration::CannotLoadConfigurationException(sMessage, _xContext) );
610 case BOOTSTRAP_DATA_OK:
611 break;
613 return uno::Any();
615 // ---------------------------------------------------------------------------------------
617 static
618 inline
619 bool urlExists(rtl::OUString const& _sURL)
621 osl::DirectoryItem aCheck;
622 return (osl::DirectoryItem::get(_sURL,aCheck) == osl::DirectoryItem::E_None);
624 // ---------------------------------------------------------------------------------------
626 static
627 rtl::OUString buildBootstrapError( sal_Char const* _sWhat, rtl::OUString const& _sName, sal_Char const* _sHow)
629 rtl::OUStringBuffer sMessage;
631 sMessage.appendAscii(RTL_CONSTASCII_STRINGPARAM("The program cannot start. "));
632 sMessage.appendAscii(_sWhat);
633 sMessage.appendAscii(RTL_CONSTASCII_STRINGPARAM(" '")).append(_sName).appendAscii(RTL_CONSTASCII_STRINGPARAM("' "));
634 sMessage.appendAscii(_sHow).appendAscii(". ");
636 return sMessage.makeStringAndClear();
638 // ---------------------------------------------------------------------------------------
640 BootstrapResult getBootstrapErrorMessage(BootstrapContext const & aContext, ContextReader const & aSettings, rtl::OUString& _rMessage, rtl::OUString& _rIniFile )
642 BootstrapResult eResult = BOOTSTRAP_DATA_OK;
644 _rIniFile = aContext.getBootstrapURL();
646 if ( !urlExists(_rIniFile) )
648 _rMessage = buildBootstrapError("The configuration file ",_rIniFile.copy(1+_rIniFile.lastIndexOf('/')),"is missing");
649 eResult = MISSING_BOOTSTRAP_FILE;
651 else if (!aSettings.isUnoBackend())
653 _rMessage = buildBootstrapError("The configuration file ",_rIniFile.copy(1+_rIniFile.lastIndexOf('/')),"is for an older version of the configuration database");
654 eResult = INCOMPLETE_BOOTSTRAP_FILE;
656 else if (!aSettings.isBootstrapValid() )
658 _rMessage = buildBootstrapError("Needed information to access",rtl::OUString::createFromAscii("application"), "configuration data is missing");
659 eResult = INCOMPLETE_BOOTSTRAP_DATA;
662 return eResult;
664 // ---------------------------------------------------------------------------------------
665 } // anonymous namespace
666 // ---------------------------------------------------------------------------------------
667 uno::Any BootstrapContext::makeBootstrapException()
669 ContextReader aReader(this);
671 if (aReader.isBootstrapValid()) return uno::Any();
673 rtl::OUString sMessage,sURL;
675 BootstrapResult rc = getBootstrapErrorMessage(*this,aReader,sMessage,sURL);
677 return impl_makeBootstrapException(rc,sMessage,sURL,*this);
679 // ---------------------------------------------------------------------------
680 rtl::OUString SAL_CALL
681 BootstrapContext::getImplementationName(void)
682 throw (uno::RuntimeException)
684 return ServiceInfoHelper(&k_BootstrapContextServiceInfo).getImplementationName() ;
686 //------------------------------------------------------------------------------
688 sal_Bool SAL_CALL
689 BootstrapContext::supportsService(const rtl::OUString& aServiceName)
690 throw (uno::RuntimeException)
692 return ServiceInfoHelper(&k_BootstrapContextServiceInfo).supportsService(aServiceName) ;
694 //------------------------------------------------------------------------------
695 uno::Sequence<rtl::OUString> SAL_CALL
696 BootstrapContext::getSupportedServiceNames(void)
697 throw (uno::RuntimeException)
699 return ServiceInfoHelper(&k_BootstrapContextServiceInfo).getSupportedServiceNames() ;
701 // ---------------------------------------------------------------------------------------
702 } // namespace configmgr