webwork/src/main/webwork/config CachingConfiguration.java,NONE,1.1

[email protected] Wed, 05 Nov 2003 02:18:40 -0800
Newsgroups gmane.comp.java.open-symphony.cvs
Message-ID <[email protected]>
Update of /cvsroot/opensymphony/webwork/src/main/webwork/config
In directory sc8-pr-cvs1:/tmp/cvs-serv11871

Added Files:
	CachingConfiguration.java 
Log Message:
This is a caching implementation of Configuration that may be used
instead of DefaultConfiguration. Fixes Jira issue WW-368

--- NEW FILE: CachingConfiguration.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 ([email protected])
 *	@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();
   }
}




-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive?  Does it
help you create better code?   SHARE THE LOVE, and help us help
YOU!  Click Here: http://sourceforge.net/donate/