Package org.jtester.module.tracer.spring

Source Code of org.jtester.module.tracer.spring.TracerMethodRegexPointcut

package org.jtester.module.tracer.spring;

import java.lang.reflect.Modifier;

import org.springframework.aop.ClassFilter;
import org.springframework.aop.support.JdkRegexpMethodPointcut;

@SuppressWarnings("rawtypes")
public class TracerMethodRegexPointcut extends JdkRegexpMethodPointcut {

  private static final long serialVersionUID = 8342662318985403824L;

  public TracerMethodRegexPointcut() {
    super.setPatterns(patterns);
  }

  @Override
  public ClassFilter getClassFilter() {
    final ClassFilter filter = super.getClassFilter();
    return new ClassFilter() {
      public boolean matches(Class clazz) {
        int modifier = clazz.getModifiers();
        if (Modifier.isFinal(modifier)) {
          return false;
        }
        String clazzName = clazz.getName();
        if (beenFilted(clazzName)) {
          return false;
        } else {
          return filter.matches(clazz);
        }
      }
    };
  }

  private final static String[] patterns = new String[] { ".*" };

  private final static String[] FilterClazzPrefix = new String[] { "java.",// <br>
      "javax.", "org.springframework.", "org.hibernate.", "com.ibatis." };

  /**
   * 过滤package
   *
   * @param clazzName
   * @return
   */
  public static boolean beenFilted(String clazzName) {
    for (String prefix : FilterClazzPrefix) {
      if (clazzName.startsWith(prefix)) {
        return true;
      }
    }
    return false;
  }
}
TOP

Related Classes of org.jtester.module.tracer.spring.TracerMethodRegexPointcut

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.