Author: cbegin Date: Sat Nov 5 22:46:31 2005 New Revision: 331088 URL: http://svn.apache.org/viewcvs?rev=331088&view=rev Log: Updated BeanAction library in JP4, incremented ibatis version
Removed: ibatis/trunk/java/mapper/mapper2/FREEZEMARKER Modified: ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/ActionContext.java ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/ActionInterceptor.java ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/ActionInvoker.java ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/BaseBean.java ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/BeanAction.java ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/BeanActionException.java ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/DefaultActionInterceptor.java ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/httpmap/ApplicationMap.java ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/httpmap/BaseHttpMap.java ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/httpmap/CookieMap.java ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/httpmap/ParameterMap.java ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/httpmap/RequestMap.java ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/httpmap/SessionMap.java ibatis/trunk/java/mapper/mapper2/build/build.properties Modified: ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/ActionContext.java URL: http://svn.apache.org/viewcvs/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/ActionContext.java?rev=331088&r1=331087&r2=331088&view=diff ============================================================================== --- ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/ActionContext.java (original) +++ ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/ActionContext.java Sat Nov 5 22:46:31 2005 @@ -9,30 +9,41 @@ /** * The ActionContext class gives simplified, thread-safe access to + * <p/> * the request and response, as well as form parameters, request + * <p/> * attributes, session attributes, application attributes. Much + * <p/> * of this can be accopmplished without using the Struts or even + * <p/> * the Servlet API, therefore isolating your application from + * <p/> * presentation framework details. * <p/> + * <p/> + * <p/> * This class also provides facilities for simpler message and error + * <p/> * message handling. Although not as powerful as that provided by + * <p/> * Struts, it is great for simple applications that don't require + * <p/> * internationalization or the flexibility of resource bundles. * <p/> + * <p/> + * <p/> * <i>Note: A more complete error and message handling API will be implemented.</i> * <p/> + * <p/> + * <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; @@ -110,3 +121,4 @@ return ctx; } } + Modified: ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/ActionInterceptor.java URL: http://svn.apache.org/viewcvs/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/ActionInterceptor.java?rev=331088&r1=331087&r2=331088&view=diff ============================================================================== --- ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/ActionInterceptor.java (original) +++ ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/ActionInterceptor.java Sat Nov 5 22:46:31 2005 @@ -1,7 +1,6 @@ package org.apache.struts.beanaction; public interface ActionInterceptor { - - String intercept (ActionInvoker invoker); - + String intercept(ActionInvoker invoker); } + Modified: ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/ActionInvoker.java URL: http://svn.apache.org/viewcvs/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/ActionInvoker.java?rev=331088&r1=331087&r2=331088&view=diff ============================================================================== --- ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/ActionInvoker.java (original) +++ ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/ActionInvoker.java Sat Nov 5 22:46:31 2005 @@ -3,7 +3,6 @@ import java.lang.reflect.Method; public class ActionInvoker { - private Method method; private BaseBean bean; @@ -12,12 +11,12 @@ this.bean = bean; } - public String invoke () { + public String invoke() { try { return (String) method.invoke(bean, null); } catch (Exception e) { - throw new BeanActionException ("Error invoking Action. Cause: " + e, e); + throw new BeanActionException("Error invoking Action. Cause: " + e, e); } } - } + Modified: ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/BaseBean.java URL: http://svn.apache.org/viewcvs/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/BaseBean.java?rev=331088&r1=331087&r2=331088&view=diff ============================================================================== --- ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/BaseBean.java (original) +++ ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/BaseBean.java Sat Nov 5 22:46:31 2005 @@ -8,16 +8,27 @@ /** * All actions mapped through the BeanAction class should be mapped + * <p/> * to a subclass of BaseBean (or have no form bean mapping at all). * <p/> + * <p/> + * <p/> * The BaseBean class simplifies the validate() and reset() methods + * <p/> * by allowing them to be managed without Struts dependencies. Quite + * <p/> * simply, subclasses can override the parameterless validate() + * <p/> * and reset() methods and set errors and messages using the ActionContext + * <p/> * class. * <p/> + * <p/> + * <p/> * <i>Note: Full error, message and internationalization support is not complete.</i> * <p/> + * <p/> + * <p/> * Date: Mar 12, 2004 9:20:39 PM * * @author Clinton Begin @@ -50,5 +61,5 @@ public ActionInterceptor getInterceptor() { return interceptor; } - } + Modified: ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/BeanAction.java URL: http://svn.apache.org/viewcvs/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/BeanAction.java?rev=331088&r1=331087&r2=331088&view=diff ============================================================================== --- ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/BeanAction.java (original) +++ ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/BeanAction.java Sat Nov 5 22:46:31 2005 @@ -11,96 +11,187 @@ /** * BeanAction is an extension to the typical Struts Action class that + * <p/> * enables mappings to bean methods. This allows for a more typical + * <p/> * Object Oriented design where each object has behaviour as part of + * <p/> * its definition. Instead of writing separate Actions and Forms, + * <p/> * BeanAction allows you to simply have a Bean, which models both + * <p/> * the state and the methods that operate on that state. * <p/> + * <p/> + * <p/> * In addition to the simpler packaging, BeanAction also simplifies the + * <p/> * Struts progamming paradigm and reduces dependency on Struts. Using + * <p/> * this pattern could allow easier migration to newer frameworks like JSF. * <p/> + * <p/> + * <p/> * The method signatures are greatly simplified to the following + * <p/> * <pre> + * <p/> * public String myActionMethod() { + * <p/> * //..work + * <p/> * return "success"; + * <p/> * } + * <p/> * </pre> + * <p/> * The return parameter becomes simply the name of the forward (as defined + * <p/> * in the config file as usual). Form parameters, request, response, session, + * <p/> * attributes, and cookies are all accessed via the ActionContext class (see the + * <p/> * ActionContext javadocs for more). * <p/> + * <p/> + * <p/> * The forms that you map to a BaseAction mapping must be a subclass of the + * <p/> * BaseBean class. BaseBean continues to simplify the validation and + * <p/> * reset methods by removing the parameters from the signature as was done with + * <p/> * the above action method example. * <p/> + * <p/> + * <p/> * There are 3 ways to map a BeanAction in the struts configuration file. + * <p/> * They are as follows. * <p/> + * <p/> + * <p/> * <B>URL Pattern</B> * <p/> + * <p/> + * <p/> * This approach uses the end of the action definition to determine which + * <p/> * method to call on the Bean. For example if you request the URL: * <p/> + * <p/> + * <p/> * http://localhost/jpetstore4/shop/viewOrder.do * <p/> + * <p/> + * <p/> * Then the method called would be "viewOrder" (of the mapped bean as specified + * <p/> * by the name="" parameter in the mapping below). The mapping used for this + * <p/> * approach is as follows. + * <p/> * <pre> + * <p/> * <action path="/shop/<b>viewOrder</b>" type="org.apache.struts.beanaction.BeanAction" + * <p/> * name="orderBean" scope="session" + * <p/> * validate="false"> + * <p/> * <forward name="success" path="/order/ViewOrder.jsp"/> + * <p/> * </action> + * <p/> * </pre> * <p/> + * <p/> + * <p/> * <B>Method Parameter</B> * <p/> + * <p/> + * <p/> * This approach uses the Struts action parameter within the mapping + * <p/> * to determine the method to call on the Bean. For example the + * <p/> * following action mapping would cause the "viewOrder" method to + * <p/> * be called on the bean ("orderBean"). The mapping used for this + * <p/> * approach is as follows. + * <p/> * <pre> + * <p/> * <action path="/shop/viewOrder" type="org.apache.struts.beanaction.BeanAction" + * <p/> * <b>name="orderBean" parameter="viewOrder"</b> scope="session" + * <p/> * validate="false"> + * <p/> * <forward name="success" path="/order/ViewOrder.jsp"/> + * <p/> * </action> + * <p/> * </pre> + * <p/> * <B>No Method call</B> * <p/> + * <p/> + * <p/> * BeanAction will ignore any Struts action mappings without beans associated + * <p/> * to them (i.e. no name="" attribute in the mapping). If you do want to associate + * <p/> * a bean to the action mapping, but do not want a method to be called, simply + * <p/> * set the parameter to an asterisk ("*"). The mapping used for this approach + * <p/> * is as follows (no method will be called). + * <p/> * <pre> + * <p/> * <action path="/shop/viewOrder" type="org.apache.struts.beanaction.BeanAction" + * <p/> * <b>name="orderBean" parameter="*"</b> scope="session" + * <p/> * validate="false"> + * <p/> * <forward name="success" path="/order/ViewOrder.jsp"/> + * <p/> * </action> + * <p/> * </pre> * <p/> * <p/> + * <p/> + * <p/> + * <p/> * TO-DO List + * <p/> * <ul> + * <p/> * <li> Ignore mappings to methods that don't exist. + * <p/> * </ul> + * <p/> * </p> + * <p/> * <B>A WORK IN PROGRESS</B> * <p/> + * <p/> + * <p/> * <i>The BeanAction Struts extension is a work in progress. While it demonstrates + * <p/> * good patterns for application development, the framework itself is very new and + * <p/> * should not be considered stable. Your comments and suggestions are welcome. + * <p/> * Please visit <a href="http://www.ibatis.com">http://www.ibatis.com</a> for contact information.</i> * <p/> + * <p/> + * <p/> * Date: Mar 11, 2004 10:03:56 PM * * @author Clinton Begin @@ -108,17 +199,12 @@ * @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 { - + 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."); @@ -126,14 +212,11 @@ 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)) { @@ -147,7 +230,10 @@ } } + + // Path Based Method Mapping + if (method == null && !NO_METHOD_CALL.equals(methodName)) { methodName = mapping.getPath(); if (methodName.length() > 1) { @@ -166,13 +252,11 @@ } } } - } catch (Exception e) { forward = "error"; request.setAttribute("BeanActionException", e); } - return mapping.findForward(forward); } - } + Modified: ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/BeanActionException.java URL: http://svn.apache.org/viewcvs/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/BeanActionException.java?rev=331088&r1=331087&r2=331088&view=diff ============================================================================== --- ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/BeanActionException.java (original) +++ ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/BeanActionException.java Sat Nov 5 22:46:31 2005 @@ -1,32 +1,35 @@ package org.apache.struts.beanaction; -import com.ibatis.common.exception.NestedRuntimeException; +import org.apache.commons.lang.exception.NestableRuntimeException; /** * This exception is thrown internally by BeanAction and + * <p/> * can also be used by bean action methods as a general + * <p/> * or base exception. * <p/> + * <p/> + * <p/> * Date: Mar 13, 2004 8:17:00 PM * * @author Clinton Begin */ -public class BeanActionException extends NestedRuntimeException { - +public class BeanActionException extends NestableRuntimeException { public BeanActionException() { super(); } - public BeanActionException(String s) { - super(s); + public BeanActionException(String string) { + super(string); } public BeanActionException(Throwable throwable) { super(throwable); } - public BeanActionException(String s, Throwable throwable) { - super(s, throwable); + public BeanActionException(String string, Throwable throwable) { + super(string, throwable); } - } + Modified: ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/DefaultActionInterceptor.java URL: http://svn.apache.org/viewcvs/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/DefaultActionInterceptor.java?rev=331088&r1=331087&r2=331088&view=diff ============================================================================== --- ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/DefaultActionInterceptor.java (original) +++ ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/DefaultActionInterceptor.java Sat Nov 5 22:46:31 2005 @@ -1,9 +1,8 @@ package org.apache.struts.beanaction; public class DefaultActionInterceptor implements ActionInterceptor { - public String intercept(ActionInvoker invoker) { return invoker.invoke(); } - } + Modified: ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/httpmap/ApplicationMap.java URL: http://svn.apache.org/viewcvs/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/httpmap/ApplicationMap.java?rev=331088&r1=331087&r2=331088&view=diff ============================================================================== --- ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/httpmap/ApplicationMap.java (original) +++ ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/httpmap/ApplicationMap.java Sat Nov 5 22:46:31 2005 @@ -7,12 +7,13 @@ /** * Map to wrap application scope attributes. * <p/> + * <p/> + * <p/> * Date: Mar 11, 2004 11:21:25 PM * * @author Clinton Begin */ public class ApplicationMap extends BaseHttpMap { - private ServletContext context; public ApplicationMap(HttpServletRequest request) { @@ -34,5 +35,5 @@ protected void removeValue(Object key) { context.removeAttribute(String.valueOf(key)); } - } + Modified: ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/httpmap/BaseHttpMap.java URL: http://svn.apache.org/viewcvs/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/httpmap/BaseHttpMap.java?rev=331088&r1=331087&r2=331088&view=diff ============================================================================== --- ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/httpmap/BaseHttpMap.java (original) +++ ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/httpmap/BaseHttpMap.java Sat Nov 5 22:46:31 2005 @@ -4,12 +4,12 @@ /** * <p/> + * <p/> * Date: Mar 11, 2004 10:39:51 PM * * @author Clinton Begin */ public abstract class BaseHttpMap implements Map { - public int size() { return keySet().size(); } @@ -59,18 +59,18 @@ public Set keySet() { Set keySet = new HashSet(); - Enumeration enum = getNames(); - while (enum.hasMoreElements()) { - keySet.add(enum.nextElement()); + Enumeration names = getNames(); + while (names.hasMoreElements()) { + keySet.add(names.nextElement()); } return keySet; } public Collection values() { List list = new ArrayList(); - Enumeration enum = getNames(); - while (enum.hasMoreElements()) { - list.add(getValue(enum.nextElement())); + Enumeration names = getNames(); + while (names.hasMoreElements()) { + list.add(getValue(names.nextElement())); } return list; } @@ -79,7 +79,6 @@ return new HashSet(); } - protected abstract Enumeration getNames(); protected abstract Object getValue(Object key); @@ -87,5 +86,5 @@ protected abstract void putValue(Object key, Object value); protected abstract void removeValue(Object key); - } + Modified: ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/httpmap/CookieMap.java URL: http://svn.apache.org/viewcvs/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/httpmap/CookieMap.java?rev=331088&r1=331087&r2=331088&view=diff ============================================================================== --- ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/httpmap/CookieMap.java (original) +++ ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/httpmap/CookieMap.java Sat Nov 5 22:46:31 2005 @@ -7,12 +7,13 @@ /** * Map to wrap cookie names and values (READ ONLY). * <p/> + * <p/> + * <p/> * Date: Mar 11, 2004 11:31:35 PM * * @author Clinton Begin */ public class CookieMap extends BaseHttpMap { - private Cookie[] cookies; public CookieMap(HttpServletRequest request) { @@ -44,9 +45,7 @@ * Cookie Enumerator Class */ private class CookieEnumerator implements Enumeration { - private int i = 0; - private Cookie[] cookieArray; public CookieEnumerator(Cookie[] cookies) { @@ -62,7 +61,6 @@ i++; return element; } - } - } + Modified: ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/httpmap/ParameterMap.java URL: http://svn.apache.org/viewcvs/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/httpmap/ParameterMap.java?rev=331088&r1=331087&r2=331088&view=diff ============================================================================== --- ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/httpmap/ParameterMap.java (original) +++ ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/httpmap/ParameterMap.java Sat Nov 5 22:46:31 2005 @@ -6,12 +6,13 @@ /** * Map to wrap form parameters. * <p/> + * <p/> + * <p/> * Date: Mar 11, 2004 10:35:52 PM * * @author Clinton Begin */ public class ParameterMap extends BaseHttpMap { - private HttpServletRequest request; public ParameterMap(HttpServletRequest request) { @@ -37,5 +38,5 @@ protected void removeValue(Object key) { throw new UnsupportedOperationException("Cannot remove value from ParameterMap."); } - } + Modified: ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/httpmap/RequestMap.java URL: http://svn.apache.org/viewcvs/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/httpmap/RequestMap.java?rev=331088&r1=331087&r2=331088&view=diff ============================================================================== --- ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/httpmap/RequestMap.java (original) +++ ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/httpmap/RequestMap.java Sat Nov 5 22:46:31 2005 @@ -11,7 +11,6 @@ * @author Clinton Begin */ public class RequestMap extends BaseHttpMap { - private HttpServletRequest request; public RequestMap(HttpServletRequest request) { @@ -33,5 +32,4 @@ protected void removeValue(Object key) { request.removeAttribute(String.valueOf(key)); } - } Modified: ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/httpmap/SessionMap.java URL: http://svn.apache.org/viewcvs/ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/httpmap/SessionMap.java?rev=331088&r1=331087&r2=331088&view=diff ============================================================================== --- ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/httpmap/SessionMap.java (original) +++ ibatis/trunk/java/jpetstore/jpetstore4/src/org/apache/struts/beanaction/httpmap/SessionMap.java Sat Nov 5 22:46:31 2005 @@ -7,12 +7,13 @@ /** * Map to wrap session scope attributes. * <p/> + * <p/> + * <p/> * Date: Mar 11, 2004 10:35:42 PM * * @author Clinton Begin */ public class SessionMap extends BaseHttpMap { - private HttpSession session; public SessionMap(HttpServletRequest request) { @@ -34,5 +35,5 @@ protected void removeValue(Object key) { session.removeAttribute(String.valueOf(key)); } - } + Modified: ibatis/trunk/java/mapper/mapper2/build/build.properties URL: http://svn.apache.org/viewcvs/ibatis/trunk/java/mapper/mapper2/build/build.properties?rev=331088&r1=331087&r2=331088&view=diff ============================================================================== --- ibatis/trunk/java/mapper/mapper2/build/build.properties (original) +++ ibatis/trunk/java/mapper/mapper2/build/build.properties Sat Nov 5 22:46:31 2005 @@ -31,6 +31,6 @@ reports.coverage=./reports/coverage deploy.path=./exploded -deploy.prefix=iBATIS_DBL-2.1.5. +deploy.prefix=iBATIS_DBL-2.1.6. deploy.ext=.zip deploy.files=./deploy