1 17 18 package org.apache.geronimo.classloaderserver; 19 20 import java.net.URL ; 21 22 import org.apache.commons.logging.Log; 23 import org.apache.commons.logging.LogFactory; 24 import org.apache.geronimo.gbean.GBeanInfo; 25 import org.apache.geronimo.gbean.GBeanInfoBuilder; 26 import org.apache.geronimo.gbean.GBeanLifecycle; 27 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory; 28 import org.apache.geronimo.kernel.config.Configuration; 29 import org.apache.geronimo.kernel.config.ConfigurationClassLoader; 30 31 32 36 public class ConfigurationClassLoaderExporter implements GBeanLifecycle { 37 private static final Log log = LogFactory.getLog(ConfigurationClassLoaderExporter.class); 38 39 private final ClassLoaderServer networkServer; 40 private final Configuration configuration; 41 private ClassLoaderInfoAdapter adapter; 42 43 public ConfigurationClassLoaderExporter(ClassLoaderServer networkServer, Configuration configuration) { 44 this.networkServer = networkServer; 45 this.configuration = configuration; 46 } 47 48 public void doStart() throws Exception { 49 ConfigurationClassLoader cl = configuration.getConfigurationClassLoader(); 50 51 adapter = new ClassLoaderInfoAdapter(cl); 52 networkServer.export(adapter); 53 } 54 55 public void doStop() throws Exception { 56 networkServer.unexport(adapter); 57 } 58 59 public void doFail() { 60 try { 61 networkServer.unexport(adapter); 62 } catch (ClassLoaderServerException e) { 63 log.error(e); 64 } 65 } 66 67 private static class ClassLoaderInfoAdapter implements ClassLoaderInfo { 68 private final ConfigurationClassLoader cl; 69 70 private ClassLoaderInfoAdapter(ConfigurationClassLoader cl) { 71 this.cl = cl; 72 } 73 74 public ClassLoader getClassLoader() { 75 return cl; 76 } 77 78 public Object getID() { 79 return cl.getID(); 80 } 81 82 public void setClassLoaderServerURLs(URL [] urls) { 83 cl.setClassLoaderServerURLs(urls); 84 } 85 } 86 87 public static final GBeanInfo GBEAN_INFO; 88 89 static { 90 GBeanInfoBuilder infoBuilder = new GBeanInfoBuilder("ConfigurationClassLoader Exporter", ConfigurationClassLoaderExporter.class); 91 92 infoBuilder.addReference("ClassLoaderServer", ClassLoaderServer.class, NameFactory.GERONIMO_SERVICE); 93 infoBuilder.addReference("Configuration", Configuration.class, NameFactory.CONFIGURATION_ENTRY); 94 95 infoBuilder.setConstructor(new String [] {"ClassLoaderServer", "Configuration"}); 96 97 GBEAN_INFO = infoBuilder.getBeanInfo(); 98 } 99 100 public static GBeanInfo getGBeanInfo() { 101 return GBEAN_INFO; 102 } 103 } 104 105 | Popular Tags |