1 22 package org.jboss.iiop; 23 24 import java.util.Collections ; 25 import java.util.Map ; 26 import java.util.WeakHashMap ; 27 import javax.management.ObjectName ; 28 29 import org.jboss.logging.Logger; 30 import org.jboss.mx.loading.RepositoryClassLoader; 31 import org.jboss.proxy.compiler.IIOPStubCompiler; 32 import org.jboss.web.WebClassLoader; 33 34 40 public class WebCL extends WebClassLoader 41 { 42 43 static Logger logger = Logger.getLogger(WebCL.class); 44 45 46 private Map loadedStubMap = Collections.synchronizedMap(new WeakHashMap ()); 47 48 49 public WebCL(ObjectName container, RepositoryClassLoader parent) 50 { 51 super(container, parent); 52 logger.debug("Constructed WebCL " + this.toString()); 53 logger.debug(" parent " + parent.toString()); 54 55 standard = true; 57 } 58 59 60 public String getKey() 61 { 62 String className = getClass().getName(); 63 int dot = className.lastIndexOf('.'); 64 if( dot >= 0 ) 65 className = className.substring(dot+1); 66 String jndiName = getContainer().getKeyProperty("jndiName"); 67 String key = className + '[' + jndiName + ']'; 68 return key; 69 } 70 71 72 public byte[] getBytes(Class clz) { 73 byte[] code = (byte[])loadedStubMap.get(clz); 74 return (code == null) ? null : (byte[])code.clone(); 75 } 76 77 protected Class findClass(String name) 78 throws ClassNotFoundException 79 { 80 if (logger.isTraceEnabled()) { 81 logger.trace("findClass(" + name + ") called"); 82 } 83 if (name.endsWith("_Stub")) { 84 int start = name.lastIndexOf('.') + 1; 85 if (name.charAt(start) == '_') { 86 String pkg = name.substring(0, start); 87 String interfaceName = pkg + name.substring(start + 1, 88 name.length() - 5); 89 90 if (interfaceName.startsWith("org.omg.stub.com.sun.")) 97 interfaceName = interfaceName.substring(13); 98 99 Class intf = super.loadClass(interfaceName); 100 if (logger.isTraceEnabled()) { 101 logger.trace("loaded class " + interfaceName); 102 } 103 104 try { 105 byte[] code = 106 IIOPStubCompiler.compile(intf, name); 107 108 if (logger.isTraceEnabled()) { 109 logger.trace("compiled stub class for " 110 + interfaceName); 111 } 112 Class clz = defineClass(name, code, 0, code.length); 113 if (logger.isTraceEnabled()) { 114 logger.trace("defined stub class for " 115 + interfaceName); 116 } 117 resolveClass(clz); 118 try { 119 clz.newInstance(); 120 } 121 catch (Throwable t) { 122 throw new org.jboss.util.NestedRuntimeException(t); 124 } 125 if (logger.isTraceEnabled()) { 126 logger.trace("resolved stub class for " 127 + interfaceName); 128 } 129 loadedStubMap.put(clz, code); 130 return clz; 131 } 132 catch (RuntimeException e) { 133 logger.error("failed finding class " + name, e); 134 return super.findClass(name); 136 } 137 } 138 else { 139 return super.findClass(name); 140 } 141 } 142 else { 143 return super.findClass(name); 144 } 145 } 146 147 } 148 | Popular Tags |