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.app.exec.Executable;
    18  import org.as2lib.env.overload.Overload;
    19  import org.as2lib.aop.JoinPoint;
    20  import org.as2lib.aop.Pointcut;
    21  import org.as2lib.aop.advice.AbstractAfterThrowingAdvice;
    22  import org.as2lib.aop.advice.AfterThrowingAdvice;
    23  
    24  /**
    25   * {@code DynamicAfterThrowingAdvice} executes a callback at the weave-in point.
    26   * 
    27   * @author Simon Wacker
    28   */
    29  class org.as2lib.aop.advice.DynamicAfterThrowingAdvice extends AbstractAfterThrowingAdvice implements AfterThrowingAdvice {
    30  	
    31  	/** The callback to invoke. */
    32  	private var callback:Executable;
    33  	
    34  	/**
    35  	 * @overload #DynamicAfterThrowingAdviceByPointcut
    36  	 * @overload #DynamicAfterThrowingAdviceByPointcutPattern
    37  	 */
    38  	public function DynamicAfterThrowingAdvice() {
    39  		var o:Overload = new Overload(this);
    40  		o.addHandler([Pointcut, Executable], DynamicAfterThrowingAdviceByPointcut);
    41  		o.addHandler([String, Executable], DynamicAfterThrowingAdviceByPointcutPattern);
    42  		o.forward(arguments);
    43  	}
    44  	
    45  	/**
    46  	 * Constrcuts a new {@code DynamicAfterThrowingAdvice} instance with a pointcut.
    47  	 *
    48  	 * @param pointcut the pointcut that determines the join points to weave this
    49  	 * advice in
    50  	 * @param callback the callback that is executed at the weave-in point
    51  	 */
    52  	private function DynamicAfterThrowingAdviceByPointcut(pointcut:Pointcut, callback:Executable) {
    53  		setPointcutByPointcut(pointcut);
    54  		this.callback = callback;
    55  	}
    56  	
    57  	/**
    58  	 * Constrcuts a new {@code DynamicAfterThrowingAdvice} instance with a pointcut pattern.
    59  	 *
    60  	 * @param pointcut the pointcut that determines the join points to weave this
    61  	 * advice in
    62  	 * @param callback the callback that is executed at the weave-in point
    63  	 */
    64  	private function DynamicAfterThrowingAdviceByPointcutPattern(pointcut:String, callback:Executable) {
    65  		setPointcutByString(pointcut);
    66  		this.callback = callback;
    67  	}
    68  	
    69  	/**
    70  	 * Executes the callback passing the passed {@code joinPoint} and {@code throwable}.
    71  	 * 
    72  	 * @param joinPoint the join point this advice was woven into
    73  	 * @param throwable the throwable thrown by the given {@code joinPoint}
    74  	 */
    75  	public function execute(joinPoint:JoinPoint, throwable):Void {
    76  		callback.execute(joinPoint, throwable);
    77  	}
    78  	
    79  }