1 28 29 package com.caucho.loader; 30 31 import com.caucho.config.ConfigException; 32 import com.caucho.log.Log; 33 import com.caucho.vfs.Path; 34 35 import java.io.InputStream ; 36 import java.net.URL ; 37 import java.security.CodeSource ; 38 import java.security.cert.Certificate ; 39 import java.util.Vector ; 40 import java.util.logging.Level ; 41 import java.util.logging.Logger ; 42 43 44 47 abstract public class Loader { 48 protected static final Logger log = Log.open(Loader.class); 49 50 private DynamicClassLoader _loader; 51 52 55 public void setLoader(DynamicClassLoader loader) 56 { 57 _loader = loader; 58 } 59 60 63 public DynamicClassLoader getLoader() 64 { 65 return _loader; 66 } 67 68 71 public void validate() 72 throws ConfigException 73 { 74 } 75 76 81 protected ClassEntry getClassEntry(String name) 82 throws ClassNotFoundException 83 { 84 String pathName = name.replace('.', '/') + ".class"; 85 86 Path path = getPath(pathName); 88 89 if (path != null && path.getLength() > 0) 90 return new ClassEntry(_loader, name, path, path, 91 getCodeSource(path)); 92 else 93 return null; 94 } 95 96 101 public URL getResource(String name) 102 { 103 Path path; 104 105 if (name.startsWith("/")) 106 path = getPath("." + name); 107 else 108 path = getPath(name); 109 110 if (path != null && path.exists()) { 111 try { 112 return new URL (path.getURL()); 113 } catch (Exception e) { 114 e.printStackTrace(); 115 log.log(Level.FINER, e.toString(), e); 116 } 117 } 118 119 return null; 120 } 121 122 127 public void getResources(Vector <URL > resources, String name) 128 { 129 Path path; 130 131 if (name.startsWith("/")) 132 path = getPath("." + name); 133 else 134 path = getPath(name); 135 136 if (path != null && path.canRead()) { 137 try { 138 resources.add(new URL (path.getURL())); 139 } catch (Exception e) { 140 } 141 } 142 } 143 144 149 public InputStream getResourceAsStream(String name) 150 { 151 Path path; 152 153 if (name.startsWith("/")) 154 path = getPath("." + name); 155 else 156 path = getPath(name); 157 158 if (path != null && path.canRead()) { 159 try { 160 return path.openRead(); 161 } catch (Exception e) { 162 } 163 } 164 165 return null; 166 } 167 168 171 public Path getPath(String name) 172 { 173 return null; 174 } 175 176 179 protected CodeSource getCodeSource(Path path) 180 { 181 try { 182 return new CodeSource (new URL (path.getURL()), 183 (Certificate []) path.getCertificates()); 184 } catch (Exception e) { 185 log.log(Level.WARNING, e.toString(), e); 186 187 return null; 188 } 189 } 190 191 194 protected String getClassPath(String head) 195 { 196 return head; 197 } 198 199 202 protected String getSourcePath(String head) 203 { 204 return getClassPath(head); 205 } 206 207 210 protected void destroy() 211 { 212 } 213 } 214 | Popular Tags |