Exemple #1
0
  @Override
  public URL getResource(String name) {
    URL result = null;

    result = super.getResource(name);
    if (result != null) return result;

    if (getParent() == null) {
      result = Gate.getClassLoader().findResource(name);
      if (result != null) return result;
    }

    Set<GateClassLoader> children;
    synchronized (childClassLoaders) {
      children = new LinkedHashSet<GateClassLoader>(childClassLoaders.values());
    }

    for (GateClassLoader cl : children) {
      if (!cl.isIsolated()) {
        result = cl.getResource(name);
        if (result != null) return result;
      }
    }

    return null;
  }
Exemple #2
0
  /**
   * Causes the specified classloader to be forgotten, making it and all the class definitions
   * loaded by it available for garbage collection
   *
   * @param id the id of the classloader to forget
   */
  public void forgetClassLoader(String id) {

    GateClassLoader gcl;

    synchronized (childClassLoaders) {
      gcl = childClassLoaders.remove(id);
    }

    if (gcl != null && !gcl.isIsolated()) {
      Introspector.flushCaches();
      AbstractResource.flushBeanInfoCache();
    }
  }
Exemple #3
0
  /** Delegate loading to the super class (loadClass has protected access there). */
  private Class<?> loadClass(
      String name, boolean resolve, boolean localOnly, Set<GateClassLoader> visited)
      throws ClassNotFoundException {

    Class<?> previous = findLoadedClass(name);

    if (previous != null) {
      if (DEBUG) System.out.println("CACHE HIT: " + name + " -- " + id);

      return previous;
    }

    if (DEBUG)
      System.out.println(
          name + " -- " + id + ": " + localOnly + "/" + isolated + "/" + getParent());

    // to ensure we don't end up looping through the same classloader
    // twice we
    // keep a track of which ones we have already visited
    visited.add(this);

    if (!this.equals(Gate.getClassLoader())) {
      try {
        // first we see if we can find the class via the system class
        // path
        Class<?> found = Gate.getClassLoader().getParent().loadClass(name);

        URL url = findResource(name.replace('.', '/') + ".class");
        if (url != null)
          log.warn(
              name
                  + " is available via both the system classpath and a plugin; the plugin classes will be ignored");

        // if we got to here then the class has been found via the
        // system
        // classpath so return it and stop looking
        return found;

      } catch (ClassNotFoundException e) {
        // this can safely be ignored
      }
    }

    try {
      // try loading and returning by looking within this classloader
      return super.loadClass(name, resolve);
    } catch (ClassNotFoundException e) {
      // this can safely be ignored
    }

    if (this.getParent() != null && this.getParent() instanceof GateClassLoader)
      visited.add((GateClassLoader) this.getParent());

    if (!localOnly) {
      // if we aren't just looking locally then...

      if (getParent() == null) {
        try {
          // if this classloader doesn't have a parent then it must be
          // disposable, but as we haven't found the class we need yet
          // we should
          // now look into the main GATE classloader
          return Gate.getClassLoader().loadClass(name, resolve, false, visited);
        } catch (ClassNotFoundException e) {
          // this can safely be ignored
        }
      }

      Set<GateClassLoader> children;
      synchronized (childClassLoaders) {
        children = new LinkedHashSet<GateClassLoader>(childClassLoaders.values());
      }

      // make sure we don't visit a classloader we've already been
      // through
      children.removeAll(visited);

      for (GateClassLoader cl : children) {
        // the class isn't to be found in either this classloader or the
        // main
        // GATE classloader so let's check all the other disposable
        // classloaders
        try {
          if (!cl.isIsolated()) return cl.loadClass(name, resolve, true, visited);
        } catch (ClassNotFoundException e) {
          // this can safely be ignored
        }
      }
    }

    // if we got to here then no matter where we have looked we have
    // been unable
    // to find the class requested so throw an exception
    throw new ClassNotFoundException(name);
  }