You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ibatis.apache.org by cb...@apache.org on 2005/03/22 07:12:49 UTC

svn commit: r158552 - in incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction: ./ httpmap/

Author: cbegin
Date: Mon Mar 21 22:12:46 2005
New Revision: 158552

URL: http://svn.apache.org/viewcvs?view=rev&rev=158552
Log:
updated beanaction framework

Added:
    incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/ActionContext.java
    incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/ActionInterceptor.java
    incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/ActionInvoker.java
    incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/BaseBean.java
    incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/BeanAction.java
    incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/BeanActionException.java
    incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/DefaultActionInterceptor.java
    incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/httpmap/ApplicationMap.java
    incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/httpmap/BaseHttpMap.java
    incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/httpmap/CookieMap.java
    incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/httpmap/ParameterMap.java
    incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/httpmap/RequestMap.java
    incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/httpmap/SessionMap.java

Added: incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/ActionContext.java
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/ActionContext.java?view=auto&rev=158552
==============================================================================
--- incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/ActionContext.java (added)
+++ incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/ActionContext.java Mon Mar 21 22:12:46 2005
@@ -0,0 +1,112 @@
+package org.apache.struts.beanaction;
+
+import org.apache.struts.beanaction.httpmap.*;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * The ActionContext class gives simplified, thread-safe access to
+ * the request and response, as well as form parameters, request
+ * attributes, session attributes, application attributes.  Much
+ * of this can be accopmplished without using the Struts or even
+ * the Servlet API, therefore isolating your application from
+ * presentation framework details.
+ * <p/>
+ * This class also provides facilities for simpler message and error
+ * message handling.  Although not as powerful as that provided by
+ * Struts, it is great for simple applications that don't require
+ * internationalization or the flexibility of resource bundles.
+ * <p/>
+ * <i>Note: A more complete error and message handling API will be implemented.</i>
+ * <p/>
+ * Date: Mar 9, 2004 9:57:39 PM
+ *
+ * @author Clinton Begin
+ */
+public class ActionContext {
+
+  private static final ThreadLocal localContext = new ThreadLocal();
+
+  private HttpServletRequest request;
+  private HttpServletResponse response;
+
+  private Map cookieMap;
+  private Map parameterMap;
+  private Map requestMap;
+  private Map sessionMap;
+  private Map applicationMap;
+
+  public ActionContext() {
+    cookieMap = new HashMap();
+    parameterMap = new HashMap();
+    requestMap = new HashMap();
+    sessionMap = new HashMap();
+    applicationMap = new HashMap();
+  }
+
+  static void initCurrentContext(HttpServletRequest request, HttpServletResponse response) {
+    ActionContext ctx = getActionContext();
+    ctx.request = request;
+    ctx.response = response;
+    ctx.cookieMap = null;
+    ctx.parameterMap = null;
+    ctx.requestMap = null;
+    ctx.sessionMap = null;
+    ctx.applicationMap = null;
+  }
+
+  public Map getCookieMap() {
+    if (cookieMap == null) {
+      cookieMap = new CookieMap(request);
+    }
+    return cookieMap;
+  }
+
+  public Map getParameterMap() {
+    if (parameterMap == null) {
+      parameterMap = new ParameterMap(request);
+    }
+    return parameterMap;
+  }
+
+  public Map getRequestMap() {
+    if (requestMap == null) {
+      requestMap = new RequestMap(request);
+    }
+    return requestMap;
+  }
+
+  public Map getSessionMap() {
+    if (sessionMap == null) {
+      sessionMap = new SessionMap(request);
+    }
+    return sessionMap;
+  }
+
+  public Map getApplicationMap() {
+    if (applicationMap == null) {
+      applicationMap = new ApplicationMap(request);
+    }
+    return applicationMap;
+  }
+
+  public HttpServletRequest getRequest() {
+    return request;
+  }
+
+  public HttpServletResponse getResponse() {
+    return response;
+  }
+
+  public static ActionContext getActionContext() {
+    ActionContext ctx = (ActionContext) localContext.get();
+    if (ctx == null) {
+      ctx = new ActionContext();
+      localContext.set(ctx);
+    }
+    return ctx;
+  }
+}

Added: incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/ActionInterceptor.java
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/ActionInterceptor.java?view=auto&rev=158552
==============================================================================
--- incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/ActionInterceptor.java (added)
+++ incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/ActionInterceptor.java Mon Mar 21 22:12:46 2005
@@ -0,0 +1,7 @@
+package org.apache.struts.beanaction;
+
+public interface ActionInterceptor {
+
+  String intercept (ActionInvoker invoker);
+
+}

Added: incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/ActionInvoker.java
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/ActionInvoker.java?view=auto&rev=158552
==============================================================================
--- incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/ActionInvoker.java (added)
+++ incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/ActionInvoker.java Mon Mar 21 22:12:46 2005
@@ -0,0 +1,23 @@
+package org.apache.struts.beanaction;
+
+import java.lang.reflect.Method;
+
+public class ActionInvoker {
+
+  private Method method;
+  private BaseBean bean;
+
+  public ActionInvoker(BaseBean bean, Method method) {
+    this.method = method;
+    this.bean = bean;
+  }
+
+  public String invoke () {
+    try {
+      return (String) method.invoke(bean, null);
+    } catch (Exception e) {
+      throw new BeanActionException ("Error invoking Action.  Cause: " + e, e);
+    }
+  }
+
+}

Added: incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/BaseBean.java
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/BaseBean.java?view=auto&rev=158552
==============================================================================
--- incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/BaseBean.java (added)
+++ incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/BaseBean.java Mon Mar 21 22:12:46 2005
@@ -0,0 +1,54 @@
+package org.apache.struts.beanaction;
+
+import org.apache.struts.action.ActionMapping;
+import org.apache.struts.validator.ValidatorActionForm;
+
+import javax.servlet.ServletRequest;
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * All actions mapped through the BeanAction class should be mapped
+ * to a subclass of BaseBean (or have no form bean mapping at all).
+ * <p/>
+ * The BaseBean class simplifies the validate() and reset() methods
+ * by allowing them to be managed without Struts dependencies. Quite
+ * simply, subclasses can override the parameterless validate()
+ * and reset() methods and set errors and messages using the ActionContext
+ * class.
+ * <p/>
+ * <i>Note:  Full error, message and internationalization support is not complete.</i>
+ * <p/>
+ * Date: Mar 12, 2004 9:20:39 PM
+ *
+ * @author Clinton Begin
+ */
+public abstract class BaseBean extends ValidatorActionForm {
+
+  private ActionInterceptor interceptor;
+
+  protected BaseBean() {
+    this.interceptor = new DefaultActionInterceptor();
+  }
+
+  protected BaseBean(ActionInterceptor interceptor) {
+    this.interceptor = interceptor;
+  }
+
+  public final void reset(ActionMapping mapping, ServletRequest request) {
+    ActionContext.initCurrentContext((HttpServletRequest) request, null);
+    reset();
+  }
+
+  public final void reset(ActionMapping mapping, HttpServletRequest request) {
+    ActionContext.initCurrentContext((HttpServletRequest) request, null);
+    reset();
+  }
+
+  public void reset() {
+  }
+
+  public ActionInterceptor getInterceptor() {
+    return interceptor;
+  }
+
+}

Added: incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/BeanAction.java
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/BeanAction.java?view=auto&rev=158552
==============================================================================
--- incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/BeanAction.java (added)
+++ incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/BeanAction.java Mon Mar 21 22:12:46 2005
@@ -0,0 +1,178 @@
+package org.apache.struts.beanaction;
+
+import org.apache.struts.action.Action;
+import org.apache.struts.action.ActionForm;
+import org.apache.struts.action.ActionForward;
+import org.apache.struts.action.ActionMapping;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.lang.reflect.Method;
+
+/**
+ * BeanAction is an extension to the typical Struts Action class that
+ * enables mappings to bean methods.  This allows for a more typical
+ * Object Oriented design where each object has behaviour as part of
+ * its definition.  Instead of writing separate Actions and Forms,
+ * BeanAction allows you to simply have a Bean, which models both
+ * the state and the methods that operate on that state.
+ * <p/>
+ * In addition to the simpler packaging, BeanAction also simplifies the
+ * Struts progamming paradigm and reduces dependency on Struts.  Using
+ * this pattern could allow easier migration to newer frameworks like JSF.
+ * <p/>
+ * The method signatures are greatly simplified to the following
+ * <pre>
+ * public String myActionMethod() {
+ *   //..work
+ *   return "success";
+ * }
+ * </pre>
+ * The return parameter becomes simply the name of the forward (as defined
+ * in the config file as usual).  Form parameters, request, response, session,
+ * attributes, and cookies are all accessed via the ActionContext class (see the
+ * ActionContext javadocs for more).
+ * <p/>
+ * The forms that you map to a BaseAction mapping must be a subclass of the
+ * BaseBean class.  BaseBean continues to simplify the validation and
+ * reset methods by removing the parameters from the signature as was done with
+ * the above action method example.
+ * <p/>
+ * There are 3 ways to map a BeanAction in the struts configuration file.
+ * They are as follows.
+ * <p/>
+ * <B>URL Pattern</B>
+ * <p/>
+ * This approach uses the end of the action definition to determine which
+ * method to call on the Bean.  For example if you request the URL:
+ * <p/>
+ * http://localhost/jpetstore4/shop/viewOrder.do
+ * <p/>
+ * Then the method called would be "viewOrder" (of the mapped bean as specified
+ * by the name="" parameter in the mapping below).  The mapping used for this
+ * approach is as follows.
+ * <pre>
+ *  &lt;action path="/shop/<b>viewOrder</b>" type="org.apache.struts.beanaction.BeanAction"
+ *    name="orderBean" scope="session"
+ *    validate="false"&gt;
+ *    &lt;forward name="success" path="/order/ViewOrder.jsp"/&gt;
+ *  &lt;/action&gt;
+ * </pre>
+ * <p/>
+ * <B>Method Parameter</B>
+ * <p/>
+ * This approach uses the Struts action parameter within the mapping
+ * to determine the method to call on the Bean.  For example the
+ * following action mapping would cause the "viewOrder" method to
+ * be called on the bean ("orderBean").  The mapping used for this
+ * approach is as follows.
+ * <pre>
+ *  &lt;action path="/shop/viewOrder" type="org.apache.struts.beanaction.BeanAction"
+ *    <b>name="orderBean" parameter="viewOrder"</b> scope="session"
+ *    validate="false"&gt;
+ *    &lt;forward name="success" path="/order/ViewOrder.jsp"/&gt;
+ *  &lt;/action&gt;
+ * </pre>
+ * <B>No Method call</B>
+ * <p/>
+ * BeanAction will ignore any Struts action mappings without beans associated
+ * to them (i.e. no name="" attribute in the mapping).  If you do want to associate
+ * a bean to the action mapping, but do not want a method to be called, simply
+ * set the parameter to an asterisk ("*").  The mapping used for this approach
+ * is as follows (no method will be called).
+ * <pre>
+ *  &lt;action path="/shop/viewOrder" type="org.apache.struts.beanaction.BeanAction"
+ *    <b>name="orderBean" parameter="*"</b> scope="session"
+ *    validate="false"&gt;
+ *    &lt;forward name="success" path="/order/ViewOrder.jsp"/&gt;
+ *  &lt;/action&gt;
+ * </pre>
+ * <p/>
+ * <p/>
+ * TO-DO List
+ * <ul>
+ * <li> Ignore mappings to methods that don't exist.
+ * </ul>
+ * </p>
+ * <B>A WORK IN PROGRESS</B>
+ * <p/>
+ * <i>The BeanAction Struts extension is a work in progress.  While it demonstrates
+ * good patterns for application development, the framework itself is very new and
+ * should not be considered stable.  Your comments and suggestions are welcome.
+ * Please visit <a href="http://www.ibatis.com">http://www.ibatis.com</a> for contact information.</i>
+ * <p/>
+ * Date: Mar 11, 2004 10:03:56 PM
+ *
+ * @author Clinton Begin
+ * @see org.apache.struts.beanaction.BaseBean
+ * @see ActionContext
+ */
+public class BeanAction extends Action {
+
+  private static final String NO_METHOD_CALL = "*";
+  private static final String SUCCESS_FORWARD = "success";
+
+  public final ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
+      throws Exception {
+
+    String forward = SUCCESS_FORWARD;
+
+    try {
+
+      if (!(form instanceof BaseBean)) {
+        if (form != null) {
+          throw new BeanActionException("The form for mapping '" + mapping.getPath() + "' named '" + mapping.getName() + "' was not an instance of BaseBean.  BeanAction requires an BaseBean instance.");
+        } else {
+          throw new BeanActionException("The form for mapping '" + mapping.getPath() + "' named '" + mapping.getName() + "' was null.  BeanAction requires an BaseBean instance.");
+        }
+      }
+
+      BaseBean bean = (BaseBean) form;
+
+      ActionContext.initCurrentContext(request, response);
+
+      if (bean != null) {
+
+        // Explicit Method Mapping
+        Method method = null;
+        String methodName = mapping.getParameter();
+        if (methodName != null && !NO_METHOD_CALL.equals(methodName)) {
+          try {
+            method = bean.getClass().getMethod(methodName, null);
+            synchronized (bean) {
+              forward = bean.getInterceptor().intercept(new ActionInvoker(bean, method));
+            }
+          } catch (Exception e) {
+            throw new BeanActionException("Error dispatching bean action via method parameter ('" + methodName + "').  Cause: " + e, e);
+          }
+        }
+
+        // Path Based Method Mapping
+        if (method == null && !NO_METHOD_CALL.equals(methodName)) {
+          methodName = mapping.getPath();
+          if (methodName.length() > 1) {
+            int slash = methodName.lastIndexOf("/") + 1;
+            methodName = methodName.substring(slash);
+            if (methodName.length() > 0) {
+              try {
+                method = bean.getClass().getMethod(methodName, null);
+                synchronized (bean) {
+                  forward = bean.getInterceptor().intercept(new ActionInvoker(bean, method));
+                }
+              } catch (Exception e) {
+                throw new BeanActionException("Error dispatching bean action via URL pattern ('" + methodName + "').  Cause: " + e, e);
+              }
+            }
+          }
+        }
+      }
+
+    } catch (Exception e) {
+      forward = "error";
+      request.setAttribute("BeanActionException", e);
+    }
+
+    return mapping.findForward(forward);
+  }
+
+}

Added: incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/BeanActionException.java
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/BeanActionException.java?view=auto&rev=158552
==============================================================================
--- incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/BeanActionException.java (added)
+++ incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/BeanActionException.java Mon Mar 21 22:12:46 2005
@@ -0,0 +1,32 @@
+package org.apache.struts.beanaction;
+
+import com.ibatis.common.exception.NestedRuntimeException;
+
+/**
+ * This exception is thrown internally by BeanAction and
+ * can also be used by bean action methods as a general
+ * or base exception.
+ * <p/>
+ * Date: Mar 13, 2004 8:17:00 PM
+ *
+ * @author Clinton Begin
+ */
+public class BeanActionException extends NestedRuntimeException {
+
+  public BeanActionException() {
+    super();
+  }
+
+  public BeanActionException(String s) {
+    super(s);
+  }
+
+  public BeanActionException(Throwable throwable) {
+    super(throwable);
+  }
+
+  public BeanActionException(String s, Throwable throwable) {
+    super(s, throwable);
+  }
+
+}

Added: incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/DefaultActionInterceptor.java
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/DefaultActionInterceptor.java?view=auto&rev=158552
==============================================================================
--- incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/DefaultActionInterceptor.java (added)
+++ incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/DefaultActionInterceptor.java Mon Mar 21 22:12:46 2005
@@ -0,0 +1,9 @@
+package org.apache.struts.beanaction;
+
+public class DefaultActionInterceptor implements ActionInterceptor {
+
+  public String intercept(ActionInvoker invoker) {
+    return invoker.invoke();
+  }
+
+}

Added: incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/httpmap/ApplicationMap.java
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/httpmap/ApplicationMap.java?view=auto&rev=158552
==============================================================================
--- incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/httpmap/ApplicationMap.java (added)
+++ incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/httpmap/ApplicationMap.java Mon Mar 21 22:12:46 2005
@@ -0,0 +1,38 @@
+package org.apache.struts.beanaction.httpmap;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import java.util.Enumeration;
+
+/**
+ * Map to wrap application scope attributes.
+ * <p/>
+ * Date: Mar 11, 2004 11:21:25 PM
+ *
+ * @author Clinton Begin
+ */
+public class ApplicationMap extends BaseHttpMap {
+
+  private ServletContext context;
+
+  public ApplicationMap(HttpServletRequest request) {
+    context = request.getSession().getServletContext();
+  }
+
+  protected Enumeration getNames() {
+    return context.getAttributeNames();
+  }
+
+  protected Object getValue(Object key) {
+    return context.getAttribute(String.valueOf(key));
+  }
+
+  protected void putValue(Object key, Object value) {
+    context.setAttribute(String.valueOf(key), value);
+  }
+
+  protected void removeValue(Object key) {
+    context.removeAttribute(String.valueOf(key));
+  }
+
+}

Added: incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/httpmap/BaseHttpMap.java
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/httpmap/BaseHttpMap.java?view=auto&rev=158552
==============================================================================
--- incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/httpmap/BaseHttpMap.java (added)
+++ incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/httpmap/BaseHttpMap.java Mon Mar 21 22:12:46 2005
@@ -0,0 +1,91 @@
+package org.apache.struts.beanaction.httpmap;
+
+import java.util.*;
+
+/**
+ * <p/>
+ * Date: Mar 11, 2004 10:39:51 PM
+ *
+ * @author Clinton Begin
+ */
+public abstract class BaseHttpMap implements Map {
+
+  public int size() {
+    return keySet().size();
+  }
+
+  public boolean isEmpty() {
+    return keySet().size() == 0;
+  }
+
+  public boolean containsKey(Object key) {
+    return keySet().contains(key);
+  }
+
+  public boolean containsValue(Object value) {
+    return values().contains(value);
+  }
+
+  public Object get(Object key) {
+    return getValue(key);
+  }
+
+  public Object put(Object key, Object value) {
+    Object old = getValue(key);
+    putValue(key, value);
+    return old;
+  }
+
+  public Object remove(Object key) {
+    Object old = getValue(key);
+    removeValue(key);
+    return old;
+  }
+
+  public void putAll(Map map) {
+    Iterator i = map.keySet().iterator();
+    while (i.hasNext()) {
+      Object key = i.next();
+      putValue(key, map.get(key));
+    }
+  }
+
+  public void clear() {
+    Iterator i = keySet().iterator();
+    while (i.hasNext()) {
+      removeValue(i.next());
+    }
+  }
+
+  public Set keySet() {
+    Set keySet = new HashSet();
+    Enumeration enum = getNames();
+    while (enum.hasMoreElements()) {
+      keySet.add(enum.nextElement());
+    }
+    return keySet;
+  }
+
+  public Collection values() {
+    List list = new ArrayList();
+    Enumeration enum = getNames();
+    while (enum.hasMoreElements()) {
+      list.add(getValue(enum.nextElement()));
+    }
+    return list;
+  }
+
+  public Set entrySet() {
+    return new HashSet();
+  }
+
+
+  protected abstract Enumeration getNames();
+
+  protected abstract Object getValue(Object key);
+
+  protected abstract void putValue(Object key, Object value);
+
+  protected abstract void removeValue(Object key);
+
+}

Added: incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/httpmap/CookieMap.java
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/httpmap/CookieMap.java?view=auto&rev=158552
==============================================================================
--- incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/httpmap/CookieMap.java (added)
+++ incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/httpmap/CookieMap.java Mon Mar 21 22:12:46 2005
@@ -0,0 +1,68 @@
+package org.apache.struts.beanaction.httpmap;
+
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import java.util.Enumeration;
+
+/**
+ * Map to wrap cookie names and values (READ ONLY).
+ * <p/>
+ * Date: Mar 11, 2004 11:31:35 PM
+ *
+ * @author Clinton Begin
+ */
+public class CookieMap extends BaseHttpMap {
+
+  private Cookie[] cookies;
+
+  public CookieMap(HttpServletRequest request) {
+    cookies = request.getCookies();
+  }
+
+  protected Enumeration getNames() {
+    return new CookieEnumerator(cookies);
+  }
+
+  protected Object getValue(Object key) {
+    for (int i = 0; i < cookies.length; i++) {
+      if (key.equals(cookies[i].getName())) {
+        return cookies[i].getValue();
+      }
+    }
+    return null;
+  }
+
+  protected void putValue(Object key, Object value) {
+    throw new UnsupportedOperationException();
+  }
+
+  protected void removeValue(Object key) {
+    throw new UnsupportedOperationException();
+  }
+
+  /**
+   * Cookie Enumerator Class
+   */
+  private class CookieEnumerator implements Enumeration {
+
+    private int i = 0;
+
+    private Cookie[] cookieArray;
+
+    public CookieEnumerator(Cookie[] cookies) {
+      this.cookieArray = cookies;
+    }
+
+    public synchronized boolean hasMoreElements() {
+      return cookieArray.length > i;
+    }
+
+    public synchronized Object nextElement() {
+      Object element = cookieArray[i];
+      i++;
+      return element;
+    }
+
+  }
+
+}

Added: incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/httpmap/ParameterMap.java
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/httpmap/ParameterMap.java?view=auto&rev=158552
==============================================================================
--- incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/httpmap/ParameterMap.java (added)
+++ incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/httpmap/ParameterMap.java Mon Mar 21 22:12:46 2005
@@ -0,0 +1,41 @@
+package org.apache.struts.beanaction.httpmap;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.Enumeration;
+
+/**
+ * Map to wrap form parameters.
+ * <p/>
+ * Date: Mar 11, 2004 10:35:52 PM
+ *
+ * @author Clinton Begin
+ */
+public class ParameterMap extends BaseHttpMap {
+
+  private HttpServletRequest request;
+
+  public ParameterMap(HttpServletRequest request) {
+    this.request = request;
+  }
+
+  protected Enumeration getNames() {
+    return request.getParameterNames();
+  }
+
+  protected Object getValue(Object key) {
+    return request.getParameter(String.valueOf(key));
+  }
+
+  protected Object[] getValues(Object key) {
+    return request.getParameterValues(String.valueOf(key));
+  }
+
+  protected void putValue(Object key, Object value) {
+    throw new UnsupportedOperationException("Cannot put value to ParameterMap.");
+  }
+
+  protected void removeValue(Object key) {
+    throw new UnsupportedOperationException("Cannot remove value from ParameterMap.");
+  }
+
+}

Added: incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/httpmap/RequestMap.java
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/httpmap/RequestMap.java?view=auto&rev=158552
==============================================================================
--- incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/httpmap/RequestMap.java (added)
+++ incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/httpmap/RequestMap.java Mon Mar 21 22:12:46 2005
@@ -0,0 +1,37 @@
+package org.apache.struts.beanaction.httpmap;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.Enumeration;
+
+/**
+ * Map to wrap request scope attributes.
+ * <p/>
+ * Date: Mar 11, 2004 10:35:34 PM
+ *
+ * @author Clinton Begin
+ */
+public class RequestMap extends BaseHttpMap {
+
+  private HttpServletRequest request;
+
+  public RequestMap(HttpServletRequest request) {
+    this.request = request;
+  }
+
+  protected Enumeration getNames() {
+    return request.getAttributeNames();
+  }
+
+  protected Object getValue(Object key) {
+    return request.getAttribute(String.valueOf(key));
+  }
+
+  protected void putValue(Object key, Object value) {
+    request.setAttribute(String.valueOf(key), value);
+  }
+
+  protected void removeValue(Object key) {
+    request.removeAttribute(String.valueOf(key));
+  }
+
+}

Added: incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/httpmap/SessionMap.java
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/httpmap/SessionMap.java?view=auto&rev=158552
==============================================================================
--- incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/httpmap/SessionMap.java (added)
+++ incubator/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/httpmap/SessionMap.java Mon Mar 21 22:12:46 2005
@@ -0,0 +1,38 @@
+package org.apache.struts.beanaction.httpmap;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+import java.util.Enumeration;
+
+/**
+ * Map to wrap session scope attributes.
+ * <p/>
+ * Date: Mar 11, 2004 10:35:42 PM
+ *
+ * @author Clinton Begin
+ */
+public class SessionMap extends BaseHttpMap {
+
+  private HttpSession session;
+
+  public SessionMap(HttpServletRequest request) {
+    this.session = request.getSession();
+  }
+
+  protected Enumeration getNames() {
+    return session.getAttributeNames();
+  }
+
+  protected Object getValue(Object key) {
+    return session.getAttribute(String.valueOf(key));
+  }
+
+  protected void putValue(Object key, Object value) {
+    session.setAttribute(String.valueOf(key), value);
+  }
+
+  protected void removeValue(Object key) {
+    session.removeAttribute(String.valueOf(key));
+  }
+
+}