1 7 package com.tirsen.nanning.definition; 8 9 import java.lang.reflect.Method ; 10 import java.util.regex.Matcher ; 11 import java.util.regex.Pattern ; 12 13 import com.tirsen.nanning.attribute.Attributes; 14 import com.tirsen.nanning.FilterMethodsInterceptor; 15 16 27 public abstract class BasicInterceptor implements DefinitionAwareInterceptor, FilterMethodsInterceptor { 28 public static String METHOD_NAME_FILTER_ATTRIBUTE_NAME = "methodNameFilter"; 29 30 private InterceptorDefinition interceptorDefinition = null; 31 32 38 public boolean interceptsMethod(Method method) { 39 InterceptorDefinition interceptorDefinition = getInterceptorDefinition(); 40 String methodNameFilterPattern = (String ) interceptorDefinition.getAttribute(METHOD_NAME_FILTER_ATTRIBUTE_NAME); 41 42 if (methodNameFilterPattern != null) { 43 methodNameFilterPattern = (String ) interceptorDefinition.getAttribute(METHOD_NAME_FILTER_ATTRIBUTE_NAME); 44 } else { 45 try { 47 methodNameFilterPattern = Attributes.getAttribute(this.getClass(), METHOD_NAME_FILTER_ATTRIBUTE_NAME); 48 methodNameFilterPattern = Pattern.compile(". ").matcher(methodNameFilterPattern).replaceAll(".*"); 50 51 } catch (Exception e) { 52 return true; 54 } 55 56 } 57 if (methodNameFilterPattern != null) { 58 Matcher m = Pattern.compile(methodNameFilterPattern).matcher(method.getName()); 59 return m.matches(); 60 } 61 return true; 63 } 64 65 public InterceptorDefinition getInterceptorDefinition() { 66 return interceptorDefinition; 67 } 68 69 public void setInterceptorDefinition(InterceptorDefinition interceptorDefinition) { 70 this.interceptorDefinition = interceptorDefinition; 71 } 72 } 73 | Popular Tags |