1 22 package org.jboss.kernel.plugins.dependency; 23 24 import java.util.List ; 25 26 import org.jboss.beans.info.spi.BeanInfo; 27 import org.jboss.beans.metadata.spi.BeanMetaData; 28 import org.jboss.beans.metadata.spi.InstallMetaData; 29 import org.jboss.beans.metadata.spi.ParameterMetaData; 30 import org.jboss.joinpoint.spi.MethodJoinpoint; 31 import org.jboss.kernel.Kernel; 32 import org.jboss.kernel.plugins.config.Configurator; 33 import org.jboss.kernel.spi.config.KernelConfigurator; 34 import org.jboss.kernel.spi.dependency.KernelController; 35 import org.jboss.kernel.spi.dependency.KernelControllerContext; 36 import org.jboss.kernel.spi.registry.KernelRegistry; 37 38 44 public class InstallAction extends KernelControllerContextAction 45 { 46 public void installAction(KernelControllerContext context) throws Throwable 47 { 48 KernelController controller = (KernelController) context.getController(); 49 Kernel kernel = controller.getKernel(); 50 KernelRegistry registry = kernel.getRegistry(); 51 52 BeanMetaData metaData = context.getBeanMetaData(); 53 Object name = metaData.getName(); 54 registry.registerEntry(name, context); 55 controller.addSupplies(context); 56 57 List installs = metaData.getInstalls(); 58 if (installs != null) 59 { 60 for (int i = 0; i < installs.size(); ++i) 61 { 62 InstallMetaData install = (InstallMetaData) installs.get(i); 63 KernelControllerContext target = context; 64 if (install.getBean() != null) 65 target = (KernelControllerContext) controller.getContext(install.getBean(), install.getDependentState()); 66 dispatch(target, install.getMethodName(), install.getParameters()); 67 } 68 } 69 } 70 71 public void uninstallAction(KernelControllerContext context) 72 { 73 KernelController controller = (KernelController) context.getController(); 74 Kernel kernel = controller.getKernel(); 75 KernelRegistry registry = kernel.getRegistry(); 76 BeanMetaData metaData = context.getBeanMetaData(); 77 Object name = metaData.getName(); 78 79 List uninstalls = metaData.getUninstalls(); 80 if (uninstalls != null) 81 { 82 for (int i = uninstalls.size()-1; i >= 0; --i) 83 { 84 InstallMetaData uninstall = (InstallMetaData) uninstalls.get(i); 85 KernelControllerContext target = context; 86 if (uninstall.getBean() != null) 87 { 88 target = (KernelControllerContext) controller.getContext(uninstall.getBean(), uninstall.getDependentState()); 89 if (target == null) 90 { 91 log.warn("Ignoring uninstall action on target in incorrect state " + uninstall.getBean()); 92 continue; 93 } 94 } 95 try 96 { 97 dispatch(target, uninstall.getMethodName(), uninstall.getParameters()); 98 } 99 catch (Throwable t) 100 { 101 log.warn("Ignoring uninstall action on target " + uninstall, t); 102 continue; 103 } 104 } 105 } 106 107 try 108 { 109 controller.removeSupplies(context); 110 registry.unregisterEntry(name); 111 } 112 catch (Throwable t) 113 { 114 log.warn("Ignoring unregistered entry at uninstall " + name); 115 } 116 } 117 118 protected void dispatch(KernelControllerContext context, String method, List <ParameterMetaData> parameters) throws Throwable 119 { 120 KernelController controller = (KernelController) context.getController(); 121 KernelConfigurator configurator = controller.getKernel().getConfigurator(); 122 BeanInfo info = context.getBeanInfo(); 123 BeanMetaData metaData = context.getBeanMetaData(); 124 ClassLoader cl = Configurator.getClassLoader(metaData); 125 MethodJoinpoint joinpoint = configurator.getMethodJoinPoint(info, cl, method, parameters, false, true); 126 joinpoint.setTarget(context.getTarget()); 127 dispatchJoinPoint(context, joinpoint); 128 } 129 } | Popular Tags |