1 package com.thoughtworks.xstream.core.util; 2 3 import java.util.ArrayList ; 4 import java.util.Collections ; 5 import java.util.Iterator ; 6 import java.util.List ; 7 8 35 public class CompositeClassLoader extends ClassLoader { 36 37 private final List classLoaders = Collections.synchronizedList(new ArrayList ()); 38 39 public CompositeClassLoader() { 40 add(Object .class.getClassLoader()); add(getClass().getClassLoader()); } 43 44 48 public void add(ClassLoader classLoader) { 49 if (classLoader != null) { 50 classLoaders.add(0, classLoader); 51 } 52 } 53 54 public Class loadClass(String name) throws ClassNotFoundException { 55 for (Iterator iterator = classLoaders.iterator(); iterator.hasNext();) { 56 ClassLoader classLoader = (ClassLoader ) iterator.next(); 57 try { 58 return classLoader.loadClass(name); 59 } catch (ClassNotFoundException notFound) { 60 } 62 } 63 ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); 67 if (contextClassLoader != null) { 68 return contextClassLoader.loadClass(name); 69 } else { 70 throw new ClassNotFoundException (name); 71 } 72 } 73 74 } 75 | Popular Tags |