1 package net.sf.crispy.filter; 2 3 import java.lang.reflect.Method; 4 import java.util.HashSet; 5 import java.util.Set; 6 7 import net.sf.crispy.InterceptorFilterContext; 8 9 public class SimpleNameInterceptorFilter extends AbstractInterceptorFilter { 10 11 private Set filterObjects = null; 12 13 14 public SimpleNameInterceptorFilter(Class pvFilterClass) { 15 filterObjects = new HashSet(1); 16 filterObjects.add(pvFilterClass.getName()); 17 filterObjectsType = FILTER_TYPE_CLASS; 18 } 19 20 public SimpleNameInterceptorFilter(Class pvFilterClass[]) { 21 filterObjects = new HashSet (pvFilterClass.length); 22 filterObjectsType = FILTER_TYPE_CLASS; 23 for (int i = 0; i < pvFilterClass.length; i++) { 24 filterObjects.add(pvFilterClass[i].getName()); 25 } 26 } 27 28 public SimpleNameInterceptorFilter(Method pvFilterMethod) { 29 filterObjects = new HashSet(1); 30 filterObjects.add(pvFilterMethod.getName()); 31 filterObjectsType = FILTER_TYPE_METHOD; 32 } 33 34 public SimpleNameInterceptorFilter(Method pvFilterMethod[]) { 35 filterObjects = new HashSet (pvFilterMethod.length); 36 filterObjectsType = FILTER_TYPE_METHOD; 37 for (int i = 0; i < pvFilterMethod.length; i++) { 38 filterObjects.add(pvFilterMethod[i].getName()); 39 } 40 } 41 42 public SimpleNameInterceptorFilter(Throwable pvFilterThrowable) { 43 filterObjects = new HashSet(1); 44 filterObjects.add(pvFilterThrowable.getClass().getName()); 45 filterObjectsType = FILTER_TYPE_THROWABLE; 46 } 47 48 public SimpleNameInterceptorFilter(Throwable pvFilterThrowable[]) { 49 filterObjects = new HashSet (pvFilterThrowable.length); 50 filterObjectsType = FILTER_TYPE_THROWABLE; 51 for (int i = 0; i < pvFilterThrowable.length; i++) { 52 filterObjects.add(pvFilterThrowable[i].getClass().getName()); 53 } 54 } 55 56 57 public SimpleNameInterceptorFilter(String pvFilterNames, int pvFilterType) { 58 filterObjects = new HashSet(1); 59 filterObjects.add(pvFilterNames); 60 filterObjectsType = pvFilterType; 61 } 62 63 public SimpleNameInterceptorFilter(String pvFilterNames[], int pvFilterType) { 64 filterObjects = new HashSet (pvFilterNames.length); 65 filterObjectsType = pvFilterType; 66 for (int i = 0; i < pvFilterNames.length; i++) { 67 filterObjects.add(pvFilterNames[i]); 68 } 69 } 70 71 72 73 public boolean accept(InterceptorFilterContext pvContext) { 74 boolean ret = false; 75 switch (filterObjectsType) { 76 case FILTER_TYPE_METHOD: 77 if (pvContext.getMethod() != null) { 78 ret = filterObjects.contains(pvContext.getMethod().getName()); 79 } 80 break; 81 case FILTER_TYPE_CLASS: 82 if (pvContext.getInvocationClass() != null) { 83 ret = filterObjects.contains(pvContext.getInvocationClass().getName()); 84 } 85 break; 86 case FILTER_TYPE_THROWABLE: 87 if (pvContext.getThrowable() != null) { 88 ret = filterObjects.contains(pvContext.getThrowable().getClass().getName()); 89 } 90 break; 91 default: 92 ret = false; 93 break; 94 } 95 return negate(ret); 96 } 97 98 99 }