/* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
/** Bootstrap offers functionality to obtain a context or simply a service manager. The service manager can create a few basic services, whose implementations are: <ul> <li>com.sun.star.comp.loader.JavaLoader</li> <li>com.sun.star.comp.urlresolver.UrlResolver</li> <li>com.sun.star.comp.bridgefactory.BridgeFactory</li> <li>com.sun.star.comp.connections.Connector</li> <li>com.sun.star.comp.connections.Acceptor</li> <li>com.sun.star.comp.servicemanager.ServiceManager</li> </ul>
Other services can be inserted into the service manager by using its XSet interface: <pre> XSet xSet = UnoRuntime.queryInterface( XSet.class, aMultiComponentFactory ); // insert the service manager xSet.insert( aSingleComponentFactory ); </pre>
*/ publicclass Bootstrap {
privatestaticvoid insertBasicFactories(
XSet xSet, XImplementationLoader xImpLoader ) throws Exception
{ // insert the factory of the loader
xSet.insert( xImpLoader.activate( "com.sun.star.comp.loader.JavaLoader", null, null, null ) );
// insert the factory of the URLResolver
xSet.insert( xImpLoader.activate( "com.sun.star.comp.urlresolver.UrlResolver", null, null, null ) );
/** * Returns an array of default commandline options to start bootstrapped * instance of soffice with. You may use it in connection with bootstrap * method for example like this: * <pre> * List list = Arrays.asList( Bootstrap.getDefaultOptions() ); * list.remove("--nologo"); * list.remove("--nodefault"); * list.add("--invisible"); * * Bootstrap.bootstrap( list.toArray( new String[list.size()] ); * </pre> * * @return an array of default commandline options * @see #bootstrap( String[] ) * @since LibreOffice 5.1
*/ publicstaticfinal String[] getDefaultOptions()
{ returnnew String[]
{ "--nologo", "--nodefault", "--norestore", "--nolockcheck"
};
}
/** backwards compatibility stub. @param context_entries the hash table contains mappings of entry names (type string) to context entries (type class ComponentContextEntry). @throws Exception if things go awry. @return a new context.
*/ publicstatic XComponentContext createInitialComponentContext( Hashtable<String, Object> context_entries ) throws Exception
{ return createInitialComponentContext((Map<String, Object>) context_entries);
} /** Bootstraps an initial component context with service manager and basic jurt components inserted. @param context_entries the hash table contains mappings of entry names (type string) to context entries (type class ComponentContextEntry). @throws Exception if things go awry. @return a new context.
*/ publicstatic XComponentContext createInitialComponentContext( Map<String, Object> context_entries ) throws Exception
{
ServiceManager xSMgr = new ServiceManager();
/** * Bootstraps a servicemanager with the jurt base components registered. * * See also UNOIDL <code>com.sun.star.lang.ServiceManager</code>. * * @throws Exception if things go awry. * @return a freshly bootstrapped service manager
*/ publicstatic XMultiServiceFactory createSimpleServiceManager() throws Exception
{ return UnoRuntime.queryInterface(
XMultiServiceFactory.class, createInitialComponentContext( (Map<String, Object>) null ).getServiceManager() );
}
/** Bootstraps the initial component context from a native UNO installation.
@throws Exception if things go awry. @return a freshly bootstrapped component context.
@throws Exception if things go awry. @return a freshly bootstrapped component context.
*/ publicstaticfinal XComponentContext defaultBootstrap_InitialComponentContext(
String ini_file, Map<String,String> bootstrap_parameters ) throws Exception
{ // jni convenience: easier to iterate over array than calling Hashtable
String pairs [] = null; if (null != bootstrap_parameters)
{
pairs = new String [ 2 * bootstrap_parameters.size() ]; int n = 0; for (Map.Entry<String, String> bootstrap_parameter : bootstrap_parameters.entrySet()) {
pairs[ n++ ] = bootstrap_parameter.getKey();
pairs[ n++ ] = bootstrap_parameter.getValue();
}
}
if (! m_loaded_juh)
{ if ("The Android Project".equals(System.getProperty("java.vendor")))
{ // Find out if we are configured with DISABLE_DYNLOADING or // not. Try to load the lo-bootstrap shared library which // won't exist in the DISABLE_DYNLOADING case. (And which will // be already loaded otherwise, so nothing unexpected happens // that case.) Yeah, this would be simpler if I just could be // bothered to keep a separate branch for DISABLE_DYNLOADING // on Android, merging in master periodically, until I know // for sure whether it is what I want, or not.
/** * Bootstraps the component context from a UNO installation. * * @throws BootstrapException if things go awry. * * @return a bootstrapped component context. * * @since UDK 3.1.0
*/ publicstaticfinal XComponentContext bootstrap() throws BootstrapException {
/** * Bootstraps the component context from a UNO installation. * * @param argArray * an array of strings - commandline options to start instance of * soffice with * @see #getDefaultOptions() * * @throws BootstrapException if things go awry. * * @return a bootstrapped component context. * * @since LibreOffice 5.1
*/ publicstaticfinal XComponentContext bootstrap( String[] argArray ) throws BootstrapException {
XComponentContext xContext = null;
try { // create default local component context
XComponentContext xLocalContext =
createInitialComponentContext( (Map<String, Object>) null ); if ( xLocalContext == null ) thrownew BootstrapException( "no local component context!" );
// find office executable relative to this class's class loader
String sOffice =
System.getProperty( "os.name" ).startsWith( "Windows" ) ? "soffice.exe" : "soffice";
File fOffice = NativeLibraryLoader.getResource(
Bootstrap.class.getClassLoader(), sOffice ); if ( fOffice == null ) thrownew BootstrapException( "no office executable found!" );
// create random pipe name
String sPipeName = "uno" + Long.toString(randomPipeName.nextLong() & 0x7fffffffffffffffL);
// wait until office is started for (int i = 0;; ++i) { try { // try to connect to office
Object context = xUrlResolver.resolve( sConnect );
xContext = UnoRuntime.queryInterface(
XComponentContext.class, context); if ( xContext == null ) thrownew BootstrapException( "no component context!" ); break;
} catch ( com.sun.star.connection.NoConnectException ex ) { // Wait 500 ms, then try to connect again, but do not wait // longer than 5 min (= 600 * 500 ms) total: if (i == 600) { thrownew BootstrapException(ex);
} Thread.sleep( 500 );
}
}
} catch ( BootstrapException e ) { throw e;
} catch ( java.lang.RuntimeException e ) { throw e;
} catch ( java.lang.Exception e ) { thrownew BootstrapException( e );
}
return xContext;
}
/** * Bootstraps the component context from a websocket location. * * @param url * the ws:// or wss:// url of the websocket server * * @throws BootstrapException if things go awry. * * @return a bootstrapped component context. * * @since LibreOffice 24.2
*/ publicstaticfinal XComponentContext bootstrapWebsocketConnection( String url ) throws BootstrapException {
XComponentContext xContext = null;
try { // create default local component context
XComponentContext xLocalContext =
createInitialComponentContext( (Map<String, Object>) null ); if ( xLocalContext == null ) thrownew BootstrapException( "no local component context!" );
// initial service manager
XMultiComponentFactory xLocalServiceManager =
xLocalContext.getServiceManager(); if ( xLocalServiceManager == null ) thrownew BootstrapException( "no initial service manager!" );
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.