1 17 package org.apache.servicemix.geronimo; 18 19 import java.net.URI ; 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 28 public class Component implements GBeanLifecycle { 29 30 private static final Log log = LogFactory.getLog(Component.class); 31 32 private String name; 33 34 private String description; 35 36 private String type; 37 38 private String className; 39 40 private Container container; 41 42 private URI rootDir; 43 44 private URI installDir; 45 46 private URI workDir; 47 48 private javax.jbi.component.Component component; 49 50 private ClassLoader classLoader; 51 52 public Component(String name, String description, String type, String className, Container container, 53 URL configurationBaseUrl, ClassLoader classLoader) throws Exception { 54 this.name = name; 55 this.description = description; 56 this.type = type; 57 this.className = className; 58 this.container = container; 59 if (configurationBaseUrl.getProtocol().equalsIgnoreCase("file")) { 61 this.rootDir = new URI ("file", configurationBaseUrl.getPath(), null); 62 } else { 63 this.rootDir = URI.create(configurationBaseUrl.toString()); 64 } 65 this.installDir = rootDir.resolve("install/"); 66 this.workDir = rootDir.resolve("workspace/"); 67 this.classLoader = classLoader; 68 log.info("Created JBI component: " + name); 69 } 70 71 public void doStart() throws Exception { 72 log.info("doStart called for JBI component: " + name); 73 try { 74 component = (javax.jbi.component.Component) classLoader.loadClass(className).newInstance(); 75 container.register(this); 76 } catch (ClassNotFoundException e) { 77 log.error(classLoader); 78 } 79 } 80 81 public void doStop() throws Exception { 82 log.info("doStop called for JBI component: " + name); 83 container.unregister(this); 84 component = null; 85 } 86 87 public void doFail() { 88 log.info("doFail called for JBI component: " + name); 89 component = null; 90 } 91 92 public String getType() { 93 return type; 94 } 95 96 public String getName() { 97 return name; 98 } 99 100 public String getDescription() { 101 return description; 102 } 103 104 public URI getInstallDir() { 105 return installDir; 106 } 107 108 public URI getWorkDir() { 109 return workDir; 110 } 111 112 public URI getRootDir() { 113 return rootDir; 114 } 115 116 public javax.jbi.component.Component getComponent() { 117 return component; 118 } 119 120 public static final GBeanInfo GBEAN_INFO; 121 122 static { 123 GBeanInfoBuilder infoFactory = new GBeanInfoBuilder("JBIComponent", Component.class, "JBIComponent"); 124 infoFactory.addAttribute("name", String .class, true); 125 infoFactory.addAttribute("description", String .class, true); 126 infoFactory.addAttribute("type", String .class, true); 127 infoFactory.addAttribute("className", String .class, true); 128 infoFactory.addReference("container", Container.class); 129 infoFactory.addAttribute("configurationBaseUrl", URL .class, true); 130 infoFactory.addAttribute("classLoader", ClassLoader .class, false); 131 infoFactory.setConstructor(new String [] { "name", "description", "type", "className", "container", 132 "configurationBaseUrl", "classLoader" }); 133 GBEAN_INFO = infoFactory.getBeanInfo(); 134 } 135 136 public static GBeanInfo getGBeanInfo() { 137 return GBEAN_INFO; 138 } 139 140 } 141 | Popular Tags |