1 22 package org.jboss.kernel.plugins.dependency; 23 24 import java.util.List ; 25 import java.util.Set ; 26 27 import org.jboss.beans.info.spi.BeanInfo; 28 import org.jboss.beans.metadata.spi.BeanMetaData; 29 import org.jboss.beans.metadata.spi.ParameterMetaData; 30 import org.jboss.joinpoint.spi.JoinpointException; 31 import org.jboss.joinpoint.spi.MethodJoinpoint; 32 import org.jboss.kernel.Kernel; 33 import org.jboss.kernel.plugins.config.Configurator; 34 import org.jboss.kernel.spi.config.KernelConfigurator; 35 import org.jboss.kernel.spi.dependency.KernelController; 36 import org.jboss.kernel.spi.dependency.KernelControllerContext; 37 import org.jboss.repository.spi.MetaDataContext; 38 import org.jboss.reflect.spi.AnnotationValue; 39 import org.jboss.reflect.spi.MethodInfo; 40 41 47 public abstract class LifecycleAction extends KernelControllerContextAction 48 { 49 52 public LifecycleAction() 53 { 54 } 55 56 62 public abstract String getInstallMethod(BeanMetaData beanMetaData); 63 64 69 public abstract String getDefaultInstallMethod(); 70 71 76 public abstract String getInstallAnnotation(); 77 78 84 public abstract List <ParameterMetaData> getInstallParameters(BeanMetaData beanMetaData); 85 86 92 public abstract String getUninstallMethod(BeanMetaData beanMetaData); 93 94 99 public abstract String getDefaultUninstallMethod(); 100 101 106 public abstract String getUninstallAnnotation(); 107 108 114 public abstract List <ParameterMetaData> getUninstallParameters(BeanMetaData beanMetaData); 115 116 public void installAction(KernelControllerContext context) throws Throwable 117 { 118 boolean trace = log.isTraceEnabled(); 119 120 KernelController controller = (KernelController) context.getController(); 121 Kernel kernel = controller.getKernel(); 122 KernelConfigurator configurator = kernel.getConfigurator(); 123 124 Object target = context.getTarget(); 125 BeanInfo info = context.getBeanInfo(); 126 BeanMetaData metaData = context.getBeanMetaData(); 127 String method = getInstallMethod(context); 128 List <ParameterMetaData> parameters = getInstallParameters(context); 129 MethodJoinpoint joinpoint; 130 try 131 { 132 ClassLoader cl = Configurator.getClassLoader(metaData); 133 joinpoint = configurator.getMethodJoinPoint(info, cl, method, parameters, false, true); 134 } 135 catch (JoinpointException ignored) 136 { 137 if (trace) 138 { 139 if (parameters == null) 140 log.trace("No " + method + " method for " + context); 141 else 142 log.trace("No " + method + parameters + " method for " + context); 143 } 144 return; 145 } 146 joinpoint.setTarget(target); 147 dispatchJoinPoint(context, joinpoint); 148 } 149 150 public void uninstallAction(KernelControllerContext context) 151 { 152 boolean trace = log.isTraceEnabled(); 153 154 KernelController controller = (KernelController) context.getController(); 155 Kernel kernel = controller.getKernel(); 156 KernelConfigurator configurator = kernel.getConfigurator(); 157 158 Object target = context.getTarget(); 159 BeanInfo info = context.getBeanInfo(); 160 BeanMetaData metaData = context.getBeanMetaData(); 161 String method = getUninstallMethod(context); 162 List <ParameterMetaData> parameters = getUninstallParameters(context); 163 MethodJoinpoint joinpoint; 164 try 165 { 166 ClassLoader cl = Configurator.getClassLoader(metaData); 167 joinpoint = configurator.getMethodJoinPoint(info, cl, method, parameters, false, true); 168 joinpoint.setTarget(target); 169 dispatchJoinPoint(context, joinpoint); 170 } 171 catch (JoinpointException ignored) 172 { 173 if (trace) 174 { 175 if (parameters == null) 176 log.trace("No " + method + " method for " + context); 177 else 178 log.trace("No " + method + parameters + " method for " + context); 179 } 180 } 181 catch (Throwable throwable) 182 { 183 log.warn("Error during " + method, throwable); 184 } 185 } 186 187 193 public String getInstallMethod(KernelControllerContext context) 194 { 195 String installMethod = getInstallMethod(context.getBeanMetaData()); 196 if (installMethod != null) 197 { 198 return installMethod; 199 } 200 BeanInfo beanInfo = context.getBeanInfo(); 201 Set <MethodInfo> methods = beanInfo.getMethods(); 202 if (methods != null) 203 { 204 for (MethodInfo mi : methods) 205 { 206 if (mi.isAnnotationPresent(getInstallAnnotation())) 207 { 208 return mi.getName(); 209 } 210 } 211 } 212 return getDefaultInstallMethod(); 213 } 214 215 221 public List <ParameterMetaData> getInstallParameters(KernelControllerContext context) 222 { 223 return getInstallParameters(context.getBeanMetaData()); 225 } 226 227 233 public String getUninstallMethod(KernelControllerContext context) 234 { 235 String uninstallMethod = getUninstallMethod(context.getBeanMetaData()); 236 if (uninstallMethod != null) 237 { 238 return uninstallMethod; 239 } 240 BeanInfo beanInfo = context.getBeanInfo(); 241 Set <MethodInfo> methods = beanInfo.getMethods(); 242 if (methods != null) 243 { 244 for (MethodInfo mi : methods) 245 { 246 if (mi.isAnnotationPresent(getUninstallAnnotation())) 247 { 248 return mi.getName(); 249 } 250 } 251 } 252 return getDefaultUninstallMethod(); 253 } 254 255 261 public List <ParameterMetaData> getUninstallParameters(KernelControllerContext context) 262 { 263 return getUninstallParameters(context.getBeanMetaData()); 265 } 266 267 } | Popular Tags |