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.env.except.IllegalArgumentException;
    18  import org.as2lib.aop.joinpoint.AbstractJoinPoint;
    19  import org.as2lib.env.reflect.MethodInfo;
    20  import org.as2lib.env.reflect.TypeMemberInfo;
    21  import org.as2lib.aop.JoinPoint;
    22  
    23  /**
    24   * {@code MethodJoinPoint} represents a method as join point.
    25   * 
    26   * @author Simon Wacker
    27   */
    28  class org.as2lib.aop.joinpoint.MethodJoinPoint extends AbstractJoinPoint implements JoinPoint {
    29  	
    30  	/** The info of the represented method. */
    31  	private var info:MethodInfo;
    32  	
    33  	/**
    34  	 * Constructs a new {@code MethodJoinPoint} instance.
    35  	 *
    36  	 * @param info the info of the represented method
    37  	 * @param thiz the logical this of the interception
    38  	 * @throws IllegalArgumentException if argument {@code info} is {@code null} or
    39  	 * {@code undefined}
    40  	 * @see <a href="http://www.simonwacker.com/blog/archives/000068.php">Passing Context</a>
    41  	 */
    42  	public function MethodJoinPoint(info:MethodInfo, thiz) {
    43  		super(thiz);
    44  		if (!info) throw new IllegalArgumentException("Argument 'info' must not be 'null' nor 'undefined'.", this, arguments);
    45  		this.info = info;
    46  	}
    47  	
    48  	/**
    49  	 * Returns the info of the represented method. This is a {@link MethodInfo}
    50  	 * instance.
    51  	 * 
    52  	 * @return the info of the represented method
    53  	 */
    54  	public function getInfo(Void):TypeMemberInfo {
    55  		return this.info;
    56  	}
    57  	
    58  	/**
    59  	 * Proceeds this join point by executing the represented method passing the given
    60  	 * arguments and returning the result of the execution.
    61  	 * 
    62  	 * @param args the arguments to use for the execution
    63  	 * @return the result of the execution
    64  	 */
    65  	public function proceed(args:Array) {
    66  		return proceedMethod(this.info, args);
    67  	}
    68  	
    69  	/**
    70  	 * Returns the type of this join point.
    71  	 * 
    72  	 * @return {@link AbstractJoinPoint#METHOD}
    73  	 */
    74  	public function getType(Void):Number {
    75  		return METHOD;
    76  	}
    77  	
    78  	/**
    79  	 * Returns a copy of this join point with an updated logical this. This join point
    80  	 * is left unchanged.
    81  	 * 
    82  	 * @param thiz the new logical this
    83  	 * @return a copy of this join point with an updated logical this
    84  	 * @see #getThis
    85  	 */
    86  	public function update(thiz):JoinPoint {
    87  		return new MethodJoinPoint(this.info, thiz);
    88  	}
    89  	
    90  	/**
    91  	 * Returns a copy of this join point that reflects its current state.
    92  	 * 
    93  	 * <p>It is common practice to create a new join point for a not-fixed method info.
    94  	 * This is when the underlying concrete method this join point reflects may change.
    95  	 * To make the concrete method and other parts that may change fixed you can use
    96  	 * this method to get a new fixed join point, a snapshot.
    97  	 * 
    98  	 * @return a snapshot of this join point
    99  	 */
   100  	public function snapshot(Void):JoinPoint {
   101  		return new MethodJoinPoint(this.info.snapshot(), getThis());
   102  	}
   103  	
   104  }