1 package net.sf.crispy.filter; 2 3 import net.sf.crispy.InterceptorFilterContext; 4 5 public class NamePatternInterceptorFilter extends AbstractInterceptorFilter { 6 7 private String pattern = null; 8 9 10 public NamePatternInterceptorFilter(String pvPattern, int pvFilterType) { 11 setPattern(pvPattern); 12 filterObjectsType = pvFilterType; 13 } 14 15 public final void setPattern(String pvPattern) { pattern = pvPattern; } 16 public String getPattern() { return pattern; } 17 18 public boolean accept(InterceptorFilterContext pvContext) { 19 boolean ret = false; 20 switch (filterObjectsType) { 21 case FILTER_TYPE_METHOD: 22 if (pvContext.getMethod() != null) { 23 ret = matches(pvContext.getMethod().getName()); 24 } 25 break; 26 case FILTER_TYPE_CLASS: 27 ret = matches(pvContext.getInvocationClass().getName()); 28 break; 29 case FILTER_TYPE_THROWABLE: 30 if (pvContext.getThrowable() != null) { 31 ret = matches(pvContext.getThrowable().getClass().getName()); 32 } 33 break; 34 default: 35 ret = false; 36 break; 37 } 38 return negate(ret); 39 } 40 41 private boolean matches(String pvName) { 42 boolean ret = true; 43 if ((getPattern() != null) && (getPattern().length() > 0)) { 44 ret = pvName.matches(getPattern()); 45 } 46 return ret; 47 } 48 49 }