1 22 package org.objectweb.petals.classloader; 23 24 import java.io.IOException ; 25 import java.io.InputStream ; 26 import java.net.URL ; 27 import java.util.List ; 28 29 33 public class ComponentClassLoader extends PetalsClassLoader { 34 35 39 private List <String > sharedLibrariesNameList; 40 41 private SharedLibrariesClassLoader sharedLibrariesClassLoader; 42 43 public ComponentClassLoader(URL [] baseUrls, List <String > classpathLocations, SharedLibrariesClassLoader parent, List <String > sharedLibrariesNameList) throws IOException { 44 super(baseUrls, classpathLocations, parent); 45 46 this.sharedLibrariesNameList = sharedLibrariesNameList; 47 48 this.sharedLibrariesClassLoader = parent; 49 } 50 51 57 @Override 58 protected synchronized Class <?> loadClass(String className, boolean resolve) throws ClassNotFoundException { 59 Class <?> clazz = null; 60 clazz = findLoadedClass(className); 61 if (clazz == null) { 62 if (useParentFirst(className, true)) { 64 try { 65 clazz = sharedLibrariesClassLoader.loadClass(className, resolve, sharedLibrariesNameList); 66 } 67 catch (ClassNotFoundException cnfe) { 68 clazz = findClass(className); 69 } 70 } 71 else { 73 try { 74 clazz = findClass(className); 75 } 76 catch (ClassNotFoundException cnfe) { 77 if (isIsolated()) { 78 throw cnfe; 79 } 80 else { 81 clazz = sharedLibrariesClassLoader.loadClass(className, resolve, sharedLibrariesNameList); 82 } 83 } 84 } 85 } 86 if (resolve) { 87 resolveClass(clazz); 88 } 89 return clazz; 90 } 91 92 98 @Override 99 public synchronized URL getResource(String resourceName) { 100 URL url = null; 101 if (isParentFirst()) { 103 url = sharedLibrariesClassLoader.getResource(resourceName, sharedLibrariesNameList); 104 if (url == null){ 105 url = super.getResource(resourceName); 107 } 108 } 109 else { 111 url = super.getResource(resourceName); 112 if (url == null){ 113 url = sharedLibrariesClassLoader.getResource(resourceName, sharedLibrariesNameList); 115 } 116 } 117 return url; 118 } 119 120 126 @Override 127 public synchronized InputStream getResourceAsStream(String resourceName) { 128 InputStream inputStream = null; 129 if (isParentFirst()) { 131 inputStream = sharedLibrariesClassLoader.getResourceAsStream(resourceName, sharedLibrariesNameList); 132 if (inputStream == null){ 133 inputStream = super.getResourceAsStream(resourceName); 135 } 136 } 137 else { 139 inputStream = super.getResourceAsStream(resourceName); 140 if (inputStream == null){ 141 inputStream = sharedLibrariesClassLoader.getResourceAsStream(resourceName, sharedLibrariesNameList); 143 } 144 } 145 return inputStream; 146 } 147 148 149 } 150 | Popular Tags |