summaryrefslogtreecommitdiff
path: root/configmgr/source/misc/bootstrap.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'configmgr/source/misc/bootstrap.cxx')
-rw-r--r--configmgr/source/misc/bootstrap.cxx1703
1 files changed, 500 insertions, 1203 deletions
diff --git a/configmgr/source/misc/bootstrap.cxx b/configmgr/source/misc/bootstrap.cxx
index c8ec2c3814..740ea28a42 100644
--- a/configmgr/source/misc/bootstrap.cxx
+++ b/configmgr/source/misc/bootstrap.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: bootstrap.cxx,v $
*
- * $Revision: 1.25 $
+ * $Revision: 1.26 $
*
- * last change: $Author: jb $ $Date: 2002-10-24 15:44:02 $
+ * last change: $Author: hr $ $Date: 2003-03-19 16:19:22 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -63,9 +63,13 @@
#include "bootstrap.hxx"
-#ifndef CONFIGMGR_SESSIONFACTORY_HXX_
-#include "sessionfactory.hxx"
+#ifndef CONFIGMGR_API_FACTORY_HXX_
+#include "confapifactory.hxx"
#endif
+#ifndef CONFIGMGR_SERVICEINFOHELPER_HXX_
+#include "serviceinfohelper.hxx"
+#endif
+
#ifndef CONFIGMGR_MATCHLOCALE_HXX
#include "matchlocale.hxx"
#endif
@@ -74,6 +78,9 @@
#include "tracer.hxx"
#endif
+#ifndef _CPPUHELPER_COMPONENT_CONTEXT_HXX_
+#include <cppuhelper/component_context.hxx>
+#endif
#ifndef _RTL_BOOTSTRAP_HXX_
#include <rtl/bootstrap.hxx>
#endif
@@ -98,6 +105,9 @@
#include <osl/diagnose.h>
#endif
+#ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_
+#include <com/sun/star/lang/DisposedException.hpp>
+#endif
#ifndef _COM_SUN_STAR_CONFIGURATION_MISSINGBOOTSTRAPFILEEXCEPTION_HPP_
#include <com/sun/star/configuration/MissingBootstrapFileException.hpp>
#endif
@@ -115,1052 +125,648 @@
#endif
// ---------------------------------------------------------------------------------------
-#define BOOTSTRAP_CONFIGMGR_DATA SAL_CONFIGFILE("configmgr")
-// ---------------------------------------------------------------------------------------
-#define SETTING_UNOSERVICE "BackendService"
-#define SETTING_UNOWRAPPER "BackendWrapper"
-#define SETTING_OFFLINE "Offline"
-// ---------------------------------------------------------------------------------------
-// configuration bootstrap items
-#define BOOTSTRAP_ITEM_PREFIX_ "CFG_"
-
-#define BOOTSTRAP_ITEM_SERVERTYPE "CFG_ServerType"
-#define BOOTSTRAP_ITEM_UNOSERVICE BOOTSTRAP_ITEM_PREFIX_ SETTING_UNOSERVICE
-#define BOOTSTRAP_ITEM_UNOWRAPPER BOOTSTRAP_ITEM_PREFIX_ SETTING_UNOWRAPPER
-#define BOOTSTRAP_ITEM_OFFLINE /*BOOTSTRAP_ITEM_PREFIX_*/ SETTING_OFFLINE
-#define BOOTSTRAP_ITEM_LOCALE BOOTSTRAP_ITEM_PREFIX_ "Locale"
-#define BOOTSTRAP_ITEM_ASYNCENABLE BOOTSTRAP_ITEM_PREFIX_ "EnableAsync"
-
-#define BOOTSTRAP_ITEM_SOURCE_PATH "CFG_BaseDataURL"
-#define BOOTSTRAP_ITEM_UPDATE_PATH "CFG_UserDataURL"
-
-#define BOOTSTRAP_ITEM_SERVER "CFG_Server"
-#define BOOTSTRAP_ITEM_TIMEOUT "CFG_Timeout_ms"
-
-#define BOOTSTRAP_ITEM_USER "CFG_User"
-#define BOOTSTRAP_ITEM_PASSWORD "CFG_Password"
-
-#define BOOTSTRAP_ITEM_PROFILE_NAME "CFG_INIFILE"
-
-// ---------------------------------------------------------------------------------------
-// default bootstrap values from an INI ('sregistryrc')
-#define BOOTSTRAP_FROM_PROFILE(sect,key) "${$" BOOTSTRAP_ITEM_PROFILE_NAME ":" sect ":" key "}"
-
-#define BOOTSTRAP_SERVERTYPE_FROM_PROFILE BOOTSTRAP_FROM_PROFILE(SREGISTRY_SECTION_CONFIGURATION,SREGISTRY_KEY_SERVERTYPE)
-#define BOOTSTRAP_UNOSERVICE_FROM_PROFILE BOOTSTRAP_FROM_PROFILE(SREGISTRY_SECTION_CONFIGURATION,BOOTSTRAP_ITEM_UNOSERVICE)
-#define BOOTSTRAP_UNOWRAPPER_FROM_PROFILE BOOTSTRAP_FROM_PROFILE(SREGISTRY_SECTION_CONFIGURATION,BOOTSTRAP_ITEM_UNOWRAPPER)
-
-#define BOOTSTRAP_LOCALE_FROM_PROFILE BOOTSTRAP_FROM_PROFILE(SREGISTRY_SECTION_CONFIGURATION,SREGISTRY_KEY_LOCALE)
-#define BOOTSTRAP_ASYNCENABLE_FROM_PROFILE BOOTSTRAP_FROM_PROFILE(SREGISTRY_SECTION_CONFIGURATION,SREGISTRY_KEY_ASYNC)
-
-#define BOOTSTRAP_SERVER_FROM_PROFILE BOOTSTRAP_FROM_PROFILE(SREGISTRY_SECTION_REMOTE,SREGISTRY_KEY_SERVER)
-#define BOOTSTRAP_TIMEOUT_FROM_PROFILE BOOTSTRAP_FROM_PROFILE(SREGISTRY_SECTION_REMOTE,SREGISTRY_KEY_TIMEOUT)
-
-#define BOOTSTRAP_BASEPATH_FROM_PROFILE BOOTSTRAP_FROM_PROFILE(SREGISTRY_SECTION_LOCAL,SREGISTRY_KEY_SOURCEPATH)
-#define BOOTSTRAP_DATAPATH_FROM_PROFILE BOOTSTRAP_FROM_PROFILE(SREGISTRY_SECTION_LOCAL,SREGISTRY_KEY_UPDATEPATH)
+// legacy argument names
+#define ARGUMENT_LOCALE_COMPAT "locale"
+#define ARGUMENT_ASYNC_COMPAT "lazywrite"
+#define ARGUMENT_SERVERTYPE_COMPAT "servertype"
-#define BOOTSTRAP_USER_FROM_PROFILE BOOTSTRAP_FROM_PROFILE(SREGISTRY_SECTION_AUTHENTICATION,SREGISTRY_KEY_USER)
-#define BOOTSTRAP_PASSWORD_FROM_PROFILE BOOTSTRAP_FROM_PROFILE(SREGISTRY_SECTION_AUTHENTICATION,SREGISTRY_KEY_PASSWORD)
+// legacy servertype setting
+#define SETTING_SERVERTYPE_COMPAT "ServerType"
+#define BOOTSTRAP_SERVERTYPE_COMPAT CONTEXT_ITEM_PREFIX_ SETTING_SERVERTYPE_COMPAT
-// ---------------------------------------------------------------------------------------
-// sections and entries of srgeistryrc
-#define SREGISTRY_SECTION_CONFIGURATION "configuration"
-#define SREGISTRY_KEY_SERVERTYPE "servertype"
-#define SREGISTRY_KEY_SESSIONCLASS "service"
-#define SREGISTRY_KEY_LOCALE "locale"
-#define SREGISTRY_KEY_ASYNC "enable_async"
-
-#define SREGISTRY_SECTION_REMOTE "RemoteRegistry"
-#define SREGISTRY_KEY_SERVER "Server"
-#define SREGISTRY_KEY_TIMEOUT "Timeout"
-
-#define SREGISTRY_SECTION_LOCAL "LocalRegistry"
-#define SREGISTRY_KEY_SOURCEPATH "sourcepath"
-#define SREGISTRY_KEY_UPDATEPATH "updatepath"
-
-#define SREGISTRY_SECTION_AUTHENTICATION "Authentication"
-#define SREGISTRY_KEY_USER "User"
-#define SREGISTRY_KEY_PASSWORD "Password"
-// ---------------------------------------------------------------------------------------
-
-// legacy settings
-#define SETTING_SERVERTYPE "servertype"
-#define SETTING_SESSIONCLASS "_session_class_"
-#define SETTING_LOCALE "locale"
-#define SETTING_ASYNC "lazywrite"
-
-// portal settings
-#define SETTING_SERVICE "service"
-// remote settings
-#define SETTING_SERVER "server"
-#define SETTING_PORT "port"
-#define SETTING_TIMEOUT "timeout"
-// local settings
-#define SETTING_SOURCEPATH "sourcepath"
-#define SETTING_UPDATEPATH "updatepath"
-#define SETTING_REINITIALIZE "reinitialize"
-// authentication settings
-#define SETTING_USER "user"
-#define SETTING_PASSWORD "password"
-// 'option' settings
-
-// ---------------------------------------------------------------------------------------
-#define SERVICE_USERSESSION "configuration"
-#define SERVICE_ADMINSESSION "adminconfiguration"
+#define SERVERTYPE_UNO_COMPAT "uno"
+#define SERVERTYPE_PLUGIN_COMPAT "plugin"
// ---------------------------------------------------------------------------------------
#define NAME( N ) OUString(RTL_CONSTASCII_USTRINGPARAM(N))
#define ITEM( N ) OUString(RTL_CONSTASCII_USTRINGPARAM(N))
// ---------------------------------------------------------------------------------------
+// -------------------------------------------------------------------------
+
+// ---------------------------------------------------------------------------------------
namespace configmgr
{
- using namespace ::com::sun::star::uno;
- using namespace ::com::sun::star::lang;
- using namespace ::com::sun::star::beans;
- namespace uno = ::com::sun::star::uno;
-
// ---------------------------------------------------------------------------------------
- static const sal_Char* pKnownSettings[] =
- {
- SETTING_SERVERTYPE,
- SETTING_USER, SETTING_PASSWORD,
- SETTING_SERVER, SETTING_SERVICE, SETTING_PORT,
- SETTING_TIMEOUT,
- SETTING_LOCALE, SETTING_ASYNC,
- SETTING_SOURCEPATH, SETTING_UPDATEPATH, SETTING_REINITIALIZE,
- SETTING_UNOSERVICE, SETTING_UNOWRAPPER, SETTING_OFFLINE
- };
-
// ---------------------------------------------------------------------------------------
- typedef char const * AsciiString;
+ const sal_Char k_BootstrapContextImplName[] = "com.sun.star.comp.configuration.bootstrap.BootstrapContext" ;
+ const sal_Char k_BootstrapContextServiceName[] = "com.sun.star.configuration.bootstrap.BootstrapContext" ;
- struct SessionClass
+ // -------------------------------------------------------------------------
+ static AsciiServiceName const k_BootstrapContextServiceNames [] =
{
- AsciiString name;
- SessionFactoryFunc create;
+ k_BootstrapContextServiceName,
+ 0
};
-
-// ---------------------------------------------------------------------------------------
- SessionClass const aSessionClasses[] =
- {
- { UNO_SESSION_IDENTIFIER, createNoSession },
- { REMOTE_SESSION_IDENTIFIER, createRemoteSession },
- { LOCAL_SESSION_IDENTIFIER, createLocalSession },
- { PORTAL_SESSION_IDENTIFIER, createPortalSession },
- { SETUP_SESSION_IDENTIFIER, createSetupSession }
+ static const ServiceImplementationInfo k_BootstrapContextServiceInfo =
+ {
+ k_BootstrapContextImplName,
+ k_BootstrapContextServiceNames,
+ 0
+ };
+ static const SingletonRegistrationInfo k_BootstrapContextSingletonInfo =
+ {
+ A_BootstrapContextSingletonName,
+ k_BootstrapContextImplName,
+ k_BootstrapContextServiceName,
+ 0
};
- int const nSessionClasses = sizeof(aSessionClasses)/sizeof(aSessionClasses[0]);
-
-// ---------------------------------------------------------------------------------------
- OUString Settings::Setting::toString() const
- {
- OUString sReturn;
-
- sal_Bool bSuccess = this->m_aValue >>= sReturn;
-
- OSL_ENSURE(bSuccess || !this->m_aValue.hasValue(), "Settings::Setting::toString: setting is not a string!");
-
- return sReturn;
- }
-
// ---------------------------------------------------------------------------------------
- sal_Int32 Settings::Setting::toInt32() const
- {
- sal_Int32 nReturn = 0;
-
- sal_Bool bSuccess = this->m_aValue >>= nReturn;
- if (!bSuccess)
- {
- OUString sValue;
- if (this->m_aValue >>= sValue)
- {
- nReturn = sValue.toInt32();
- bSuccess = (nReturn != 0 );
- }
- }
- OSL_ENSURE(bSuccess || !this->m_aValue.hasValue(), "Settings::getIntSetting: setting is not an integer!");
- return nReturn;
- }
-
// ---------------------------------------------------------------------------------------
- sal_Bool Settings::Setting::toBool() const
+ uno::Reference<uno::XInterface> SAL_CALL
+ instantiateBootstrapContext( CreationContext const& xTargetContext )
{
- sal_Bool bReturn = false;
-
- switch (this->m_aValue.getValueTypeClass())
- {
- case uno::TypeClass_BOOLEAN:
- bReturn = *static_cast<sal_Bool const*>(this->m_aValue.getValue());
- break;
-
- case uno::TypeClass_LONG:
- bReturn = (0 != *static_cast<sal_Int32 const*>(this->m_aValue.getValue()));
- break;
+ CreationContext xContext = UnoContextTunnel::recoverContext(xTargetContext);
- case uno::TypeClass_STRING:
- {
-
- OUString sValue; OSL_VERIFY(this->m_aValue >>= sValue);
- if (sValue.getLength() == 0)
- {
- bReturn = false;
- }
- else if (sValue.equalsIgnoreAsciiCase(OUString::createFromAscii("true")) ||
- sValue.equalsIgnoreAsciiCase(OUString::createFromAscii("yes")) )
- {
- bReturn = true;
- }
- else if (sValue.equalsIgnoreAsciiCase(OUString::createFromAscii("false")) ||
- sValue.equalsIgnoreAsciiCase(OUString::createFromAscii("no")) )
- {
- bReturn = false;
- }
- else
- OSL_ENSURE(false, "Settings::Setting::toBool: string setting is no known bool value name!");
-
- } break;
+ BootstrapContext * pContext = new BootstrapContext(xContext);
+ CreationContext xResult(pContext);
- default:
- OSL_ENSURE(false, "Settings::Setting::toBool: setting is not a boolean!");
- case uno::TypeClass_VOID: // don't assert, if no value
- break;
- }
+ pContext->initialize();
- return bReturn;
+ return xResult;
}
-// ---------------------------------------------------------------------------------------
- Settings::Settings()
+ const SingletonRegistrationInfo * getBootstrapContextSingletonInfo()
{
+ return &k_BootstrapContextSingletonInfo;
}
-
-// ---------------------------------------------------------------------------------------
- Settings::Settings(const Sequence< Any >& _rOverrides, Origin _eOrigin)
+ const ServiceRegistrationInfo * getBootstrapContextServiceInfo()
{
- implAddOverrides(_rOverrides,_eOrigin);
+ return getRegistrationInfo(&k_BootstrapContextServiceInfo);
}
-
// ---------------------------------------------------------------------------------------
- void Settings::mergeOverrides(const Settings& _rOverrides)
+// ---------------------------------------------------------------------------
+
+ static
+ inline
+ cppu::ContextEntry_Init makeEntry(beans::NamedValue const & aOverride)
{
- for (Iterator it = _rOverrides.begin(); it != _rOverrides.end(); ++it)
- {
- m_aImpl[it->first] = it->second;
- }
+ return cppu::ContextEntry_Init(aOverride.Name,aOverride.Value);
}
+// ---------------------------------------------------------------------------
-// ---------------------------------------------------------------------------------------
- void Settings::implAddOverrides(const Sequence< Any >& _rOverrides, Origin _eOrigin)
+ static
+ cppu::ContextEntry_Init makeSingleton(SingletonRegistrationInfo const * pSingletonInfo)
{
- // transfer the runtime overrides
- const sal_Int32 nCount = _rOverrides.getLength();
- OSL_ENSURE(0 <= nCount && nCount <= 0x7FFF, "Unexpected number of arguments");
+ OSL_ASSERT( pSingletonInfo &&
+ pSingletonInfo->singletonName &&
+ pSingletonInfo->instantiatedServiceName );
- Any const * pOverrides = _rOverrides.getConstArray();
- for (sal_Int32 nArg = 0; nArg < nCount; ++nArg)
- {
- OUString sName;
- Any aValue;
-
- if ( implExtractOverride(pOverrides[nArg],sName,aValue) )
- {
- putSetting(sName, Setting(aValue, _eOrigin));
- CFG_TRACE_INFO("provider bootstrapping: runtime parameter: %s", OUSTRING2ASCII(sName));
- }
- else
- {
- CFG_TRACE_ERROR("provider bootstrapping: illegal parameter of type %s", OUSTRING2ASCII(pOverrides[nArg].getValueType().getTypeName()));
- throw IllegalArgumentException(OUString::createFromAscii("Configuration: Provider Creation Argument is not a com.sun.star.beans.PropertyValue or NameValue."), NULL, sal_Int16(nArg));
- }
- }
- }
+ rtl::OUStringBuffer aSingletonName;
+ aSingletonName.appendAscii( RTL_CONSTASCII_STRINGPARAM(SINGLETON_) );
+ aSingletonName.appendAscii(pSingletonInfo->singletonName);
-// ---------------------------------------------------------------------------------------
- bool Settings::implExtractOverride(const Any & _rOverride, Name& _rName, Any& _rValue)
- {
- {
- PropertyValue aCurrentArgPV;
- // it must be a PropertyValue
- if (_rOverride >>= aCurrentArgPV)
- {
- _rName = aCurrentArgPV.Name;
- _rValue = aCurrentArgPV.Value;
-
- return true;
- }
- }
- {
- NamedValue aCurrentArgNV;
- // or a NamedValue
- if (_rOverride >>= aCurrentArgNV)
- {
- _rName = aCurrentArgNV.Name;
- _rValue = aCurrentArgNV.Value;
-
- return true;
- }
- }
+ OUString const aServiceName = OUString::createFromAscii(pSingletonInfo->instantiatedServiceName);
- return false;
+ return cppu::ContextEntry_Init(aSingletonName.makeStringAndClear(), uno::makeAny(aServiceName), true);
}
+// ---------------------------------------------------------------------------
-// ---------------------------------------------------------------------------------------
- static bool isEmptySettingValue(uno::Any const& aAny)
- {
- if (!aAny.hasValue())
- {
- return true;
- }
-
+BootstrapContext::Context BootstrapContext::createWrapper(Context const & _xContext, Overrides const & _aOverrides)
+{
+ std::vector< cppu::ContextEntry_Init > aContextEntries;
+ aContextEntries.reserve(_aOverrides.getLength() + 6);
- // string check
- OUString sStringCheck;
- if (aAny >>= sStringCheck)
- {
- // it's a string - check if empty
- return (0 == sStringCheck.getLength());
- }
+ // marker + bootstrap context
+ aContextEntries.push_back( cppu::ContextEntry_Init(NAME(CONTEXT_ITEM_IS_WRAPPER_CONTEXT), uno::makeAny(sal_True)) );
+ aContextEntries.push_back( cppu::ContextEntry_Init(NAME(CONTEXT_ITEM_IS_BOOTSTRAP_CONTEXT), uno::makeAny(sal_False)) );
- // boolean check - 'false' must be accepted
- if (aAny.getValueType() == ::getBooleanCppuType())
- {
- return false;
- }
+ aContextEntries.push_back( makeSingleton(getBootstrapContextSingletonInfo()) );
- // integer check
- sal_Int32 nIntCheck = 0;
- if (aAny >>= nIntCheck)
- {
- // it's an int - check for zero
- return(0 == nIntCheck);
- }
-
- OSL_ENSURE(false, "Unknown settings type");
- return false; // nevertheless accept
+ // singletons except for passthrough
+ if (!isPassthrough(_xContext))
+ {
+ aContextEntries.push_back( makeSingleton(getDefaultProviderSingletonInfo()) );
+ aContextEntries.push_back( makeSingleton(backend::getDefaultBackendSingletonInfo()) );
+ aContextEntries.push_back( makeSingleton(backend::getDefaultSingleBackendSingletonInfo()) );
}
-// ---------------------------------------------------------------------------------------
- void Settings::putSetting(Name const& _pName, const Setting& _rSetting)
- {
- // catch invalid settings
- if ( ! isEmptySettingValue(_rSetting.value()) )
- {
- m_aImpl[_pName] = _rSetting;
- }
+ for (sal_Int32 i = 0; i<_aOverrides.getLength(); ++i)
+ aContextEntries.push_back( makeEntry(_aOverrides[i]) );
- else
- {
- CFG_TRACE_WARNING("bootstrap: Putting empty setting for '%s'. Will be cleared instead");
- this->clearSetting(_pName);
- }
- }
+ return cppu::createComponentContext(&aContextEntries.front(),aContextEntries.size(),_xContext);
+}
+// ---------------------------------------------------------------------------
-// ---------------------------------------------------------------------------------------
- void Settings::clearSetting(Name const& _pName)
- {
- m_aImpl.erase(_pName);
- }
+sal_Bool BootstrapContext::isWrapper(Context const & _xContext)
+{
+ OSL_ASSERT(_xContext.is());
+ if (!_xContext.is()) return false;
-// ---------------------------------------------------------------------------------------
- sal_Bool Settings::haveSetting(Name const& _pName) const
- {
- Iterator aPos = m_aImpl.find(_pName);
+ uno::Any aSetting = _xContext->getValueByName( NAME(CONTEXT_ITEM_IS_WRAPPER_CONTEXT) );
- // have a setting at all ?
- return (aPos != m_aImpl.end());
- }
+ if (!aSetting.hasValue()) return false;
-// ---------------------------------------------------------------------------------------
- Settings::Origin Settings::getOrigin(Name const& _pName) const
- {
- Iterator aPos = m_aImpl.find(_pName);
-
- // have a setting at all ?
- return (aPos != m_aImpl.end()) ? aPos->second.origin() : SO_NOT_SET;
- }
+ sal_Bool bValue = false;
+ OSL_VERIFY(aSetting >>= bValue);
-// ---------------------------------------------------------------------------------------
- Settings::Setting Settings::getMaybeSetting(Name const& _pName) const
- {
- Iterator aPos = m_aImpl.find(_pName);
+ return bValue;
+}
+// ---------------------------------------------------------------------------
+// ---------------------------------------------------------------------------
- if (aPos != m_aImpl.end())
- return aPos->second;
+BootstrapContext::BootstrapContext(Context const & _xContext)
+: ComponentContext(_xContext)
+{
+}
+// ---------------------------------------------------------------------------
- else
- return Setting();
- }
+BootstrapContext::~BootstrapContext()
+{
+}
+// ---------------------------------------------------------------------------
-// ---------------------------------------------------------------------------------------
- Settings::Setting Settings::getSetting(Name const& _pName) const
+void BootstrapContext::initialize()
+{
+ // get default Bootstrap URL
+ OUString sURL;
+ uno::Any aExplicitURL;
+ if ( this->lookupInContext(aExplicitURL,NAME(CONTEXT_ITEM_PREFIX_ SETTING_INIFILE)) )
{
- OSL_ENSURE(haveSetting(_pName), "Settings::getSetting: don't have the requested setting!");
- return getMaybeSetting(_pName);
+ OSL_VERIFY(aExplicitURL >>= sURL);
}
-
-// ---------------------------------------------------------------------------------------
- OUString Settings::getStringSetting(Name const& _pName) const
+ else if (!rtl::Bootstrap::get(NAME(BOOTSTRAP_ITEM_INIFILE),sURL))
{
- Setting aSetting = this->getSetting(_pName);
-
- return aSetting.toString();
+ sURL = getDefaultConfigurationBootstrapURL();
}
-// ---------------------------------------------------------------------------------------
- sal_Int32 Settings::getIntSetting(Name const& _pName) const
- {
- Setting aSetting = this->getSetting(_pName);
-
- return aSetting.toInt32();
- }
+ ComponentContext::initialize(sURL);
+}
+// ---------------------------------------------------------------------------
-// ---------------------------------------------------------------------------------------
- sal_Bool Settings::getBoolSetting(Name const& _pName) const
+static OUString getCurrentModuleDirectory() // URL including terminating slash
+{
+ OUString aFileURL;
+ if ( !osl::Module::getUrlFromAddress((void*)&getCurrentModuleDirectory,aFileURL) )
{
- Setting aSetting = this->getSetting(_pName);
+ OSL_TRACE(false, "Cannot locate current module - using executable instead");
- return aSetting.toBool();
+ OSL_VERIFY(osl_Process_E_None == osl_getExecutableFile(&aFileURL.pData));
}
-// ---------------------------------------------------------------------------------------
- ConnectionSettings::ConnectionSettings(const uno::Sequence< uno::Any >& _rOverrides,
- Settings::Origin _eOrigin)
- : m_aSettings(_rOverrides, _eOrigin)
- {
- // translate compatibility and special settings
- implNormalizeSettings();
- }
+ OSL_ENSURE(0 < aFileURL.lastIndexOf('/'), "Cannot find directory for module URL");
+ return aFileURL.copy(0, aFileURL.lastIndexOf('/') + 1);
+}
// ---------------------------------------------------------------------------------------
-
- uno::Sequence< beans::NamedValue > ConnectionSettings::getUnoSettings() const
- {
- uno::Sequence< beans::NamedValue > aResult( m_aSettings.size() );
- beans::NamedValue * p = aResult.getArray();
+OUString BootstrapContext::getDefaultConfigurationBootstrapURL()
+{
+ return getCurrentModuleDirectory() + OUString(RTL_CONSTASCII_USTRINGPARAM(CONFIGMGR_INIFILE));
+}
+// ---------------------------------------------------------------------------------------
- for ( Settings::Iterator it = m_aSettings.begin(); it != m_aSettings.end(); ++it )
- {
- p->Name = it->first;
- p->Value = it->second.value();
- ++p;
- }
+OUString BootstrapContext::makeContextName(OUString const & _aName)
+{
+ // check that it isn't long already
+ OSL_ENSURE(!_aName.matchIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM(CONTEXT_MODULE_PREFIX_) ),
+ "configmgr::BootstrapContext: passing argument in long context form won't work");
- OSL_ASSERT(p - aResult.getConstArray() == aResult.getLength());
+ return NAME(CONTEXT_ITEM_PREFIX_).concat(_aName);
+}
+// ---------------------------------------------------------------------------
- return aResult;
+OUString BootstrapContext::makeBootstrapName(OUString const & _aName)
+{
+ // check if already is short
+ if (!_aName.matchIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM(CONTEXT_ITEM_PREFIX_) ) )
+ {
+ OSL_TRACE( "configmgr: Cannot map name to bootstrap name: %s",
+ rtl::OUStringToOString(_aName,RTL_TEXTENCODING_ASCII_US).getStr() );
+ return _aName;
}
-// ---------------------------------------------------------------------------------------
+ return NAME(BOOTSTRAP_ITEM_PREFIX_).concat(_aName.copy(RTL_CONSTASCII_LENGTH(CONTEXT_ITEM_PREFIX_)));
+}
+// ---------------------------------------------------------------------------
+
+uno::Any SAL_CALL
+ BootstrapContext::getValueByName( const OUString& aName )
+ throw (uno::RuntimeException)
+{
+ sal_Bool const bOurName = aName.matchIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM(CONTEXT_MODULE_PREFIX_) );
- void ConnectionSettings::setSessionType(const OUString& _rSessionIdentifier, Settings::Origin _eOrigin)
+ if (bOurName)
{
- putSetting(NAME(SETTING_SERVERTYPE), Settings::Setting(_rSessionIdentifier, _eOrigin));
- }
+ if (aName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(CONTEXT_ITEM_BOOTSTRAP_ERROR) ) )
+ return this->makeBootstrapException();
-// ---------------------------------------------------------------------------------------
- void ConnectionSettings::setService(const OUString& _rService, Settings::Origin _eOrigin)
+ if (aName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(CONTEXT_ITEM_PREFIX_ SETTING_INIFILE) ) )
+ return uno::makeAny( this->getBootstrapURL() );
+
+ if (aName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(CONTEXT_ITEM_IS_BOOTSTRAP_CONTEXT) ) )
+ return uno::makeAny( sal_True );
+ }
+ else if (aName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(SINGLETON_ A_BootstrapContextSingletonName) ) )
{
- putSetting(NAME(SETTING_SERVICE), Settings::Setting(_rService, _eOrigin));
+ return uno::makeAny( Context(this) );
}
-// ---------------------------------------------------------------------------------------
- sal_Bool ConnectionSettings::isSessionTypeKnown() const { return haveSetting(NAME(SETTING_SERVERTYPE)); }
- sal_Bool ConnectionSettings::hasUnoBackendService() const { return haveSetting(NAME(SETTING_UNOSERVICE)); }
- sal_Bool ConnectionSettings::hasUnoBackendWrapper() const { return haveSetting(NAME(SETTING_UNOWRAPPER)); }
- sal_Bool ConnectionSettings::hasUser() const { return haveSetting(NAME(SETTING_USER)); }
- sal_Bool ConnectionSettings::hasPassword() const { return haveSetting(NAME(SETTING_PASSWORD)); }
- sal_Bool ConnectionSettings::hasLocale() const { return haveSetting(NAME(SETTING_LOCALE)); }
- sal_Bool ConnectionSettings::hasServer() const { return haveSetting(NAME(SETTING_SERVER)); }
- sal_Bool ConnectionSettings::hasService() const { return haveSetting(NAME(SETTING_SERVICE)); }
- sal_Bool ConnectionSettings::hasPort() const { return haveSetting(NAME(SETTING_PORT)); }
- sal_Bool ConnectionSettings::hasTimeout() const { return haveSetting(NAME(SETTING_TIMEOUT)); }
- sal_Bool ConnectionSettings::hasAsyncSetting() const { return haveSetting(NAME(SETTING_ASYNC)); }
- sal_Bool ConnectionSettings::hasOfflineSetting() const { return haveSetting(NAME(SETTING_OFFLINE)); }
- sal_Bool ConnectionSettings::hasReinitializeFlag() const { return haveSetting(NAME(SETTING_REINITIALIZE)); }
+ uno::Any aResult;
-// ---------------------------------------------------------------------------------------
- OUString ConnectionSettings::getSessionType() const { return m_aSettings.getStringSetting(NAME(SETTING_SERVERTYPE)); }
- OUString ConnectionSettings::getUnoBackendService() const { return m_aSettings.getStringSetting(NAME(SETTING_UNOSERVICE)); }
- OUString ConnectionSettings::getUnoBackendWrapper() const { return m_aSettings.getStringSetting(NAME(SETTING_UNOWRAPPER)); }
- OUString ConnectionSettings::getUser() const { return m_aSettings.getStringSetting(NAME(SETTING_USER)); }
- OUString ConnectionSettings::getPassword() const { return m_aSettings.getStringSetting(NAME(SETTING_PASSWORD)); }
- OUString ConnectionSettings::getLocale() const { return m_aSettings.getStringSetting(NAME(SETTING_LOCALE)); }
- OUString ConnectionSettings::getSourcePath() const { return m_aSettings.getStringSetting(NAME(SETTING_SOURCEPATH)); }
- OUString ConnectionSettings::getUpdatePath() const { return m_aSettings.getStringSetting(NAME(SETTING_UPDATEPATH)); }
- OUString ConnectionSettings::getServer() const { return m_aSettings.getStringSetting(NAME(SETTING_SERVER)); }
- OUString ConnectionSettings::getService() const { return m_aSettings.getStringSetting(NAME(SETTING_SERVICE)); }
- sal_Int32 ConnectionSettings::getPort() const { return m_aSettings.getIntSetting(NAME(SETTING_PORT)); }
- sal_Int32 ConnectionSettings::getTimeout() const { return m_aSettings.getIntSetting(NAME(SETTING_TIMEOUT)); }
- sal_Bool ConnectionSettings::getAsyncSetting() const { return m_aSettings.getBoolSetting(NAME(SETTING_ASYNC)); }
- sal_Bool ConnectionSettings::getOfflineSetting() const { return m_aSettings.getBoolSetting(NAME(SETTING_OFFLINE)); }
- sal_Bool ConnectionSettings::getReinitializeFlag() const { return m_aSettings.getBoolSetting(NAME(SETTING_REINITIALIZE)); }
+ bool bFound = lookupInContext ( aResult, aName );
-// ---------------------------------------------------------------------------------------
- sal_Bool ConnectionSettings::isSourcePathValid() const
+ if (!bFound && bOurName) // requires: CONTEXT_ITEM_PREFIX_ starts with CONTEXT_MODULE_PREFIX_
{
- return haveSetting(NAME(SETTING_SOURCEPATH));
+ if ( aName.matchIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM(CONTEXT_ITEM_PREFIX_) ) )
+ {
+ bFound = lookupInBootstrap( aResult, makeBootstrapName(aName) );
+ }
}
-
-// ---------------------------------------------------------------------------------------
- sal_Bool ConnectionSettings::isUpdatePathValid() const
+#if 0
+ if (!bFound && bOurName)
{
- return haveSetting(NAME(SETTING_UPDATEPATH));
+ OSL_TRACE( "configmgr: Cannot find bootstrap data item: %s",
+ rtl::OUStringToOString(aName,RTL_TEXTENCODING_ASCII_US).getStr() );
}
+#endif
+ return aResult;
+}
+// ---------------------------------------------------------------------------
-// ---------------------------------------------------------------------------------------
- static inline bool isValidFileURL(OUString const& _sFileURL)
+#if 0
+uno::Any BootstrapContext::makeDefaultProvider()
+{
{
- using osl::File;
-
- OUString sSystemPath;
- return _sFileURL.getLength() && (File::E_None == File::getSystemPathFromFileURL(_sFileURL, sSystemPath));
+ osl::MutexGuard lock(mutex());
+ if (m_xDefaultProvider.is())
+ return uno::makeAny(m_xDefaultProvider);
}
-// ---------------------------------------------------------------------------------------
- static
- bool implEnsureAbsoluteURL(OUString & _rsURL) // also strips embedded dots etc.
- {
- using osl::File;
- OUString sBasePath = _rsURL;
- OSL_VERIFY(osl_Process_E_None == osl_getProcessWorkingDir(&sBasePath.pData));
+ if (isPassthrough())
+ {
+ Context xDelegate = basecontext();
+ if (!xDelegate.is())
+ throw lang::DisposedException(NAME("BootstrapContext: No base context"),*this);
- OUString sAbsolute;
- if ( File::E_None == File::getAbsoluteFileURL(sBasePath, _rsURL, sAbsolute))
+ uno::Any aResult = xDelegate->getValueByName( SINGLETON(A_DefaultProviderSingletonName) );
+
+ osl::MutexGuard relock(mutex());
+ if (!m_xDefaultProvider.is())
{
- _rsURL = sAbsolute;
- return true;
+ aResult >>= m_xDefaultProvider;
+ return aResult;
}
else
- {
- OSL_ENSURE(false, "Could not get absolute file URL for valid URL");
- return false;
- }
+ return uno::makeAny(m_xDefaultProvider);
}
-// ---------------------------------------------------------------------------------------
-
- static
- bool implNormalizeURL(OUString const & _sPathOrURL, OUString& _rsURL)
+ else
{
- using osl::File;
-
- OUString sOther;
-
- bool bURL = false;
+ ServiceManager xMgr = this->getServiceManager();
+ if (!xMgr.is())
+ throw lang::DisposedException(NAME("BootstrapContext: No service factory"),*this);
- // if empty, clear _rsURL, but return false
- if (_sPathOrURL.getLength() == 0)
+ try
{
- _rsURL = _sPathOrURL;
- bURL = false;
- }
+ uno::Reference<uno::XInterface> xDefaultProvider = xMgr->createInstanceWithContext(NAME(A_DefaultProviderServiceAndImplName),this);
+
+ osl::MutexGuard relock(mutex());
+ if (!m_xDefaultProvider.is())
+ m_xDefaultProvider = xDefaultProvider;
- // check if it already was normalized
- else if ( File::E_None == File::getSystemPathFromFileURL(_sPathOrURL, sOther) )
- {
- _rsURL = _sPathOrURL;
- bURL = true;
+ return uno::makeAny(m_xDefaultProvider);
}
-
- // allow for system pathes
- else if ( File::E_None == File::getFileURLFromSystemPath(_sPathOrURL, sOther) )
- {
- CFG_TRACE_WARNING_NI("provider bootstrapping: URL was specified as system path '%s'.", OUSTRING2ASCII(_sPathOrURL));
- _rsURL = sOther;
- bURL = true;
+ catch (uno::RuntimeException &) { throw; }
+ catch (uno::Exception & )
+ {
+ throw uno::RuntimeException(NAME("BootstrapContext:Exception occurred while instantiating DefaultProvider"),*this);
}
-
- else
- bURL = false;
-
- return bURL && implEnsureAbsoluteURL(_rsURL);
}
-// ---------------------------------------------------------------------------------------
- bool ConnectionSettings::implNormalizePathSetting(Settings::Name const& _pSetting)
- {
- using osl::File;
-
- if (!haveSetting(_pSetting))
- return false;
-
- Settings::Setting aSetting = getSetting(_pSetting);
+}
+// ---------------------------------------------------------------------------
- OUString const sValue = aSetting.toString();
+uno::Any BootstrapContext::makeDefaultBackend()
+{
+ {
+ osl::MutexGuard lock(mutex());
+ if (m_xDefaultBackend.is())
+ return uno::makeAny(m_xDefaultBackend);
+ }
- OUString sNormalized;
+ if (isPassthrough())
+ {
+ Context xDelegate = basecontext();
+ if (!xDelegate.is())
+ throw lang::DisposedException(NAME("BootstrapContext: No base context"),*this);
- if ( implNormalizeURL(sValue,sNormalized) )
+ uno::Any aResult = xDelegate->getValueByName( SINGLETON(K_DefaultBackendSingletonName) );
+
+ osl::MutexGuard relock(mutex());
+ if (!m_xDefaultBackend.is())
{
- putSetting(_pSetting, Settings::Setting(sNormalized,aSetting.origin()) );
- return true;
+ aResult >>= m_xDefaultBackend;
+ return aResult;
}
else
- {
- CFG_TRACE_ERROR_NI("provider bootstrapping: could not normalize URL (setting: %s, value: %s).", OUSTRING2ASCII(_pSetting), OUSTRING2ASCII(sValue));
- clearSetting(_pSetting);
- return false;
- }
+ return uno::makeAny(m_xDefaultBackend);
}
-
-// ---------------------------------------------------------------------------------------
- bool ConnectionSettings::checkSettings() const
+ else
{
- bool bCheckResult = true;
+ ServiceManager xMgr = this->getServiceManager();
+ if (!xMgr.is())
+ throw lang::DisposedException(NAME("BootstrapContext: No service factory"),*this);
- #if 0 // defined(_DEBUG) || defined(CFG_ENABLE_TRACING)
- const int cKnownSettingsCount = sizeof(pKnownSettings)/sizeof(pKnownSettings[0]);
-
- // check if we know all the settings
- for ( Settings::Iterator aCheck = m_aSettings.begin();
- aCheck != m_aSettings.end();
- ++aCheck
- )
+ try
{
- bool bRecognized = false;
- for (sal_Int32 i=0; i<cKnownSettingsCount; ++i)
- {
- if (aCheck->first.equalsAscii(pKnownSettings[i]))
- {
- bRecognized = true;
- break;
- }
- }
-
- if (!bRecognized)
- {
- OSL_ENSURE(bRecognized, "Configuration: unknown provider parameter\n");
- CFG_TRACE_WARNING_NI("provider bootstrapping: unrecognized parameter found: %s", aCheck->first.getStr() );
- bCheckResult = false;
- }
+ uno::Reference<uno::XInterface> xDefaultBackend = xMgr->createInstanceWithContext(NAME(K_DefaultBackendServiceAndImplName),this);
+
+ osl::MutexGuard relock(mutex());
+ if (!m_xDefaultBackend.is())
+ m_xDefaultBackend = xDefaultBackend;
+ return uno::makeAny(m_xDefaultBackend);
+ }
+ catch (uno::RuntimeException &) { throw; }
+ catch (uno::Exception & )
+ {
+ throw uno::RuntimeException(NAME("BootstrapContext:Exception occurred while instantiating DefaultBackend"),*this);
}
- #endif
-
- return bCheckResult;
- }
-
-// ---------------------------------------------------------------------------------------
- bool ConnectionSettings::validate()
- {
- checkSettings();
-
- // determine the session type
- implDetermineSessionType();
-
- return implDetermineSessionType() && isComplete( getSessionType() );
}
+}
+// ---------------------------------------------------------------------------
-// ---------------------------------------------------------------------------------------
- bool ConnectionSettings::isComplete() const
+uno::Any BootstrapContext::makeDefaultSingleBackend()
+{
{
- return isSessionTypeKnown() && ! isPlugin() && isComplete(getSessionType());
+ osl::MutexGuard lock(mutex());
+ if (m_xDefaultSingleBackend.is())
+ return uno::makeAny(m_xDefaultSingleBackend);
}
-// ---------------------------------------------------------------------------------------
- bool ConnectionSettings::isComplete(OUString const& sSessionType) const
+ if (isPassthrough())
{
- if( (0 == sSessionType.compareToAscii(LOCAL_SESSION_IDENTIFIER)) ||
- (0 == sSessionType.compareToAscii(SETUP_SESSION_IDENTIFIER)) )
- {
- // local sessions needs a source path
- return !! isSourcePathValid();
- }
+ Context xDelegate = basecontext();
+ if (!xDelegate.is())
+ throw lang::DisposedException(NAME("BootstrapContext: No base context"),*this);
- else if(0 == sSessionType.compareToAscii(UNO_SESSION_IDENTIFIER) )
+ uno::Any aResult = xDelegate->getValueByName( SINGLETON(K_DefaultSingleBackendSingletonName) );
+
+ osl::MutexGuard relock(mutex());
+ if (!m_xDefaultSingleBackend.is())
{
- // cannot check backend-specific arguments here
- return hasUnoBackendService() ||
- hasUnoBackendWrapper() && hasOfflineSetting() && getOfflineSetting();
+ aResult >>= m_xDefaultSingleBackend;
+ return aResult;
}
+ else
+ return uno::makeAny(m_xDefaultSingleBackend);
+ }
+ else
+ {
+ ServiceManager xMgr = this->getServiceManager();
+ if (!xMgr.is())
+ throw lang::DisposedException(NAME("BootstrapContext: No service factory"),*this);
- else if(0 == sSessionType.compareToAscii(PORTAL_SESSION_IDENTIFIER) )
+ try
{
- return true;
- }
+ uno::Reference<uno::XInterface> xDefaultSingleBackend = xMgr->createInstanceWithContext(NAME(K_DefaultSingleBackendServiceAndImplName),this);
+
+ osl::MutexGuard relock(mutex());
+ if (!m_xDefaultSingleBackend.is())
+ m_xDefaultSingleBackend = xDefaultSingleBackend;
- else if(0 == sSessionType.compareToAscii(REMOTE_SESSION_IDENTIFIER) )
- {
- // remote sessions needs a server (and a user ?)
- return hasServer() && hasUser();
+ return uno::makeAny(m_xDefaultSingleBackend);
}
- else
- {
- OSL_ENSURE(0 == sSessionType.compareToAscii(PLUGIN_SESSION_IDENTIFIER),
- "Unknown session type, cannot determine validity of settings");
- return false; // assume false
+ catch (uno::RuntimeException &) { throw; }
+ catch (uno::Exception & )
+ {
+ throw uno::RuntimeException(NAME("BootstrapContext:Exception occurred while instantiating DefaultSingleBackend"),*this);
}
-
}
-
-// ---------------------------------------------------------------------------------------
- void ConnectionSettings::implMergeOverrides(const Settings& _rOverrides)
+}
+// ---------------------------------------------------------------------------
+#endif
+// ---------------------------------------------------------------------------
+// class ContextReader
+// ---------------------------------------------------------------------------
+
+ ContextReader::ContextReader(Context const & context)
+ : m_basecontext(context)
+ , m_fullcontext()
{
- // update path validity depends on data in its base source path
- if (_rOverrides.haveSetting(NAME(SETTING_SOURCEPATH)))
+ OSL_ENSURE(context.is(), "ERROR: trying to create reader on NULL context\n");
+ if (context.is())
{
- this->clearSetting(NAME(SETTING_SOURCEPATH));
- this->clearSetting(NAME(SETTING_UPDATEPATH));
+ uno::Any aBootstrapContext = context->getValueByName( SINGLETON(A_BootstrapContextSingletonName) );
+ aBootstrapContext >>= m_fullcontext;
}
+ }
+// ---------------------------------------------------------------------------
- // port is only valid relative to server (and may even be part of the server setting)
- if (_rOverrides.haveSetting(NAME(SETTING_SERVER)))
- {
- this->clearSetting(NAME(SETTING_SERVER));
- this->clearSetting(NAME(SETTING_PORT));
- }
+ uno::Reference< lang::XMultiComponentFactory > ContextReader::getServiceManager() const
+ {
+ OSL_ASSERT(m_basecontext.is());
+ return m_basecontext->getServiceManager();
+ }
+// ---------------------------------------------------------------------------
+ inline
+ uno::Any ContextReader::getSetting(OUString const & _aSetting) const
+ {
+ OSL_ASSERT(m_basecontext.is());
+ return getBestContext()->getValueByName(_aSetting);
+ }
- // if changing the user, password must be changed as well
- if (_rOverrides.haveSetting(NAME(SETTING_USER)))
- {
- this->clearSetting(NAME(SETTING_USER));
- this->clearSetting(NAME(SETTING_PASSWORD));
- }
+ inline
+ sal_Bool ContextReader::hasSetting(OUString const & _aSetting) const
+ {
+ return getSetting(_aSetting).hasValue();
+ }
- m_aSettings.mergeOverrides(_rOverrides);
+ inline
+ sal_Bool ContextReader::getBoolSetting(OUString const & _aSetting, sal_Bool bValue = false) const
+ {
+ getSetting(_aSetting) >>= bValue;
+ return bValue;
}
+ inline
+ OUString ContextReader::getStringSetting(OUString const & _aSetting, OUString aValue = OUString()) const
+ {
+ getSetting(_aSetting) >>= aValue;
+ return aValue;
+ }
// ---------------------------------------------------------------------------------------
- void ConnectionSettings::implNormalizeRemoteServer()
+
+ sal_Bool ContextReader::isUnoBackend() const
{
- Settings::Name const sServerSetting = NAME(SETTING_SERVER);
- Settings::Name const sPortSetting = NAME(SETTING_PORT);
-
- if (haveSetting(sServerSetting) && !haveSetting(sPortSetting))
+ OUString aSettingName = NAME(BOOTSTRAP_SERVERTYPE_COMPAT);
+
+ OUString aValue;
+ if (getSetting(aSettingName) >>= aValue)
{
- Settings::Setting aServerData = getSetting(sServerSetting);
-
- OUString sServerAndPort = aServerData.toString();
-
- // there was such an entry
- const sal_Int32 nColon = sServerAndPort.lastIndexOf(':');
- if (0 <= nColon)
- {
- if (sal_Int32 nPort = sServerAndPort.copy(nColon+1).toInt32())
- {
- OUString sServer = sServerAndPort.copy(0, nColon);
-
- Settings::Origin eOrigin = aServerData.origin();
- putSetting(sServerSetting, Settings::Setting(sServer, eOrigin));
- putSetting(sPortSetting, Settings::Setting(nPort, eOrigin));
- }
- }
+ return aValue.equalsAscii(SERVERTYPE_UNO_COMPAT);
+ }
+ else
+ {
+ return true;
}
-
}
// ---------------------------------------------------------------------------------------
- void ConnectionSettings::implNormalizeSettings()
+
+ sal_Bool ContextReader::hasUnoBackendService() const
{
- implNormalizePathSetting(NAME(SETTING_SOURCEPATH));
- implNormalizePathSetting(NAME(SETTING_UPDATEPATH));
-
- implNormalizeRemoteServer();
+ return hasSetting( NAME(CONTEXT_ITEM_PREFIX_ SETTING_UNOSERVICE) );
}
-
-// ---------------------------------------------------------------------------------------
- bool ConnectionSettings::implDetermineSessionType()
+ sal_Bool ContextReader::hasUnoBackendWrapper() const
{
- Settings::Name const sSettingServertype = NAME(SETTING_SERVERTYPE);
- if (!haveSetting(sSettingServertype))
- { // we already have the setting
- CFG_TRACE_INFO("provider bootstrapping: no session type. looking for fallback");
-
- char const * psSessionType = NULL;
- if (haveSetting(NAME(SETTING_UNOSERVICE)))
- {
- psSessionType = UNO_SESSION_IDENTIFIER;
- }
- else if (haveSetting(NAME(SETTING_SOURCEPATH)) && haveSetting(NAME(SETTING_UPDATEPATH)))
- {
- psSessionType = LOCAL_SESSION_IDENTIFIER;
- }
- else if (haveSetting(NAME(SETTING_SERVER)))
- {
- psSessionType = REMOTE_SESSION_IDENTIFIER;
- }
- else if (haveSetting(NAME(SETTING_SERVICE)))
- {
- psSessionType = PORTAL_SESSION_IDENTIFIER;
- }
- else
- {
- CFG_TRACE_WARNING_NI("provider bootstrapping: cannot determine session type"
- "- using fallback to '"UNO_SESSION_IDENTIFIER"'");
- psSessionType = PORTAL_SESSION_IDENTIFIER;
- }
-
- if (!psSessionType)
- {
- CFG_TRACE_WARNING_NI("provider bootstrapping: cannot determine session type");
- return false;
- }
-
- OUString sSessionType = OUString::createFromAscii(psSessionType);
- putSetting(sSettingServertype, Settings::Setting(sSessionType, Settings::SO_FALLBACK));
- }
- CFG_TRACE_INFO_NI("provider bootstrapping: using session type: %s",
- OUSTRING2ASCII(m_aSettings.getStringSetting(sSettingServertype)));
-
- return true;
+ return hasSetting( NAME(CONTEXT_ITEM_PREFIX_ SETTING_UNOWRAPPER) );
}
-// ---------------------------------------------------------------------------------------
-
- bool ConnectionSettings::isUnoBackend() const
+ sal_Bool ContextReader::hasLocale() const
{
- if (!isSessionTypeKnown()) return false;
-
- OUString const sSessionType = getSessionType();
- return (0 == sSessionType.compareToAscii(UNO_SESSION_IDENTIFIER));
+ return hasSetting( NAME(CONTEXT_ITEM_PREFIX_ SETTING_LOCALE_NEW) );
+ }
+ sal_Bool ContextReader::hasAsyncSetting() const
+ {
+ return hasSetting( NAME(CONTEXT_ITEM_PREFIX_ SETTING_ASYNC_NEW) );
+ }
+ sal_Bool ContextReader::hasOfflineSetting() const
+ {
+ return hasSetting( NAME(CONTEXT_ITEM_PREFIX_ SETTING_OFFLINE) );
}
// ---------------------------------------------------------------------------------------
- sal_Bool ConnectionSettings::isPlugin() const
- {
- if (!isSessionTypeKnown()) return false;
- OUString const sSessionType = getSessionType();
- return (0 == sSessionType.compareToAscii(PLUGIN_SESSION_IDENTIFIER));
-
+ OUString ContextReader::getUnoBackendService() const
+ {
+ return getStringSetting( NAME(CONTEXT_ITEM_PREFIX_ SETTING_UNOSERVICE) );
}
-
-// ---------------------------------------------------------------------------------------
- sal_Bool ConnectionSettings::isLocalSession() const
- {
- if (!isSessionTypeKnown()) return false;
-
- OUString const sSessionType = getSessionType();
- return (0 == sSessionType.compareToAscii(LOCAL_SESSION_IDENTIFIER)) ||
- (0 == sSessionType.compareToAscii(SETUP_SESSION_IDENTIFIER));
-
+ OUString ContextReader::getUnoBackendWrapper() const
+ {
+ return getStringSetting( NAME(CONTEXT_ITEM_PREFIX_ SETTING_UNOWRAPPER) );
}
-// ---------------------------------------------------------------------------------------
- sal_Bool ConnectionSettings::isRemoteSession() const
- {
- if (!isSessionTypeKnown()) return false;
-
- OUString const sSessionType = getSessionType();
- return (0 == sSessionType.compareToAscii(PORTAL_SESSION_IDENTIFIER)) ||
- (0 == sSessionType.compareToAscii(REMOTE_SESSION_IDENTIFIER));
-
+ OUString ContextReader::getLocale() const
+ {
+ return getStringSetting( NAME(CONTEXT_ITEM_PREFIX_ SETTING_LOCALE_NEW) );
}
-
-// ---------------------------------------------------------------------------------------
- sal_Bool ConnectionSettings::isServiceRequired() const
- {
- OUString const sSessionType = getSessionType();
- return (0 == sSessionType.compareToAscii(PORTAL_SESSION_IDENTIFIER));
-
+ sal_Bool ContextReader::getAsyncSetting() const
+ {
+ return getBoolSetting( NAME(CONTEXT_ITEM_PREFIX_ SETTING_ASYNC_NEW) );
+ }
+ sal_Bool ContextReader::getOfflineSetting() const
+ {
+ return getBoolSetting( NAME(CONTEXT_ITEM_PREFIX_ SETTING_OFFLINE) );
}
-// ---------------------------------------------------------------------------------------
-
- sal_Bool ConnectionSettings::isAdminSession() const
+ // get a special setting
+ sal_Bool ContextReader::isAdminService() const
{
- OSL_ENSURE(haveSetting(NAME(SETTING_SESSIONCLASS)),"Cannot determine session class");
+ return getBoolSetting( NAME(CONTEXT_ITEM_ADMINFLAG) );
+ }
- return getSetting(NAME(SETTING_SESSIONCLASS)).toString().equalsAscii(SERVICE_ADMINSESSION);
+ sal_Bool ContextReader::isBootstrapValid() const
+ {
+ return this->isUnoBackend() &&
+ this->hasUnoBackendService() &&
+ (this->hasUnoBackendWrapper() || !this->getOfflineSetting());
+ }
+ uno::Any ContextReader::getBootstrapError() const
+ {
+ return getSetting( NAME(CONTEXT_ITEM_BOOTSTRAP_ERROR) );
}
// ---------------------------------------------------------------------------------------
- void ConnectionSettings::setUserSession()
+ bool ContextReader::isBootstrapContext(Context const & _xContext)
{
- OSL_ENSURE(isUnoBackend() || isLocalSession() || isRemoteSession(),"Invalid/No session type for user session");
- OSL_ENSURE(getSessionType().compareToAscii(SETUP_SESSION_IDENTIFIER) != 0, "WARNING: Explicit creation of 'setup' sessions is obsolete. Create 'AdministrationProvider' service instead");
-
- OUString const sService( RTL_CONSTASCII_USTRINGPARAM(SERVICE_USERSESSION) );
+ OSL_ASSERT(_xContext.is());
+ if (!_xContext.is()) return false;
- if( !hasService() && isServiceRequired() )
- {
- CFG_TRACE_INFO("No service set for user session. Using default service '%s'",OUSTRING2ASCII(sService));
-
- this->setService(sService, Settings::SO_DEFAULT);
- }
-
- if ( !hasAsyncSetting() )
- {
- Any aDefaultAsync = makeAny(sal_Bool(true));
- putSetting( NAME(SETTING_ASYNC), Settings::Setting(aDefaultAsync, Settings::SO_DEFAULT) );
- OSL_ASSERT( hasAsyncSetting() && getAsyncSetting() );
- }
-
- putSetting(NAME(SETTING_SESSIONCLASS),Settings::Setting(sService, Settings::SO_DEFAULT));
+ uno::Any aSetting = _xContext->getValueByName( NAME(CONTEXT_ITEM_IS_BOOTSTRAP_CONTEXT) );
+
+ sal_Bool bValue = false;
+ return (aSetting >>= bValue) && bValue;
}
+// ---------------------------------------------------------------------------
-// ---------------------------------------------------------------------------------------
- void ConnectionSettings::setAdminSession()
+ bool ContextReader::testAdminService(Context const & context, bool bAdmin)
{
- OSL_ENSURE(isUnoBackend() || isLocalSession() || isRemoteSession(),"Invalid/No session type for admin session");
- if (isLocalSession())
- {
- OSL_ENSURE(!hasUser(), "Local Admin Session has 'user' parameter - ignoring (admin data will be used)");
-
- if (getSessionType().compareToAscii(LOCAL_SESSION_IDENTIFIER) == 0)
- {
- CFG_TRACE_INFO("Local Admin session: Changing session type to 'setup'");
-
- OUString const sSetup( RTL_CONSTASCII_USTRINGPARAM(SETUP_SESSION_IDENTIFIER) );
- this->setSessionType(sSetup,Settings::SO_DEFAULT);
- }
- else
- OSL_ENSURE(getSessionType().compareToAscii(SETUP_SESSION_IDENTIFIER) != 0, "WARNING: Explicit creation of 'setup' sessions is obsolete. ");
- }
+ OSL_ASSERT(context.is());
+ if (!context.is()) return false;
- OUString const sService( RTL_CONSTASCII_USTRINGPARAM(SERVICE_ADMINSESSION) );
-
- if( !hasService() && isServiceRequired() )
- {
- CFG_TRACE_INFO("No service set for admin session. Using default service '%s'",OUSTRING2ASCII(sService));
+ uno::Any aSetting = context->getValueByName( NAME(CONTEXT_ITEM_ADMINFLAG) );
+
+ sal_Bool bValue = false;
+ bool bTest = (aSetting >>= bValue) && bValue;
- this->setService(sService, Settings::SO_DEFAULT);
- }
+ return bTest == bAdmin;
+ }
+// ---------------------------------------------------------------------------
+// ---------------------------------------------------------------------------------------
- if ( !hasAsyncSetting() )
+ bool ArgumentHelper::extractArgument(beans::NamedValue & rValue, const uno::Any & aOverride)
+ {
+ if ( ! (aOverride >>= rValue) )
{
- Any aDefaultNoAsync = makeAny(sal_Bool(false));
- putSetting( NAME(SETTING_ASYNC), Settings::Setting(aDefaultNoAsync, Settings::SO_DEFAULT) );
- OSL_ASSERT( hasAsyncSetting() && !getAsyncSetting() );
- }
+ // it must be a PropertyValue, if it isn't a NamedValue
+ beans::PropertyValue aPV;
+ if ( !(aOverride >>= aPV) )
+ return false;
- if (!hasLocale())
- {
- CFG_TRACE_INFO("Settings for Admin session: Using 'all locales' by default");
- this->setAnyLocale(Settings::SO_DEFAULT);
+ rValue.Name = aPV.Name;
+ rValue.Value = aPV.Value;
}
- putSetting(NAME(SETTING_SESSIONCLASS),Settings::Setting(sService, Settings::SO_DEFAULT));
+ return true;
}
// ---------------------------------------------------------------------------------------
- void ConnectionSettings::setAnyLocale(Settings::Origin _eOrigin)
+
+ bool ArgumentHelper::checkBackendArgument(beans::NamedValue const & aAdjustedValue)
{
- rtl::OUString sAnyLocale = localehelper::getAnyLocale();
+ bool isWrappable =
+ aAdjustedValue.Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(CONTEXT_ITEM_PREFIX_ SETTING_ASYNC_NEW)) ||
+ aAdjustedValue.Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(CONTEXT_ITEM_PREFIX_ SETTING_LOCALE_NEW));
- this->putSetting( NAME(SETTING_LOCALE), Settings::Setting(sAnyLocale, _eOrigin));
+ if (isWrappable) return false;
+
+ m_bHasBackendArguments = true;
+ return true;
}
// ---------------------------------------------------------------------------------------
- void ConnectionSettings::setUserSession(const OUString& _rRemoteServiceName)
- {
- this->setService(_rRemoteServiceName, Settings::SO_MANUAL);
- this->setUserSession();
- }
-// ---------------------------------------------------------------------------------------
- void ConnectionSettings::setAdminSession(const OUString& _rRemoteServiceName)
+ bool ArgumentHelper::filterAndAdjustArgument(beans::NamedValue & rValue)
{
- this->setService(_rRemoteServiceName, Settings::SO_MANUAL);
- this->setAdminSession();
- }
+ // handle old servertype argument and filter the 'plugin' value
+ if (rValue.Name.equalsAscii(ARGUMENT_SERVERTYPE_COMPAT))
+ {
+ OUString aServertype;
+ if (! (rValue.Value >>= aServertype))
+ return false;
-// ---------------------------------------------------------------------------------------
- IConfigSession* ConnectionSettings::createConnection(Reference<XMultiServiceFactory> const& _rxServiceMgr) const
- {
- OUString sSessionType = getSessionType();
- OSL_ENSURE(!isPlugin(), "Settings::createConnection: can't create a plugin session!");
+ if (aServertype.equalsAscii(SERVERTYPE_PLUGIN_COMPAT))
+ return false;
- for(int i= 0; i<nSessionClasses; ++i)
- {
- if (0 == sSessionType.compareToAscii(aSessionClasses[i].name))
- {
- return aSessionClasses[i].create(_rxServiceMgr, *this);
- }
+ rValue.Name = NAME(BOOTSTRAP_SERVERTYPE_COMPAT);
+ // check, if it is already there
+ uno::Any const aExistingValue = m_context->getValueByName(rValue.Name);
+
+ if (aExistingValue.hasValue())
+ return !(aExistingValue == rValue.Value);
+
+ else
+ return !aServertype.equalsAscii(SERVERTYPE_UNO_COMPAT);
}
- OSL_ENSURE(false, "unable to bootstrap the configuration - no match for session type!");
- return 0;
- }
+ // map old argument names for comatibility
+ else if (rValue.Name.equalsAscii(ARGUMENT_LOCALE_COMPAT))
+ rValue.Name = NAME(SETTING_LOCALE_NEW);
-// ---------------------------------------------------------------------------------------
-// caching helpers
-//---------------------------------------------------------------------------------------
- OUString buildConnectString(const ConnectionSettings& _rSettings)
- {
- OSL_ENSURE(_rSettings.isComplete(),"WARNING: creating connect string for incomplete settings");
+ else if (rValue.Name.equalsAscii(ARGUMENT_ASYNC_COMPAT))
+ rValue.Name = NAME(SETTING_ASYNC_NEW);
- rtl::OUStringBuffer sConnect = _rSettings.getSessionType();
+ // give the item a long name
+ rValue.Name = BootstrapContext::makeContextName(rValue.Name);
-#if 0 // disabled: service may not be set
- if (_rSettings.isServiceRequired() && _rSettings.hasService())
- {
- sConnect.append(sal_Unicode(':'));
- sConnect.append(_rSettings.getService());
- }
-#endif
- if (_rSettings.isUnoBackend())
- {
- // no support for connection strings
- return OUString();
- }
- else if (_rSettings.isLocalSession())
- {
- if (_rSettings.isSourcePathValid())
- {
- sConnect.appendAscii(RTL_CONSTASCII_STRINGPARAM(":share@"));
- sConnect.append(_rSettings.getSourcePath());
- }
- if (_rSettings.isUpdatePathValid())
- {
- sConnect.appendAscii(RTL_CONSTASCII_STRINGPARAM(":user@"));
- sConnect.append(_rSettings.getUpdatePath());
- }
- // maybe consider user here as well ?
- }
- else if (_rSettings.isRemoteSession())
- {
- if (_rSettings.hasServer() || _rSettings.hasPort())
- {
- sConnect.append(sal_Unicode('@'));
-
- if ( _rSettings.hasServer())
- {
- sConnect.append(_rSettings.getServer());
- }
-
- if ( _rSettings.hasPort())
- {
- sConnect.append(sal_Unicode(':'));
- sConnect.append(_rSettings.getPort());
- }
- }
-
- if (_rSettings.hasUser())
- {
- sConnect.appendAscii(RTL_CONSTASCII_STRINGPARAM(";user="));
- sConnect.append(_rSettings.getUser());
- }
- if (_rSettings.hasPassword())
- {
- sConnect.appendAscii(RTL_CONSTASCII_STRINGPARAM(";pwd="));
- sConnect.append(_rSettings.getPassword());
- }
- if (_rSettings.hasTimeout())
- {
- sConnect.appendAscii(RTL_CONSTASCII_STRINGPARAM(";timeout="));
- sConnect.append( _rSettings.getTimeout());
- }
- }
- else
- {
- OSL_ENSURE(false, "Unknown session type");
- }
+ // check, if it is already there
+ uno::Any const aExistingValue = m_context->getValueByName(rValue.Name);
- if (_rSettings.hasLocale())
- {
- sConnect.appendAscii(RTL_CONSTASCII_STRINGPARAM(";locale="));
- sConnect.append(_rSettings.getLocale());
- }
- if (_rSettings.hasAsyncSetting())
- {
- sConnect.appendAscii(RTL_CONSTASCII_STRINGPARAM(";async="));
- sConnect.append(_rSettings.getAsyncSetting());
- }
- if (_rSettings.hasReinitializeFlag() && _rSettings.getReinitializeFlag())
- {
- sConnect.appendAscii(RTL_CONSTASCII_STRINGPARAM(";reinitialize="));
- sConnect.append(_rSettings.getReinitializeFlag());
- }
+ return ! (aExistingValue == rValue.Value);
+ }
+// ---------------------------------------------------------------------------------------
- return sConnect.makeStringAndClear();
+ beans::NamedValue ArgumentHelper::makeAdminServiceOverride(sal_Bool bAdmin)
+ {
+ return beans::NamedValue( NAME(CONTEXT_ITEM_ADMINFLAG), uno::makeAny(bAdmin) );
}
// ---------------------------------------------------------------------------------------
-// - bootstrapping helper
+// ---------------------------------------------------------------------------------------
+// - bootstrapping error checking helper
// ---------------------------------------------------------------------------------------
namespace {
// ---------------------------------------------------------------------------------------
@@ -1208,7 +814,7 @@ namespace {
// ---------------------------------------------------------------------------------------
static
- void impl_raiseBootstrapException( BootstrapResult _rc, OUString const& _sMessage, OUString const& _sURL, Reference< XInterface > _xContext )
+ uno::Any impl_makeBootstrapException( BootstrapResult _rc, OUString const& _sMessage, OUString const& _sURL, uno::Reference< uno::XInterface > _xContext )
{
OUString sMessage(_sMessage);
// ensure a message
@@ -1225,348 +831,31 @@ namespace {
switch (_rc)
{
case MISSING_BOOTSTRAP_FILE:
- throw MissingBootstrapFileException(sMessage, _xContext, _sURL);
+ return uno::makeAny( MissingBootstrapFileException(sMessage, _xContext, _sURL) );
case INCOMPLETE_BOOTSTRAP_FILE:
- throw InvalidBootstrapFileException(sMessage, _xContext, _sURL);
+ return uno::makeAny( InvalidBootstrapFileException(sMessage, _xContext, _sURL) );
default: OSL_ENSURE(false, "Undefined BootstrapResult code");
case INCOMPLETE_BOOTSTRAP_DATA:
case BOOTSTRAP_FAILURE:
- throw CannotLoadConfigurationException(sMessage, _xContext);
+ return uno::makeAny( CannotLoadConfigurationException(sMessage, _xContext) );
case BOOTSTRAP_DATA_OK:
break;
}
+ return uno::Any();
}
// ---------------------------------------------------------------------------------------
-} // anonymous namespace
-
-// ---------------------------------------------------------------------------------------
-// bootstrapping
-// ---------------------------------------------------------------------------------------
-
-BootstrapSettings::Context getBootstrapContext(const Reference< XMultiServiceFactory >& _xORB)
-{
- Reference< XComponentContext > xContext;
-
- Reference< XPropertySet > xORBPS( _xORB, UNO_QUERY );
- if (xORBPS.is())
- try
- {
- OUString const k_CONTEXT(RTL_CONSTASCII_USTRINGPARAM("DefaultContext"));
-
- OSL_VERIFY( xORBPS->getPropertyValue(k_CONTEXT) >>= xContext );
- }
- catch (UnknownPropertyException & )
- {
- OSL_TRACE("Warning: Cannot get context - Service manager has no DefaultContext property");
- }
- catch (Exception& )
- {
- OSL_TRACE("Warning: Cannot get context - Unexpected exception retrieving DefaultContext");
- }
- else
- OSL_TRACE("Warning: Cannot get context - ServiceManager is no PropertySet");
-
- return xContext;
-}
-// ---------------------------------------------------------------------------------------
-// class BootstrapSettings::Impl
-// ---------------------------------------------------------------------------------------
- struct BootstrapSettings::Impl
- {
- Impl(Context const & xContext);
-
- bool hasInifile() const;
- bool getInifile(OUString& _rInifile) const;
- bool hasExistingInifile() const;
-
- void collectSettings(Settings& _rSettings);
- void collectDefaultsFromINI(Settings& _rSettings);
- void adjustToInstallation(Settings& _rSettings);
-
- void addSetting(Settings& _rSettings,Settings::Name const & _sSetting, OUString const& _sBootstrapItem);
- void addWithDefault(Settings& _rSettings,Settings::Name const & _sSetting, OUString const& _sBootstrapItem, OUString const& _sDefault);
- void maybeAddWithDefault(Settings& _rSettings,Settings::Name const & _sSetting, OUString const& _sBootstrapItem, OUString const& _sDefault);
-
- BootstrapResult getBootstrapErrorMessage(ConnectionSettings const& _rSettings, OUString& _rMessage, OUString& _rIniFile ) const;
-
- static bool urlExists(OUString const& _sURL);
- rtl::Bootstrap m_data;
- Context m_context;
- };
-
-// ---------------------------------------------------------------------------------------
-
- void BootstrapSettings::bootstrap(Context const & xContext)
- {
- CFG_TRACE_INFO("provider bootstrapping: collecting bootstrap setting");
-
- Impl aBootstrapper(xContext);
-
- aBootstrapper.collectSettings(this->settings.m_aSettings);
-
- if ( aBootstrapper.hasExistingInifile() )
- aBootstrapper.collectDefaultsFromINI(this->settings.m_aSettings);
-
- this->settings.implNormalizeSettings();
-
- this->valid = this->settings.implDetermineSessionType();
-
- aBootstrapper.adjustToInstallation(this->settings.m_aSettings);
- this->settings.implNormalizeSettings();
-
- if (this->valid)
- {
- this->valid = this->settings.isComplete();
-
- if (!this->valid)
- CFG_TRACE_WARNING_NI("provider bootstrapping: bootstrap data is incomplete");
- }
- else
- {
- CFG_TRACE_WARNING_NI("provider bootstrapping: could not collect bootstrap data");
-
- if (!this->settings.implDetermineSessionType())
- CFG_TRACE_ERROR_NI("provider bootstrapping: no default session available");
- }
- }
-// ---------------------------------------------------------------------------------------
-
- void BootstrapSettings::raiseBootstrapException(Reference< XInterface > const & _xContext ) const
- {
- if (!this->valid)
- {
- OUString sMessage,sURL;
-
- BootstrapResult rc = Impl( Context() ).getBootstrapErrorMessage(this->settings,sMessage,sURL);
-
- impl_raiseBootstrapException(rc,sMessage,sURL,_xContext);
-
- OSL_ASSERT(rc == BOOTSTRAP_DATA_OK);
-
- // could not discover what went wrong => no exception here
- OSL_ENSURE(false, "cannot detect bootstrap error");
- }
- }
-// ---------------------------------------------------------------------------------------
-
- static OUString getCurrentModuleDirectory()
- {
- OUString aFileURL;
- if ( !osl::Module::getUrlFromAddress((void*)&getCurrentModuleDirectory,aFileURL) )
- {
- OSL_TRACE(false, "Cannot locate current module - using executable instead");
-
- OSL_VERIFY(osl_Process_E_None == osl_getExecutableFile(&aFileURL.pData));
- }
-
- OSL_ENSURE(0 < aFileURL.lastIndexOf('/'), "Cannot find directory for module URL");
-
- return aFileURL.copy(0, aFileURL.lastIndexOf('/'));
- }
-// ---------------------------------------------------------------------------------------
- OUString BootstrapSettings::getURL()
- {
- return getCurrentModuleDirectory() + OUString(RTL_CONSTASCII_USTRINGPARAM("/"BOOTSTRAP_CONFIGMGR_DATA));
- }
-// ---------------------------------------------------------------------------------------
- BootstrapSettings::Impl::Impl(Context const & xContext)
- : m_data(getURL())
- , m_context(xContext)
- {
- }
-// ---------------------------------------------------------------------------------------
+ static
inline
- bool BootstrapSettings::Impl::urlExists(OUString const& _sURL)
+ bool urlExists(OUString const& _sURL)
{
osl::DirectoryItem aCheck;
return (osl::DirectoryItem::get(_sURL,aCheck) == osl::DirectoryItem::E_None);
}
// ---------------------------------------------------------------------------------------
- inline
- bool BootstrapSettings::Impl::getInifile(OUString& _rInifile) const
- {
- if (m_data.getFrom(ITEM(BOOTSTRAP_ITEM_PROFILE_NAME),_rInifile))
- {
- return true;
- }
- else
- {
- return false;
- }
- }
-// ---------------------------------------------------------------------------------------
-
- bool BootstrapSettings::Impl::hasInifile() const
- {
- OUString sInifile;
- bool bResult = getInifile(sInifile);
- return bResult;
- }
-// ---------------------------------------------------------------------------------------
-
- bool BootstrapSettings::Impl::hasExistingInifile() const
- {
- OUString sInifile;
- if ( getInifile(sInifile) )
- {
- if (urlExists(sInifile))
- {
- CFG_TRACE_INFO_NI("provider bootstrapping: using configuration INI file '%'", OUSTRING2ASCII(sInifile));
- return true;
- }
- else
- CFG_TRACE_WARNING_NI("provider bootstrapping: specified configuration INI file '%s' does not exist", OUSTRING2ASCII(sInifile));
- }
- else
- CFG_TRACE_INFO_NI("provider bootstrapping: no configuration INI file specified");
-
- return false;
- }
-// ---------------------------------------------------------------------------------------
-
- void BootstrapSettings::Impl::addWithDefault(Settings& _rSettings,Settings::Name const & _sSetting, OUString const& _sBootstrapItem, OUString const& _sDefault)
- {
- OUString sValue;
- m_data.getFrom(_sBootstrapItem, sValue, _sDefault);
- if (sValue.getLength())
- _rSettings.putSetting( _sSetting, Settings::Setting(sValue, Settings::SO_INIFILE) );
- }
-// ---------------------------------------------------------------------------------------
-
- void BootstrapSettings::Impl::addSetting(Settings& _rSettings,Settings::Name const & _sSetting, OUString const& _sBootstrapItem)
- {
- if (m_context.is())
- {
- static const OUString sPrefix(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.configuration.bootstrap."));
- uno::Any aValue = m_context->getValueByName( sPrefix + _sSetting );
-
- if (aValue.hasValue())
- {
- _rSettings.putSetting(_sSetting,Settings::Setting(aValue, Settings::SO_BOOTSTRAP) );
- return;
- }
- }
-
- // not available from context
- OUString sValue;
- if (m_data.getFrom(_sBootstrapItem,sValue))
- {
- _rSettings.putSetting(_sSetting,Settings::Setting(sValue, Settings::SO_BOOTSTRAP) );
- }
- }
-// ---------------------------------------------------------------------------------------
-
- inline
- void BootstrapSettings::Impl::maybeAddWithDefault(Settings& _rSettings,Settings::Name const & _sSetting, OUString const& _sBootstrapItem, OUString const& _sDefault)
- {
- if (!_rSettings.haveSetting(_sSetting))
- {
- addWithDefault(_rSettings,_sSetting,_sBootstrapItem,_sDefault);
- }
- }
-// ---------------------------------------------------------------------------------------
-
- void BootstrapSettings::Impl::collectDefaultsFromINI(Settings& _rSettings)
- {
- OUString sDummy;
- maybeAddWithDefault(_rSettings, NAME(SETTING_SERVERTYPE), ITEM(BOOTSTRAP_ITEM_SERVERTYPE), ITEM(BOOTSTRAP_SERVERTYPE_FROM_PROFILE) );
- maybeAddWithDefault(_rSettings, NAME(SETTING_UNOSERVICE), ITEM(BOOTSTRAP_ITEM_UNOSERVICE), ITEM(BOOTSTRAP_UNOSERVICE_FROM_PROFILE) );
- maybeAddWithDefault(_rSettings, NAME(SETTING_UNOWRAPPER), ITEM(BOOTSTRAP_ITEM_UNOWRAPPER), ITEM(BOOTSTRAP_UNOWRAPPER_FROM_PROFILE) );
- maybeAddWithDefault(_rSettings, NAME(SETTING_LOCALE), ITEM(BOOTSTRAP_ITEM_LOCALE), ITEM(BOOTSTRAP_LOCALE_FROM_PROFILE) );
- maybeAddWithDefault(_rSettings, NAME(SETTING_ASYNC), ITEM(BOOTSTRAP_ITEM_ASYNCENABLE), ITEM(BOOTSTRAP_ASYNCENABLE_FROM_PROFILE) );
- maybeAddWithDefault(_rSettings, NAME(SETTING_SOURCEPATH), ITEM(BOOTSTRAP_ITEM_SOURCE_PATH), ITEM(BOOTSTRAP_BASEPATH_FROM_PROFILE) );
- maybeAddWithDefault(_rSettings, NAME(SETTING_UPDATEPATH), ITEM(BOOTSTRAP_ITEM_UPDATE_PATH), ITEM(BOOTSTRAP_DATAPATH_FROM_PROFILE) );
- maybeAddWithDefault(_rSettings, NAME(SETTING_SERVER), ITEM(BOOTSTRAP_ITEM_SERVER), ITEM(BOOTSTRAP_SERVER_FROM_PROFILE) );
- maybeAddWithDefault(_rSettings, NAME(SETTING_TIMEOUT), ITEM(BOOTSTRAP_ITEM_TIMEOUT), ITEM(BOOTSTRAP_TIMEOUT_FROM_PROFILE) );
- maybeAddWithDefault(_rSettings, NAME(SETTING_USER), ITEM(BOOTSTRAP_ITEM_USER), ITEM(BOOTSTRAP_USER_FROM_PROFILE) );
- maybeAddWithDefault(_rSettings, NAME(SETTING_PASSWORD), ITEM(BOOTSTRAP_ITEM_PASSWORD), ITEM(BOOTSTRAP_PASSWORD_FROM_PROFILE) );
-
- }
-// ---------------------------------------------------------------------------------------
-
- void BootstrapSettings::Impl::collectSettings(Settings& _rSettings)
- {
- addSetting(_rSettings, NAME(SETTING_SERVERTYPE), ITEM(BOOTSTRAP_ITEM_SERVERTYPE) );
- addSetting(_rSettings, NAME(SETTING_UNOSERVICE), ITEM(BOOTSTRAP_ITEM_UNOSERVICE) );
- addSetting(_rSettings, NAME(SETTING_UNOWRAPPER), ITEM(BOOTSTRAP_ITEM_UNOWRAPPER) );
- addSetting(_rSettings, NAME(SETTING_OFFLINE), ITEM(BOOTSTRAP_ITEM_OFFLINE) );
- addSetting(_rSettings, NAME(SETTING_LOCALE), ITEM(BOOTSTRAP_ITEM_LOCALE) );
- addSetting(_rSettings, NAME(SETTING_ASYNC), ITEM(BOOTSTRAP_ITEM_ASYNCENABLE) );
- addSetting(_rSettings, NAME(SETTING_SOURCEPATH), ITEM(BOOTSTRAP_ITEM_SOURCE_PATH) );
- addSetting(_rSettings, NAME(SETTING_UPDATEPATH), ITEM(BOOTSTRAP_ITEM_UPDATE_PATH) );
- addSetting(_rSettings, NAME(SETTING_SERVER), ITEM(BOOTSTRAP_ITEM_SERVER) );
- addSetting(_rSettings, NAME(SETTING_TIMEOUT), ITEM(BOOTSTRAP_ITEM_TIMEOUT) );
- addSetting(_rSettings, NAME(SETTING_USER), ITEM(BOOTSTRAP_ITEM_USER) );
- addSetting(_rSettings, NAME(SETTING_PASSWORD), ITEM(BOOTSTRAP_ITEM_PASSWORD) );
- }
-// ---------------------------------------------------------------------------------------
- static inline void getDirWithDefault(
- rtl::Bootstrap& _rData,
- OUString const& _sItem,
- OUString& _sResult,
- OUString const& _sDefault
- )
- {
- _rData.getFrom(_sItem,_sResult,_sDefault);
- }
- //----------------------------------------
- #define BOOTSTRAP_ITEM_SHAREDIR "$BaseInstallation/share"
- #define BOOTSTRAP_ITEM_USERDIR "$UserInstallation/user"
- #define CONFIGURATION_STANDARDPATH "config/registry"
- #define BOOTSTRAP_BASEPATH_DEFAULT ITEM(BOOTSTRAP_ITEM_SHAREDIR"/"CONFIGURATION_STANDARDPATH)
- #define BOOTSTRAP_DATAPATH_DEFAULT ITEM(BOOTSTRAP_ITEM_USERDIR "/"CONFIGURATION_STANDARDPATH)
-
-// ---------------------------------------------------------------------------------------
-
- static inline OUString getDefaultSourcePath(rtl::Bootstrap& _rData)
- {
- OUString sResult;
-
- getDirWithDefault(_rData,ITEM(BOOTSTRAP_ITEM_SOURCE_PATH),sResult,BOOTSTRAP_BASEPATH_DEFAULT);
-
- return sResult;
- }
-// ---------------------------------------------------------------------------------------
-
- static inline OUString getDefaultUpdatePath(rtl::Bootstrap& _rData)
- {
- OUString sResult;
-
- getDirWithDefault(_rData,ITEM(BOOTSTRAP_ITEM_UPDATE_PATH),sResult,BOOTSTRAP_DATAPATH_DEFAULT);
-
- return sResult;
- }
-// ---------------------------------------------------------------------------------------
- // if we do not already have path settings, try to use the defaults (of an office install)
- void BootstrapSettings::Impl::adjustToInstallation(Settings& _rSettings)
- {
- // if we do not already have a source path setting, create one from the base install path
- Settings::Name const sSourceSetting = NAME(SETTING_SOURCEPATH);
- if (!_rSettings.haveSetting(sSourceSetting))
- {
- OUString aSourcePath = getDefaultSourcePath(m_data);
-
- if (isValidFileURL(aSourcePath) && urlExists(aSourcePath))
- {
- _rSettings.putSetting(sSourceSetting,Settings::Setting(aSourcePath,Settings::SO_DEFAULT));
-
- // and then also try to update the Update-path
- Settings::Name const sUpdateSetting = NAME(SETTING_UPDATEPATH);
- if (!_rSettings.haveSetting(sUpdateSetting))
- {
- OUString aUpdatePath = getDefaultUpdatePath(m_data);
-
- if (isValidFileURL(aUpdatePath))
- _rSettings.putSetting(sUpdateSetting,Settings::Setting(aUpdatePath,Settings::SO_DEFAULT));
- }
- }
- }
- }
-// ---------------------------------------------------------------------------------------
static
OUString buildBootstrapError( sal_Char const* _sWhat, OUString const& _sName, sal_Char const* _sHow)
@@ -1582,38 +871,46 @@ BootstrapSettings::Context getBootstrapContext(const Reference< XMultiServiceFac
}
// ---------------------------------------------------------------------------------------
- BootstrapResult BootstrapSettings::Impl::getBootstrapErrorMessage(ConnectionSettings const & _rSettings, OUString& _rMessage, OUString& _rIniFile ) const
+ BootstrapResult getBootstrapErrorMessage(BootstrapContext const & aContext, ContextReader const & aSettings, OUString& _rMessage, OUString& _rIniFile )
{
BootstrapResult eResult = BOOTSTRAP_DATA_OK;
- if ( this->getInifile(_rIniFile) )
+ _rIniFile = aContext.getBootstrapURL();
+
+ if ( !urlExists(_rIniFile) )
{
- if ( urlExists(_rIniFile) )
- {
- _rMessage = buildBootstrapError("The configuration file ",_rIniFile.copy(1+_rIniFile.lastIndexOf('/')),"is invalid");
- eResult = INCOMPLETE_BOOTSTRAP_FILE;
- }
- else
- {
- _rMessage = buildBootstrapError("The configuration file ",_rIniFile.copy(1+_rIniFile.lastIndexOf('/')),"is missing");
- eResult = MISSING_BOOTSTRAP_FILE;
- }
+ _rMessage = buildBootstrapError("The configuration file ",_rIniFile.copy(1+_rIniFile.lastIndexOf('/')),"is missing");
+ eResult = MISSING_BOOTSTRAP_FILE;
}
- else if (!_rSettings.isSessionTypeKnown())
+ else if (!aSettings.isUnoBackend())
{
- _rMessage = buildBootstrapError("Needed information to access",OUString::createFromAscii("application"),"configuration data is missing");
- eResult = BOOTSTRAP_FAILURE;
+ _rMessage = buildBootstrapError("The configuration file ",_rIniFile.copy(1+_rIniFile.lastIndexOf('/')),"is for an older version of the configuration database");
+ eResult = INCOMPLETE_BOOTSTRAP_FILE;
}
- else if (!_rSettings.isComplete() )
+ else if (!aSettings.isBootstrapValid() )
{
- _rMessage = buildBootstrapError("Needed information to access",_rSettings.getSessionType(), "configuration data is missing");
+ _rMessage = buildBootstrapError("Needed information to access",OUString::createFromAscii("application"), "configuration data is missing");
eResult = INCOMPLETE_BOOTSTRAP_DATA;
}
return eResult;
}
// ---------------------------------------------------------------------------------------
+} // anonymous namespace
+// ---------------------------------------------------------------------------------------
+uno::Any BootstrapContext::makeBootstrapException()
+{
+ ContextReader aReader(this);
+ if (aReader.isBootstrapValid()) return uno::Any();
+
+ OUString sMessage,sURL;
+
+ BootstrapResult rc = getBootstrapErrorMessage(*this,aReader,sMessage,sURL);
+
+ return impl_makeBootstrapException(rc,sMessage,sURL,*this);
+}
+// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------------------
} // namespace configmgr