commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1243699 [1/3] - in /commons/proper/chain/trunk/src: changes/ main/java/org/apache/commons/chain/ main/java/org/apache/commons/chain/config/ main/java/org/apache/commons/chain/generic/ main/java/org/apache/commons/chain/impl/ main/java/org/...
Date Mon, 13 Feb 2012 21:19:09 GMT
Author: simonetripodi
Date: Mon Feb 13 21:19:07 2012
New Revision: 1243699

URL: http://svn.apache.org/viewvc?rev=1243699&view=rev
Log:
[CHAIN-58] Update Chain Context interface to use K,V generics - patch submitted by Elijah Zupancic

Added:
    commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/impl/ContextMap.java   (with props)
Modified:
    commons/proper/chain/trunk/src/changes/changes.xml
    commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/Catalog.java
    commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/CatalogFactory.java
    commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/Chain.java
    commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/Command.java
    commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/Context.java
    commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/Filter.java
    commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/config/ConfigCatalogRule.java
    commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/config/ConfigParser.java
    commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/config/ConfigRegisterRule.java
    commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/generic/CopyCommand.java
    commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/generic/DispatchCommand.java
    commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/generic/DispatchLookupCommand.java
    commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/generic/LookupCommand.java
    commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/generic/RemoveCommand.java
    commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/impl/CatalogBase.java
    commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/impl/CatalogFactoryBase.java
    commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/impl/ChainBase.java
    commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/impl/ContextBase.java
    commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/AbstractGetLocaleCommand.java
    commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/AbstractSetLocaleCommand.java
    commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/ChainListener.java
    commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/ChainServlet.java
    commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/WebContext.java
    commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/faces/FacesGetLocaleCommand.java
    commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/faces/FacesSetLocaleCommand.java
    commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/faces/FacesWebContext.java
    commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/portlet/PortletGetLocaleCommand.java
    commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/portlet/PortletSetLocaleCommand.java
    commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/servlet/ChainProcessor.java
    commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/servlet/PathInfoMapper.java
    commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/servlet/RequestParameterMapper.java
    commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/servlet/ServletGetLocaleCommand.java
    commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/servlet/ServletPathMapper.java
    commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/servlet/ServletSetLocaleCommand.java
    commons/proper/chain/trunk/src/test/java/org/apache/commons/chain/config/ConfigParser2TestCase.java
    commons/proper/chain/trunk/src/test/java/org/apache/commons/chain/config/ConfigParserTestCase.java
    commons/proper/chain/trunk/src/test/java/org/apache/commons/chain/config/TestChain.java
    commons/proper/chain/trunk/src/test/java/org/apache/commons/chain/config/TestCommand.java
    commons/proper/chain/trunk/src/test/java/org/apache/commons/chain/generic/DispatchCommandTestCase.java
    commons/proper/chain/trunk/src/test/java/org/apache/commons/chain/generic/DispatchLookupCommandTestCase.java
    commons/proper/chain/trunk/src/test/java/org/apache/commons/chain/generic/LookupCommandTestCase.java
    commons/proper/chain/trunk/src/test/java/org/apache/commons/chain/impl/AddingCommand.java
    commons/proper/chain/trunk/src/test/java/org/apache/commons/chain/impl/CatalogBaseTestCase.java
    commons/proper/chain/trunk/src/test/java/org/apache/commons/chain/impl/CatalogFactoryBaseTestCase.java
    commons/proper/chain/trunk/src/test/java/org/apache/commons/chain/impl/ChainBaseTestCase.java
    commons/proper/chain/trunk/src/test/java/org/apache/commons/chain/impl/ContextBaseTestCase.java
    commons/proper/chain/trunk/src/test/java/org/apache/commons/chain/impl/DelegatingCommand.java
    commons/proper/chain/trunk/src/test/java/org/apache/commons/chain/impl/DelegatingFilter.java
    commons/proper/chain/trunk/src/test/java/org/apache/commons/chain/impl/ExceptionCommand.java
    commons/proper/chain/trunk/src/test/java/org/apache/commons/chain/impl/ExceptionFilter.java
    commons/proper/chain/trunk/src/test/java/org/apache/commons/chain/impl/NonDelegatingCommand.java
    commons/proper/chain/trunk/src/test/java/org/apache/commons/chain/impl/NonDelegatingFilter.java
    commons/proper/chain/trunk/src/test/java/org/apache/commons/chain/impl/TestContext.java
    commons/proper/chain/trunk/src/test/java/org/apache/commons/chain/impl/TestContextTestCase.java
    commons/proper/chain/trunk/src/test/java/org/apache/commons/chain/web/MockEnumeration.java
    commons/proper/chain/trunk/src/test/java/org/apache/commons/chain/web/portlet/MockPortletContext.java
    commons/proper/chain/trunk/src/test/java/org/apache/commons/chain/web/portlet/MockPortletRequest.java
    commons/proper/chain/trunk/src/test/java/org/apache/commons/chain/web/portlet/MockPortletSession.java
    commons/proper/chain/trunk/src/test/java/org/apache/commons/chain/web/portlet/PortletGetLocaleCommandTestCase.java
    commons/proper/chain/trunk/src/test/java/org/apache/commons/chain/web/portlet/PortletWebContextTestCase.java
    commons/proper/chain/trunk/src/test/java/org/apache/commons/chain/web/servlet/MockHttpServletRequest.java
    commons/proper/chain/trunk/src/test/java/org/apache/commons/chain/web/servlet/MockHttpSession.java
    commons/proper/chain/trunk/src/test/java/org/apache/commons/chain/web/servlet/MockServletConfig.java
    commons/proper/chain/trunk/src/test/java/org/apache/commons/chain/web/servlet/MockServletContext.java
    commons/proper/chain/trunk/src/test/java/org/apache/commons/chain/web/servlet/ServletGetLocaleCommandTestCase.java
    commons/proper/chain/trunk/src/test/java/org/apache/commons/chain/web/servlet/ServletSetLocaleCommandTestCase.java
    commons/proper/chain/trunk/src/test/java/org/apache/commons/chain/web/servlet/ServletWebContextTestCase.java

Modified: commons/proper/chain/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/src/changes/changes.xml?rev=1243699&r1=1243698&r2=1243699&view=diff
==============================================================================
--- commons/proper/chain/trunk/src/changes/changes.xml (original)
+++ commons/proper/chain/trunk/src/changes/changes.xml Mon Feb 13 21:19:07 2012
@@ -43,6 +43,9 @@ The <action> type attribute can be add,u
       <action dev="simonetripodi" type="add" issue="CHAIN-61" due-to="Elijah Zupancic">
         Chain 2.0 trunk build is throwing many warnings as a result of generification changes.
       </action>
+      <action dev="simonetripodi" type="update" issue="CHAIN-58" due-to="Elijah Zupancic">
+        Update Chain Context interface to use K,V generics
+      </action>
       <action dev="simonetripodi" type="add" issue="CHAIN-56">
          clever Context with generic type "auto-cast" feature.
       </action>

Modified: commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/Catalog.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/Catalog.java?rev=1243699&r1=1243698&r2=1243699&view=diff
==============================================================================
--- commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/Catalog.java (original)
+++ commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/Catalog.java Mon Feb 13 21:19:07 2012
@@ -18,6 +18,7 @@ package org.apache.commons.chain;
 
 
 import java.util.Iterator;
+import java.util.Map;
 
 
 /**
@@ -27,11 +28,15 @@ import java.util.Iterator;
  * is optional, but convenient when there are multiple possible chains
  * that can be selected and executed based on environmental conditions.</p>
  *
+ * @param <K> the type of keys maintained by the context associated with this command
+ * @param <V> the type of mapped values
+ * @param <C> Type of the context associated with this command
+ *
  * @author Craig R. McClanahan
  * @version $Revision$ $Date$
  */
 
-public interface Catalog {
+public interface Catalog<K, V, C extends Map<K, V>> {
 
 
     /**
@@ -46,24 +51,22 @@ public interface Catalog {
      * to the set of named commands known to this {@link Catalog},
      * replacing any previous command for that name.
      *
-     * @param <C> Type of the context associated with this command
      * @param name Name of the new command
      * @param command {@link Command} or {@link Chain} to be returned
      *  for later lookups on this name
      */
-    <C extends Context> void addCommand(String name, Command<C> command);
+    void addCommand(String name, Command<K, V, C> command);
 
 
     /**
      * <p>Return the {@link Command} or {@link Chain} associated with the
      * specified name, if any; otherwise, return <code>null</code>.</p>
      *
-     * @param <C> Type of the context associated with this command
      * @param name Name for which a {@link Command} or {@link Chain}
      *  should be retrieved
      * @return The Command associated with the specified name.
      */
-    <C extends Context> Command<C> getCommand(String name);
+    Command<K, V, C> getCommand(String name);
 
 
 

Modified: commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/CatalogFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/CatalogFactory.java?rev=1243699&r1=1243698&r2=1243699&view=diff
==============================================================================
--- commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/CatalogFactory.java (original)
+++ commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/CatalogFactory.java Mon Feb 13 21:19:07 2012
@@ -19,8 +19,8 @@ package org.apache.commons.chain;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
-import org.apache.commons.chain.impl.CatalogFactoryBase;
 
+import org.apache.commons.chain.impl.CatalogFactoryBase;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -34,11 +34,15 @@ import org.apache.commons.logging.LogFac
  * a resolution mechanism which allows lookup of a command based on a single
  * String which encodes both the catalog and command names.</p>
  *
+ * @param <K> the type of keys maintained by the context associated with this command
+ * @param <V> the type of mapped values
+ * @param <C> Type of the context associated with this command
+ *
  * @author Sean Schofield
  * @version $Revision$ $Date$
  */
 
-public abstract class CatalogFactory {
+public abstract class CatalogFactory<K, V, C extends Map<K, V>> {
 
 
     /**
@@ -58,7 +62,7 @@ public abstract class CatalogFactory {
      *
      * @return the default Catalog instance
      */
-    public abstract Catalog getCatalog();
+    public abstract Catalog<K, V, C> getCatalog();
 
 
     /**
@@ -66,7 +70,7 @@ public abstract class CatalogFactory {
      *
      * @param catalog the default Catalog instance
      */
-    public abstract void setCatalog(Catalog catalog);
+    public abstract void setCatalog(Catalog<K, V, C> catalog);
 
 
     /**
@@ -76,7 +80,7 @@ public abstract class CatalogFactory {
      * @param name the name of the Catalog to retrieve
      * @return the specified Catalog
      */
-    public abstract Catalog getCatalog(String name);
+    public abstract Catalog<K, V, C> getCatalog(String name);
 
 
     /**
@@ -86,7 +90,7 @@ public abstract class CatalogFactory {
      * @param name the name of the Catalog to add
      * @param catalog the Catalog to add
      */
-    public abstract void addCatalog(String name, Catalog catalog);
+    public abstract void addCatalog(String name, Catalog<K, V, C> catalog);
 
 
     /**
@@ -123,11 +127,11 @@ public abstract class CatalogFactory {
      *
      * @since Chain 1.1
      */
-    public <C extends Context> Command<C> getCommand(String commandID) {
+    public Command<K, V, C> getCommand(String commandID) {
 
         String commandName = commandID;
         String catalogName = null;
-        Catalog catalog = null;
+        Catalog<K, V, C> catalog = null;
 
         if (commandID != null) {
             int splitPos = commandID.indexOf(DELIMITER);
@@ -170,8 +174,8 @@ public abstract class CatalogFactory {
      * <p>The set of registered {@link CatalogFactory} instances,
      * keyed by the relevant class loader.</p>
      */
-    private static final Map<ClassLoader, CatalogFactory> factories =
-            new HashMap<ClassLoader, CatalogFactory>();
+    private static final Map<ClassLoader, CatalogFactory<?, ?, ? extends Map<?, ?>>> factories =
+            new HashMap<ClassLoader, CatalogFactory<?, ?, ? extends Map<?, ?>>>();
 
 
     // -------------------------------------------------------- Static Methods
@@ -187,19 +191,24 @@ public abstract class CatalogFactory {
      *
      * @return the per-application singleton instance of {@link CatalogFactory}
      */
-    public static CatalogFactory getInstance() {
+    public static <K, V, C extends Map<K, V>> CatalogFactory<K, V, C> getInstance() {
 
-        CatalogFactory factory = null;
+        CatalogFactory<?, ?, ? extends Map<?, ?>> factory = null;
         ClassLoader cl = getClassLoader();
         synchronized (factories) {
             factory = factories.get(cl);
             if (factory == null) {
-                factory = new CatalogFactoryBase();
+                factory = new CatalogFactoryBase<K, V, C>();
                 factories.put(cl, factory);
             }
         }
-        return factory;
 
+        /* This should always convert cleanly because we are using the
+         * base most generic for definition. */
+        @SuppressWarnings("unchecked")
+        CatalogFactory<K, V, C> result = (CatalogFactory<K, V, C>) factory;
+
+        return result;
     }
 
 

Modified: commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/Chain.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/Chain.java?rev=1243699&r1=1243698&r2=1243699&view=diff
==============================================================================
--- commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/Chain.java (original)
+++ commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/Chain.java Mon Feb 13 21:19:07 2012
@@ -16,6 +16,8 @@
  */
 package org.apache.commons.chain;
 
+import java.util.Map;
+
 
 /**
  * <p>A {@link Chain} represents a configured list of
@@ -53,7 +55,7 @@ package org.apache.commons.chain;
  * @version $Revision$ $Date$
  */
 
-public interface Chain<C extends Context> extends Command<C> {
+public interface Chain<K, V, C extends Map<K, V>> extends Command<K, V, C> {
 
 
     /**
@@ -70,7 +72,7 @@ public interface Chain<C extends Context
      * @exception IllegalStateException if this {@link Chain} has already
      *  been executed at least once, so no further configuration is allowed
      */
-    void addCommand(Command<C> command);
+    void addCommand(Command<K, V, C> command);
 
 
     /**

Modified: commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/Command.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/Command.java?rev=1243699&r1=1243698&r2=1243699&view=diff
==============================================================================
--- commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/Command.java (original)
+++ commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/Command.java Mon Feb 13 21:19:07 2012
@@ -16,6 +16,8 @@
  */
 package org.apache.commons.chain;
 
+import java.util.Map;
+
 
 /**
  * <p>A {@link Command} encapsulates a unit of processing work to be
@@ -73,13 +75,15 @@ package org.apache.commons.chain;
  * being used in this fashion, as opposed to JavaBeans properties that simply
  * configure the internal operation of this {@link Command}.</p>
  *
+ * @param <K> the type of keys maintained by the context associated with this command
+ * @param <V> the type of mapped values
  * @param <C> Type of the context associated with this command
  *
  * @author Craig R. McClanahan
  * @version $Revision$ $Date$
  */
 
-public interface Command<C extends Context> {
+public interface Command<K, V, C extends Map<K, V>> {
 
     /**
      * <p>Commands should return <code>CONTINUE_PROCESSING</code> if the processing
@@ -98,6 +102,7 @@ public interface Command<C extends Conte
      * @since Chain 1.1
      */
     public static final boolean PROCESSING_COMPLETE = true;
+
     /**
      * <p>Execute a unit of processing work to be performed.  This
      * {@link Command} may either complete the required processing
@@ -118,8 +123,6 @@ public interface Command<C extends Conte
      *  of this {@link Context} should be delegated to a subsequent
      *  {@link Command} in an enclosing {@link Chain}
      */
-
     boolean execute(C context) throws Exception;
 
-
 }

Modified: commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/Context.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/Context.java?rev=1243699&r1=1243698&r2=1243699&view=diff
==============================================================================
--- commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/Context.java (original)
+++ commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/Context.java Mon Feb 13 21:19:07 2012
@@ -56,11 +56,13 @@ import java.util.Map;
  * simultaneously unless this is explicitly documented for a particular
  * implementation.</p>
  *
+ * @param <K> the type of keys maintained by the context associated with this catalog
+ * @param <V> the type of mapped values
  * @author Craig R. McClanahan
  * @version $Revision$ $Date$
  */
 
-public interface Context extends Map<String, Object> {
+public interface Context<K, V> extends Map<K, V> {
 
     /**
      * That method enhances the {@link #get(Object)} method that helps users
@@ -75,6 +77,6 @@ public interface Context extends Map<Str
      * @see #get(Object)
      * @since 2.0
      */
-    <T> T retrieve(String key);
+    <T extends V> T retrieve(K key);
 
 }

Modified: commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/Filter.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/Filter.java?rev=1243699&r1=1243698&r2=1243699&view=diff
==============================================================================
--- commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/Filter.java (original)
+++ commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/Filter.java Mon Feb 13 21:19:07 2012
@@ -16,6 +16,8 @@
  */
 package org.apache.commons.chain;
 
+import java.util.Map;
+
 
 /**
  * <p>A {@link Filter} is a specialized {@link Command} that also expects
@@ -37,13 +39,15 @@ package org.apache.commons.chain;
  * can reliably release such resources in the <code>postprocess()</code>
  * method, which is guaranteed to be called by the owning {@link Chain}.</p>
  *
+ * @param <K> the type of keys maintained by the context associated with this command
+ * @param <V> the type of mapped values
  * @param <C> Type of the context associated with this command
  *
  * @author Craig R. McClanahan
  * @version $Revision$ $Date$
  */
 
-public interface Filter<C extends Context> extends Command<C> {
+public interface Filter<K, V, C extends Map<K, V>> extends Command<K, V, C> {
 
 
     /**

Modified: commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/config/ConfigCatalogRule.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/config/ConfigCatalogRule.java?rev=1243699&r1=1243698&r2=1243699&view=diff
==============================================================================
--- commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/config/ConfigCatalogRule.java (original)
+++ commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/config/ConfigCatalogRule.java Mon Feb 13 21:19:07 2012
@@ -17,6 +17,8 @@
 package org.apache.commons.chain.config;
 
 
+import java.util.Map;
+
 import org.apache.commons.chain.Catalog;
 import org.apache.commons.chain.CatalogFactory;
 import org.apache.commons.digester.Rule;
@@ -89,12 +91,13 @@ class ConfigCatalogRule extends Rule {
      *   the element name otherwise
      * @param attributes The attribute list of this element
      */
+    @Override
     public void begin(String namespace, String name, Attributes attributes)
         throws Exception {
 
         // Retrieve any current Catalog with the specified name
-        Catalog catalog = null;
-        CatalogFactory factory = CatalogFactory.getInstance();
+        Catalog<Object, Object, Map<Object, Object>> catalog = null;
+        CatalogFactory<Object, Object, Map<Object, Object>> factory = CatalogFactory.getInstance();
         String nameValue = attributes.getValue(nameAttribute);
         if (nameValue == null) {
             catalog = factory.getCatalog();
@@ -105,8 +108,16 @@ class ConfigCatalogRule extends Rule {
         // Create and register a new Catalog instance if necessary
         if (catalog == null) {
             Class<?> clazz = digester.getClassLoader().loadClass(catalogClass);
-            catalog = (Catalog) clazz.newInstance();
+
+            /* Convert catalog pulled from digester to default generic signature
+             * with the assumption that the Catalog returned from digester will
+             * comply with the the historic chain contract. */
+            Catalog<Object, Object, Map<Object, Object>> digesterCatalog = (Catalog<Object, Object, Map<Object, Object>>) clazz.newInstance();
+
+            catalog = digesterCatalog;
+
             if (nameValue == null) {
+
                 factory.setCatalog(catalog);
             } else {
                 factory.addCatalog(nameValue, catalog);
@@ -115,8 +126,6 @@ class ConfigCatalogRule extends Rule {
 
         // Push this Catalog onto the top of the stack
         digester.push(catalog);
-
     }
 
-
 }

Modified: commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/config/ConfigParser.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/config/ConfigParser.java?rev=1243699&r1=1243698&r2=1243699&view=diff
==============================================================================
--- commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/config/ConfigParser.java (original)
+++ commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/config/ConfigParser.java Mon Feb 13 21:19:07 2012
@@ -19,6 +19,7 @@ package org.apache.commons.chain.config;
 
 import java.net.URL;
 import org.apache.commons.chain.Catalog;
+import org.apache.commons.chain.Context;
 import org.apache.commons.digester.Digester;
 import org.apache.commons.digester.RuleSet;
 
@@ -157,7 +158,7 @@ public class ConfigParser {
      *  element(s) embedded
      */
     @Deprecated
-    public void parse(Catalog catalog, URL url) throws Exception {
+    public <K, V, C extends Context<K, V>> void parse(Catalog<K, V, C> catalog, URL url) throws Exception {
 
         // Prepare our Digester instance
         Digester digester = getDigester();

Modified: commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/config/ConfigRegisterRule.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/config/ConfigRegisterRule.java?rev=1243699&r1=1243698&r2=1243699&view=diff
==============================================================================
--- commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/config/ConfigRegisterRule.java (original)
+++ commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/config/ConfigRegisterRule.java Mon Feb 13 21:19:07 2012
@@ -17,6 +17,8 @@
 package org.apache.commons.chain.config;
 
 
+import java.util.Map;
+
 import org.apache.commons.chain.Catalog;
 import org.apache.commons.chain.Chain;
 import org.apache.commons.chain.Command;
@@ -88,12 +90,12 @@ class ConfigRegisterRule extends Rule {
             || !(top instanceof Command)) {
             return;
         }
-        
+
         /* All commands can consume a generic context. Here we depend on
          * the configuration being correct because the rule binding is
          * dynamic. */
-        @SuppressWarnings("unchecked")
-        Command<Context> command = (Command<Context>) top;
+        Command<Object, Object, Map<Object, Object>> command =
+                (Command<Object, Object, Map<Object, Object>>) top;
 
         // Is the next object a Catalog or a Chain?
         Object next = digester.peek(1);
@@ -105,17 +107,18 @@ class ConfigRegisterRule extends Rule {
         if (next instanceof Catalog) {
             String nameValue = attributes.getValue(nameAttribute);
             if (nameValue != null) {
-                Catalog catalog = (Catalog) next;
+                /* We are dynamically building a catalog and assigning
+                 * generics to the most base types possible. */
+                Catalog<Object, Object, Map<Object, Object>> catalog =
+                        (Catalog<Object, Object, Map<Object, Object>>) next;
                 catalog.addCommand(nameValue, command);
             }
         } else if (next instanceof Chain) {
             /* Like above - the chain is being dynamically generated,
              * so we can add a generic context signature at compile-time. */
-            @SuppressWarnings("unchecked")
-            Chain<Context> chain = (Chain<Context>) next;
+            Chain<Object, Object, Map<Object, Object>> chain = (Chain<Object, Object, Map<Object, Object>>) next;
             chain.addCommand(command);
         }
-
     }
 
 

Modified: commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/generic/CopyCommand.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/generic/CopyCommand.java?rev=1243699&r1=1243698&r2=1243699&view=diff
==============================================================================
--- commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/generic/CopyCommand.java (original)
+++ commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/generic/CopyCommand.java Mon Feb 13 21:19:07 2012
@@ -17,6 +17,8 @@
 package org.apache.commons.chain.generic;
 
 
+import java.util.Map;
+
 import org.apache.commons.chain.Command;
 import org.apache.commons.chain.Context;
 
@@ -25,26 +27,28 @@ import org.apache.commons.chain.Context;
  * <p>Copy a specified literal value, or a context attribute stored under
  * the <code>fromKey</code> (if any), to the <code>toKey</code>.</p>
  *
+ * @param <K> the type of keys maintained by the context associated with this command
+ * @param <V> the type of mapped values
  * @param <C> Type of the context associated with this command
  *
  * @author Craig R. McClanahan
  * @version $Revision$ $Date$
  */
 
-public class CopyCommand<C extends Context> implements Command<C> {
+public class CopyCommand<K, V, C extends Map<K, V>> implements Command<K, V, C> {
 
 
     // -------------------------------------------------------------- Properties
 
 
-    private String fromKey = null;
+    private K fromKey = null;
 
 
     /**
      * <p>Return the context attribute key for the source attribute.</p>
      * @return The source attribute key.
      */
-    public String getFromKey() {
+    public K getFromKey() {
 
     return (this.fromKey);
 
@@ -56,21 +60,21 @@ public class CopyCommand<C extends Conte
      *
      * @param fromKey The new key
      */
-    public void setFromKey(String fromKey) {
+    public void setFromKey(K fromKey) {
 
     this.fromKey = fromKey;
 
     }
 
 
-    private String toKey = null;
+    private K toKey = null;
 
 
     /**
      * <p>Return the context attribute key for the destination attribute.</p>
      * @return The destination attribute key.
      */
-    public String getToKey() {
+    public K getToKey() {
 
     return (this.toKey);
 
@@ -82,21 +86,21 @@ public class CopyCommand<C extends Conte
      *
      * @param toKey The new key
      */
-    public void setToKey(String toKey) {
+    public void setToKey(K toKey) {
 
     this.toKey = toKey;
 
     }
 
 
-    private String value = null;
+    private V value = null;
 
 
     /**
      * <p>Return the literal value to be copied.</p>
      * @return The literal value.
      */
-    public String getValue() {
+    public V getValue() {
 
         return (this.value);
 
@@ -108,7 +112,7 @@ public class CopyCommand<C extends Conte
      *
      * @param value The new value
      */
-    public void setValue(String value) {
+    public void setValue(V value) {
 
         this.value = value;
 
@@ -129,7 +133,7 @@ public class CopyCommand<C extends Conte
      */
     public boolean execute(C context) throws Exception {
 
-        Object value = this.value;
+        V value = this.value;
 
         if (value == null) {
             value = context.get(getFromKey());

Modified: commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/generic/DispatchCommand.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/generic/DispatchCommand.java?rev=1243699&r1=1243698&r2=1243699&view=diff
==============================================================================
--- commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/generic/DispatchCommand.java (original)
+++ commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/generic/DispatchCommand.java Mon Feb 13 21:19:07 2012
@@ -29,11 +29,13 @@ import java.util.WeakHashMap;
  * For use by developers who prefer to group related functionality into a single class
  * rather than an inheritance family.
  *
+ * @param <K> the type of keys maintained by the context associated with this command
+ * @param <V> the type of mapped values
  * @param <C> Type of the context associated with this command
  *
  * @since Chain 1.1
  */
-public abstract class DispatchCommand<C extends Context> implements Command<C> {
+public abstract class DispatchCommand<K, V, C extends Context<K, V>> implements Command<K, V, C> {
 
     /** Cache of methods */
     private final Map<String, Method> methods = new WeakHashMap<String, Method>();

Modified: commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/generic/DispatchLookupCommand.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/generic/DispatchLookupCommand.java?rev=1243699&r1=1243698&r2=1243699&view=diff
==============================================================================
--- commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/generic/DispatchLookupCommand.java (original)
+++ commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/generic/DispatchLookupCommand.java Mon Feb 13 21:19:07 2012
@@ -47,6 +47,8 @@ import java.util.WeakHashMap;
  * silently ignored.  Otherwise, a lookup failure will trigger an
  * <code>IllegalArgumentException</code>.</p>
  *
+ * @param <K> the type of keys maintained by the context associated with this catalog
+ * @param <V> the type of mapped values
  * @param <C> Type of the context associated with this command
  *
  * @author Sean Schofield
@@ -54,7 +56,8 @@ import java.util.WeakHashMap;
  * @since Chain 1.1
  */
 
-public class DispatchLookupCommand<C extends Context> extends LookupCommand<C> implements Filter<C> {
+public class DispatchLookupCommand<K, V, C extends Context<K, V>>
+    extends LookupCommand<K, V, C> implements Filter<K, V, C> {
 
     // -------------------------------------------------------------- Constructors
 
@@ -70,7 +73,7 @@ public class DispatchLookupCommand<C ext
      * to given <code>factory</code>.
      * @param factory The Catalog Factory.
      */
-    public DispatchLookupCommand(CatalogFactory factory) {
+    public DispatchLookupCommand(CatalogFactory<K, V, C> factory) {
         super(factory);
     }
 
@@ -139,6 +142,7 @@ public class DispatchLookupCommand<C ext
      * @throws Exception if no such {@link Command} can be found and the
      *  <code>optional</code> property is set to <code>false</code>
      */
+	@Override
     public boolean execute(C context) throws Exception {
 
         if (this.getMethod() == null && this.getMethodKey() == null) {
@@ -147,7 +151,7 @@ public class DispatchLookupCommand<C ext
             );
         }
 
-        Command<C> command = getCommand(context);
+        Command<K, V, C> command = getCommand(context);
 
         if (command != null) {
             Method methodObject = extractMethod(command, context);
@@ -210,7 +214,7 @@ public class DispatchLookupCommand<C ext
      *    specified name.
      * @throws NullPointerException if no methodName can be determined
      */
-    private Method extractMethod(Command<C> command, C context)
+    private Method extractMethod(Command<K, V, C> command, C context)
         throws NoSuchMethodException {
 
         String methodName = this.getMethod();

Modified: commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/generic/LookupCommand.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/generic/LookupCommand.java?rev=1243699&r1=1243698&r2=1243699&view=diff
==============================================================================
--- commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/generic/LookupCommand.java (original)
+++ commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/generic/LookupCommand.java Mon Feb 13 21:19:07 2012
@@ -17,6 +17,8 @@
 package org.apache.commons.chain.generic;
 
 
+import java.util.Map;
+
 import org.apache.commons.chain.Catalog;
 import org.apache.commons.chain.CatalogFactory;
 import org.apache.commons.chain.Command;
@@ -46,7 +48,7 @@ import org.apache.commons.chain.Filter;
  * @version $Revision$ $Date$
  */
 
-public class LookupCommand<C extends Context> implements Filter<C> {
+public class LookupCommand<K, V, C extends Map<K, V>> implements Filter<K, V, C> {
 
 
     // -------------------------------------------------------------- Constructors
@@ -58,7 +60,7 @@ public class LookupCommand<C extends Con
      * @since Chain 1.1
      */
     public LookupCommand() {
-        this(CatalogFactory.getInstance());
+        this(CatalogFactory.<K, V, C>getInstance());
     }
 
     /**
@@ -69,14 +71,14 @@ public class LookupCommand<C extends Con
      *
      * @since Chain 1.1
      */
-    public LookupCommand(CatalogFactory factory) {
+    public LookupCommand(CatalogFactory<K, V, C> factory) {
         this.catalogFactory = factory;
     }
 
 
     // -------------------------------------------------------------- Properties
 
-    private CatalogFactory catalogFactory = null;
+    private CatalogFactory<K, V, C> catalogFactory = null;
 
     /**
      * <p>Set the {@link CatalogFactory} from which lookups will be
@@ -86,7 +88,7 @@ public class LookupCommand<C extends Con
      *
      * @since Chain 1.1
      */
-    public void setCatalogFactory(CatalogFactory catalogFactory) {
+    public void setCatalogFactory(CatalogFactory<K, V, C> catalogFactory) {
         this.catalogFactory = catalogFactory;
     }
 
@@ -96,7 +98,7 @@ public class LookupCommand<C extends Con
      *
      * @since Chain 1.1
      */
-    public CatalogFactory getCatalogFactory() {
+    public CatalogFactory<K, V, C> getCatalogFactory() {
 
         return this.catalogFactory;
     }
@@ -302,7 +304,7 @@ public class LookupCommand<C extends Con
      */
     public boolean execute(C context) throws Exception {
 
-        Command<C> command = getCommand(context);
+        Command<K, V, C> command = getCommand(context);
         if (command != null) {
             boolean result = (command.execute(context));
             if (isIgnoreExecuteResult()) {
@@ -331,10 +333,10 @@ public class LookupCommand<C extends Con
      */
     public boolean postprocess(C context, Exception exception) {
 
-        Command<C> command = getCommand(context);
+        Command<K, V, C> command = getCommand(context);
         if (command != null) {
             if (command instanceof Filter) {
-                boolean result = (((Filter<C>) command).postprocess(context, exception));
+                boolean result = (((Filter<K, V, C>) command).postprocess(context, exception));
                 if (isIgnorePostprocessResult()) {
                     return false;
                 }
@@ -359,14 +361,14 @@ public class LookupCommand<C extends Con
      *
      * @since Chain 1.2
      */
-    protected Catalog getCatalog(C context) {
-        CatalogFactory lookupFactory = this.catalogFactory;
+    protected Catalog<K, V, C> getCatalog(C context) {
+        CatalogFactory<K, V, C> lookupFactory = this.catalogFactory;
         if (lookupFactory == null) {
             lookupFactory = CatalogFactory.getInstance();
         }
 
         String catalogName = getCatalogName();
-        Catalog catalog = null;
+        Catalog<K, V, C> catalog = null;
         if (catalogName == null) {
             // use default catalog
             catalog = lookupFactory.getCatalog();
@@ -396,11 +398,11 @@ public class LookupCommand<C extends Con
      *  can be found and the <code>optional</code> property is set
      *  to <code>false</code>
      */
-    protected Command<C> getCommand(C context) {
+    protected Command<K, V, C> getCommand(C context) {
 
-        Catalog catalog = getCatalog(context);
+        Catalog<K, V, C> catalog = getCatalog(context);
 
-        Command<C> command = null;
+        Command<K, V, C> command = null;
         String name = getCommandName(context);
         if (name != null) {
             command = catalog.getCommand(name);

Modified: commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/generic/RemoveCommand.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/generic/RemoveCommand.java?rev=1243699&r1=1243698&r2=1243699&view=diff
==============================================================================
--- commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/generic/RemoveCommand.java (original)
+++ commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/generic/RemoveCommand.java Mon Feb 13 21:19:07 2012
@@ -24,26 +24,28 @@ import org.apache.commons.chain.Context;
 /**
  * <p>Remove any context attribute stored under the <code>fromKey</code>.</p>
  *
+ * @param <K> the type of keys maintained by the context associated with this catalog
+ * @param <V> the type of mapped values
  * @param <C> Type of the context associated with this command
  *
  * @author Craig R. McClanahan
  * @version $Revision$ $Date$
  */
 
-public class RemoveCommand<C extends Context> implements Command<C> {
+public class RemoveCommand<K, V, C extends Context<K, V>> implements Command<K, V, C> {
 
 
     // -------------------------------------------------------------- Properties
 
 
-    private String fromKey = null;
+    private K fromKey = null;
 
 
     /**
      * <p>Return the context attribute key for the attribute.</p>
      * @return The context attribute key.
      */
-    public String getFromKey() {
+    public K getFromKey() {
 
     return (this.fromKey);
 
@@ -55,7 +57,7 @@ public class RemoveCommand<C extends Con
      *
      * @param fromKey The new key
      */
-    public void setFromKey(String fromKey) {
+    public void setFromKey(K fromKey) {
 
     this.fromKey = fromKey;
 

Modified: commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/impl/CatalogBase.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/impl/CatalogBase.java?rev=1243699&r1=1243698&r2=1243699&view=diff
==============================================================================
--- commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/impl/CatalogBase.java (original)
+++ commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/impl/CatalogBase.java Mon Feb 13 21:19:07 2012
@@ -21,9 +21,9 @@ import static java.util.Collections.unmo
 import java.util.Iterator;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
+
 import org.apache.commons.chain.Catalog;
 import org.apache.commons.chain.Command;
-import org.apache.commons.chain.Context;
 
 
 /**
@@ -32,12 +32,16 @@ import org.apache.commons.chain.Context;
  *
  * <p>This implementation is thread-safe.</p>
  *
+ * @param <K> the type of keys maintained by the context associated with this catalog
+ * @param <V> the type of mapped values
+ * @param <C> Type of the context associated with this catalog
+ *
  * @author Craig R. McClanahan
  * @author Matthew J. Sgarlata
  * @version $Revision$ $Date$
  */
 
-public class CatalogBase implements Catalog {
+public class CatalogBase<K, V, C extends Map<K, V>> implements Catalog<K, V, C> {
 
 
     // ----------------------------------------------------- Instance Variables
@@ -46,7 +50,8 @@ public class CatalogBase implements Cata
     /**
      * <p>The map of named {@link Command}s, keyed by name.
      */
-    private final Map<String, Command<? extends Context>> commands = new ConcurrentHashMap<String, Command<? extends Context>>();
+    private final Map<String, Command<K, V, C>> commands =
+            new ConcurrentHashMap<String, Command<K, V, C>>();
 
 
     // --------------------------------------------------------- Constructors
@@ -64,7 +69,7 @@ public class CatalogBase implements Cata
      *
      * @since Chain 1.1
      */
-    public CatalogBase( Map<String, Command<? extends Context>> commands ) {
+    public CatalogBase(Map<String, Command<K, V, C>> commands ) {
         this.commands.putAll( commands );
     }
 
@@ -76,12 +81,11 @@ public class CatalogBase implements Cata
      * to the set of named commands known to this {@link Catalog},
      * replacing any previous command for that name.
      *
-     * @param <C> Type of the context associated with this command
      * @param name Name of the new command
      * @param command {@link Command} to be returned
      *  for later lookups on this name
      */
-    public <C extends Context> void addCommand(String name, Command<C> command) {
+    public void addCommand(String name, Command<K, V, C> command) {
 
         commands.put(name, command);
 
@@ -91,15 +95,13 @@ public class CatalogBase implements Cata
      * <p>Return the {@link Command} associated with the
      * specified name, if any; otherwise, return <code>null</code>.</p>
      *
-     * @param <C> Type of the context associated with this command
      * @param name Name for which a {@link Command}
      *  should be retrieved
      * @return The Command associated with the specified name.
      */
-    public Command<? extends Context> getCommand(String name) {
+    public Command<K, V, C> getCommand(String name) {
 
-        Command<? extends Context> command = commands.get(name);
-        return command;
+        return commands.get(name);
 
     }
 
@@ -109,7 +111,7 @@ public class CatalogBase implements Cata
      * @return The map of named {@link Command}s, keyed by name.
      * @since 2.0
      */
-    public Map<String, Command<? extends Context>> getCommands() {
+    public Map<String, Command<K, V, C>> getCommands() {
         return unmodifiableMap(commands);
     }
 

Modified: commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/impl/CatalogFactoryBase.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/impl/CatalogFactoryBase.java?rev=1243699&r1=1243698&r2=1243699&view=diff
==============================================================================
--- commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/impl/CatalogFactoryBase.java (original)
+++ commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/impl/CatalogFactoryBase.java Mon Feb 13 21:19:07 2012
@@ -20,6 +20,7 @@ package org.apache.commons.chain.impl;
 import java.util.Iterator;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
+
 import org.apache.commons.chain.Catalog;
 import org.apache.commons.chain.CatalogFactory;
 
@@ -30,7 +31,7 @@ import org.apache.commons.chain.CatalogF
  * @version $Revision$ $Date$
  */
 
-public class CatalogFactoryBase extends CatalogFactory {
+public class CatalogFactoryBase<K, V, C extends Map<K, V>> extends CatalogFactory<K, V, C> {
 
 
     // ----------------------------------------------------------- Constructors
@@ -49,14 +50,14 @@ public class CatalogFactoryBase extends 
     /**
      * <p>The default {@link Catalog} for this {@link CatalogFactory}.</p>
      */
-    private Catalog catalog = null;
+    private Catalog<K, V, C> catalog = null;
 
 
     /**
      * <p>Map of named {@link Catalog}s, keyed by catalog name.</p>
      */
-    private final Map<String, Catalog> catalogs =
-            new ConcurrentHashMap<String, Catalog>();
+    private final Map<String, Catalog<K, V, C>> catalogs =
+            new ConcurrentHashMap<String, Catalog<K, V, C>>();
 
 
     // --------------------------------------------------------- Public Methods
@@ -68,7 +69,7 @@ public class CatalogFactoryBase extends 
      *
      * @return the default Catalog instance
      */
-    public Catalog getCatalog() {
+    public Catalog<K, V, C> getCatalog() {
 
         return catalog;
 
@@ -80,7 +81,7 @@ public class CatalogFactoryBase extends 
      *
      * @param catalog the default Catalog instance
      */
-    public void setCatalog(Catalog catalog) {
+    public void setCatalog(Catalog<K, V, C> catalog) {
 
         this.catalog = catalog;
 
@@ -94,7 +95,8 @@ public class CatalogFactoryBase extends 
      * @param name the name of the Catalog to retrieve
      * @return the specified Catalog
      */
-    public Catalog getCatalog(String name) {
+	@Override
+    public Catalog<K, V, C> getCatalog(String name) {
 
         return catalogs.get(name);
 
@@ -108,7 +110,7 @@ public class CatalogFactoryBase extends 
      * @param name the name of the Catalog to add
      * @param catalog the Catalog to add
      */
-    public void addCatalog(String name, Catalog catalog) {
+    public void addCatalog(String name, Catalog<K, V, C> catalog) {
 
             catalogs.put(name, catalog);
 

Modified: commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/impl/ChainBase.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/impl/ChainBase.java?rev=1243699&r1=1243698&r2=1243699&view=diff
==============================================================================
--- commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/impl/ChainBase.java (original)
+++ commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/impl/ChainBase.java Mon Feb 13 21:19:07 2012
@@ -20,6 +20,7 @@ package org.apache.commons.chain.impl;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.commons.chain.Chain;
 import org.apache.commons.chain.Command;
@@ -30,13 +31,15 @@ import org.apache.commons.chain.Filter;
 /**
  * <p>Convenience base class for {@link Chain} implementations.</p>
  *
- * @param <C> Type of the context associated with this command
+ * @param <K> the type of keys maintained by the context associated with this chain
+ * @param <V> the type of mapped values
+ * @param <C> Type of the context associated with this chain
  *
  * @author Craig R. McClanahan
  * @version $Revision$ $Date$
  */
 
-public class ChainBase<C extends Context> implements Chain<C> {
+public class ChainBase<K, V, C extends Map<K, V>> implements Chain<K, V, C> {
 
 
     // ----------------------------------------------------------- Constructors
@@ -59,7 +62,7 @@ public class ChainBase<C extends Context
      * @exception IllegalArgumentException if <code>command</code>
      *  is <code>null</code>
      */
-    public ChainBase(Command<C> command) {
+    public ChainBase(Command<K, V, C> command) {
 
         addCommand(command);
 
@@ -76,7 +79,7 @@ public class ChainBase<C extends Context
      *  or one of the individual {@link Command} elements,
      *  is <code>null</code>
      */
-    public ChainBase(Command<C>[] commands) {
+    public ChainBase(Command<K, V, C>[] commands) {
 
         if (commands == null) {
             throw new IllegalArgumentException();
@@ -98,7 +101,7 @@ public class ChainBase<C extends Context
      *  or one of the individual {@link Command} elements,
      *  is <code>null</code>
      */
-    public ChainBase(Collection<Command<C>> commands) {
+    public ChainBase(Collection<Command<K, V, C>> commands) {
 
         if (commands == null) {
             throw new IllegalArgumentException();
@@ -116,7 +119,7 @@ public class ChainBase<C extends Context
      * the order in which they may delegate processing to the remainder of
      * the {@link Chain}.</p>
      */
-    private final List<Command<C>> commands = new ArrayList<Command<C>>();
+    private final List<Command<K, V, C>> commands = new ArrayList<Command<K, V, C>>();
 
 
     /**
@@ -138,7 +141,7 @@ public class ChainBase<C extends Context
      *  is <code>null</code>
      * @exception IllegalStateException if no further configuration is allowed
      */
-    public void addCommand(Command<C> command) {
+    public void addCommand(Command<K, V, C> command) {
 
         if (command == null) {
             throw new IllegalArgumentException();
@@ -206,7 +209,7 @@ public class ChainBase<C extends Context
             if (commands.get(j) instanceof Filter) {
                 try {
                     result =
-                        ((Filter<C>) commands.get(j)).postprocess(context,
+                        ((Filter<K, V, C>) commands.get(j)).postprocess(context,
                                                            saveException);
                     if (result) {
                         handled = true;
@@ -248,7 +251,7 @@ public class ChainBase<C extends Context
      * {@link Chain}.  This method is package private, and is used only
      * for the unit tests.</p>
      */
-    List<Command<C>> getCommands() {
+    List<Command<K, V, C>> getCommands() {
 
         return (commands);
 

Modified: commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/impl/ContextBase.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/impl/ContextBase.java?rev=1243699&r1=1243698&r2=1243699&view=diff
==============================================================================
--- commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/impl/ContextBase.java (original)
+++ commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/impl/ContextBase.java Mon Feb 13 21:19:07 2012
@@ -29,7 +29,6 @@ import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
 
 import org.apache.commons.chain.Context;
 
@@ -52,15 +51,14 @@ import org.apache.commons.chain.Context;
  * @version $Revision$ $Date$
  */
 
-public class ContextBase extends ConcurrentHashMap<String, Object> 
-        implements Context {
+public class ContextBase extends ContextMap<String, Object> {
 
 
     // ------------------------------------------------------------ Constructors
 
 
     /**
-     * 
+     *
      */
     private static final long serialVersionUID = -3137668177106072122L;
 
@@ -127,7 +125,7 @@ public class ContextBase extends Concurr
      * key that is actually a property.  This value is used to ensure that
      * <code>equals()</code> comparisons will always fail.</p>
      */
-    private static Object singleton;
+    private static final Object singleton;
 
     static {
 
@@ -328,7 +326,7 @@ public class ContextBase extends Concurr
     public Object put(String key, Object value) {
         /*
          * ConcurrentHashMap doesn't accept null values, see
-         * http://download.oracle.com/javase/1.5.0/docs/api/java/util/concurrent/ConcurrentHashMap.html#put(K, V)
+         * http://download.oracle.com/javase/1.5.0/docs/api/java/util/concurrent/ConcurrentHashMap.html#put(String, Object)
          */
         if (value == null) {
             if (containsKey(key)) {
@@ -363,20 +361,6 @@ public class ContextBase extends Concurr
 
 
     /**
-     * {@inheritDoc}
-     */
-    public <T> T retrieve(String key) {
-        Object valueObject = get(key);
-        if (valueObject == null) {
-            return null;
-        }
-        @SuppressWarnings("unchecked") // will throw ClassCastException if type are not assignable
-        T value = (T) valueObject;
-        return value;
-    }
-
-
-    /**
      * <p>Override the default <code>Map</code> behavior to call the
      * <code>put()</code> method individually for each key-value pair
      * in the specified <code>Map</code>.</p>
@@ -536,7 +520,7 @@ public class ContextBase extends Concurr
                     ("Property '" + descriptor.getName()
                      + "' is not readable");
             }
-            return (method.invoke(this, zeroParams));
+            return method.invoke(this, zeroParams);
         } catch (Exception e) {
             throw new UnsupportedOperationException
                 ("Exception reading property '" + descriptor.getName()
@@ -623,24 +607,23 @@ public class ContextBase extends Concurr
      */
     private class EntrySetImpl extends AbstractSet<Entry<String, Object>> {
 
-            @Override
-            public void clear() {
+        @Override
+        public void clear() {
             ContextBase.this.clear();
         }
 
-            @Override
-            public boolean contains(Object obj) {
-            if (!(obj instanceof Map.Entry && 
-                    ((Map.Entry)obj).getKey() instanceof String)) {
+        @Override
+        public boolean contains(Object obj) {
+            if (!(obj instanceof Map.Entry)) {
                 return (false);
             }
-            
+
             /* The contains method is expecting the search type to be of the
              * same type stored. This contract is enforced as a precondition.
              * So we can safely suppress type safety warnings below. */
             @SuppressWarnings("unchecked")
             Map.Entry<String, Object> entry = (Map.Entry<String, Object>) obj;
-            Entry actual = ContextBase.this.entry(entry.getKey());
+            Entry<String, Object> actual = ContextBase.this.entry(entry.getKey());
             if (actual != null) {
                 return (actual.equals(entry));
             } else {
@@ -648,20 +631,19 @@ public class ContextBase extends Concurr
             }
         }
 
-            @Override
-            public boolean isEmpty() {
+        @Override
+        public boolean isEmpty() {
             return (ContextBase.this.isEmpty());
         }
 
-            public Iterator<Entry<String, Object>> iterator() {
+        public Iterator<Entry<String, Object>> iterator() {
             return (ContextBase.this.entriesIterator());
         }
 
-            @Override
-            public boolean remove(Object obj) {
-            if (obj instanceof Map.Entry && 
-                    ((Map.Entry)obj).getKey() instanceof String ) {
-                
+        @Override
+        public boolean remove(Object obj) {
+            if (obj instanceof Map.Entry) {
+
                 /* The remove method is expecting an input of the the same
                  * type as the entry set. This precondition is checked above,
                  * so we can safely suppress the unchecked warnings. */
@@ -673,7 +655,7 @@ public class ContextBase extends Concurr
             }
         }
 
-            public int size() {
+        public int size() {
             return (ContextBase.this.size());
         }
 
@@ -719,14 +701,14 @@ public class ContextBase extends Concurr
         private String key;
         private Object value;
 
-            @Override
-            public boolean equals(Object obj) {
+        @Override
+        public boolean equals(Object obj) {
             if (obj == null) {
                 return (false);
             } else if (!(obj instanceof Map.Entry)) {
                 return (false);
             }
-            Map.Entry entry = (Map.Entry) obj;
+            Map.Entry<?, ?> entry = (Map.Entry<?, ?>) obj;
             if (key == null) {
                 return (entry.getKey() == null);
             }
@@ -762,8 +744,8 @@ public class ContextBase extends Concurr
             return (previous);
         }
 
-            @Override
-            public String toString() {
+        @Override
+        public String toString() {
             return getKey() + "=" + getValue();
         }
     }
@@ -775,13 +757,13 @@ public class ContextBase extends Concurr
      */
     private class ValuesImpl extends AbstractCollection<Object> {
 
-            @Override
-            public void clear() {
+        @Override
+        public void clear() {
             ContextBase.this.clear();
         }
 
-            @Override
-            public boolean contains(Object obj) {
+        @Override
+        public boolean contains(Object obj) {
             if (!(obj instanceof Map.Entry)) {
                 return (false);
             }
@@ -789,32 +771,31 @@ public class ContextBase extends Concurr
             return (ContextBase.this.containsValue(entry.getValue()));
         }
 
-            @Override
-            public boolean isEmpty() {
+        @Override
+        public boolean isEmpty() {
             return (ContextBase.this.isEmpty());
         }
 
-            public Iterator<Object> iterator() {
+        public Iterator<Object> iterator() {
             return (ContextBase.this.valuesIterator());
         }
 
-            @Override
-            public boolean remove(Object obj) {
-            if (obj instanceof Map.Entry && 
-                    ((Map.Entry)obj).getKey() instanceof String) {
-                
+        @Override
+        public boolean remove(Object obj) {
+            if (obj instanceof Map.Entry) {
+
                 /* We are expecting the passed entry to be of a type
                  * Entry<String, Object>. This is checked in the precondition
                  * above, so we can safely suppress unchecked warnings. */
                 @SuppressWarnings("unchecked")
-                Map.Entry<String, Object> entry = (Map.Entry) obj;
+                Map.Entry<String, Object> entry = (Map.Entry<String, Object>) obj;
                 return (ContextBase.this.remove(entry));
             } else {
                 return (false);
             }
         }
 
-            public int size() {
+        public int size() {
             return (ContextBase.this.size());
         }
 

Added: commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/impl/ContextMap.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/impl/ContextMap.java?rev=1243699&view=auto
==============================================================================
--- commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/impl/ContextMap.java (added)
+++ commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/impl/ContextMap.java Mon Feb 13 21:19:07 2012
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.chain.impl;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.commons.chain.Context;
+
+/**
+ * Convenience base class for {@link Context} implementations.
+ *
+ * @param <K> the type of keys maintained by the context associated with this context
+ * @param <V> the type of mapped values
+ *
+ * @since 2.0
+ */
+public class ContextMap<K, V> extends ConcurrentHashMap<K, V> implements Context<K, V> {
+
+    /**
+     *
+     */
+    private static final long serialVersionUID = 6980950395387220980L;
+
+    /**
+     * Creates a new, empty Context with a default initial capacity, load factor, and concurrencyLevel.
+     */
+    public ContextMap() {
+        super();
+    }
+
+    /**
+     * Creates a new, empty Context with the specified initial capacity, and with default load factor and concurrencyLevel
+     *
+     * @param initialCapacity the initial capacity.
+     */
+    public ContextMap(int initialCapacity) {
+        super(initialCapacity);
+    }
+
+    /**
+     * Creates a new, empty Context with the specified initial capacity, load factor, and concurrency level.
+     *
+     * @param initialCapacity the initial capacity.
+     * @param loadFactor the load factor threshold, used to control resizing.
+     * @param concurrencyLevel the estimated number of concurrently updating threads.
+     */
+    public ContextMap(int initialCapacity, float loadFactor, int concurrencyLevel) {
+        super(initialCapacity, loadFactor, concurrencyLevel);
+    }
+
+    /**
+     * Creates a new Context with the same mappings as the given map.
+     *
+     * @param t Map whose key-value pairs are added
+     */
+    public ContextMap(Map<? extends K, ? extends V> t) {
+        super(t);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public <T extends V> T retrieve(K key) {
+        V valueObject = get(key);
+        if (valueObject == null) {
+            return null;
+        }
+        // will throw ClassCastException if type are not assignable anyway
+        @SuppressWarnings("unchecked")
+        T value = (T) valueObject;
+        return value;
+    }
+
+}

Propchange: commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/impl/ContextMap.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/impl/ContextMap.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/impl/ContextMap.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/AbstractGetLocaleCommand.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/AbstractGetLocaleCommand.java?rev=1243699&r1=1243698&r2=1243699&view=diff
==============================================================================
--- commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/AbstractGetLocaleCommand.java (original)
+++ commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/AbstractGetLocaleCommand.java Mon Feb 13 21:19:07 2012
@@ -33,7 +33,8 @@ import org.apache.commons.chain.Context;
  * @version $Revision$ $Date$
  */
 
-public abstract class AbstractGetLocaleCommand<C extends Context> implements Command<C> {
+public abstract class AbstractGetLocaleCommand<C extends WebContext>
+        implements Command<String, Object, C> {
 
 
     // -------------------------------------------------------------- Properties

Modified: commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/AbstractSetLocaleCommand.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/AbstractSetLocaleCommand.java?rev=1243699&r1=1243698&r2=1243699&view=diff
==============================================================================
--- commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/AbstractSetLocaleCommand.java (original)
+++ commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/AbstractSetLocaleCommand.java Mon Feb 13 21:19:07 2012
@@ -34,7 +34,8 @@ import org.apache.commons.chain.Context;
  * @version $Revision$ $Date$
  */
 
-public abstract class AbstractSetLocaleCommand<C extends Context> implements Command<C> {
+public abstract class AbstractSetLocaleCommand<C extends WebContext>
+        implements Command<String, Object, C> {
 
 
     // -------------------------------------------------------------- Properties

Modified: commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/ChainListener.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/ChainListener.java?rev=1243699&r1=1243698&r2=1243699&view=diff
==============================================================================
--- commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/ChainListener.java (original)
+++ commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/ChainListener.java Mon Feb 13 21:19:07 2012
@@ -29,6 +29,7 @@ import org.apache.commons.chain.Catalog;
 import org.apache.commons.chain.CatalogFactory;
 import org.apache.commons.chain.config.ConfigParser;
 import org.apache.commons.chain.impl.CatalogBase;
+import org.apache.commons.chain.web.servlet.ServletWebContext;
 import org.apache.commons.digester.RuleSet;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -180,11 +181,11 @@ public class ChainListener implements Se
         String webResources = context.getInitParameter(CONFIG_WEB_RESOURCE);
 
         // Retrieve or create the Catalog instance we may be updating
-        Catalog catalog = null;
+        Catalog<String, Object, ServletWebContext> catalog = null;
         if (attr != null) {
-            catalog = (Catalog) context.getAttribute(attr);
+            catalog = (Catalog<String, Object, ServletWebContext>) context.getAttribute(attr);
             if (catalog == null) {
-                catalog = new CatalogBase();
+                catalog = new CatalogBase<String, Object, ServletWebContext>();
             }
         }
 

Modified: commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/ChainServlet.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/ChainServlet.java?rev=1243699&r1=1243698&r2=1243699&view=diff
==============================================================================
--- commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/ChainServlet.java (original)
+++ commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/ChainServlet.java Mon Feb 13 21:19:07 2012
@@ -28,6 +28,7 @@ import org.apache.commons.chain.Catalog;
 import org.apache.commons.chain.CatalogFactory;
 import org.apache.commons.chain.config.ConfigParser;
 import org.apache.commons.chain.impl.CatalogBase;
+import org.apache.commons.chain.web.servlet.ServletWebContext;
 import org.apache.commons.digester.RuleSet;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -100,7 +101,7 @@ public class ChainServlet extends HttpSe
 
 
     /**
-     * 
+     *
      */
     private static final long serialVersionUID = -6545081938506661333L;
 
@@ -182,11 +183,11 @@ public class ChainServlet extends HttpSe
         String webResources = context.getInitParameter(CONFIG_WEB_RESOURCE);
 
         // Retrieve or create the Catalog instance we may be updating
-        Catalog catalog = null;
+        Catalog<String, Object, ServletWebContext> catalog = null;
         if (attr != null) {
-            catalog = (Catalog) context.getAttribute(attr);
+            catalog = (Catalog<String, Object, ServletWebContext>) context.getAttribute(attr);
             if (catalog == null) {
-                catalog = new CatalogBase();
+                catalog = new CatalogBase<String, Object, ServletWebContext>();
             }
         }
 

Modified: commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/WebContext.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/WebContext.java?rev=1243699&r1=1243698&r2=1243699&view=diff
==============================================================================
--- commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/WebContext.java (original)
+++ commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/WebContext.java Mon Feb 13 21:19:07 2012
@@ -43,7 +43,7 @@ import org.apache.commons.chain.impl.Con
 public abstract class WebContext extends ContextBase {
 
     /**
-     * 
+     *
      */
     private static final long serialVersionUID = 6804961872140299027L;
 

Modified: commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/faces/FacesGetLocaleCommand.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/faces/FacesGetLocaleCommand.java?rev=1243699&r1=1243698&r2=1243699&view=diff
==============================================================================
--- commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/faces/FacesGetLocaleCommand.java (original)
+++ commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/faces/FacesGetLocaleCommand.java Mon Feb 13 21:19:07 2012
@@ -18,7 +18,9 @@ package org.apache.commons.chain.web.fac
 
 
 import java.util.Locale;
+
 import javax.faces.context.FacesContext;
+
 import org.apache.commons.chain.Context;
 import org.apache.commons.chain.web.AbstractGetLocaleCommand;
 
@@ -30,7 +32,8 @@ import org.apache.commons.chain.web.Abst
  * @param <C> Type of the context associated with this command
  */
 
-public class FacesGetLocaleCommand<C extends Context> extends AbstractGetLocaleCommand<C> {
+public class FacesGetLocaleCommand
+        extends AbstractGetLocaleCommand<FacesWebContext> {
 
 
     // ------------------------------------------------------- Protected Methods
@@ -42,7 +45,7 @@ public class FacesGetLocaleCommand<C ext
      * @param context The {@link Context} we are operating on.
      * @return The Locale for the request.
      */
-    protected Locale getLocale(C context) {
+    protected Locale getLocale(FacesWebContext context) {
 
     FacesContext fcontext = (FacesContext)
         context.get("context");

Modified: commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/faces/FacesSetLocaleCommand.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/faces/FacesSetLocaleCommand.java?rev=1243699&r1=1243698&r2=1243699&view=diff
==============================================================================
--- commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/faces/FacesSetLocaleCommand.java (original)
+++ commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/faces/FacesSetLocaleCommand.java Mon Feb 13 21:19:07 2012
@@ -30,7 +30,8 @@ import org.apache.commons.chain.web.Abst
  * @param <C> Type of the context associated with this command
  */
 
-public class FacesSetLocaleCommand<C extends Context> extends AbstractSetLocaleCommand<C> {
+public class FacesSetLocaleCommand
+        extends AbstractSetLocaleCommand<FacesWebContext> {
 
 
     // ------------------------------------------------------- Protected Methods
@@ -42,7 +43,7 @@ public class FacesSetLocaleCommand<C ext
      * @param context The {@link Context} we are operating on.
      * @param locale The Locale for the request.
      */
-    protected void setLocale(Context context, Locale locale) {
+    protected void setLocale(FacesWebContext context, Locale locale) {
 
     FacesContext fcontext = (FacesContext)
         context.get("context");

Modified: commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/faces/FacesWebContext.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/faces/FacesWebContext.java?rev=1243699&r1=1243698&r2=1243699&view=diff
==============================================================================
--- commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/faces/FacesWebContext.java (original)
+++ commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/faces/FacesWebContext.java Mon Feb 13 21:19:07 2012
@@ -42,7 +42,7 @@ public class FacesWebContext extends Web
 
 
     /**
-     * 
+     *
      */
     private static final long serialVersionUID = -1429681424077509130L;
 
@@ -129,11 +129,11 @@ public class FacesWebContext extends Web
      * @return Application scope Map.
      */
     public Map<String, Object> getApplicationScope() {
-        
+
         @SuppressWarnings("unchecked") // Assume faces is following contract
-        Map<String, Object> scope = (Map<String, Object>) 
+        Map<String, Object> scope = (Map<String, Object>)
                 context.getExternalContext().getApplicationMap();
-        
+
         return (scope);
 
     }
@@ -145,11 +145,11 @@ public class FacesWebContext extends Web
      * @return Header values Map.
      */
     public Map<String, String> getHeader() {
-        
+
         @SuppressWarnings("unchecked") // Assume faces is following contract
         Map<String, String> headers = (Map<String, String>)
                 context.getExternalContext().getRequestHeaderMap();
-        
+
         return (headers);
 
     }
@@ -161,11 +161,11 @@ public class FacesWebContext extends Web
      * @return Header values Map.
      */
     public Map<String, String[]> getHeaderValues() {
-        
+
         @SuppressWarnings("unchecked") // Assume faces is following contract
         Map<String, String[]> headerValues = (Map<String, String[]>)
-            context.getExternalContext().getRequestHeaderValuesMap();    
-        
+            context.getExternalContext().getRequestHeaderValuesMap();
+
         return (headerValues);
 
     }
@@ -177,11 +177,11 @@ public class FacesWebContext extends Web
      * @return Initialization parameter Map.
      */
     public Map<String, String> getInitParam() {
-        
+
         @SuppressWarnings("unchecked") // Assume faces is following contract
         Map<String, String> initParams = (Map<String, String>)
                 context.getExternalContext().getInitParameterMap();
-        
+
         return (initParams);
 
     }
@@ -195,8 +195,8 @@ public class FacesWebContext extends Web
     public Map<String, String> getParam() {
         @SuppressWarnings("unchecked")
         Map<String, String> params = (Map<String, String>)
-                context.getExternalContext().getRequestParameterMap();        
-        
+                context.getExternalContext().getRequestParameterMap();
+
         return (params);
 
     }
@@ -211,7 +211,7 @@ public class FacesWebContext extends Web
         @SuppressWarnings("unchecked") // Assume faces is following contract
         Map<String, String[]> paramValues = (Map<String, String[]>)
                 context.getExternalContext().getRequestParameterValuesMap();
-        
+
         return (paramValues);
 
     }
@@ -241,8 +241,8 @@ public class FacesWebContext extends Web
             if (cookieObj instanceof Cookie) {
                 // See comment above about type safety check
                 @SuppressWarnings("unchecked")
-                Map<String, Cookie> cookieMap = Collections.checkedMap(
-                        (Map)facesCookieMap, String.class, Cookie.class);
+                Map<String, Cookie> cookieMap = (Map<String, Cookie>) Collections.checkedMap(
+                        (Map) facesCookieMap, String.class, Cookie.class);
 
                 return cookieMap;
             } else {
@@ -262,11 +262,11 @@ public class FacesWebContext extends Web
      * @return Request scope Map.
      */
     public Map<String, Object> getRequestScope() {
-        
+
         @SuppressWarnings("unchecked")  // Assume faces is following contract
         Map<String, Object> scope = (Map<String, Object>)
                 context.getExternalContext().getRequestMap();
-        
+
         return (scope);
 
     }
@@ -278,11 +278,11 @@ public class FacesWebContext extends Web
      * @return Session scope Map.
      */
     public Map<String, Object> getSessionScope() {
-        
+
         @SuppressWarnings("unchecked")  // Assume faces is following contract
         Map<String, Object> scope = (Map<String, Object>)
                 context.getExternalContext().getSessionMap();
-        
+
         return (scope);
 
     }

Modified: commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/portlet/PortletGetLocaleCommand.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/portlet/PortletGetLocaleCommand.java?rev=1243699&r1=1243698&r2=1243699&view=diff
==============================================================================
--- commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/portlet/PortletGetLocaleCommand.java (original)
+++ commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/portlet/PortletGetLocaleCommand.java Mon Feb 13 21:19:07 2012
@@ -30,7 +30,8 @@ import org.apache.commons.chain.web.Abst
  * @param <C> Type of the context associated with this command
  */
 
-public class PortletGetLocaleCommand<C extends Context> extends AbstractGetLocaleCommand<C> {
+public class PortletGetLocaleCommand
+        extends AbstractGetLocaleCommand<PortletWebContext> {
 
 
     // ------------------------------------------------------- Protected Methods
@@ -42,7 +43,7 @@ public class PortletGetLocaleCommand<C e
      * @param context The {@link Context} we are operating on.
      * @return The Locale for the request.
      */
-    protected Locale getLocale(C context) {
+    protected Locale getLocale(PortletWebContext context) {
 
     PortletRequest request = (PortletRequest)
         context.get("request");

Modified: commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/portlet/PortletSetLocaleCommand.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/portlet/PortletSetLocaleCommand.java?rev=1243699&r1=1243698&r2=1243699&view=diff
==============================================================================
--- commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/portlet/PortletSetLocaleCommand.java (original)
+++ commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/portlet/PortletSetLocaleCommand.java Mon Feb 13 21:19:07 2012
@@ -31,7 +31,8 @@ import org.apache.commons.chain.web.Abst
  *
  */
 
-public class PortletSetLocaleCommand<C extends Context> extends AbstractSetLocaleCommand<C> {
+public class PortletSetLocaleCommand
+        extends AbstractSetLocaleCommand<PortletWebContext> {
 
 
     // ------------------------------------------------------- Protected Methods
@@ -43,7 +44,7 @@ public class PortletSetLocaleCommand<C e
      * @param context The {@link Context} we are operating on.
      * @param locale The Locale for the request.
      */
-    protected void setLocale(Context context, Locale locale) {
+    protected void setLocale(PortletWebContext context, Locale locale) {
 
     // PortletResponse response = (PortletResponse)
     //    context.get("response");

Modified: commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/servlet/ChainProcessor.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/servlet/ChainProcessor.java?rev=1243699&r1=1243698&r2=1243699&view=diff
==============================================================================
--- commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/servlet/ChainProcessor.java (original)
+++ commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/servlet/ChainProcessor.java Mon Feb 13 21:19:07 2012
@@ -18,9 +18,12 @@ package org.apache.commons.chain.web.ser
 
 
 import java.io.IOException;
+
+import javax.servlet.ServletContext;
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+
 import org.apache.commons.chain.Catalog;
 import org.apache.commons.chain.CatalogFactory;
 import org.apache.commons.chain.Command;
@@ -61,7 +64,7 @@ public class ChainProcessor extends Chai
 
 
     /**
-     * 
+     *
      */
     private static final long serialVersionUID = -6817532768031279260L;
 
@@ -131,6 +134,7 @@ public class ChainProcessor extends Chai
     /**
      * <p>Clean up as this application is shut down.</p>
      */
+    @Override
     public void destroy() {
 
         super.destroy();
@@ -146,6 +150,7 @@ public class ChainProcessor extends Chai
      *
      * @exception ServletException if an initialization error occurs
      */
+    @Override
     public void init() throws ServletException {
 
         super.init();
@@ -170,27 +175,47 @@ public class ChainProcessor extends Chai
      * @exception IOException if an input/output error occurs
      * @exception ServletException if a servlet exception occurs
      */
+    @Override
     public void service(HttpServletRequest request,
                         HttpServletResponse response)
         throws IOException, ServletException {
 
         ServletWebContext context =
             new ServletWebContext(getServletContext(), request, response);
-        Catalog theCatalog = null;
+        Catalog<String, Object, ServletWebContext> theCatalog = null;
+
         if (attribute != null) {
-            theCatalog = (Catalog) getServletContext().getAttribute
-                (this.attribute);
+            ServletContext servletContext = getServletContext();
+            Object testAttribute = servletContext.getAttribute(this.attribute);
+
+            if (testAttribute instanceof Catalog) {
+                /* "attribute" should always contain an instance of a
+                 * Catalog class according to the historical chain convention.
+                 * Although, we now double-check that it is in fact a catalog
+                 * here, we still need to suppress warnings because of the
+                 * type erasure of generics. */
+                @SuppressWarnings("unchecked")
+                Catalog<String, Object, ServletWebContext> attributeCatalog =
+                     (Catalog<String, Object, ServletWebContext>)testAttribute;
+                theCatalog = attributeCatalog;
+            }
+            else {
+                String msg = "The object stored as the attribute [" +
+                        attribute + "] was not of the expected type [" +
+                        "Catalog]";
+                throw new IllegalArgumentException(msg);
+            }
         } else if (catalog != null) {
-            theCatalog = CatalogFactory.getInstance().getCatalog(catalog);
+            theCatalog = CatalogFactory.<String, Object, ServletWebContext>getInstance().getCatalog(catalog);
         } else {
-            theCatalog = CatalogFactory.getInstance().getCatalog();
+            theCatalog = CatalogFactory.<String, Object, ServletWebContext>getInstance().getCatalog();
         }
         if (attribute == null) {
             request.setAttribute(CATALOG_DEFAULT, theCatalog);
         }
-        Command<ServletWebContext> command = theCatalog.getCommand(this.command);
+        Command<String, Object, ServletWebContext> cmd = theCatalog.getCommand(this.command);
         try {
-            command.execute(context);
+            cmd.execute(context);
         } catch (Exception e) {
             throw new ServletException(e);
         }

Modified: commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/servlet/PathInfoMapper.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/servlet/PathInfoMapper.java?rev=1243699&r1=1243698&r2=1243699&view=diff
==============================================================================
--- commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/servlet/PathInfoMapper.java (original)
+++ commons/proper/chain/trunk/src/main/java/org/apache/commons/chain/web/servlet/PathInfoMapper.java Mon Feb 13 21:19:07 2012
@@ -37,7 +37,7 @@ import org.apache.commons.chain.generic.
  * @author Craig R. McClanahan
  */
 
-public class PathInfoMapper<C extends Context> extends LookupCommand<C> {
+public class PathInfoMapper extends LookupCommand<String, Object, ServletWebContext> {
 
 
     // ------------------------------------------------------ Instance Variables
@@ -96,11 +96,9 @@ public class PathInfoMapper<C extends Co
      * @since Chain 1.2
      */
     @Override
-    protected String getCommandName(Context context) {
-
+    protected String getCommandName(ServletWebContext context) {
         // Look up the extra path information for this request
-        ServletWebContext swcontext = (ServletWebContext) context;
-        HttpServletRequest request = swcontext.getRequest();
+        HttpServletRequest request = context.getRequest();
         String pathInfo = (String)
             request.getAttribute("javax.servlet.include.path_info");
         if (pathInfo == null) {
@@ -122,8 +120,11 @@ public class PathInfoMapper<C extends Co
      * @since Chain 1.2
      */
     @Override
-    protected Catalog getCatalog(C context) {
-        Catalog catalog = (Catalog) context.get(getCatalogName());
+    protected Catalog<String, Object, ServletWebContext> getCatalog(ServletWebContext context) {
+        /* Assume that the object returned will be a catalog because of chain's
+         * historical contract. */
+        @SuppressWarnings("unchecked")
+        Catalog<String, Object, ServletWebContext> catalog = (Catalog<String, Object, ServletWebContext>) context.get(getCatalogName());
         if (catalog == null) {
             catalog = super.getCatalog(context);
         }



Mime
View raw message