1 28 29 package com.caucho.iiop; 30 31 import com.caucho.config.ConfigException; 32 import com.caucho.ejb.AbstractStubLoader; 33 import com.caucho.loader.DynamicClassLoader; 34 import com.caucho.log.Log; 35 import com.caucho.server.util.CauchoSystem; 36 import com.caucho.util.CharBuffer; 37 import com.caucho.vfs.Path; 38 39 import java.net.URL ; 40 import java.security.CodeSource ; 41 import java.security.cert.Certificate ; 42 import java.util.HashSet ; 43 import java.util.logging.Level ; 44 import java.util.logging.Logger ; 45 46 50 public class IiopStubLoader extends AbstractStubLoader { 51 private static final Logger log = Log.open(IiopStubLoader.class); 52 53 private HashSet <String > _stubClassNames = new HashSet <String >(); 54 55 private CodeSource _codeSource; 56 57 60 public IiopStubLoader() 61 { 62 } 63 64 69 public IiopStubLoader(Path path) 70 { 71 setPath(path); 72 } 73 74 77 public void setLoader(DynamicClassLoader loader) 78 { 79 super.setLoader(loader); 80 81 loader.addURL(getPath()); 82 } 83 84 87 public void init() 88 throws ConfigException 89 { 90 try { 91 _codeSource = new CodeSource (new URL (getPath().getURL()), 92 (Certificate []) null); 93 } catch (Exception e) { 94 log.log(Level.FINE, e.toString(), e); 95 } 96 } 97 98 101 public void addStubClass(String className) 102 { 103 System.out.println("PATH: " + getPath()); 104 105 int p = className.lastIndexOf('.'); 106 107 if (p > 0) { 108 String tail = className.substring(p + 1); 109 110 tail = "_" + tail + "_Stub"; 111 112 className = className.substring(0, p) + '.' + tail; 113 } 114 else 115 className = "_" + className + "_Stub"; 116 117 className = "org.omg.stub." + className; 118 119 className = className.replace('.', '/') + ".class"; 120 121 System.out.println("CL: " + className); 122 123 _stubClassNames.add(className); 124 } 125 126 133 public Path getPath(String name) 134 { 135 if (! _stubClassNames.contains(name)) 136 return null; 137 138 Path stubClassPath = getPath().lookup(name); 139 140 System.out.println("PATH: " + stubClassPath.getNativePath()); 141 142 if (stubClassPath.canRead()) 143 return stubClassPath; 144 145 String fullClassName = name.substring(0, name.length() - ".class".length()); 146 fullClassName = fullClassName.replace('/', '.'); 147 148 String className = fullClassName.substring("org.omg.stub.".length()); 149 className = className.replace('/', '.'); 150 151 int p = className.lastIndexOf('.'); 152 if (p > 0) { 153 String tail = className.substring(p + 1); 154 155 tail = tail.substring(1, tail.length() - "_Stub".length()); 156 157 className = className.substring(0, p) + '.' + tail; 158 } 159 160 Thread thread = Thread.currentThread(); 161 ClassLoader loader = thread.getContextClassLoader(); 162 163 try { 164 System.out.println("ZOOM: " + className); 165 166 Class cl = Class.forName(className, false, loader); 167 System.out.println("CL: " + cl); 168 169 IiopStubCompiler compiler = new IiopStubCompiler(cl); 170 compiler.setFullClassName(fullClassName); 171 compiler.setClassDir(getPath()); 172 173 compiler.generate(); 174 compiler.compileJava(); 175 176 System.out.println("OOK-OOK-OOK"); 177 178 if (stubClassPath.canRead()) 179 return stubClassPath; 180 } catch (Exception e) { 181 e.printStackTrace(); 182 log.log(Level.WARNING, e.toString(), e); 183 } 184 185 return null; 186 } 187 188 191 protected CodeSource getCodeSource(Path path) 192 { 193 return _codeSource; 194 } 195 196 199 protected String getClassPath(String head) 200 { 201 CharBuffer cb = new CharBuffer(); 202 203 if (! head.equals("")) { 204 cb.append(head); 205 cb.append(CauchoSystem.getPathSeparatorChar()); 206 } 207 208 if (getPath().isDirectory()) 209 cb.append(getPath().getNativePath()); 210 211 return cb.toString(); 212 } 213 214 217 public String toString() 218 { 219 return "IiopStubLoader[" + getPath() + "]"; 220 } 221 } 222 | Popular Tags |