コード例 #1
0
  /**
   * Loads the class <code>qualifiedName</code> from the specified <code>bundle</code> if possible.
   *
   * @param bundle The bundle from which to load the sought class.
   * @param qualifiedName Qualified name of the class that is to be loaded.
   * @return An instance of the class if it could be loaded, <code>null</code> otherwise.
   */
  private Class<?> internalLoadClass(Bundle bundle, String qualifiedName) {
    try {
      WorkspaceClassInstance workspaceInstance = workspaceLoadedClasses.get(qualifiedName);
      final Class<?> clazz;
      if (workspaceInstance == null) {
        clazz = bundle.loadClass(qualifiedName);
        workspaceLoadedClasses.put(
            qualifiedName, new WorkspaceClassInstance(clazz, bundle.getSymbolicName()));
      } else if (workspaceInstance.isStale()) {
        clazz = bundle.loadClass(qualifiedName);
        workspaceInstance.setStale(false);
        workspaceInstance.setClass(clazz);
      } else {
        clazz = workspaceInstance.getClassInstance();
      }

      return clazz;
    } catch (ClassNotFoundException e) {
      e.fillInStackTrace();
      AcceleoCommonPlugin.log(
          AcceleoCommonMessages.getString(
              "BundleClassLookupFailure", //$NON-NLS-1$
              qualifiedName,
              bundle.getSymbolicName()),
          e,
          false);
    }
    return null;
  }
コード例 #2
0
  private static Connection connect(String url) throws SQLException {
    // Step 1: Load the JDBC driver.
    try {
      DatabaseUtil.loadDatabaseDriver(url);
    } catch (ClassNotFoundException e) {
      log.error("Could not find JDBC driver class.", e);
      throw (SQLException) e.fillInStackTrace();
    }

    // Step 2: Establish the connection to the database.
    String username = Context.getRuntimeProperties().getProperty("connection.username");
    String password = Context.getRuntimeProperties().getProperty("connection.password");
    log.debug(
        "connecting to DATABASE: "
            + OpenmrsConstants.DATABASE_NAME
            + " USERNAME: "******" URL: "
            + url);
    return DriverManager.getConnection(url, username, password);
  }