View Javadoc
1 package org.codehaus.nanning.config; 2 3 import java.lang.reflect.Method; 4 import java.util.Iterator; 5 import java.util.List; 6 7 import org.codehaus.nanning.AspectException; 8 import org.codehaus.nanning.AspectInstance; 9 import org.codehaus.nanning.MethodInterceptor; 10 import org.codehaus.nanning.Mixin; 11 12 public abstract class Pointcut { 13 14 /*** 15 * Reuses the same interceptor on every advised method 16 * @param instance 17 * @param interceptor 18 */ 19 public void advise(AspectInstance instance, MethodInterceptor interceptor) { 20 advise(instance, interceptor, null); 21 } 22 23 /*** 24 * Instantiates a new interceptor for each advised method. 25 * @param instance 26 * @param interceptorClass 27 */ 28 public void advise(AspectInstance instance, Class interceptorClass) { 29 advise(instance, null, interceptorClass); 30 } 31 32 public void advise(AspectInstance instance, MethodInterceptor interceptor, Class interceptorClass) { 33 List mixins = instance.getMixins(); 34 for (Iterator iterator = mixins.iterator(); iterator.hasNext();) { 35 Mixin mixin = (Mixin) iterator.next(); 36 Method[] methods = mixin.getAllMethods(); 37 for (int i = 0; i < methods.length; i++) { 38 Method method = methods[i]; 39 if (adviseMethod(instance, mixin, method)) { 40 if (interceptor != null) { 41 mixin.addInterceptor(method, interceptor); 42 } else if (interceptorClass != null) { 43 try { 44 mixin.addInterceptor(method, (MethodInterceptor) interceptorClass.newInstance()); 45 } catch (Exception e) { 46 throw new AspectException(e); 47 } 48 } else { 49 assert false : "interceptor or class needs to be specified"; 50 } 51 } 52 } 53 } 54 } 55 56 /*** 57 * Override this method for a pointcut that selects methods to advise. 58 * 59 * @param instance 60 * @param mixin 61 * @param method 62 * @return 63 */ 64 public boolean adviseMethod(AspectInstance instance, Mixin mixin, Method method) { 65 return false; 66 } 67 68 /*** 69 * Override this method for a pointcut that selects aspect-instances to introduce on. 70 * 71 * @param instance 72 * @return 73 */ 74 public boolean introduceOn(AspectInstance instance) { 75 return false; 76 } 77 78 public void introduce(AspectInstance instance, Mixin mixin) { 79 if (introduceOn(instance)) { 80 instance.addMixin(mixin); 81 } 82 } 83 }

This page was automatically generated by Maven