delegatingconfiguration.java

来自「webwork source」· Java 代码 · 共 114 行

JAVA
114
字号
/* * WebWork, Web Application Framework * * Distributable under Apache license. * See terms of license at opensource.org */package webwork.config;import java.util.ArrayList;import java.util.Iterator;/** * Delegating implementation of configuration. Delegates to a list of other configurations. * *	@author Rickard 謆erg (rickard@middleware-company.com) *	@version $Revision: 1.7 $ * */public class DelegatingConfiguration   extends Configuration{   // Attributes ----------------------------------------------------   Configuration[] configList;   // Constructors --------------------------------------------------   public DelegatingConfiguration(Configuration[] aConfigList)   {      configList = aConfigList;   }   /**    * Get a named setting.    */   public Object getImpl(String aName)      throws IllegalArgumentException   {      // Delegate to the other configurations      IllegalArgumentException e = null;      for (int i = 0; i < configList.length; i++)      {         try         {            return configList[i].getImpl(aName);         } catch (IllegalArgumentException ex)         {            e = ex;            // Try next config         }      }      throw e;   }   /**    * Set a named setting    */   public void setImpl(String aName, Object aValue)      throws IllegalArgumentException, UnsupportedOperationException   {      // Determine which config to use by using get      // Delegate to the other configurations      IllegalArgumentException e = null;      for (int i = 0; i < configList.length; i++)      {         try         {            configList[i].getImpl(aName);            // Found it, now try setting            configList[i].setImpl(aName, aValue);            // Worked, now return            return;         } catch (IllegalArgumentException ex)         {            e = ex;            // Try next config         }      }      throw e;   }   /**    * List setting names    */   public Iterator listImpl()   {      boolean workedAtAll = false;      ArrayList settingList = new ArrayList();      UnsupportedOperationException e = null;      for (int i = 0; i < configList.length; i++)      {         try         {            Iterator list = configList[i].listImpl();            while (list.hasNext())            {               settingList.add(list.next());            }            workedAtAll = true;         } catch (UnsupportedOperationException ex)         {            e = ex;            // Try next config         }      }      if (!workedAtAll)         throw e == null ? new UnsupportedOperationException() : e;      else         return settingList.iterator();   }}

⌨️ 快捷键说明

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