| Commit in servicemix/base/src/main/java/org/servicemix/jbi/framework on MAIN | |||
| ClassLoaderService.java | +131 | -105 | 1.5 -> 1.6 |
Switched classloader so that parent is the current classloader, also added some output to determine what the parent of the current classloader is after some cross-platform problems.
servicemix/base/src/main/java/org/servicemix/jbi/framework
diff -u -r1.5 -r1.6 --- ClassLoaderService.java 1 Aug 2005 00:04:41 -0000 1.5 +++ ClassLoaderService.java 2 Aug 2005 16:49:48 -0000 1.6 @@ -18,6 +18,7 @@
**/ package org.servicemix.jbi.framework;
+
import java.io.File; import java.net.MalformedURLException; import java.net.URL;
@@ -33,112 +34,137 @@
/** * Build custom class loader *
- * @version $Revision: 1.5 $
+ * @version $Revision: 1.6 $
*/
public class ClassLoaderService {
- private static final Log log = LogFactory.getLog(ClassLoaderService.class); - private Map sharedLibraryMap = new ConcurrentHashMap();
+ private static final Log log = LogFactory.getLog(ClassLoaderService.class);
+
+ private Map sharedLibraryMap = new ConcurrentHashMap();
+
+ /**
+ * Buld a Custom ClassLoader
+ *
+ * @param dir
+ * @param classPathNames
+ * @param parentFirst
+ * @return ClassLoader
+ * @throws MalformedURLException
+ * @throws MalformedURLException
+ * @throws DeploymentException
+ */
+ public InstallationClassLoader buildClassLoader(File dir,
+ String[] classPathNames, boolean parentFirst)
+ throws MalformedURLException, DeploymentException {
+ return buildClassLoader(dir, classPathNames, parentFirst, null);
+ }
+
+ /**
+ * Buld a Custom ClassLoader
+ *
+ * @param dir
+ * @param classPathNames
+ * @param parentFirst
+ * @param list
+ * @return ClassLoader
+ * @throws MalformedURLException
+ * @throws MalformedURLException
+ * @throws DeploymentException
+ */
+ public InstallationClassLoader buildClassLoader(File dir,
+ String[] classPathNames, boolean parentFirst,
+ SharedLibraryList[] list) throws MalformedURLException,
+ DeploymentException {
+ InstallationClassLoader result = null;
+
+ // Looking into ClassLoader
+ ClassLoader parent = getClass().getClassLoader().getParent();
+ log.info("Identified parent classloader [" + parent + "]");
+ parent = parent != null ? parent.getParent() : ClassLoader
+ .getSystemClassLoader();
+ log.info("Parent classloader is now [" + parent + "]");
+ parent = parent != null ? parent : ClassLoader.getSystemClassLoader();
+ log.info("Parent classloader is now [" + parent + "]");
+
+ // Overriding
+ parent = getClass().getClassLoader();
+
+ URL[] urls = new URL[classPathNames.length];
+ for (int i = 0; i < classPathNames.length; i++) {
+ File file = new File(dir, classPathNames[i]);
+ if (!file.exists()) {
+ throw new DeploymentException("Unable to add File " + file
+ + " to class path as it doesn't exist: "
+ + file.getAbsolutePath());
+ }
+ urls[i] = file.toURL();
+ }
+ if (parentFirst) {
+ result = new ParentFirstClassLoader(urls, parent);
+ } else {
+ result = new SelfFirstClassLoader(urls, parent);
+ }
+ if (list != null) {
+ for (int i = 0; i < list.length; i++) {
+ String name = list[i].getName();
+ ClassLoader cl = (ClassLoader) sharedLibraryMap.get(name);
+ if (cl != null) {
+ result.addSharedLibraryLoader(cl);
+ } else {
+ log.error("Could not find shared library: " + name);
+ }
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Add a shared library
+ *
+ * @param dir
+ * @param sl
+ * @throws MalformedURLException
+ */
+ public void addSharedLibrary(File dir, SharedLibrary sl)
+ throws MalformedURLException {
+ if (sl != null) {
+ boolean parentFirst = sl.isParentFirstClassLoaderDelegation();
+ String name = sl.getIdentification().getName();
+
+ // Looking into ClassLoader
+ ClassLoader parent = getClass().getClassLoader().getParent();
+ log.info("Identified parent classloader [" + parent + "]");
+ parent = parent != null ? parent.getParent() : ClassLoader
+ .getSystemClassLoader();
+ log.info("Parent classloader is now [" + parent + "]");
+ parent = parent != null ? parent : ClassLoader.getSystemClassLoader();
+ log.info("Parent classloader is now [" + parent + "]");
+
+ // Overriding
+ parent = getClass().getClassLoader();
+
+ ClassPath cp = sl.getSharedLibraryClassPath();
+ String[] classPathNames = cp.getPathElements();
+ URL[] urls = new URL[classPathNames.length];
+ for (int i = 0; i < classPathNames.length; i++) {
+ File file = new File(dir, classPathNames[i]);
+ urls[i] = file.toURL();
+ }
+ if (parentFirst) {
+ sharedLibraryMap.put(name, new ParentFirstClassLoader(urls,
+ parent));
+ } else {
+ sharedLibraryMap.put(name, new SelfFirstClassLoader(urls,
+ parent));
+ }
+ }
+ }
- /**
- * Buld a Custom ClassLoader
- *
- * @param dir
- * @param classPathNames
- * @param parentFirst
- * @return ClassLoader
- * @throws MalformedURLException
- * @throws MalformedURLException
- * @throws DeploymentException
- */
- public InstallationClassLoader buildClassLoader(File dir, String[] classPathNames, boolean parentFirst)
- throws MalformedURLException, DeploymentException {
- return buildClassLoader(dir, classPathNames, parentFirst, null);
- }
-
- /**
- * Buld a Custom ClassLoader
- *
- * @param dir
- * @param classPathNames
- * @param parentFirst
- * @param list
- * @return ClassLoader
- * @throws MalformedURLException
- * @throws MalformedURLException
- * @throws DeploymentException
- */
- public InstallationClassLoader buildClassLoader(File dir, String[] classPathNames, boolean parentFirst, SharedLibraryList[] list)
- throws MalformedURLException, DeploymentException {
- InstallationClassLoader result = null;
- ClassLoader parent = getClass().getClassLoader().getParent();
- parent = parent != null ? parent.getParent() : ClassLoader.getSystemClassLoader();
- parent = parent != null ? parent : ClassLoader.getSystemClassLoader();
- URL[] urls = new URL[classPathNames.length];
- for (int i = 0;i < classPathNames.length;i++) {
- File file = new File(dir, classPathNames[i]);
- if (!file.exists()){
- throw new DeploymentException("Unable to add File " + file + " to class path as it doesn't exist: " + file.getAbsolutePath());
- }
- urls[i] = file.toURL();
- }
- if (parentFirst) {
- result = new ParentFirstClassLoader(urls, parent);
- }
- else {
- result = new SelfFirstClassLoader(urls, parent);
- }
- if (list != null) {
- for (int i = 0;i < list.length;i++) {
- String name = list[i].getName();
- ClassLoader cl = (ClassLoader) sharedLibraryMap.get(name);
- if (cl != null) {
- result.addSharedLibraryLoader(cl);
- }
- else {
- log.error("Could not find shared library: " + name);
- }
- }
- }
- return result;
- }
-
- /**
- * Add a shared library
- *
- * @param dir
- * @param sl
- * @throws MalformedURLException
- */
- public void addSharedLibrary(File dir, SharedLibrary sl) throws MalformedURLException {
- if (sl != null) {
- boolean parentFirst = sl.isParentFirstClassLoaderDelegation();
- String name = sl.getIdentification().getName();
- ClassLoader parent = getClass().getClassLoader().getParent();
- parent = parent != null ? parent.getParent() : ClassLoader.getSystemClassLoader();
- parent = parent != null ? parent : ClassLoader.getSystemClassLoader();
- ClassPath cp = sl.getSharedLibraryClassPath();
- String[] classPathNames = cp.getPathElements();
- URL[] urls = new URL[classPathNames.length];
- for (int i = 0;i < classPathNames.length;i++) {
- File file = new File(dir, classPathNames[i]);
- urls[i] = file.toURL();
- }
- if (parentFirst) {
- sharedLibraryMap.put(name, new ParentFirstClassLoader(urls, parent));
- }
- else {
- sharedLibraryMap.put(name, new SelfFirstClassLoader(urls, parent));
- }
- }
- }
-
-
- /**
- * Remove a SharedLibrary
- *
- * @param id
- */
- public void removeSharedLibrary(String id) {
- sharedLibraryMap.remove(id);
- }
+ /**
+ * Remove a SharedLibrary
+ *
+ * @param id
+ */
+ public void removeSharedLibrary(String id) {
+ sharedLibraryMap.remove(id);
+ }
}
