Ejemplo n.º 1
0
  /* ------------------------------------------------------------------ */
  private boolean ensureDataSource() throws Exception {
    m_orb = (XMultiServiceFactory) param.getMSF();

    XNameAccess databaseContext =
        UnoRuntime.queryInterface(
            XNameAccess.class, m_orb.createInstance("com.sun.star.sdb.DatabaseContext"));
    XNamingService namingService = UnoRuntime.queryInterface(XNamingService.class, databaseContext);

    // revoke the data source, if it previously existed
    if (databaseContext.hasByName(m_dataSourceName)) namingService.revokeObject(m_dataSourceName);

    // // create a new ODB file, and register it with its URL
    m_databaseDocument = new HsqlDatabase(m_orb);
    String documentURL = m_databaseDocument.getDocumentURL();
    namingService.registerObject(m_dataSourceName, databaseContext.getByName(documentURL));

    m_dataSource =
        UnoRuntime.queryInterface(XDataSource.class, databaseContext.getByName(m_dataSourceName));
    m_dataSourceProps = dbfTools.queryPropertySet(m_dataSource);

    XPropertySet dataSourceSettings =
        UnoRuntime.queryInterface(
            XPropertySet.class, m_dataSourceProps.getPropertyValue("Settings"));
    dataSourceSettings.setPropertyValue("FormsCheckRequiredFields", new Boolean(false));

    return m_dataSource != null;
  }
  /**
   * 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);
  }
Ejemplo n.º 3
0
  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 that no exceptions were thrown.
   *
   * <p>Has <b> OK </b> status if the method successfully returns and no exceptions were thrown.
   *
   * <p>The following method tests are to be completed successfully before :
   */
  public void _registerObject() throws StatusException {
    try {
      oObj.registerObject("MyFactory", regObject);
    } catch (com.sun.star.uno.Exception e) {
      log.println("Exception while registering object :" + e);
      tRes.tested("registerObject()", false);
      return;
    }

    tRes.tested("registerObject()", true);
  }
  /**
   * 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;
    }
  }