OpenOffice UNO Default Bootstrapping


Contents

Abstract
What does UNO need to Bootstrap
Creating a Default Bootstrapped Context
Examples

Abstract

Currently a lot of UNO applications and libraries use different concepts to bootstrap. Some estimate the needed bootstrap info to be passed via command line arguments. Others use some hard coded mechanisms. To be able to develop UNO applications which are extensible in the same manor, a unified default bootstrapping for UNO is needed.

What does UNO need to Bootstrap

Several things are needed to bootstrap a UNO application or UNO dependent application, for example the services the application wants to utilize or the types of the services, if they are not compiled in. Even a mutable and persistent registry for holding application specific data is sometimes needed. (E.g. in case of OpenOffice/StarOffice). To bootstrap an UNO application an inital UNO-context is needed. Two new functions in cppuhelper are providing a default bootstrapped initial UNO-context.

   Reference<XComponentContext> SAL_CALL defaultBootstrap_InitialComponentContext() 
     SAL_THROW((Exception));

   Reference<XComponentContext> SAL_CALL defaultBootstrap_InitialComponentContext(
     const OUString & iniFile) SAL_THROW((Exception));
  
The first function views UNO itself as a subsystem in the sense of microdeployment, the subsystems name is, as might be expected, uno. Please look at the microdeployment for a more comprehensive explanation of subsystems. The second allows to pass the subsystems name. This e.g. usable while building a new subsystem which should not use UNO default configurations. The bootstrap parameters for UNO are the following: These parameters are all optional and specify rdb files, which are used as type or service repositorys. UNO_TYPES and UNO_SERVICES may be space separated lists of rdb files, which become merged in the order of listing. Each rdb has to be specified as a file URL. E.g. the following example defines an environment variable for UNO_TYPES, which consists of three rdbs:
setenv UNO_TYPES "first.rdb second.rdb third.rdb" 

The UNO parameters can be given via command line, environment variables, via an optional unorc/uno.ini or via an application specific rc/ini file. If they are not defined by any of these ways, they are searched beneath the cppuhelper library with the subsystems name, expanded with the appropriate suffixes, which are "_types.rdb" respectivly "_services.rdb". E.g. the full names would be "uno_types.rdb" respectivly "uno_services.rdb". Certainly this only holds true, if using the first function, if using your own subsystems name, the uno prefix would be replaced with the given parameter.

Creating a Default Bootstrapped UNO Context

The default bootstrapping is quite simple to use. Here is a short example of an exectuables main function:
  int main(void) {
    Reference xComponentContext = 
	  defaultBootstrap_InitialComponentContext();

	...
  }
  
Alternatively a libraries/subsystems init function may looks like this:
  int createSomeThinh(void) {
    OUString libraryFileUrl;
    Module::getModuleUrl((void *)createSomeThinh, libraryFileUrl);

	// cut the library extension
    iniName = libraryFileUrl.copy(0, libraryFileUrl.lastIndexOf((sal_Unicode)'.')); 
	// add the rc file extension
    iniName += OUString(RTL_CONSTASCII_USTRINGPARAM(SAL_CONFIGFILE(""))); 

    Reference xComponentContext = 
	  defaultBootstrap_InitialComponentContext(iniName);

	...
  }
  

The library code uses the librarys name as the subsystem name and passes it to defaultBootstrap_InitialComponentContext. To get a libraries name, the method getModuleUrl can be used, this method takes a pointer as parameter and tries to locate the belonging library.

Examples

Some examples a given, which utilize the UNO default bootstrapping mechanism. These are examples of exectuables and libraries.

Bootstrapping OpenOffice

OpenOffice uses the same file as types and as services rdb. It also uses a user dependent writeable rdb, which should be located in the users configuration directory.

Typically a unorc in an office installation looks like this:

  [Bootstrap]
  UNO_TYPES=$SYSBINDIR/applicat.rdb
  UNO_SERVICES=$SYSBINDIR/applicat.rdb
  

And the sofficerc looks like this:

  [Bootstrap]
  Logo=1
  UNO_WRITERDB=$SYSUSERCONFIG/.user60.rdb