Package ch.ethz.prose.filter

Source Code of ch.ethz.prose.filter.ExceptionMessageFilter

//
//  This file is part of the prose package.
//
//  The contents of this file are subject to the Mozilla Public License
//  Version 1.1 (the "License"); you may not use this file except in
//  compliance with the License. You may obtain a copy of the License at
//  http://www.mozilla.org/MPL/
//
//  Software distributed under the License is distributed on an "AS IS" basis,
//  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
//  for the specific language governing rights and limitations under the
//  License.
//
//  The Original Code is prose.
//
//  The Initial Developer of the Original Code is Andrei Popovici. Portions
//  created by Andrei Popovici are Copyright (C) 2002 Andrei Popovici.
//  All Rights Reserved.
//
//  Contributor(s):
//  $Id: ExceptionMessageFilter.java,v 1.4 2008/11/18 11:38:01 anicoara Exp $
//  =====================================================================
//
package ch.ethz.prose.filter;

import ch.ethz.jvmai.ExceptionJoinPoint;
import ch.ethz.jvmai.ExceptionCatchJoinPoint;
import ch.ethz.jvmai.CodeJoinPoint;
import ch.ethz.jvmai.JoinPointKinds;
import ch.ethz.prose.engine.JoinPointRequest;
import java.lang.String;
import org.apache.regexp.RE;
import org.apache.regexp.RESyntaxException;


/**
* ExceptionMessageFilter class
*
* @version $Revision: 1.4 $
* @author   Angela Nicoara
*/
class ExceptionMessageFilter extends PointCutter implements JoinPointKinds {

  private static final long serialVersionUID = 3257009851912435252L;
  protected RE re;
  private String regexp;

  protected ExceptionMessageFilter(String regexp) {
    acceptMask = MASK_EXCEPTION_THROW_ARGS_JP | MASK_EXCEPTION_CATCH_ARGS_JP;    
    mayFilterStaticallyMask = 0;
    canFilterStaticallyMask = 0;
    this.regexp = regexp;
    if (regexp == null) {
      re = null;
    }
    else {
      try {
        re = new RE(regexp);
      }
      catch (RESyntaxException e) {
        throw new IllegalArgumentException("NameExpression: " + regexp + " is not a valid regexp." +
            e.toString());
      }
    }
  }

  protected boolean doIsSpecialRequest(JoinPointRequest jpr) {
    throw new Error("We cannot and may not filter static events");
  }


  protected boolean doIsSpecialEvent(CodeJoinPoint jpe) {
    String message;
    //System.out.println("\n ExceptionMessageFilter -> doIsSpecialEvent \n");

    switch (jpe.getMask() & (MASK_EXCEPTION_THROW_ARGS_JP | MASK_EXCEPTION_CATCH_ARGS_JP)) {
    case MASK_EXCEPTION_THROW_ARGS_JP:
      //System.out.println("\n ExceptionMessageFilter -> doIsSpecialEvent -> MASK_EXCEPTION_THROW_ARGS_JP \n");  // angy test
      message = ((ExceptionJoinPoint)jpe).getException().getMessage();
      break;
    case MASK_EXCEPTION_CATCH_ARGS_JP:
      //System.out.println("\n ExceptionMessageFilter -> doIsSpecialEvent -> MASK_EXCEPTION_CATCH_ARGS_JP \n"); //angy test
      message = ((ExceptionCatchJoinPoint)jpe).getException().getMessage();
      break;
    default:
      throw new Error("ExceptionMessageFilter.doIsSpecialEvent: unrequested request");
    }

    if (re == null || message  == null)
      return regexp == message ;
    else
      return re.match(message);
  }


  public String toString() {
    return ("Exceptions.message(\"" + regexp + "\")");
  }

}
TOP

Related Classes of ch.ethz.prose.filter.ExceptionMessageFilter

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.