1 27 package ch.ethz.prose.filter; 28 29 import java.util.*; 31 import java.io.*; 32 import ch.ethz.jvmai.JoinPoint; 33 import ch.ethz.jvmai.ClassSpecific; 34 import ch.ethz.jvmai.CodeJoinPoint; 35 import ch.ethz.jvmai.JoinPointKinds; 36 import ch.ethz.prose.engine.JoinPointRequest; 37 38 44 public 45 class ExecutionsInSubclassFilter extends PointCutter implements JoinPointKinds { 46 47 final public static int SUBCLASS_INHERITANCE = 1; 48 final public static int SUPERCLASS_INHERITANCE = 2; 49 final public static int NO_INHERITANCE =3; 50 51 private int inheritanceType; 52 private Class subOrSuperClass; 53 54 public ExecutionsInSubclassFilter(Class cls, int inhType) 55 { 56 if (cls == null) 57 throw new IllegalArgumentException ("null argument illegal"); 58 59 subOrSuperClass = cls; 60 acceptMask = MASK_ALL_JP; 61 mayFilterStaticallyMask = MASK_METHOD_ENTRY_JP | MASK_METHOD_EXIT_JP; 62 canFilterStaticallyMask = MASK_METHOD_ENTRY_JP | MASK_METHOD_EXIT_JP; 63 this.inheritanceType = inhType; 64 } 65 66 71 protected boolean doIsSpecialRequest(JoinPointRequest jpr) 72 { 73 try 74 { 75 Class classDeclaringTheMentryExit = ((ClassSpecific)jpr).getTargetClass(); 76 if (inheritanceType == SUBCLASS_INHERITANCE) 77 return subOrSuperClass.isAssignableFrom(classDeclaringTheMentryExit); 79 80 if (inheritanceType == SUPERCLASS_INHERITANCE) 81 return classDeclaringTheMentryExit.isAssignableFrom(subOrSuperClass); 83 84 if (inheritanceType == NO_INHERITANCE) 85 return classDeclaringTheMentryExit.equals(subOrSuperClass); 86 else 87 throw new Error ("_doIsSpecialReques was supplied with an illegal state"); 88 } 89 catch (ClassCastException jprWasNotClassSpecific) 90 { 91 throw new Error ("request was allowed in spite of mayFilterStaticallyMask"); 92 } 93 } 94 95 99 protected boolean doIsSpecialEvent(CodeJoinPoint jp) 100 { 101 Class classDeclaringExecutedCode = jp.getMethod().getDeclaringClass(); 102 if (inheritanceType == SUBCLASS_INHERITANCE) 103 return subOrSuperClass.isAssignableFrom(classDeclaringExecutedCode); 105 else 106 return classDeclaringExecutedCode.isAssignableFrom(subOrSuperClass); 108 } 109 110 } 111 112 113 | Popular Tags |