Commits

Anonymous committed 7294c2f

Making migration configuration code use WebWork configuration classes in com.opensymphony.webwork

git-svn-id: http://svn.opensymphony.com/svn/webwork/trunk@247573baa09-0c28-0410-bef9-dab3c582ae83

Comments (0)

Files changed (17)

src/java/com/opensymphony/webwork/views/velocity/ParamDirective.java

     }
 
     /**
-     *
-     * @param contextAdapter
-     * @param writer
-     * @param node
-     * @return
-     * @throws java.io.IOException
-     * @throws org.apache.velocity.exception.ResourceNotFoundException
-     * @throws org.apache.velocity.exception.ParseErrorException
-     * @throws org.apache.velocity.exception.MethodInvocationException
-     */
+    *
+    * @param contextAdapter
+    * @param writer
+    * @param node
+    * @return
+    * @throws java.io.IOException
+    * @throws org.apache.velocity.exception.ResourceNotFoundException
+    * @throws org.apache.velocity.exception.ParseErrorException
+    * @throws org.apache.velocity.exception.MethodInvocationException
+    */
     public boolean render(InternalContextAdapter contextAdapter, Writer writer, Node node) throws IOException, ResourceNotFoundException, ParseErrorException, MethodInvocationException {
         Object object = contextAdapter.get(VelocityManager.TAG);
 

src/migration/webwork/LazyResultMap.java

 import com.opensymphony.xwork.ActionChainResult;
 import com.opensymphony.xwork.config.entities.ResultConfig;
 import com.opensymphony.webwork.dispatcher.ServletDispatcherResult;
+import com.opensymphony.webwork.config.Configuration;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import webwork.config.Configuration;
 import webwork.dispatcher.ViewMapping;
 
 import java.util.HashMap;

src/migration/webwork/MigrationConfiguration.java

 import com.opensymphony.xwork.config.RuntimeConfiguration;
 import com.opensymphony.xwork.config.impl.DefaultConfiguration;
 import com.opensymphony.xwork.config.providers.XmlConfigurationProvider;
+import com.opensymphony.webwork.config.Configuration;
 import webwork.dispatcher.ViewMapping;
 
 /**
     ViewMapping mapping;
 
     public MigrationConfiguration() {
+        Configuration.setConfiguration(new webwork.config.DefaultConfiguration());
         ConfigurationManager.addConfigurationProvider(new XmlConfigurationProvider("webwork/webwork-migration.xml"));
     }
 

src/migration/webwork/MigrationRuntimeConfiguration.java

 import com.opensymphony.xwork.config.entities.ActionConfig;
 import com.opensymphony.xwork.config.entities.PackageConfig;
 import com.opensymphony.xwork.config.entities.InterceptorStackConfig;
+import com.opensymphony.webwork.config.Configuration;
 import ognl.Ognl;
 import ognl.OgnlContext;
 import ognl.OgnlRuntime;
 import webwork.action.Action;
 import webwork.action.CommandDriven;
 import webwork.action.factory.*;
-import webwork.config.Configuration;
 import webwork.dispatcher.DefaultViewMapping;
 import webwork.dispatcher.ViewMapping;
 

src/migration/webwork/action/factory/ActionFactory.java

 
 import org.apache.commons.logging.*;
 import webwork.action.Action;
-import webwork.config.Configuration;
 import webwork.util.ClassLoaderUtils;
 
 /**
  * or the specified class cannot be instantiated, the
  * {@link MigrationActionFactory} class will be instantiated.
  *
- *	@author Rickard Öberg (rickard@middleware-company.com)
+ *	@author Rickard Öberg (rickard@middleware-company.com)
  *	@version $Revision$
  */
 public abstract class ActionFactory
       // Create default implementation
       try
       {
-         String className = Configuration.getString("webwork.action.factory");
+         String className = com.opensymphony.webwork.config.Configuration.getString("webwork.action.factory");
          try
          {
             defaultActionFactory = (ActionFactory)ClassLoaderUtils.loadClass(className, ActionFactory.class).newInstance();

src/migration/webwork/action/factory/AliasingActionFactoryProxy.java

 package webwork.action.factory;
 
 import webwork.action.Action;
-import webwork.config.Configuration;
 
 import java.util.Hashtable;
 import java.util.Map;
 
 import org.apache.commons.logging.*;
+import com.opensymphony.webwork.config.Configuration;
 
 /**
  * Aliasing action factory proxy. This will convert the given name

src/migration/webwork/action/factory/PrefixActionFactoryProxy.java

 
 import org.apache.commons.logging.*;
 import webwork.action.Action;
-import webwork.config.Configuration;
 
 import java.util.ArrayList;
 import java.util.Hashtable;
 import java.util.Map;
 import java.util.StringTokenizer;
 
+import com.opensymphony.webwork.config.Configuration;
+
 /**
  * Locate an action based on the configured list of package prefixes.
  * The configuration property <code>webwork.action.packages</code> is used

src/migration/webwork/config/Configuration.java

-/*
- * WebWork, Web Application Framework
- *
- * Distributable under Apache license.
- * See terms of license at opensource.org
- */
-package webwork.config;
-
-import org.apache.commons.logging.*;
-
-import java.util.Iterator;
-import java.util.Locale;
-import java.util.StringTokenizer;
-
-import webwork.config.DefaultConfiguration;
-import webwork.util.ClassLoaderUtils;
-
-/**
- * Access to WebWork configuration. Use the constants to access defined configuration settings.
- *
- * The implementation is pluggable. The default implementation is to use the properties file
- * "webwork.properties", which must be in classpath. To install a new implementation subclass this
- * class and call setConfiguration() with it.
- *
- *	@author Rickard Öberg (rickard@middleware-company.com)
- *	@version $Revision$
- *
- */
-public abstract class Configuration
-{
-   // Static --------------------------------------------------------
-   static Configuration configurationImpl;
-   static Configuration defaultImpl;
-   static Locale locale; // Cached locale
-
-   /**
-    * Get a named setting.
-    */
-   public static Object get(String aName)
-      throws IllegalArgumentException
-   {
-      Object val = getConfiguration().getImpl(aName);
-      return val;
-   }
-
-   /**
-    * Get a named setting as a string.
-    */
-   public static String getString(String aName)
-      throws IllegalArgumentException
-   {
-      String val = get(aName).toString();
-      return val;
-   }
-
-   /**
-    * Set a named setting
-    */
-   public static void set(String aName, Object aValue)
-      throws IllegalArgumentException, UnsupportedOperationException
-   {
-      getConfiguration().setImpl(aName, aValue);
-   }
-
-   /**
-    * List setting names
-    */
-   public static Iterator list()
-   {
-      return getConfiguration().listImpl();
-   }
-
-   /**
-    * WebWork locale accessor
-    */
-   public static Locale getLocale()
-   {
-      if (locale == null)
-      {
-         try
-         {
-            StringTokenizer localeTokens = new StringTokenizer(getString("webwork.locale"),"_");
-            String lang = null;
-            String country = null;
-            if (localeTokens.hasMoreTokens())
-               lang = localeTokens.nextToken();
-            if (localeTokens.hasMoreTokens())
-               country = localeTokens.nextToken();
-            locale = new Locale(lang, country);
-         } catch (IllegalArgumentException e)
-         {
-            // Default
-            locale = Locale.getDefault();
-         }
-      }
-
-      return locale;
-   }
-
-   /**
-    * Get the current configuration implementation.
-    */
-   public static Configuration getConfiguration()
-   {
-      return configurationImpl == null ? getDefaultConfiguration() : configurationImpl;
-   }
-
-   /**
-    * Set the current configuration implementation. Can only be called once.
-    */
-   public static void setConfiguration(Configuration aConfig)
-      throws IllegalStateException
-   {
-      if (configurationImpl != null)
-         throw new IllegalStateException("May only set configuration implementation once");
-
-      configurationImpl = aConfig;
-      locale = null; // Reset cached locale
-   }
-
-   /**
-    * Get a named setting.
-    *
-    * @throws IllegalArgumentException if there is no configuration parameter with the given name.
-    */
-   public Object getImpl(String aName)
-      throws IllegalArgumentException
-   {
-      return null;
-   }
-
-   /**
-    * Set a named setting
-    */
-   public void setImpl(String aName, Object aValue)
-      throws IllegalArgumentException, UnsupportedOperationException
-   {
-      throw new UnsupportedOperationException("This configuration does not support updating a setting");
-   }
-
-   /**
-    * List setting names
-    */
-   public Iterator listImpl()
-   {
-      throw new UnsupportedOperationException("This configuration does not support listing the settings");
-   }
-
-   private static Configuration getDefaultConfiguration()
-   {
-      if (defaultImpl == null)
-      {
-         // Create bootstrap implementation
-         defaultImpl = new DefaultConfiguration();
-
-         // Create default implementation
-         try
-         {
-            String className = getString("webwork.configuration");
-            if (!className.equals(defaultImpl.getClass().getName()))
-            {
-               try
-               {
-                  defaultImpl = (Configuration)ClassLoaderUtils.loadClass(className, Configuration.class).newInstance();
-               } catch (Exception e)
-               {
-                  LogFactory.getLog(Configuration.class).error("Could not instantiate configuration", e);
-               }
-            }
-         } catch (IllegalArgumentException ex)
-         {
-            LogFactory.getLog(Configuration.class).error("No default configuration defined", ex);
-         }
-      }
-
-      return defaultImpl;
-   }
-}

src/migration/webwork/config/DefaultConfiguration.java

 import java.util.Iterator;
 import java.util.StringTokenizer;
 
+import com.opensymphony.webwork.config.Configuration;
+import com.opensymphony.webwork.config.PropertiesConfiguration;
+import com.opensymphony.webwork.config.DelegatingConfiguration;
+
 /**
  * Default implementation of configuration. Creates and delegates to other configurations.
  *

src/migration/webwork/config/DelegatingConfiguration.java

-/*
- * 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 �berg (rickard@middleware-company.com)
- *	@version $Revision$
- *
- */
-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();
-   }
-}

src/migration/webwork/config/PropertiesConfiguration.java

-/*
- * WebWork, Web Application Framework
- *
- * Distributable under Apache license.
- * See terms of license at opensource.org
- */
-package webwork.config;
-
-import webwork.util.ClassLoaderUtils;
-
-import java.io.IOException;
-import java.net.URL;
-import java.util.Enumeration;
-import java.util.Iterator;
-import java.util.Properties;
-
-/**
- * Access configuration from a properties file.
- *
- *	@author Rickard Öberg (rickard@middleware-company.com)
- *	@version $Revision$
- *
- */
-public class PropertiesConfiguration
-   extends Configuration
-{
-   // Attributes ----------------------------------------------------
-   Properties settings;
-
-   // Constructors --------------------------------------------------
-   public PropertiesConfiguration(String aName)
-   {
-      settings = new Properties();
-
-      URL settingsUrl = ClassLoaderUtils.getResource(aName+".properties", PropertiesConfiguration.class);
-
-      if (settingsUrl == null)
-      {
-         throw new IllegalStateException(aName+".properties missing");
-      }
-
-      // Load settings
-      try
-      {
-         settings.load(settingsUrl.openStream());
-      } catch (IOException e)
-      {
-         throw new RuntimeException("Could not load "+aName+".properties:"+e);
-      }
-   }
-
-   /**
-    * Get a named setting.
-    */
-   public Object getImpl(String aName)
-      throws IllegalArgumentException
-   {
-      Object setting = settings.get(aName);
-      if (setting == null)
-         throw new IllegalArgumentException("No such setting:"+aName);
-
-      return setting;
-   }
-
-   public void setImpl(String aName, Object aValue)
-   {
-      settings.put(aName, aValue);
-   }
-
-   public Iterator listImpl()
-   {
-      return settings.keySet().iterator();
-   }
-}

src/migration/webwork/config/XMLActionConfiguration.java

 import java.util.Map;
 
 import webwork.util.ClassLoaderUtils;
+import com.opensymphony.webwork.config.Configuration;
 
 /**
  * Access view configuration from an XML file.
  *
- *	@author Rickard Öberg (rickard@middleware-company.com)
+ *	@author Rickard Öberg (rickard@middleware-company.com)
  *	@author Scott Farquhar (scott@atlassian.com)
  *	@version $Revision$
  *
  */
-public class XMLActionConfiguration
-   extends Configuration
+public class XMLActionConfiguration extends Configuration
 {
    // Attributes ----------------------------------------------------
    /**

src/migration/webwork/config/package.html

-<body>
-<p>
-This package contains a Configuration API that can be used by WebWork code and Actions to access configuration settings. The configuration store is pluggable so as to allow multiple ways of providing the configuration, while allowing code to use a simple API to access it.
-</p>
-</body>

src/migration/webwork/dispatcher/CachingViewMapping.java

  */
 package webwork.dispatcher;
 
-import webwork.action.Action;
-import webwork.config.Configuration;
-
 import java.util.Map;
 import java.util.Collections;
 import java.util.HashMap;

src/migration/webwork/dispatcher/ConfigurationViewMapping.java

 package webwork.dispatcher;
 
 import webwork.action.Action;
-import webwork.config.Configuration;
+import com.opensymphony.webwork.config.Configuration;
 
 /**
  * View mapping that uses the Configuration. This maps {action name, view name} tuples to views, e.g. JSP files.

src/migration/webwork/dispatcher/DefaultViewMapping.java

  */
 package webwork.dispatcher;
 
-import webwork.action.Action;
-import webwork.config.Configuration;
-
 /**
  * Default view mapping.
  *

src/migration/webwork/dispatcher/DynamicViewMapping.java

 
 import com.opensymphony.xwork.ActionContext;
 import com.opensymphony.xwork.util.OgnlValueStack;
+import com.opensymphony.webwork.config.Configuration;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import webwork.config.Configuration;
 
 import java.util.*;