1 23 24 package com.sun.enterprise.util; 25 26 import java.io.File ; 27 import java.util.*; 28 import java.net.*; 29 30 31 import java.util.logging.*; 33 import com.sun.logging.*; 34 36 import com.sun.enterprise.loader.EJBClassLoader; 38 import com.sun.enterprise.server.ResourcesUtil; 39 40 41 48 public class ConnectorClassLoader extends EJBClassLoader { 49 50 static Logger _logger=LogDomains.getLogger(LogDomains.UTIL_LOGGER); 52 54 private static ConnectorClassLoader classLoader = null; 55 56 60 private List classLoaderChain= new LinkedList(); 61 62 66 private ClassLoader parent= null; 67 68 72 private Map rarModuleClassLoaders = new HashMap(); 73 74 public static ConnectorClassLoader getInstance() { 75 if (classLoader == null) { 76 synchronized(ConnectorClassLoader.class) { 77 classLoader = new ConnectorClassLoader(); 78 } 79 } 80 return classLoader; 81 } 82 83 private ConnectorClassLoader() { 84 super(); 85 } 86 87 private ConnectorClassLoader(ClassLoader parent) { 89 super(parent); 90 this.parent= parent; 91 } 92 93 100 public static ConnectorClassLoader getInstance(ClassLoader parent) { 101 if (classLoader == null) { 102 synchronized(ConnectorClassLoader.class) { 103 classLoader = new ConnectorClassLoader(parent); 104 } 105 } 106 return classLoader; 107 } 108 110 111 121 public void addResourceAdapter(String rarName, String moduleDir) { 122 123 try { 124 if(!ResourcesUtil.getInstance().belongToSystemRar(rarName)) { 127 File file= new File (moduleDir); 128 EJBClassLoader cl= new EJBClassLoader(parent); 129 cl.appendURL(file.toURI().toURL()); 130 classLoaderChain.add(cl); 131 rarModuleClassLoaders.put(rarName, cl); 132 } 133 } catch (MalformedURLException ex) { 134 _logger.log( 135 Level.SEVERE, 136 "enterprise_util.connector_malformed_url", 137 ex); 138 } 139 } 140 141 147 public void removeResourceAdapter(String moduleName) { 148 EJBClassLoader classLoaderToRemove= 149 (EJBClassLoader) rarModuleClassLoaders.get(moduleName); 150 if (classLoaderToRemove != null) { 151 classLoaderChain.remove(classLoaderToRemove); 152 rarModuleClassLoaders.remove(moduleName); 153 classLoaderToRemove = null; 154 _logger.log( 155 Level.WARNING, 156 "The Connector module " 157 + moduleName 158 + " has been removed. Please redeploy all applications that " 159 + "are using this connector module's resources"); 160 } 161 } 162 163 164 169 public synchronized Class loadClass(String name, boolean resolve) 170 throws ClassNotFoundException { 171 Class clz = null; 172 if(parent != null) { 175 try { 176 clz = parent.loadClass(name); 177 if (clz != null) { 178 if(resolve) { 179 resolveClass(clz); 180 } 181 return clz; 182 } 183 } catch (ClassNotFoundException e) { 184 } 187 } else { 188 return super.loadClass(name,resolve); 189 } 190 191 for (Iterator iter= classLoaderChain.iterator(); iter.hasNext();) { 194 EJBClassLoader ccl= (EJBClassLoader) iter.next(); 195 try { 196 clz= ccl.loadClass(name); 197 if (clz != null){ 198 if(resolve) { 199 resolveClass(clz); 200 } 201 return clz; 202 } 203 } catch (ClassNotFoundException cnfe) { 204 continue; 207 } 208 } 209 210 throw new ClassNotFoundException (name); 212 } 213 214 225 226 public String getClasspath(){ 227 StringBuffer strBuf = new StringBuffer (); 228 for (int i = 0; i < classLoaderChain.size(); i++) { 229 EJBClassLoader ecl= (EJBClassLoader) classLoaderChain.get(i); 230 String eclClasspath = ecl.getClasspath(); 231 if ( eclClasspath != null) { 232 if (i > 0) strBuf.append(File.pathSeparator); 233 strBuf.append(eclClasspath); 234 } 235 } 236 return strBuf.toString(); 237 } 238 } 239 | Popular Tags |