Commits

Anonymous committed 04bb252
  • Participants
  • Parent commits 43e1818

Comments (0)

Files changed (6)

File src/java/com/opensymphony/xwork/config/entities/ActionConfig.java

 import com.opensymphony.xwork.interceptor.Interceptor;
 
 import java.io.Serializable;
-
 import java.lang.reflect.Method;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 
 /**
  * Contains everything needed to configure and execute an action:
  * <ul>
- *  <li>methodName - the method name to execute on the action. If this is null, the Action will be cast to the Action
+ * <li>methodName - the method name to execute on the action. If this is null, the Action will be cast to the Action
  * Interface and the execute() method called</li>
- *  <li>clazz - the class name for the action</li>
- *  <li>params - the params to be set for this action just before execution</li>
- *  <li>results - the result map {String -> View class}</li>
- *  <li>resultParameters - params for results {String -> Map}</li>
- *  <li>typeConverter - the Ognl TypeConverter to use when getting/setting properties</li>
+ * <li>clazz - the class name for the action</li>
+ * <li>params - the params to be set for this action just before execution</li>
+ * <li>results - the result map {String -> View class}</li>
+ * <li>resultParameters - params for results {String -> Map}</li>
+ * <li>typeConverter - the Ognl TypeConverter to use when getting/setting properties</li>
  * </ul>
  *
  * @author $Author$
 public class ActionConfig implements InterceptorListHolder, Parameterizable, Serializable {
     //~ Instance fields ////////////////////////////////////////////////////////
 
-    protected List interceptors;
     protected List externalRefs;
+    protected List interceptors;
     protected Map params;
     protected Map results;
     protected Method method;
     protected String methodName;
-	protected String packageName;
+    protected String packageName;
     private Class clazz;
 
     //~ Constructors ///////////////////////////////////////////////////////////
         params = new HashMap();
         results = new HashMap();
         interceptors = new ArrayList();
-		externalRefs = new ArrayList();
+        externalRefs = new ArrayList();
     }
+
     //Helper constuctor to maintain backward compatibility with objects that create ActionConfigs
     //TODO this should be removed if these changes are rolled in to xwork CVS
-	public ActionConfig(String methodName, Class clazz, Map parameters, Map results, List interceptors) 
-	{
-		this(methodName, clazz, parameters, results, interceptors, Collections.EMPTY_LIST, new String());
-	}
-	
-	//TODO If this is commited to CVS we should put the package arg at the front of the ctor and fix
-	//code that uses it
+    public ActionConfig(String methodName, Class clazz, Map parameters, Map results, List interceptors) {
+        this(methodName, clazz, parameters, results, interceptors, Collections.EMPTY_LIST, new String());
+    }
+
+    //TODO If this is commited to CVS we should put the package arg at the front of the ctor and fix
+    //code that uses it
     public ActionConfig(String methodName, Class clazz, Map parameters, Map results, List interceptors, List externalRefs, String packageName) {
         this.methodName = methodName;
         this.interceptors = interceptors;
         return clazz;
     }
 
+    public List getExternalRefs() {
+        return externalRefs;
+    }
+
     public List getInterceptors() {
         if (interceptors == null) {
             interceptors = new ArrayList();
 
     /**
      * Returns cached instance of the action method or null if method name was not specified
+     *
      * @return cached instance of the action method or null if method name was not specified
      */
     public Method getMethod() throws NoSuchMethodException {
         if (methodName != null) {
             method = clazz.getMethod(methodName, new Class[0]);
         } else // return default execute() method if method name is not specified
-         {
+        {
             method = clazz.getMethod("execute", new Class[0]);
         }
 
 
     /**
      * Returns name of the action method
+     *
      * @return name of the method to execute
      */
     public String getMethodName() {
         return methodName;
     }
 
+    /**
+     * @param packageName The packageName to set.
+     */
+    public void setPackageName(String packageName) {
+        this.packageName = packageName;
+    }
+
+    /**
+     * @return Returns the packageName.
+     */
+    public String getPackageName() {
+        return packageName;
+    }
+
     public void setParams(Map params) {
         this.params = params;
     }
         return results;
     }
 
+    public void addExternalRef(ExternalReference reference) {
+        getExternalRefs().add(reference);
+    }
+
+    public void addExternalRefs(List externalRefs) {
+        getExternalRefs().addAll(externalRefs);
+    }
+
     public void addInterceptor(Interceptor interceptor) {
         getInterceptors().add(interceptor);
     }
     public void addInterceptors(List interceptors) {
         getInterceptors().addAll(interceptors);
     }
-    
+
     public void addParam(String name, Object value) {
         getParams().put(name, value);
     }
     public void addResultConfig(ResultConfig resultConfig) {
         getResults().put(resultConfig.getName(), resultConfig);
     }
-    
-	public void addExternalRef(ExternalReference reference) {
-		getExternalRefs().add(reference);
-	}
-
-	public void addExternalRefs(List externalRefs) {
-		getExternalRefs().addAll(externalRefs);
-	}
-	
-	public List getExternalRefs()
-	{
-		return externalRefs;
-	}
-	
+
     public boolean equals(Object o) {
         if (this == o) {
             return true;
 
         return result;
     }
-	/**
-	 * @return Returns the packageName.
-	 */
-	public String getPackageName() {
-		return packageName;
-	}
-
-	/**
-	 * @param packageName The packageName to set.
-	 */
-	public void setPackageName(String packageName) {
-		this.packageName = packageName;
-	}
-    
+
     public String toString() {
-        return "{ActionConfig " + clazz.getName() + (methodName != null ? "." + methodName + "()" : "") + "}";
+        return "{ActionConfig " + clazz.getName() + ((methodName != null) ? ("." + methodName + "()") : "") + "}";
     }
 }

File src/java/com/opensymphony/xwork/config/entities/ExternalReference.java

 /*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+/*
  * Created on Nov 12, 2003
  *
  * To change the template for this generated file go to
  */
 package com.opensymphony.xwork.config.entities;
 
+
 /**
  * @author Ross
- *
- * Encapsulates an external reference in the xwork configuration
+ *         <p/>
+ *         Encapsulates an external reference in the xwork configuration
  */
 public class ExternalReference {
-	
-	private String name;
-	private String externalRef;
-	private boolean required = true;
-	
-	/**
-	 * default constructor
-	 */
-	public ExternalReference(){}
-	
-	/**
-	 * @param name the name of the attribute the external reference refers to
-	 * @param externalRef the name used to query the external source
-	 * @param required determines whether an exception should be thrown if the reference is not resolved
-	 */
-	public ExternalReference(String name, String externalRef, boolean required) 
-	{
-		this.name = name;
-		this.externalRef = externalRef;
-		this.required = required;
-	}
-	/**
-	 * @return Returns the externalRef.
-	 */
-	public String getExternalRef() {
-		return externalRef;
-	}
+    //~ Instance fields ////////////////////////////////////////////////////////
+
+    private String externalRef;
+    private String name;
+    private boolean required = true;
+
+    //~ Constructors ///////////////////////////////////////////////////////////
+
+    /**
+     * default constructor
+     */
+    public ExternalReference() {
+    }
+
+    /**
+     * @param name        the name of the attribute the external reference refers to
+     * @param externalRef the name used to query the external source
+     * @param required    determines whether an exception should be thrown if the reference is not resolved
+     */
+    public ExternalReference(String name, String externalRef, boolean required) {
+        this.name = name;
+        this.externalRef = externalRef;
+        this.required = required;
+    }
+
+    //~ Methods ////////////////////////////////////////////////////////////////
 
-	/**
-	 * @param externalRef The externalRef to set.
-	 */
-	public void setExternalRef(String externalRef) {
-		this.externalRef = externalRef;
-	}
+    /**
+     * @param externalRef The externalRef to set.
+     */
+    public void setExternalRef(String externalRef) {
+        this.externalRef = externalRef;
+    }
 
-	/**
-	 * @return Returns the name.
-	 */
-	public String getName() {
-		return name;
-	}
+    /**
+     * @return Returns the externalRef.
+     */
+    public String getExternalRef() {
+        return externalRef;
+    }
 
-	/**
-	 * @param name The name to set.
-	 */
-	public void setName(String name) {
-		this.name = name;
-	}
+    /**
+     * @param name The name to set.
+     */
+    public void setName(String name) {
+        this.name = name;
+    }
 
-	/**
-	 * @return Returns the required.
-	 */
-	public boolean isRequired() {
-		return required;
-	}
+    /**
+     * @return Returns the name.
+     */
+    public String getName() {
+        return name;
+    }
 
-	/**
-	 * @param required The required to set.
-	 */
-	public void setRequired(boolean required) {
-		this.required = required;
-	}
+    /**
+     * @param required The required to set.
+     */
+    public void setRequired(boolean required) {
+        this.required = required;
+    }
 
+    /**
+     * @return Returns the required.
+     */
+    public boolean isRequired() {
+        return required;
+    }
 }

File src/java/com/opensymphony/xwork/util/LocalizedTextUtil.java

 package com.opensymphony.xwork.util;
 
 import com.opensymphony.xwork.ActionContext;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
 import java.text.MessageFormat;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Locale;
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
+import java.util.*;
 
 
 /**
  * LocalizedTextUtil
+ *
  * @author Jason Carreira
- * Created Apr 19, 2003 11:02:26 PM
+ *         Created Apr 19, 2003 11:02:26 PM
  */
 public class LocalizedTextUtil {
     //~ Static fields/initializers /////////////////////////////////////////////
     /**
      * Returns a localized message for the specified text key, aTextName, substituting variables from the
      * array of params into the message.
+     *
      * @param aTextName The message key
-     * @param params An array of objects to be substituted into the message text
+     * @param params    An array of objects to be substituted into the message text
      * @return A formatted message based on the key specified
      * @throws MissingResourceException
      */
     /**
      * Calls {@link #findText(Class aClass, String aTextName, Locale locale, String defaultMessage, Object[] args)} with
      * aTextName as the default message.
+     *
      * @see #findText(Class aClass, String aTextName, Locale locale, String defaultMessage, Object[] args)
      */
     public static String findText(Class aClass, String aTextName, Locale locale) {
      * search the default message bundles</li>
      * <li>If the text has still not been found, the provided defaultMessage is returned.<li>
      * </ol>
-     * @param aClass the class whose name to use as the start point for the search
-     * @param aTextName the text key to find the text message for
-     * @param locale the locale to use to find the correct ResourceBundle
+     *
+     * @param aClass         the class whose name to use as the start point for the search
+     * @param aTextName      the text key to find the text message for
+     * @param locale         the locale to use to find the correct ResourceBundle
      * @param defaultMessage the message to be returned if no text message can be found in a resource bundle
      * @return
      */
         }
 
         return getDefaultText(aTextName, locale, valueStack, args, defaultMessage);
-
     }
 
     private static String getDefaultText(String aTextName, Locale locale, OgnlValueStack valueStack, Object[] args, String defaultMessage) {

File src/test/com/opensymphony/xwork/SimpleAction.java

     //~ Static fields/initializers /////////////////////////////////////////////
 
     public static final String COMMAND_RETURN_CODE = "com.opensymphony.xwork.SimpleAction.CommandInvoked";
-    private boolean throwException;
-
-    public SimpleAction() {
-        System.out.println("hi");
-    }
 
     //~ Instance fields ////////////////////////////////////////////////////////
 
     private String blah;
     private String name;
     private TestBean bean = new TestBean();
+    private boolean throwException;
     private int bar;
     private int baz;
     private int foo;
 
+    //~ Constructors ///////////////////////////////////////////////////////////
+
+    public SimpleAction() {
+        System.out.println("hi");
+    }
+
     //~ Methods ////////////////////////////////////////////////////////////////
 
     public void setBar(int bar) {
     }
 
     public boolean[] getBools() {
-        boolean[] b = new boolean[] {true, false, false, true};
+        boolean[] b = new boolean[]{true, false, false, true};
 
         return b;
     }
         return someList;
     }
 
+    public void setThrowException(boolean throwException) {
+        this.throwException = throwException;
+    }
+
     public String commandMethod() throws Exception {
         return COMMAND_RETURN_CODE;
     }
 
+    public String exceptionMethod() throws Exception {
+        if (throwException) {
+            throw new Exception("We're supposed to throw this");
+        }
+
+        return "OK";
+    }
+
     public String execute() throws Exception {
         if (foo == bar) {
             return ERROR;
 
         return SUCCESS;
     }
-
-    public void setThrowException(boolean throwException) {
-        this.throwException = throwException;
-    }
-
-    public String exceptionMethod() throws Exception {
-        if (throwException) {
-            throw new Exception("We're supposed to throw this");
-        }
-
-        return "OK";
-    }
 }

File src/test/com/opensymphony/xwork/interceptor/ChainingInterceptorTest.java

+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
 package com.opensymphony.xwork.interceptor;
 
-import junit.framework.TestCase;
-import com.opensymphony.xwork.util.OgnlValueStack;
-import com.opensymphony.xwork.*;
 import com.mockobjects.dynamic.Mock;
+import com.opensymphony.xwork.*;
+import com.opensymphony.xwork.util.OgnlValueStack;
+import junit.framework.TestCase;
 
 import java.util.Date;
 import java.util.HashMap;
 
 /**
  * ChainingInterceptorTest
+ *
  * @author Jason Carreira
- * Date: Nov 22, 2003 3:11:41 PM
+ *         Date: Nov 22, 2003 3:11:41 PM
  */
 public class ChainingInterceptorTest extends TestCase {
-    OgnlValueStack stack;
+    //~ Instance fields ////////////////////////////////////////////////////////
+
     ActionInvocation invocation;
-    Mock mockInvocation;
     ChainingInterceptor interceptor;
+    Mock mockInvocation;
+    OgnlValueStack stack;
 
-    protected void setUp() throws Exception {
-        super.setUp();
-        stack = new OgnlValueStack();
-        mockInvocation = new Mock(ActionInvocation.class);
-        mockInvocation.expectAndReturn("getStack",stack);
-        mockInvocation.expectAndReturn("invoke",Action.SUCCESS);
-        mockInvocation.expectAndReturn("getInvocationContext", new ActionContext(new HashMap()));
-        invocation = (ActionInvocation) mockInvocation.proxy();
-        interceptor = new ChainingInterceptor();
+    //~ Methods ////////////////////////////////////////////////////////////////
+
+    public void testActionErrorsCanBeAddedAfterChain() throws Exception {
+        SimpleAction action1 = new SimpleAction();
+        SimpleAction action2 = new SimpleAction();
+        action1.addActionError("foo");
+        mockInvocation.matchAndReturn("getAction", action2);
+        stack.push(action1);
+        stack.push(action2);
+        interceptor.intercept(invocation);
+        assertEquals(action1.getActionErrors(), action2.getActionErrors());
+        action2.addActionError("bar");
+        assertEquals(1, action1.getActionErrors().size());
+        assertEquals(2, action2.getActionErrors().size());
+        assertTrue(action2.getActionErrors().contains("bar"));
     }
 
     public void testPropertiesChained() throws Exception {
         TestBean bean = new TestBean();
         TestBeanAction action = new TestBeanAction();
-        mockInvocation.matchAndReturn("getAction",action);
+        mockInvocation.matchAndReturn("getAction", action);
         bean.setBirth(new Date());
         bean.setName("foo");
         bean.setCount(1);
         stack.push(bean);
         stack.push(action);
         interceptor.intercept(invocation);
-        assertEquals(bean.getBirth(),action.getBirth());
-        assertEquals(bean.getName(),action.getName());
-        assertEquals(bean.getCount(),action.getCount());
+        assertEquals(bean.getBirth(), action.getBirth());
+        assertEquals(bean.getName(), action.getName());
+        assertEquals(bean.getCount(), action.getCount());
     }
 
-    public void testActionErrorsCanBeAddedAfterChain() throws Exception {
-        SimpleAction action1 = new SimpleAction();
-        SimpleAction action2 = new SimpleAction();
-        action1.addActionError("foo");
-        mockInvocation.matchAndReturn("getAction",action2);
-        stack.push(action1);
-        stack.push(action2);
-        interceptor.intercept(invocation);
-        assertEquals(action1.getActionErrors(),action2.getActionErrors());
-        action2.addActionError("bar");
-        assertEquals(1,action1.getActionErrors().size());
-        assertEquals(2,action2.getActionErrors().size());
-        assertTrue(action2.getActionErrors().contains("bar"));
+    protected void setUp() throws Exception {
+        super.setUp();
+        stack = new OgnlValueStack();
+        mockInvocation = new Mock(ActionInvocation.class);
+        mockInvocation.expectAndReturn("getStack", stack);
+        mockInvocation.expectAndReturn("invoke", Action.SUCCESS);
+        mockInvocation.expectAndReturn("getInvocationContext", new ActionContext(new HashMap()));
+        invocation = (ActionInvocation) mockInvocation.proxy();
+        interceptor = new ChainingInterceptor();
     }
 
+    //~ Inner Classes //////////////////////////////////////////////////////////
+
     private class TestBeanAction extends TestBean implements Action {
         public String execute() throws Exception {
             return SUCCESS;

File src/test/com/opensymphony/xwork/util/Dog.java

 
 
 /**
- *
- *
  * @author <a href="mailto:plightbo@cisco.com">Pat Lightbody</a>
  * @author $Author$
  * @version $Revision$
     }
 
     /**
+     * @return null
+     */
+    public Integer nullMethod() {
+        return null;
+    }
+
+    /**
      * a method which is safe to call with a null argument
+     *
      * @param arg the Boolean to return
      * @return arg, if it is not null, or Boolean.TRUE if arg is null
      */
     public Boolean nullSafeMethod(Boolean arg) {
         return (arg == null) ? Boolean.TRUE : arg;
     }
-
-    /**
-     * @return null
-     */
-    public Integer nullMethod() {
-        return null;
-    }
 }