1 5 package com.tc.object.loaders; 6 7 import com.tc.object.ClientObjectManager; 8 import com.tc.object.bytecode.Manager; 9 import com.tc.object.bytecode.ManagerImpl; 10 import com.tc.object.bytecode.hook.impl.ClassProcessorHelper; 11 import com.tc.object.bytecode.hook.impl.DSOContextImpl; 12 import com.tc.object.bytecode.hook.impl.PreparedComponentsFromL2Connection; 13 import com.tc.object.config.DSOClientConfigHelper; 14 import com.tc.object.tx.ClientTransactionManager; 15 16 import java.net.URL ; 17 import java.net.URLClassLoader ; 18 import java.util.HashMap ; 19 20 24 public class IsolationClassLoader extends URLClassLoader implements NamedClassLoader { 25 private static final ClassLoader SYSTEM_LOADER = ClassLoader.getSystemClassLoader(); 26 27 private final Manager manager; 28 private final DSOClientConfigHelper config; 29 private final HashMap onLoadErrors; 30 private final StandardClassProvider classProvider; 31 32 public IsolationClassLoader(DSOClientConfigHelper config, PreparedComponentsFromL2Connection connectionComponents) { 33 this(config, true, null, null, connectionComponents); 34 } 35 36 public IsolationClassLoader(DSOClientConfigHelper config, ClientObjectManager objectManager, 37 ClientTransactionManager txManager) { 38 this(config, false, objectManager, txManager, null); 39 } 40 41 private IsolationClassLoader(DSOClientConfigHelper config, boolean startClient, ClientObjectManager objectManager, 42 ClientTransactionManager txManager, 43 PreparedComponentsFromL2Connection connectionComponents) { 44 super(getSystemURLS(), null); 45 this.config = config; 46 this.classProvider = new StandardClassProvider(); 47 this.manager = createManager(startClient, objectManager, txManager, config, connectionComponents); 48 this.onLoadErrors = new HashMap (); 49 } 50 51 public void init() { 52 manager.init(); 53 ClassProcessorHelper.setContext(this, DSOContextImpl.createContext(config, classProvider, manager)); 54 } 55 56 private static URL [] getSystemURLS() { 57 return ((URLClassLoader ) SYSTEM_LOADER).getURLs(); 58 } 59 60 private Manager createManager(boolean startClient, ClientObjectManager objectManager, 61 ClientTransactionManager txManager, DSOClientConfigHelper theConfig, 62 PreparedComponentsFromL2Connection connectionComponents) { 63 classProvider.registerNamedLoader(this); 64 return new ManagerImpl(startClient, objectManager, txManager, theConfig, classProvider, connectionComponents, false); 65 } 66 67 public void stop() { 68 this.manager.stop(); 69 } 70 71 public Class loadClass(String name) throws ClassNotFoundException { 72 throwIfNeeded(name); 73 74 if (name.startsWith("com.tc.")) { 75 return SYSTEM_LOADER.loadClass(name); 76 } else { 77 return super.loadClass(name); 78 } 79 } 80 81 private void throwIfNeeded(String name) throws ClassNotFoundException { 82 final String t = (String )onLoadErrors.get(name); 84 if (t != null) { 85 ClassNotFoundException rv = new ClassNotFoundException (t); 86 throw rv; 87 } 88 } 89 90 public String __tc_getClassLoaderName() { 91 return getClass().getName(); 92 } 93 94 public void __tc_setClassLoaderName(String name) { 95 throw new AssertionError (); 96 } 97 98 101 public void throwOnLoad(String className, String errorMessage) { 102 onLoadErrors.put(className, errorMessage); 103 } 104 105 protected Class findClass(String name) throws ClassNotFoundException { 106 throwIfNeeded(name); 107 return super.findClass(name); 108 } 109 } 110 | Popular Tags |