1 22 package org.jboss.aop.microcontainer.beans; 23 24 import org.jboss.aop.AspectManager; 25 import org.jboss.aop.advice.AspectDefinition; 26 import org.jboss.aop.advice.GenericAspectFactory; 27 import org.jboss.aop.advice.Scope; 28 import org.jboss.aop.advice.ScopeUtil; 29 import org.jboss.aop.instrument.Untransformable; 30 import org.jboss.beans.metadata.plugins.factory.GenericBeanFactory; 31 import org.jboss.dependency.spi.Controller; 32 import org.jboss.kernel.Kernel; 33 import org.jboss.kernel.spi.dependency.KernelControllerContext; 34 import org.jboss.kernel.spi.dependency.KernelControllerContextAware; 35 import org.jboss.logging.Logger; 36 import org.jboss.util.id.GUID; 37 38 44 public class Aspect implements KernelControllerContextAware, Untransformable 45 { 46 private static final Logger log = Logger.getLogger(Aspect.class); 47 48 protected AspectManager manager; 49 50 protected String adviceName = GUID.asString(); 51 52 protected String adviceBean; 53 54 protected String scope; 55 56 protected ManagedAspectDefinition definition; 57 58 protected GenericBeanFactory advice; 59 60 protected Controller controller; 61 62 63 protected String myname; 64 65 66 protected String aspectDefName; 67 68 protected Kernel kernel; 69 70 75 public String getAdviceName() 76 { 77 return adviceName; 78 } 79 80 85 public void setAdviceName(String adviceName) 86 { 87 this.adviceName = adviceName; 88 } 89 90 95 public String getAdviceBean() 96 { 97 return adviceBean; 98 } 99 100 105 public void setAdviceBean(String adviceBean) 106 { 107 this.adviceBean = adviceBean; 108 } 109 110 115 public AspectDefinition getDefinition() 116 { 117 return definition; 118 } 119 120 125 public AspectManager getManager() 126 { 127 return manager; 128 } 129 130 135 public void setManager(AspectManager manager) 136 { 137 this.manager = manager; 138 } 139 140 145 public GenericBeanFactory getAdvice() 146 { 147 return advice; 148 } 149 150 155 public void setAdvice(GenericBeanFactory advice) 156 { 157 this.advice = advice; 158 } 159 160 165 public String getScope() 166 { 167 return scope; 168 } 169 170 175 public void setScope(String scope) 176 { 177 this.scope = scope; 178 } 179 180 public void setKernelControllerContext(KernelControllerContext context) throws Exception 181 { 182 myname = (String )context.getName(); 183 controller = context.getController(); 184 kernel = context.getKernel(); 185 } 186 187 public void unsetKernelControllerContext(KernelControllerContext context) throws Exception 188 { 189 controller = null; 190 } 191 192 public void install(GenericBeanFactory factory) throws Exception 193 { 194 this.advice = factory; 195 start(); 196 } 197 198 public void start() throws Exception 199 { 200 if (definition == null) 201 { 202 aspectDefName = (adviceBean != null) ? adviceBean : myname; 203 if (manager == null) 204 throw new IllegalArgumentException ("Null manager"); 205 Scope theScope = ScopeUtil.parse(scope); 206 if (advice != null) 207 { 208 definition = new ManagedAspectDefinition(aspectDefName, theScope, new GenericBeanAspectFactory(adviceName, advice)); 209 } 210 else if (adviceBean != null && controller != null) 211 { 212 definition = new ManagedAspectDefinition(aspectDefName, theScope, new GenericBeanAspectFactory(aspectDefName, advice), false); 213 } 214 else 215 { 216 definition = new ManagedAspectDefinition(aspectDefName, theScope, new GenericAspectFactory(adviceName, null)); 217 } 218 manager.addAspectDefinition(definition); 219 } 220 221 if (adviceBean != null && advice != null) 222 { 223 definition.setDeployed(true); 224 GenericBeanAspectFactory factory = (GenericBeanAspectFactory)definition.getFactory(); 225 factory.setBeanFactory(advice); 226 } 227 log.debug("Bound aspect " + aspectDefName + "; deployed:" + definition.isDeployed()); 228 } 229 230 231 public void uninstall() throws Exception 232 { 233 stop(); 234 } 235 236 237 public void stop() 238 { 239 aspectDefName = (adviceBean != null) ? adviceBean : myname; 240 log.debug("Unbinding aspect " + aspectDefName); 241 manager.removeAspectDefinition(aspectDefName); 242 if (definition != null) 243 { 244 definition.undeploy(); 245 definition = null; 246 } 247 } 248 } | Popular Tags |