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.PointcutFactory;
    19  import org.as2lib.aop.pointcut.DynamicPointcutFactory;
    20  import org.as2lib.aop.advice.DynamicAdviceFactory;
    21  import org.as2lib.aop.advice.SimpleDynamicAdviceFactory;
    22  import org.as2lib.aop.Matcher;
    23  import org.as2lib.aop.matcher.WildcardMatcher;
    24  
    25  /**
    26   * {@code AopConfig} declares methods to configure core parts of the AOP framework.
    27   * 
    28   * @author Simon Wacker
    29   */
    30  class org.as2lib.aop.AopConfig extends BasicClass {
    31  	
    32  	/** The pointcut factory. */
    33  	private static var pointcutFactory:PointcutFactory;
    34  	
    35  	/** The dynamic advice factory. */
    36  	private static var dynamicAdviceFactory:DynamicAdviceFactory;
    37  	
    38  	/** The matcher. */
    39  	private static var matcher:Matcher;
    40  	
    41  	/**
    42  	 * Sets a new dynamic advice factory.
    43  	 *
    44  	 * @param factory the new dynamic advice factory
    45  	 */
    46  	public static function setDynamicAdviceFactory(factory:DynamicAdviceFactory):Void {
    47  		dynamicAdviceFactory = factory;
    48  	}
    49  	
    50  	/**
    51  	 * Returns the set or the default dynamic advice factory. The defult factory is
    52  	 * an instance of the {@link SimpleDynamicAdviceFactory} class.
    53  	 *
    54  	 * @return the set or the default dynamic advice factory
    55  	 */
    56  	public static function getDynamicAdviceFactory(Void):DynamicAdviceFactory {
    57  		if (!dynamicAdviceFactory) dynamicAdviceFactory = new SimpleDynamicAdviceFactory();
    58  		return dynamicAdviceFactory;
    59  	}
    60  	
    61  	/**
    62  	 * Sets a new pointcut factory.
    63  	 *
    64  	 * @param factory the new pointcut factory
    65  	 */
    66  	public static function setPointcutFactory(factory:PointcutFactory):Void {
    67  		pointcutFactory = factory;
    68  	}
    69  	
    70  	/**
    71  	 * Returns the set pointcut factory or the default one. The default one is an
    72  	 * instance of the {@link DynamicPointcutFactory} class.
    73  	 *
    74  	 * @return the set or default pointcut factory
    75  	 */
    76  	public static function getPointcutFactory(Void):PointcutFactory {
    77  		if (!pointcutFactory) pointcutFactory = new DynamicPointcutFactory();
    78  		return pointcutFactory;
    79  	}
    80  	
    81  	/**
    82  	 * Sets a new matcher.
    83  	 * 
    84  	 * @param newMatcher the new matcher
    85  	 */
    86  	public static function setMatcher(newMatcher:Matcher):Void {
    87  		matcher = newMatcher;
    88  	}
    89  	
    90  	/**
    91  	 * Returns either the set or the default matcher. The default matcher is an
    92  	 * instance of the {@link WildcardMatcher} class.
    93  	 * 
    94  	 * @return the set or default matcher
    95  	 */
    96  	public static function getMatcher(Void):Matcher {
    97  		if (!matcher) matcher = new WildcardMatcher();
    98  		return matcher;
    99  	}
   100  	
   101  	/**
   102  	 * Constructs a new {@code AopConfig} instance.
   103  	 */
   104  	private function AopConfig(Void) {
   105  	}
   106  	
   107  }