/** * Test calls the method and trying to get revoked object. * * <p>Has <b> OK </b> status if the method successfully returns and if the method <code> * getRegisteredObject</code> returns NULL or throws expected exception. * * <p>The following method tests are to be completed successfully before : * * <ul> * <li><code> registerObject </code> : to revoke the object registered * </ul> * * The following method tests are to be executed before : * * <ul> * <li><code> getRegisteredObject </code> : before object will be revoked * </ul> */ public void _revokeObject() { requiredMethod("registerObject()"); executeMethod("getRegisteredObject()"); try { oObj.revokeObject("MyFactory"); log.println("Object was revoked"); } catch (com.sun.star.uno.Exception e) { log.println("Exception revoking object :" + e); tRes.tested("revokeObject()", false); } boolean res = true; try { log.println("Trying to getRegistered object ..."); Object objregObj = oObj.getRegisteredObject("MyFactory"); log.println("No exception"); res &= objregObj == null; if (res) { log.println("But NULL was returned"); } } catch (com.sun.star.uno.Exception e) { log.println("Expected exception - OK"); } tRes.tested("revokeObject()", res); }
public static XMultiServiceFactory connect(String sConnectStr) throws com.sun.star.uno.Exception, com.sun.star.uno.RuntimeException, Exception { // Get component context XComponentContext xComponentContext = com.sun.star.comp.helper.Bootstrap.createInitialComponentContext(null); // initial serviceManager XMultiComponentFactory xLocalServiceManager = xComponentContext.getServiceManager(); // create a connector, so that it can contact the office Object oUrlResolver = xLocalServiceManager.createInstanceWithContext( "com.sun.star.bridge.UnoUrlResolver", xComponentContext); XUnoUrlResolver xUrlResolver = UnoRuntime.queryInterface(XUnoUrlResolver.class, oUrlResolver); Object oInitialObject = xUrlResolver.resolve(sConnectStr); XNamingService xName = UnoRuntime.queryInterface(XNamingService.class, oInitialObject); XMultiServiceFactory xMSF = null; if (xName != null) { System.err.println("got the remote naming service !"); Object oMSF = xName.getRegisteredObject("StarOffice.ServiceManager"); xMSF = UnoRuntime.queryInterface(XMultiServiceFactory.class, oMSF); } else System.out.println("Error: Can't get XNamingService interface from url resolver!"); return xMSF; }
/** * Test calls the method and checks return value and that no exceptions were thrown. * * <p>Has <b> OK </b> status if the method returns the same object that was registered and no * exceptions were thrown. * * <p>The following method tests are to be completed successfully before : * * <ul> * <li><code> registerObject </code> : to get in this test the object that was registered. * </ul> */ public void _getRegisteredObject() { requiredMethod("registerObject()"); try { Object getObject = oObj.getRegisteredObject("MyFactory"); tRes.tested("getRegisteredObject()", regObject.equals(getObject)); } catch (com.sun.star.uno.Exception e) { log.println("Exception calling method :" + e); tRes.tested("getRegisteredObject()", false); return; } }