use of com.sun.star.connection.XConnector in project translationstudio8 by heartsome.
the class OPConnection method connect.
/**
* (non-Javadoc)
* @see net.heartsome.cat.converter.ooconnect.OPconnect#connect()
* @throws ConnectException
*/
public void connect() throws ConnectException {
try {
XComponentContext localContext;
localContext = Bootstrap.createInitialComponentContext(null);
XMultiComponentFactory localServiceManager = localContext.getServiceManager();
XConnector connector = (XConnector) UnoRuntime.queryInterface(XConnector.class, localServiceManager.createInstanceWithContext("com.sun.star.connection.Connector", //$NON-NLS-1$
localContext));
XConnection connection = connector.connect(strConnection);
XBridgeFactory bridgeFactory = (XBridgeFactory) UnoRuntime.queryInterface(XBridgeFactory.class, //$NON-NLS-1$
localServiceManager.createInstanceWithContext("com.sun.star.bridge.BridgeFactory", localContext));
//$NON-NLS-1$ //$NON-NLS-2$
bridge = bridgeFactory.createBridge("ms2ooBridge", "urp", connection, null);
bgComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, bridge);
// bgComponent.addEventListener(this);
serviceMg = (XMultiComponentFactory) UnoRuntime.queryInterface(XMultiComponentFactory.class, bridge.getInstance(//$NON-NLS-1$
"StarOffice.ServiceManager"));
XPropertySet properties = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, serviceMg);
componentContext = (XComponentContext) UnoRuntime.queryInterface(XComponentContext.class, properties.getPropertyValue(//$NON-NLS-1$
"DefaultContext"));
connected = true;
if (connected) {
//$NON-NLS-1$
System.out.println("has already connected");
} else {
//$NON-NLS-1$
System.out.println("connect to Openoffice fail,please check OpenOffice service that have to open");
}
} catch (NoConnectException connectException) {
//$NON-NLS-1$ //$NON-NLS-2$
throw new ConnectException(MessageFormat.format(Messages.getString("ooconnect.OPConnection.msg"), strConnection + ": " + connectException.getMessage()));
} catch (Exception exception) {
//$NON-NLS-1$
throw new OPException(MessageFormat.format(Messages.getString("ooconnect.OPConnection.msg"), strConnection), exception);
} catch (java.lang.Exception e) {
if (Converter.DEBUG_MODE) {
e.printStackTrace();
}
}
}
Aggregations