1 16 17 package org.springframework.aop.framework; 18 19 import java.util.LinkedList ; 20 import java.util.List ; 21 22 import org.springframework.util.Assert; 23 24 32 public class ProxyCreatorSupport extends AdvisedSupport { 33 34 35 private AopProxyFactory aopProxyFactory; 36 37 38 private List listeners = new LinkedList (); 39 40 41 private boolean active = false; 42 43 44 47 public ProxyCreatorSupport() { 48 this.aopProxyFactory = new DefaultAopProxyFactory(); 49 } 50 51 55 public ProxyCreatorSupport(AopProxyFactory aopProxyFactory) { 56 Assert.notNull(aopProxyFactory, "AopProxyFactory must not be null"); 57 this.aopProxyFactory = aopProxyFactory; 58 } 59 60 61 67 public void setAopProxyFactory(AopProxyFactory aopProxyFactory) { 68 Assert.notNull(aopProxyFactory, "AopProxyFactory must not be null"); 69 this.aopProxyFactory = aopProxyFactory; 70 } 71 72 75 public AopProxyFactory getAopProxyFactory() { 76 return this.aopProxyFactory; 77 } 78 79 83 public void addListener(AdvisedSupportListener listener) { 84 Assert.notNull(listener, "AdvisedSupportListener must not be null"); 85 this.listeners.add(listener); 86 } 87 88 92 public void removeListener(AdvisedSupportListener listener) { 93 Assert.notNull(listener, "AdvisedSupportListener must not be null"); 94 this.listeners.remove(listener); 95 } 96 97 98 102 protected final synchronized AopProxy createAopProxy() { 103 if (!this.active) { 104 activate(); 105 } 106 return getAopProxyFactory().createAopProxy(this); 107 } 108 109 113 private void activate() { 114 this.active = true; 115 for (int i = 0; i < this.listeners.size(); i++) { 116 ((AdvisedSupportListener) this.listeners.get(i)).activated(this); 117 } 118 } 119 120 124 protected void adviceChanged() { 125 super.adviceChanged(); 126 synchronized (this) { 127 if (this.active) { 128 for (int i = 0; i < this.listeners.size(); i++) { 129 ((AdvisedSupportListener) this.listeners.get(i)).adviceChanged(this); 130 } 131 } 132 } 133 } 134 135 138 protected final synchronized boolean isActive() { 139 return this.active; 140 } 141 142 } 143 | Popular Tags |