Esempio n. 1
0
  @SuppressWarnings("unchecked")
  protected void addIfMatching(Test test, String fqn) {
    try {
      String externalName = fqn.substring(0, fqn.indexOf('.')).replace('/', '.');
      ClassLoader loader = getClassLoader();

      Class<?> type = loader.loadClass(externalName);
      if (test.matches(type)) {
        matches.add((Class<? extends T>) type);
      }
    } catch (Throwable t) {
      // Ignore
    }
  }
Esempio n. 2
0
  /**
   * Add the class designated by the fully qualified class name provided to the set of resolved
   * classes if and only if it is approved by the Test supplied.
   *
   * @param test the test used to determine if the class matches
   * @param fqn the fully qualified name of a class
   */
  protected void addIfMatching(Test test, String fqn) {
    try {
      ClassLoader loader = getClassLoader();
      if (test.doesMatchClass()) {
        String externalName = fqn.substring(0, fqn.indexOf('.')).replace('/', '.');
        if (LOG.isDebugEnabled()) {
          LOG.debug(
              "Checking to see if class " + externalName + " matches criteria [" + test + "]");
        }

        Class type = loader.loadClass(externalName);
        if (test.matches(type)) {
          classMatches.add((Class<T>) type);
        }
      }
      if (test.doesMatchResource()) {
        URL url = loader.getResource(fqn);
        if (url == null) {
          url = loader.getResource(fqn.substring(1));
        }
        if (url != null && test.matches(url)) {
          resourceMatches.add(url);
        }
      }
    } catch (Throwable t) {
      if (LOG.isWarnEnabled()) {
        LOG.warn(
            "Could not examine class '"
                + fqn
                + "' due to a "
                + t.getClass().getName()
                + " with message: "
                + t.getMessage());
      }
    }
  }