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.env.reflect.Cache;
    19  import org.as2lib.env.reflect.SimpleCache;
    20  import org.as2lib.env.reflect.PackageInfo;
    21  
    22  /**
    23   * {@code ReflectConfig} is the main config used to globally configure key parts of
    24   * the work the classes of the reflect package try to solve.
    25   * 
    26   * @author Simon Wacker
    27   */
    28  class org.as2lib.env.reflect.ReflectConfig extends BasicClass {
    29  	
    30  	/** Caches found classes and packages. */
    31  	private static var cache:Cache;
    32  	
    33  	/**
    34  	 * Private constructor.
    35  	 */
    36  	private function ReflectConfig(Void) {
    37  	}
    38  	
    39  	/**
    40  	 * Returns the cache used to cache all classes and packages that have already been
    41  	 * found.
    42  	 * 
    43  	 * <p>If no cache was set manually via {@link #setCache} the default cache will be
    44  	 * returned, that is an instance of class {@link SimpleCache} and that is configured
    45  	 * with the root package returned by the {@link PackageInfo#getRootPackage} method.
    46  	 *
    47  	 * @return the cache used to cache classes and packages
    48  	 */
    49  	public static function getCache(Void):Cache {
    50  		if (!cache) cache = new SimpleCache(PackageInfo.getRootPackage());
    51  		return cache;
    52  	}
    53  	
    54  	/**
    55  	 * Sets the new cache used to cache classes and packages.
    56  	 * 
    57  	 * <p>If {@code newCache} is {@code null} the default cache will be returned by
    58  	 * the {@link #getCache} method.
    59  	 *
    60  	 * @param cache the new cache to use
    61  	 */
    62  	public static function setCache(newCache:Cache):Void {
    63  		cache = newCache;
    64  	}
    65  	
    66  }