com.sun.star.bridge.XUnoUrlResolver Java Examples

The following examples show how to use com.sun.star.bridge.XUnoUrlResolver. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BootstrapConnector.java    From yarg with Apache License 2.0 5 votes vote down vote up
/**
 * Disconnects from an OOo server using the connection string from the
 * previous connect.
 * 
 * If there has been no previous connect, the disconnects does nothing.
 * 
 * If there has been a previous connect, disconnect tries to terminate
 * the OOo server and kills the OOo server process the connect started.
 */
public void disconnect() {

    if (oooConnectionString == null)
        return;

    // call office to terminate itself
    try {
        // get local context
        XComponentContext xLocalContext = getLocalContext();

        // create a URL resolver
        XUnoUrlResolver xUrlResolver = UnoUrlResolver.create(xLocalContext);

        // get remote context
        XComponentContext xRemoteContext = getRemoteContext(xUrlResolver);

        // get desktop to terminate office
        Object desktop = xRemoteContext.getServiceManager().createInstanceWithContext("com.sun.star.frame.Desktop",xRemoteContext);
        XDesktop xDesktop = (XDesktop) UnoRuntime.queryInterface(XDesktop.class, desktop);
        xDesktop.terminate();
    }
    catch (Exception e) {
        // Bad luck, unable to terminate office
    }

    oooServer.kill();
    oooConnectionString = null;
}
 
Example #2
Source File: BootstrapConnector.java    From yarg with Apache License 2.0 5 votes vote down vote up
/**
 * Try to connect to office.
 * 
 * @return      The remote component context
 */
protected XComponentContext getRemoteContext(XUnoUrlResolver xUrlResolver) throws BootstrapException, ConnectionSetupException, IllegalArgumentException, NoConnectException {

    Object context = xUrlResolver.resolve(oooConnectionString);
    XComponentContext xContext = (XComponentContext) UnoRuntime.queryInterface(XComponentContext.class, context);
    if (xContext == null) {
        throw new BootstrapException("no component context!");
    }
    return xContext;
}