Example #1
0
  /**
   * overriding getResource() because we want to search FIRST in this ClassLoader, then the parent,
   * the path, etc.
   */
  public URL getResource(String name) {
    try {
      if (jar != null) {
        ZipFile zipFile = jar.getZipFile();
        ZipEntry entry = zipFile.getEntry(name);
        if (entry != null) {
          return new URL(getResourceAsPath(name));
        }
      }

      Object obj = resourcesHash.get(name);
      if (obj instanceof JARClassLoader) {
        JARClassLoader classLoader = (JARClassLoader) obj;
        return classLoader.getResource(name);
      } else {
        URL ret = getSystemResource(name);
        if (ret != null) {
          Log.log(
              Log.DEBUG,
              JARClassLoader.class,
              "Would have returned null for getResource(" + name + ")");
          Log.log(Log.DEBUG, JARClassLoader.class, "returning(" + ret + ")");
        }
        return ret;
      }
    } catch (IOException io) {
      Log.log(Log.ERROR, this, io);
      return null;
    }
  } // }}}
Example #2
0
  /** @exception ClassNotFoundException if the class could not be found */
  public Class loadClass(String clazz, boolean resolveIt) throws ClassNotFoundException {
    ClassNotFoundException pending = null;
    if (delegateFirst) {
      try {
        return loadFromParent(clazz);
      } catch (ClassNotFoundException cnf) {
        // keep going if class was not found.
        pending = cnf;
      }
    }

    Object obj = classHash.get(clazz);
    if (obj == NO_CLASS) {
      // we remember which classes we don't exist
      // because BeanShell tries loading all possible
      // <imported prefix>.<class name> combinations
      throw new ClassNotFoundException(clazz);
    } else if (obj instanceof JARClassLoader) {
      JARClassLoader classLoader = (JARClassLoader) obj;
      try {
        return classLoader._loadClass(clazz, resolveIt);
      } catch (ClassNotFoundException cnf2) {
        classHash.put(clazz, NO_CLASS);
        throw cnf2;
      }
    } else if (delegateFirst) {
      // if delegating, reaching this statement means
      // the class was really not found. Otherwise
      // we'll try loading from the parent class loader.
      throw pending;
    }

    return loadFromParent(clazz);
  } // }}}
Example #3
0
  // {{{ getResourceAsStream() method
  public InputStream getResourceAsStream(String name) {
    try {
      // try in current jar first
      if (jar != null) {
        ZipFile zipFile = jar.getZipFile();
        ZipEntry entry = zipFile.getEntry(name);
        if (entry != null) {
          return zipFile.getInputStream(entry);
        }
      }
      // then try from another jar
      Object obj = resourcesHash.get(name);
      if (obj instanceof JARClassLoader) {
        JARClassLoader classLoader = (JARClassLoader) obj;
        return classLoader.getResourceAsStream(name);
      }
      // finally try from the system class loader
      return getSystemResourceAsStream(name);
    } catch (IOException io) {
      Log.log(Log.ERROR, this, io);

      return null;
    }
  } // }}}