1 package ch.ethz.prose.filter; 22 import ch.ethz.jvmai.ExceptionJoinPoint; 23 import ch.ethz.jvmai.ExceptionCatchJoinPoint; 24 import ch.ethz.jvmai.CodeJoinPoint; 25 import ch.ethz.jvmai.JoinPointKinds; 26 import ch.ethz.prose.engine.JoinPointRequest; 27 import java.lang.String ; 28 import java.lang.Throwable ; 29 import org.apache.regexp.RE; 30 import org.apache.regexp.RESyntaxException; 31 32 33 38 class ExceptionMessageFilter extends PointCutter implements JoinPointKinds 39 { 40 41 protected RE re; 42 private String regexp; 43 44 protected ExceptionMessageFilter(String regexp) 45 { 46 acceptMask = MASK_EXCEPTION_THROW_ARGS_JP | MASK_EXCEPTION_CATCH_ARGS_JP; 47 mayFilterStaticallyMask = 0; 48 canFilterStaticallyMask = 0; 49 this.regexp = regexp; 50 if (regexp == null) 51 { 52 re = null; 53 } 54 else 55 { 56 try 57 { 58 re = new RE(regexp); 59 } 60 catch (RESyntaxException e) 61 { 62 throw new IllegalArgumentException ("NameExpression: " + regexp + " is not a valid regexp." + 63 e.toString()); 64 } 65 } 66 } 67 68 protected boolean doIsSpecialRequest(JoinPointRequest jpr) 69 { 70 throw new Error ("We cannot and may not filter static events"); 71 } 72 73 74 protected boolean doIsSpecialEvent(CodeJoinPoint jpe) 75 { 76 String message; 77 79 switch (jpe.getMask() & (MASK_EXCEPTION_THROW_ARGS_JP | MASK_EXCEPTION_CATCH_ARGS_JP)) 80 { 81 case MASK_EXCEPTION_THROW_ARGS_JP: 82 message = ((ExceptionJoinPoint)jpe).getException().getMessage(); 84 break; 85 case MASK_EXCEPTION_CATCH_ARGS_JP: 86 message = ((ExceptionCatchJoinPoint)jpe).getException().getMessage(); 88 break; 89 default: 90 throw new Error ("ExceptionMessageFilter.doIsSpecialEvent: unrequested request"); 91 } 92 93 if (re == null || message == null) 94 return regexp == message ; 95 else 96 return re.match(message); 97 } 98 99 100 public String toString() 101 { 102 return ("Exceptions.message(\"" + regexp + "\")"); 103 } 104 105 } 106 | Popular Tags |