1 16 17 package org.springframework.aop.support; 18 19 import java.io.IOException ; 20 import java.io.ObjectInputStream ; 21 import java.io.Serializable ; 22 import java.util.HashSet ; 23 import java.util.Iterator ; 24 import java.util.Map ; 25 import java.util.Set ; 26 27 import org.aopalliance.intercept.MethodInvocation; 28 import org.apache.commons.logging.Log; 29 import org.apache.commons.logging.LogFactory; 30 31 import org.springframework.aop.IntroductionInfo; 32 import org.springframework.core.CollectionFactory; 33 import org.springframework.util.ClassUtils; 34 35 45 public class IntroductionInfoSupport implements IntroductionInfo, Serializable { 46 47 protected transient Log logger = LogFactory.getLog(getClass()); 48 49 50 protected Set publishedInterfaces = new HashSet (); 51 52 55 private transient Map rememberedMethods = createRememberedMethodMap(); 56 57 58 65 public void suppressInterface(Class intf) { 66 this.publishedInterfaces.remove(intf); 67 } 68 69 public Class [] getInterfaces() { 70 return (Class []) this.publishedInterfaces.toArray(new Class [this.publishedInterfaces.size()]); 71 } 72 73 78 public boolean implementsInterface(Class intf) { 79 for (Iterator it = this.publishedInterfaces.iterator(); it.hasNext();) { 80 Class pubIntf = (Class ) it.next(); 81 if (intf.isInterface() && intf.isAssignableFrom(pubIntf)) { 82 return true; 83 } 84 } 85 return false; 86 } 87 88 92 protected void implementInterfacesOnObject(Object delegate) { 93 this.publishedInterfaces.addAll(ClassUtils.getAllInterfacesAsSet(delegate)); 94 } 95 96 private Map createRememberedMethodMap() { 97 return CollectionFactory.createIdentityMapIfPossible(32); 98 } 99 100 105 protected final boolean isMethodOnIntroducedInterface(MethodInvocation mi) { 106 Boolean rememberedResult = (Boolean ) this.rememberedMethods.get(mi.getMethod()); 107 if (rememberedResult != null) { 108 return rememberedResult.booleanValue(); 109 } 110 else { 111 boolean result = implementsInterface(mi.getMethod().getDeclaringClass()); 113 this.rememberedMethods.put(mi.getMethod(), (result ? Boolean.TRUE : Boolean.FALSE)); 114 return result; 115 } 116 } 117 118 119 123 128 private void readObject(ObjectInputStream ois) throws IOException , ClassNotFoundException { 129 ois.defaultReadObject(); 131 132 this.logger = LogFactory.getLog(getClass()); 134 this.rememberedMethods = createRememberedMethodMap(); 135 } 136 137 } 138 | Popular Tags |