code: 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;
      }
docs: 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.