1  /*
     2   * Copyright the original author or authors.
     3   * 
     4   * Licensed under the MOZILLA PUBLIC LICENSE, Version 1.1 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   * 
     8   *      http://www.mozilla.org/MPL/MPL-1.1.html
     9   * 
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  import org.as2lib.aop.Aspect;
    18  import org.as2lib.aop.JoinPoint;
    19  import org.as2lib.aop.advice.AbstractAdvice;
    20  import org.as2lib.aop.advice.AfterThrowingAdvice;
    21  
    22  /**
    23   * {@code AbstractAfterThrowingAdvice} provides implementations of methods needed by
    24   * {@link AfterThrowingAdvice} implementations.
    25   * 
    26   * @author Simon Wacker
    27   */
    28  class org.as2lib.aop.advice.AbstractAfterThrowingAdvice extends AbstractAdvice {
    29  	
    30  	/**
    31  	 * Constructs a new {@code AbstractAfterThrowingAdvice} instance.
    32  	 * 
    33  	 * @param aspect (optional) the aspect that contains this advice
    34  	 */
    35  	private function AbstractAfterThrowingAdvice(aspect:Aspect) {
    36  		super(aspect);
    37  	}
    38  	
    39  	/**
    40  	 * Proceeds the passed-in {@code joinPoint} with the given {@code args} and returns
    41  	 * the result of this procession after invoking this advice's {@code execute}
    42  	 * method passing the given {@code joinPoint} and the thrown exception.
    43  	 * 
    44  	 * <p>Note that this advice's {@code execute} method is only invoked if the
    45  	 * procession of the {@code joinPoint} with the given {@code args} resulted in an
    46  	 * exception.
    47  	 * 
    48  	 * @param joinPoint the reached join point
    49  	 * @param args the arguments to use for the procession of the join point, these are
    50  	 * normally the ones that were originally passed-to the join point
    51  	 * @return the result of the procession of the given {@code joinPoint} with the
    52  	 * given {@code args}
    53  	 * @throws * if the procession of the {@code joinPoint} with the given {@code args}
    54  	 * results in an exception or if this advice's {@code execute} method threw an
    55  	 * exception
    56  	 */
    57  	private function executeJoinPoint(joinPoint:JoinPoint, args:Array) {
    58  		// 'this' in the catch block refers to '_level0' without this preceding 'this'
    59  		// (at least in the test cases)
    60  		// a detached 'this' is not allowed by MTASC we does have to store it in a variable
    61  		var x:AbstractAfterThrowingAdvice = this;
    62  		var result;
    63  		try {
    64  			result = joinPoint.proceed(args);
    65  		} catch (throwable) {
    66  			AfterThrowingAdvice(this).execute(joinPoint, throwable);
    67  			throw throwable;
    68  		}
    69  		return result;
    70  	}
    71  	
    72  }