1 27 package ch.ethz.prose.filter; 28 29 import java.util.*; 31 import java.io.*; 32 import ch.ethz.jvmai.JoinPointKinds; 33 import ch.ethz.jvmai.JoinPoint; 34 import ch.ethz.jvmai.CodeJoinPoint; 35 import ch.ethz.jvmai.ClassSpecific; 36 import ch.ethz.prose.engine.JoinPointRequest; 37 38 45 public 46 class ExecutionsInClassFilter extends PointCutter implements JoinPointKinds 47 { 48 final public static int MATCH_CLASS_NAME_OPMODE = 1; 49 final public static int MATCH_PACKAGE_NAME_OPMODE = 2; 50 final public static int MATCH_QCLASS_NAME_OPMODE = 3; 51 private NameExpression regexp; 52 private int operationMode; 53 54 63 public ExecutionsInClassFilter(String regexp, int opMode) 64 { 65 if (opMode != MATCH_CLASS_NAME_OPMODE && 66 opMode != MATCH_PACKAGE_NAME_OPMODE && 67 opMode != MATCH_QCLASS_NAME_OPMODE) 68 throw new IllegalArgumentException ("Illegal opMode value"); 69 this.regexp = new NameExpression(regexp); 70 acceptMask = MASK_ALL_JP; 71 operationMode = opMode; 72 mayFilterStaticallyMask = MASK_METHOD_ENTRY_JP | MASK_METHOD_EXIT_JP; 73 canFilterStaticallyMask = MASK_METHOD_ENTRY_JP | MASK_METHOD_EXIT_JP; 74 } 75 76 80 protected boolean doIsSpecialRequest(JoinPointRequest jpr) 81 { 82 try 83 { 84 Class targetClass; 86 boolean result; 87 targetClass = ((ClassSpecific)jpr).getTargetClass(); 88 switch(operationMode) 89 { 90 case MATCH_CLASS_NAME_OPMODE: 91 result = regexp.classMatchesRegexp(targetClass); 92 break; 93 case MATCH_QCLASS_NAME_OPMODE: 94 result = regexp.qualifiedClassMatchesRegexp(targetClass); 95 break; 96 case MATCH_PACKAGE_NAME_OPMODE: 97 result = regexp.packageMatchesRegexp(targetClass); 98 break; 99 default: throw new Error ("the opmode is illegal!"); 100 } 101 return result; 103 } 104 catch (ClassCastException jprWasNotClassSpecific) 105 { 106 throw new Error ("request was allowed in spite of mayFilterStaticallyMask"); 107 } 108 } 109 110 111 115 protected boolean doIsSpecialEvent(CodeJoinPoint jp) 116 { 117 boolean result; 119 Class classDeclaringExecutedCode = jp.getMethod().getDeclaringClass(); 120 switch (operationMode) 121 { 122 case MATCH_CLASS_NAME_OPMODE: 123 result = regexp.classMatchesRegexp(classDeclaringExecutedCode); 124 break; 125 case MATCH_QCLASS_NAME_OPMODE: 126 result = regexp.qualifiedClassMatchesRegexp(classDeclaringExecutedCode); 127 break; 128 case MATCH_PACKAGE_NAME_OPMODE: 129 result = regexp.packageMatchesRegexp(classDeclaringExecutedCode); 130 break; 131 default: throw new Error ("the opmode is illegal!"); 132 } 133 return result; 135 } 136 137 } 138 139 140 | Popular Tags |