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.BeforeAdvice;
    21  
    22  /**
    23   * @author Simon Wacker
    24   */
    25  class org.as2lib.aop.advice.AbstractBeforeAdvice extends AbstractAdvice {
    26  	
    27  	/**
    28  	 * Constructs a new {@code AbstractBeforeAdvice} instance.
    29  	 * 
    30  	 * @param aspect (optional) the aspect that contains this advice
    31  	 */
    32  	private function AbstractBeforeAdvice(aspect:Aspect) {
    33  		super(aspect);
    34  	}
    35  	
    36  	/**
    37  	 * Invokes this advice's {@code execute} method and proceeds the passed-in
    38  	 * {@code joinPoint} with the given {@code args} after that and returns the result
    39  	 * of the procession.
    40  	 * 
    41  	 * <p>The given {@code joinPoint} is not proceeded if this advice's {@code execute}
    42  	 * method threw an exception.
    43  	 * 
    44  	 * @param joinPoint the reached join point
    45  	 * @param args the arguments to use for the procession of the join point, these are
    46  	 * normally the ones that were originally passed-to the join point
    47  	 * @return the result of the procession of the given {@code joinPoint} with the
    48  	 * given {@code args}
    49  	 * @throws * if the procession of the {@code joinPoint} with the given {@code args}
    50  	 * results in an exception or if this advice's {@code execute} method threw an
    51  	 * exception
    52  	 */
    53  	private function executeJoinPoint(joinPoint:JoinPoint, args:Array) {
    54  		// create a copy of 'args' to use for the before advice because this advice's 'execute'
    55  		// method may alter the given 'args'
    56  		var a:Array = args.concat();
    57  		// 'caller' and 'callee' may be needed by the before advice
    58  		a.caller = args.caller;
    59  		a.callee = args.callee;
    60  		BeforeAdvice(this).execute(joinPoint, a);
    61  		return joinPoint.proceed(args);
    62  	}
    63  	
    64  }