⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cachingconfiguration.java

📁 webwork source
💻 JAVA
字号:
/*
 * WebWork, Web Application Framework
 *
 * Distributable under Apache license.
 * See terms of license at opensource.org
 */
package webwork.config;

import java.util.Iterator;
import java.util.Map;
import java.util.HashMap;

/**
 * This is a caching implementation of Configuration.
 * This class can be used instead of the DefaultConfiguration to 
 * make your configuration lookups more efficient.
 * At startup it iterates through all the configuration settings
 * returned by DefaultConfiguration and stores them in a Map.
 *
 *	@author Dick Zetterberg (dick@transitor.se)
 *	@version $Revision: 1.1 $
 */
public class CachingConfiguration
   extends DefaultConfiguration
{	
   // Attributes ----------------------------------------------------
   protected Map configurationMap;

   // Constructors --------------------------------------------------
   public CachingConfiguration()
   {
      // Create the configuration Map with all the keys and values
      // from the DefaultConfiguration
      configurationMap = getConfigurationMap(config);
   }

   /**
   * Create and return a Map with configuration key/values
   */
   protected Map getConfigurationMap(Configuration configObject)
   {
      // Get an iterator for the configObject
      Iterator it = configObject.listImpl();
      Map configMap = new HashMap();
      while(it.hasNext())
      {
         String key = (String) it.next();
         // Get the value for the key
         Object value = configObject.get(key);					
         // Put the key and value in the Map
         configMap.put(key, value);
      }
      return configMap;
   }

   /**
    * Get a named setting.
    */
   public Object getImpl(String aName)
      throws IllegalArgumentException
   {
      Object value = configurationMap.get(aName);
      if (value == null)
         throw new IllegalArgumentException("No such setting: " + aName);

  	   return value;
   }

   /**
    * Set a named setting
    */
   public void setImpl(String aName, Object aValue)
   {
      configurationMap.put(aName, aValue);
   }

   /**
    * List setting names
    */
   public Iterator listImpl()
   {
      return configurationMap.keySet().iterator();
   }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -