1 22 package org.jboss.kernel.plugins.dependency; 23 24 import java.util.Iterator ; 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.joinpoint.spi.TargettedJoinpoint; 30 import org.jboss.kernel.Kernel; 31 import org.jboss.kernel.spi.config.KernelConfigurator; 32 import org.jboss.kernel.spi.dependency.KernelController; 33 import org.jboss.kernel.spi.dependency.KernelControllerContext; 34 import org.jboss.kernel.spi.dependency.KernelControllerContextAware; 35 36 42 public class ConfigureAction extends KernelControllerContextAction 43 { 44 public void installAction(KernelControllerContext context) throws Throwable 45 { 46 KernelController controller = (KernelController) context.getController(); 47 Kernel kernel = controller.getKernel(); 48 KernelConfigurator configurator = kernel.getConfigurator(); 49 50 Object object = context.getTarget(); 51 BeanInfo info = context.getBeanInfo(); 52 BeanMetaData metaData = context.getBeanMetaData(); 53 Set joinPoints = configurator.getPropertySetterJoinPoints(info, metaData); 54 setAttributes(context, object, joinPoints, false); 55 56 if (object instanceof KernelControllerContextAware) 57 ((KernelControllerContextAware) object).setKernelControllerContext(context); 58 59 } 60 61 public void uninstallAction(KernelControllerContext context) 62 { 63 KernelController controller = (KernelController) context.getController(); 64 Kernel kernel = controller.getKernel(); 65 KernelConfigurator configurator = kernel.getConfigurator(); 66 67 Object object = context.getTarget(); 68 69 try 70 { 71 if (object != null) 72 { 73 if (object instanceof KernelControllerContextAware) 74 ((KernelControllerContextAware) object).unsetKernelControllerContext(context); 75 } 76 } 77 catch (Throwable ignored) 78 { 79 log.debug("Ignored error unsetting context ", ignored); 80 } 81 82 83 BeanInfo info = context.getBeanInfo(); 84 BeanMetaData metaData = context.getBeanMetaData(); 85 try 86 { 87 Set joinPoints = configurator.getPropertyNullerJoinPoints(info, metaData); 88 setAttributes(context, object, joinPoints, true); 89 } 90 catch (Throwable t) 91 { 92 log.warn("Error unconfiguring bean " + context, t); 93 } 94 } 95 96 105 protected void setAttributes(KernelControllerContext context, Object target, Set joinPoints, boolean ignoreErrors) throws Throwable 106 { 107 if (joinPoints.isEmpty() == false) 108 { 109 boolean trace = log.isTraceEnabled(); 110 111 for (Iterator i = joinPoints.iterator(); i.hasNext();) 112 { 113 TargettedJoinpoint joinPoint = (TargettedJoinpoint) i.next(); 114 joinPoint.setTarget(target); 115 try 116 { 117 dispatchJoinPoint(context, joinPoint); 118 } 119 catch (Throwable t) 120 { 121 if (ignoreErrors) 122 { 123 if (trace) 124 log.trace("Ignored for " + joinPoint, t); 125 } 126 else 127 { 128 throw t; 129 } 130 } 131 } 132 } 133 } 134 135 } | Popular Tags |