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;
    }
public void disconnect ( ) { if ( oooConnectionString == null ) return ; try { XComponentContext xLocalContext = getLocalContext ( ) ; XUnoUrlResolver xUrlResolver = UnoUrlResolver . create ( xLocalContext ) ; XComponentContext xRemoteContext = getRemoteContext ( xUrlResolver ) ; Object desktop = xRemoteContext . getServiceManager ( ) . createInstanceWithContext ( "com.sun.star.frame.Desktop" , xRemoteContext ) ; XDesktop xDesktop = ( XDesktop ) UnoRuntime . queryInterface ( XDesktop . class , desktop ) ; xDesktop . terminate ( ) ; } catch ( Exception e ) { } oooServer . kill ( ) ; oooConnectionString = null ; }
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.