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.core.BasicClass;
    18  import org.as2lib.aop.Pointcut;
    19  import org.as2lib.aop.JoinPoint;
    20  
    21  /**
    22   * {@code NotPointcut} acts like the logical not "!" operator. It wraps a pointcut and
    23   * negates the result of its {@code captures} method.
    24   * 
    25   * @author Simon Wacker
    26   */
    27  class org.as2lib.aop.pointcut.NotPointcut extends BasicClass implements Pointcut {
    28  	
    29  	/** The wrapped pointcut to negate. */
    30  	private var pointcut:Pointcut;
    31  	
    32  	/**
    33  	 * Constructs a new {@code NotPointcut} instance.
    34  	 * 
    35  	 * @param pointcut the pointcut whose {@code captures} method to negate
    36  	 */
    37  	public function NotPointcut(pointcut:Pointcut) {
    38  		this.pointcut = pointcut;
    39  	}
    40  	
    41  	/**
    42  	 * Executes the wrapped pointcut's {@code captures} method passing the given
    43  	 * {@code joinPoint}, negates the result and returns the negation.
    44  	 * 
    45  	 * <p>If the wrapped pointcut specified on construction is {@code null} or
    46  	 * {@code undefined}, {@code false} will be returned.
    47  	 * 
    48  	 * @param joinPoint the join point to check whether it is captured
    49  	 * @return the negated result of the execution of the {@code captures} method of
    50  	 * the wrapped pointcut 
    51  	 */
    52  	public function captures(joinPoint:JoinPoint):Boolean {
    53  		if (!this.pointcut) return false;
    54  		return !this.pointcut.captures(joinPoint);
    55  	}
    56  	
    57  }