示例#1
0
 public URL getResource(String name) {
   return loader.getResource(name);
 }
示例#2
0
  URL findResource(String name, boolean checkParent) {
    if ((name.length() > 1) && (name.charAt(0) == '/')) /* if name has a leading slash */
      name = name.substring(1); /* remove leading slash before search */
    String pkgName = getResourcePackageName(name);
    boolean bootDelegation = false;
    ClassLoader parentCL = getParentClassLoader();
    // follow the OSGi delegation model
    // First check the parent classloader for system resources, if it is a java resource.
    if (checkParent && parentCL != null) {
      if (pkgName.startsWith(JAVA_PACKAGE))
        // 1) if startsWith "java." delegate to parent and terminate search
        // we never delegate java resource requests past the parent
        return parentCL.getResource(name);
      else if (bundle.getFramework().isBootDelegationPackage(pkgName)) {
        // 2) if part of the bootdelegation list then delegate to parent and continue of failure
        URL result = parentCL.getResource(name);
        if (result != null) return result;
        bootDelegation = true;
      }
    }

    URL result = null;
    try {
      result = (URL) searchHooks(name, PRE_RESOURCE);
    } catch (FileNotFoundException e) {
      return null;
    } catch (ClassNotFoundException e) {
      // will not happen
    }
    if (result != null) return result;
    // 3) search the imported packages
    PackageSource source = findImportedSource(pkgName, null);
    if (source != null)
      // 3) found import source terminate search at the source
      return source.getResource(name);
    // 4) search the required bundles
    source = findRequiredSource(pkgName, null);
    if (source != null)
      // 4) attempt to load from source but continue on failure
      result = source.getResource(name);
    // 5) search the local bundle
    if (result == null) result = findLocalResource(name);
    if (result != null) return result;
    // 6) attempt to find a dynamic import source; only do this if a required source was not found
    if (source == null) {
      source = findDynamicSource(pkgName);
      if (source != null)
        // must return the result of the dynamic import and do not continue
        return source.getResource(name);
    }

    if (result == null)
      try {
        result = (URL) searchHooks(name, POST_RESOURCE);
      } catch (FileNotFoundException e) {
        return null;
      } catch (ClassNotFoundException e) {
        // will not happen
      }
    // do buddy policy loading
    if (result == null && policy != null) result = policy.doBuddyResourceLoading(name);
    if (result != null) return result;
    // hack to support backwards compatibiility for bootdelegation
    // or last resort; do class context trick to work around VM bugs
    if (parentCL != null
        && !bootDelegation
        && ((checkParent && bundle.getFramework().compatibiltyBootDelegation) || isRequestFromVM()))
      // we don't need to continue if the resource is not found here
      return parentCL.getResource(name);
    return result;
  }
示例#3
0
 public URL getEntry(String path) {
   if (path.startsWith("/")) path = path.substring(1);
   return loader.getResource(path);
 }