Back

package com.futureshocked.classloader;

/**
 * <tt>InterceptedMethod</tt> contains the class name, method name, method
 *   description, and information relating to which code modifications should
 *   be done to this method.
 */
public class InterceptedMethod {
  /**
   * The name of the class this method belongs to.
   */
  private String className;

  /**
   * The name of the method to intercept.
   */
  private String methodName;

  /**
   * The method description - if null will match all overloaded methods with
   *   the same name. For more information on the format for description see
   *   the ASM documentation. <br><br>
   * For example, a method like:<br>
   * <i>public String getSomeString(InterceptedMethod im, int count)</i>
   * <br>has a description of:<br>
   * <i>(Lcom.futureshocked.classloader.InterceptedMethod;I)Ljava.lang.String;
   * </i>
   */
  private String description;

  /**
   * The maximum depth for the static debugger.
   */
  private int staticDebuggerCount;

  /**
   * The maximum recusion level for this class (if limited).
   */
  private int maxRecursionCount;

  /**
   * <tt>true</tt> if this method should have a static debugger call inserted.
   */
  private boolean addStaticDebuggerCall;

  /**
   * <tt>true</tt> if this method should have it's recursion limited.
   */
  private boolean addRecursionLimiter;

  /**
   * Constructor that sets description to null - ie: match all overloaded
   *   methods.
   *
   * @param clazz The name of the class.
   * @param method The name of the method.
   */
  public InterceptedMethod(String clazz, String method) {
    this(clazz, method, null);
  }

  /**
   * Constructor that sets all matching variables - ie: match specific method
   *
   * @param clazz The name of the class.
   * @param method The name of the method.
   * @param desc The method description.
   */
  public InterceptedMethod(String clazz, String method, String desc) {
    this.className = clazz;
    this.methodName = method;
    this.description = desc;
  }

  /**
   * Used to match this object against a method being visited.
   * <br><br>
   * Note that matches is not the same as equals() - matches is not reflexive,
   *   in that fields 'methodName' and 'description' will not be used for
   *   comparison if they are null in THIS object (however if they are non-null
   *   in this instance but null in params passed in they will be used for
   *   matching, and return false.
   * @param className The name of the class currently being visited.
   * @param method The name of the method currently being visited.
   * @param desc The description of the method currently being visited.
   * @return <tt>true</tt> if the currently visited method should be modified
   */
  public boolean matches(String className, String method, String desc) {
    boolean equal = false;

    equal = this.className.equals(className);

    if ((methodName != null) && (equal))
      equal = methodName.equals(method);

    if ((description != null) && (equal))
      equal = description.equals(desc);

    return equal;
  }

  public String getClassName() {
    return className;
  }

  public void setClassName(String className) {
    this.className = className;
  }

  public String getMethodName() {
    return methodName;
  }

  public void setMethodName(String methodName) {
    this.methodName = methodName;
  }

  public String getDescription() {
    return description;
  }

  public void setDescription(String description) {
    this.description = description;
  }

  /**
   * Checks to see if this method should have a static debugger call inserted.
   *
   * @return <tt>true</tt> if this method should be modified.
   */
  public boolean needsStaticDebuggerCall() {
    return addStaticDebuggerCall;
  }

  public int getStaticDebuggerCallDepth() {
    return staticDebuggerCount;
  }

  public void setStaticDebuggerCall(int maxRecursionDepth) {
    this.addStaticDebuggerCall = true;
    this.staticDebuggerCount = maxRecursionDepth;
  }

  public void removeStaticDebuggerCall() {
    this.addStaticDebuggerCall = false;
  }

  /**
   * Checks to see if this method should have it's recursion limited.
   *
   * @return <tt>true</tt> if this method should be modified.
   */
  public boolean needsRecursionLimiter() {
    return addRecursionLimiter;
  }

  public int getMaxRecursionCount() {
    return maxRecursionCount;
  }

  public void setRecursionLimiter(int maxRecursionDepth) {
    this.addRecursionLimiter = true;
    this.maxRecursionCount = maxRecursionDepth;
  }

  public void removeRecursionLimiter() {
    this.addRecursionLimiter = false;
  }
}

Top