plainkeyman Newbie

Joined: 23 Nov 2004 Posts: 1
|
Posted: Tue Nov 23, 2004 6:19 pm Post subject: Problems connecting: DisposedException .. "Connection R |
|
|
i am running slackware linux with java 1.4.2_05, open office 1.1.3.
here is my code:
| Code: |
import com.sun.star.bridge.XUnoUrlResolver;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;
import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.beans.XPropertySet;
public class FirstConnection extends java.lang.Object {
private XComponentContext xRemoteContext = null;
private XMultiComponentFactory xRemoteServiceManager = null;
public static void main(String[] args) {
FirstConnection firstConnection1 = new FirstConnection();
try {
firstConnection1.useConnection();
}
catch (java.lang.Exception e) {
e.printStackTrace();
}
}
protected void useConnection() throws java.lang.Exception {
try {
xRemoteServiceManager = this.getRemoteServiceManager("uno:socket,host=localhost,port=8100;urp;StarOffice.ServiceManager");
String available = (null != xRemoteServiceManager ? "available" : "not available");
System.out.println("remote ServiceManager is " + available);
}
catch (com.sun.star.connection.NoConnectException e) {
System.err.println("No process listening on the resource");
e.printStackTrace();
throw e;
}
catch (com.sun.star.lang.DisposedException e) { //works from Patch 1
xRemoteContext = null;
throw e;
}
}
protected XMultiComponentFactory getRemoteServiceManager(String unoUrl) throws java.lang.Exception {
if (xRemoteContext == null) {
System.out.println("1");
XComponentContext xLocalContext = com.sun.star.comp.helper.Bootstrap.createInitialComponentContext(null);
System.out.println(2);
XMultiComponentFactory xLocalServiceManager = xLocalContext.getServiceManager();
System.out.println(3);
Object urlResolver = xLocalServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", xLocalContext);
// query XUnoUrlResolver interface from urlResolver object
System.out.println(4);
XUnoUrlResolver xUnoUrlResolver = (XUnoUrlResolver) UnoRuntime.queryInterface(XUnoUrlResolver.class, urlResolver);
System.out.println(5);
// Second step: use xUrlResolver interface to import the remote StarOffice.ServiceManager,
// retrieve its property DefaultContext and get the remote servicemanager
Object initialObject = xUnoUrlResolver.resolve(unoUrl);
System.out.println(6);
XPropertySet xPropertySet = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, initialObject);
System.out.println(7);
Object context = xPropertySet.getPropertyValue("DefaultContext");
System.out.println(8);
xRemoteContext = (XComponentContext)UnoRuntime.queryInterface(XComponentContext.class, context);
}
return xRemoteContext.getServiceManager();
}
}
|
it prints out 1..2..3..4..5.. and then
a DisposedException .. "Connection Reset" message
any ideas?? |
|