You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ni...@apache.org on 2007/04/27 05:59:01 UTC

svn commit: r532951 - in /jakarta/commons/proper/chain/trunk/src/java/org/apache/commons/chain: generic/LookupCommand.java web/servlet/PathInfoMapper.java web/servlet/RequestParameterMapper.java web/servlet/ServletPathMapper.java

Author: niallp
Date: Thu Apr 26 20:59:00 2007
New Revision: 532951

URL: http://svn.apache.org/viewvc?view=rev&rev=532951
Log:
Fix for CHAIN-4 - Update servlet implementation classes to be aware of CatalogFactory - thanks to Joe Germuska

Modified:
    jakarta/commons/proper/chain/trunk/src/java/org/apache/commons/chain/generic/LookupCommand.java
    jakarta/commons/proper/chain/trunk/src/java/org/apache/commons/chain/web/servlet/PathInfoMapper.java
    jakarta/commons/proper/chain/trunk/src/java/org/apache/commons/chain/web/servlet/RequestParameterMapper.java
    jakarta/commons/proper/chain/trunk/src/java/org/apache/commons/chain/web/servlet/ServletPathMapper.java

Modified: jakarta/commons/proper/chain/trunk/src/java/org/apache/commons/chain/generic/LookupCommand.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/chain/trunk/src/java/org/apache/commons/chain/generic/LookupCommand.java?view=diff&rev=532951&r1=532950&r2=532951
==============================================================================
--- jakarta/commons/proper/chain/trunk/src/java/org/apache/commons/chain/generic/LookupCommand.java (original)
+++ jakarta/commons/proper/chain/trunk/src/java/org/apache/commons/chain/generic/LookupCommand.java Thu Apr 26 20:59:00 2007
@@ -348,15 +348,16 @@
 
 
     /**
-     * <p>Return the {@link Command} instance to be delegated to.</p>
+     * <p>Return the {@link Catalog} to look up the {@link Command} in.</p>
      *
      * @param context {@link Context} for this request
-     * @return The looked-up Command.
-     * @exception IllegalArgumentException if no such {@link Command}
-     *  can be found and the <code>optional</code> property is set
-     *  to <code>false</code>
+     * @return The catalog.
+     * @exception IllegalArgumentException if no {@link Catalog}
+     *  can be found
+     *
+     * @since Chain 1.2
      */
-    protected Command getCommand(Context context) {
+    protected Catalog getCatalog(Context context) {
         CatalogFactory lookupFactory = this.catalogFactory;
         if (lookupFactory == null) {
             lookupFactory = CatalogFactory.getInstance();
@@ -380,11 +381,24 @@
             }
         }
 
+        return catalog;
+    }
+
+    /**
+     * <p>Return the {@link Command} instance to be delegated to.</p>
+     *
+     * @param context {@link Context} for this request
+     * @return The looked-up Command.
+     * @exception IllegalArgumentException if no such {@link Command}
+     *  can be found and the <code>optional</code> property is set
+     *  to <code>false</code>
+     */
+    protected Command getCommand(Context context) {
+
+        Catalog catalog = getCatalog(context);
+
         Command command = null;
-        String name = getName();
-        if (name == null) {
-            name = (String) context.get(getNameKey());
-        }
+        String name = getCommandName(context);
         if (name != null) {
             command = catalog.getCommand(name);
             if ((command == null) && !isOptional()) {
@@ -405,5 +419,22 @@
 
     }
 
+    /**
+     * <p>Return the name of the {@link Command} instance to be delegated to.</p>
+     *
+     * @param context {@link Context} for this request
+     * @return The name of the {@link Command} instance
+     *
+     * @since Chain 1.2
+     */
+    protected String getCommandName(Context context) {
+
+        String name = getName();
+        if (name == null) {
+            name = (String) context.get(getNameKey());
+        }
+        return name;
+
+    }
 
 }

Modified: jakarta/commons/proper/chain/trunk/src/java/org/apache/commons/chain/web/servlet/PathInfoMapper.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/chain/trunk/src/java/org/apache/commons/chain/web/servlet/PathInfoMapper.java?view=diff&rev=532951&r1=532950&r2=532951
==============================================================================
--- jakarta/commons/proper/chain/trunk/src/java/org/apache/commons/chain/web/servlet/PathInfoMapper.java (original)
+++ jakarta/commons/proper/chain/trunk/src/java/org/apache/commons/chain/web/servlet/PathInfoMapper.java Thu Apr 26 20:59:00 2007
@@ -19,8 +19,8 @@
 
 import javax.servlet.http.HttpServletRequest;
 import org.apache.commons.chain.Catalog;
-import org.apache.commons.chain.Command;
 import org.apache.commons.chain.Context;
+import org.apache.commons.chain.generic.LookupCommand;
 
 
 /**
@@ -35,7 +35,7 @@
  * @author Craig R. McClanahan
  */
 
-public class PathInfoMapper implements Command {
+public class PathInfoMapper extends LookupCommand {
 
 
     // ------------------------------------------------------ Instance Variables
@@ -52,6 +52,9 @@
      * stored.</p>
      *
      * @return The context key for the Catalog.
+     *
+     * @deprecated Use catalogName to specify the name of the catalog in the
+     *  catalog factory
      */
     public String getCatalogKey() {
 
@@ -65,6 +68,9 @@
      * stored.</p>
      *
      * @param catalogKey The new catalog key
+     *
+     * @deprecated Use catalogName to specify the name of the catalog in the
+     *  catalog factory
      */
     public void setCatalogKey(String catalogKey) {
 
@@ -81,11 +87,11 @@
      * select an appropriate {@link Command} to be executed.
      *
      * @param context Context for the current request
-     * @return The result of executing the Command for the request URI.
-     * @throws Exception if there is a problem executing the Command for
-     *  the request URI.
+     * @return The name of the {@link Command} instance
+     *
+     * @since Chain 1.2
      */
-    public boolean execute(Context context) throws Exception {
+    protected String getCommandName(Context context) {
 
         // Look up the extra path information for this request
         ServletWebContext swcontext = (ServletWebContext) context;
@@ -96,12 +102,26 @@
             pathInfo = request.getPathInfo();
         }
 
-        // Map to the Command specified by the extra path info
-        Catalog catalog = (Catalog) context.get(getCatalogKey());
-        Command command = catalog.getCommand(pathInfo);
-        return (command.execute(context));
+        return pathInfo;
 
     }
 
+    /**
+     * <p>Return the {@link Catalog} to look up the {@link Command} in.</p>
+     *
+     * @param context {@link Context} for this request
+     * @return The catalog.
+     * @exception IllegalArgumentException if no {@link Catalog}
+     *  can be found
+     *
+     * @since Chain 1.2
+     */
+    protected Catalog getCatalog(Context context) {
+        Catalog catalog = (Catalog) context.get(getCatalogKey());
+        if (catalog == null) {
+            catalog = super.getCatalog(context);
+        }
+        return catalog;
+    }
 
 }

Modified: jakarta/commons/proper/chain/trunk/src/java/org/apache/commons/chain/web/servlet/RequestParameterMapper.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/chain/trunk/src/java/org/apache/commons/chain/web/servlet/RequestParameterMapper.java?view=diff&rev=532951&r1=532950&r2=532951
==============================================================================
--- jakarta/commons/proper/chain/trunk/src/java/org/apache/commons/chain/web/servlet/RequestParameterMapper.java (original)
+++ jakarta/commons/proper/chain/trunk/src/java/org/apache/commons/chain/web/servlet/RequestParameterMapper.java Thu Apr 26 20:59:00 2007
@@ -19,8 +19,8 @@
 
 import javax.servlet.http.HttpServletRequest;
 import org.apache.commons.chain.Catalog;
-import org.apache.commons.chain.Command;
 import org.apache.commons.chain.Context;
+import org.apache.commons.chain.generic.LookupCommand;
 
 
 /**
@@ -36,7 +36,7 @@
  * @author Craig R. McClanahan
  */
 
-public class RequestParameterMapper implements Command {
+public class RequestParameterMapper extends LookupCommand {
 
 
     // ------------------------------------------------------ Instance Variables
@@ -67,6 +67,9 @@
      * stored.</p>
      *
      * @param catalogKey The new catalog key
+     *
+     * @deprecated Use catalogName to specify the name of the catalog in the
+     *  catalog factory
      */
     public void setCatalogKey(String catalogKey) {
 
@@ -80,6 +83,9 @@
      * selecting the {@link Command} to be executed.</p>
      *
      * @return The name of the request parameter.
+     *
+     * @deprecated Use catalogName to specify the name of the catalog in the
+     *  catalog factory
      */
     public String getParameter() {
 
@@ -109,22 +115,37 @@
      * to select an appropriate {@link Command} to be executed.
      *
      * @param context Context for the current request
-     * @return The result of executing the Command for the request parameter.
-     * @throws Exception if there is a problem executing the Command for
-     *  the request parameter.
+     * @return The name of the {@link Command} instance
+     *
+     * @since Chain 1.2
      */
-    public boolean execute(Context context) throws Exception {
+    protected String getCommandName(Context context) {
 
         // Look up the specified request parameter for this request
         ServletWebContext swcontext = (ServletWebContext) context;
         HttpServletRequest request = swcontext.getRequest();
         String value = request.getParameter(getParameter());
+        return value;
+
+    }
 
-        // Map to the Command specified by the extra path info
-        Catalog catalog = (Catalog) context.get(getCatalogKey());
-        Command command = catalog.getCommand(value);
-        return (command.execute(context));
 
+    /**
+     * <p>Return the {@link Catalog} to look up the {@link Command} in.</p>
+     *
+     * @param context {@link Context} for this request
+     * @return The catalog.
+     * @exception IllegalArgumentException if no {@link Catalog}
+     *  can be found
+     *
+     * @since Chain 1.2
+     */
+    protected Catalog getCatalog(Context context) {
+        Catalog catalog = (Catalog) context.get(getCatalogKey());
+        if (catalog == null) {
+            catalog = super.getCatalog(context);
+        }
+        return catalog;
     }
 
 

Modified: jakarta/commons/proper/chain/trunk/src/java/org/apache/commons/chain/web/servlet/ServletPathMapper.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/chain/trunk/src/java/org/apache/commons/chain/web/servlet/ServletPathMapper.java?view=diff&rev=532951&r1=532950&r2=532951
==============================================================================
--- jakarta/commons/proper/chain/trunk/src/java/org/apache/commons/chain/web/servlet/ServletPathMapper.java (original)
+++ jakarta/commons/proper/chain/trunk/src/java/org/apache/commons/chain/web/servlet/ServletPathMapper.java Thu Apr 26 20:59:00 2007
@@ -19,8 +19,8 @@
 
 import javax.servlet.http.HttpServletRequest;
 import org.apache.commons.chain.Catalog;
-import org.apache.commons.chain.Command;
 import org.apache.commons.chain.Context;
+import org.apache.commons.chain.generic.LookupCommand;
 
 
 /**
@@ -35,7 +35,7 @@
  * @author Craig R. McClanahan
  */
 
-public class ServletPathMapper implements Command {
+public class ServletPathMapper extends LookupCommand {
 
 
     // ------------------------------------------------------ Instance Variables
@@ -52,6 +52,9 @@
      * stored.</p>
      *
      * @return The context key for the Catalog.
+     *
+     * @deprecated Use catalogName to specify the name of the catalog in the
+     *  catalog factory
      */
     public String getCatalogKey() {
 
@@ -65,6 +68,9 @@
      * stored.</p>
      *
      * @param catalogKey The new catalog key
+     *
+     * @deprecated Use catalogName to specify the name of the catalog in the
+     *  catalog factory
      */
     public void setCatalogKey(String catalogKey) {
 
@@ -81,11 +87,11 @@
      * select an appropriate {@link Command} to be executed.
      *
      * @param context Context for the current request
-     * @return The result of executing the Command for the servlet path.
-     * @throws Exception if there is a problem executing the Command for
-     *  the servlet path.
+     * @return The name of the {@link Command} instance
+     *
+     * @since Chain 1.2
      */
-    public boolean execute(Context context) throws Exception {
+    protected String getCommandName(Context context) {
 
         // Look up the servlet path for this request
         ServletWebContext swcontext = (ServletWebContext) context;
@@ -96,12 +102,26 @@
             servletPath = request.getServletPath();
         }
 
-        // Map to the Command specified by the extra path info
-        Catalog catalog = (Catalog) context.get(getCatalogKey());
-        Command command = catalog.getCommand(servletPath);
-        return (command.execute(context));
+        return servletPath;
 
     }
 
+    /**
+     * <p>Return the {@link Catalog} to look up the {@link Command} in.</p>
+     *
+     * @param context {@link Context} for this request
+     * @return The catalog.
+     * @exception IllegalArgumentException if no {@link Catalog}
+     *  can be found
+     *
+     * @since Chain 1.2
+     */
+    protected Catalog getCatalog(Context context) {
+        Catalog catalog = (Catalog) context.get(getCatalogKey());
+        if (catalog == null) {
+            catalog = super.getCatalog(context);
+        }
+        return catalog;
+    }
 
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org