SetrequestSet =(Set)m_cycleCheck.get();if(requestSet==null){requestSet =newHashSet();m_cycleCheck.set(requestSet);}if(requestSet.add(name)){try{// First, try to resolve the originating module.m_resolver.resolve(this);// Get the package of the target class/resource.StringpkgName =(isClass)?Util.getClassPackage(name):Util.getResourcePackage(name);// Delegate any packages listed in the boot delegation// property to the parent class loader.if(shouldBootDelegate(pkgName)){try{// Get the appropriate class loader for delegation.ClassLoaderbdcl =getBootDelegationClassLoader();result =(isClass)?(Object)bdcl.loadClass(name):(Object)bdcl.getResource(name);// If this is a java.* package, then always terminate the// search; otherwise, continue to look locally if not found.if(pkgName.startsWith("java.")||(result!=null)){returnresult;}}catch(ClassNotFoundExceptionex){// If this is a java.* package, then always terminate the// search; otherwise, continue to look locally if not found.if(pkgName.startsWith("java.")){throwex;}}}// Look in the module's imports. Note that the search may// be aborted if this method throws an exception, otherwise// it continues if a null is returned.result =searchImports(name,isClass);// If not found, try the module's own class path.if(result==null){result =(isClass)?(Object)getClassLoader().findClass(name):(Object)getResourceLocal(name);// If still not found, then try the module's dynamic imports.if(result==null){result =searchDynamicImports(name,pkgName,isClass);}}}catch(ResolveExceptionex){if(isClass){// We do not use the resolve exception as the// cause of the exception, since this would// potentially leak internal module information.thrownewClassNotFoundException(name+" not found because "+getBundle()+" cannot resolve: "+ex.getRequirement());}else{// The spec states that if the bundle cannot be resolved, then// only the local bundle's resources should be searched. So we// will ask the module's own class path.URLurl =getResourceLocal(name);if(url!=null){returnurl;}// We need to throw a resource not found exception.thrownewResourceNotFoundException(name+" not found because "+getBundle()+" cannot resolve: "+ex.getRequirement());}}finally{requestSet.remove(name);}}else{// If a cycle is detected, we should return null to break the// cycle. This should only ever be return to internal class// loading code and not to the actual instigator of the class load.returnnull;}if(result==null){if(isClass){thrownewClassNotFoundException(name+" not found by "+this.getBundle());}else{thrownewResourceNotFoundException(name+" not found by "+this.getBundle());}}returnresult;}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
osgi
felix framework
learning to ignore osgi
private Object findClassOrResourceByDelegation(String name, boolean isClass)
throws ClassNotFoundException, ResourceNotFoundException
{
Object result = null;