struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From musa...@apache.org
Subject svn commit: r657932 - in /struts/sandbox/trunk/struts2-convention-plugin/src: main/java/org/apache/struts2/convention/ main/java/org/apache/struts2/convention/annotation/ test/java/org/apache/struts2/convention/ test/java/org/apache/struts2/convention/...
Date Mon, 19 May 2008 19:29:07 GMT
Author: musachy
Date: Mon May 19 12:29:07 2008
New Revision: 657932

URL: http://svn.apache.org/viewvc?rev=657932&view=rev
Log:
Add "params" to @Action

Added:
    struts/sandbox/trunk/struts2-convention-plugin/src/test/java/org/apache/struts2/convention/actions/params/
    struts/sandbox/trunk/struts2-convention-plugin/src/test/java/org/apache/struts2/convention/actions/params/ActionParamsMethodLevelAction.java
Modified:
    struts/sandbox/trunk/struts2-convention-plugin/src/main/java/org/apache/struts2/convention/DefaultInterceptorMapBuilder.java
    struts/sandbox/trunk/struts2-convention-plugin/src/main/java/org/apache/struts2/convention/DefaultResultMapBuilder.java
    struts/sandbox/trunk/struts2-convention-plugin/src/main/java/org/apache/struts2/convention/PackageBasedActionConfigBuilder.java
    struts/sandbox/trunk/struts2-convention-plugin/src/main/java/org/apache/struts2/convention/StringTools.java
    struts/sandbox/trunk/struts2-convention-plugin/src/main/java/org/apache/struts2/convention/annotation/Action.java
    struts/sandbox/trunk/struts2-convention-plugin/src/test/java/org/apache/struts2/convention/PackageBasedActionConfigBuilderTest.java

Modified: struts/sandbox/trunk/struts2-convention-plugin/src/main/java/org/apache/struts2/convention/DefaultInterceptorMapBuilder.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-convention-plugin/src/main/java/org/apache/struts2/convention/DefaultInterceptorMapBuilder.java?rev=657932&r1=657931&r2=657932&view=diff
==============================================================================
--- struts/sandbox/trunk/struts2-convention-plugin/src/main/java/org/apache/struts2/convention/DefaultInterceptorMapBuilder.java
(original)
+++ struts/sandbox/trunk/struts2-convention-plugin/src/main/java/org/apache/struts2/convention/DefaultInterceptorMapBuilder.java
Mon May 19 12:29:07 2008
@@ -85,7 +85,7 @@
             if (LOG.isTraceEnabled())
                 LOG.trace("Adding interceptor [#0] to [#1]",
                         interceptor.value(), actionName);
-            Map<String, String> params = createParameterMap(interceptor
+            Map<String, String> params = StringTools.createParameterMap(interceptor
                     .params());
             interceptorList.addAll(buildInterceptorList(builder,
                     interceptor, params));
@@ -94,29 +94,6 @@
 	    return interceptorList;
 	}
 
-	protected Map<String, String> createParameterMap(String[] parms) {
-		Map<String, String> map = new HashMap<String, String>();
-		int subtract = parms.length % 2;
-		if (subtract != 0) {
-			throw new ConfigurationException(
-					"The InterceptorRef annotation uses an array of strings for"
-							+ " parameters and they must be in a key value pair configuration. It looks like you"
-							+ " have specified an odd number of parameters and there should only be an even number."
-							+ " (e.g. params = {\"key\", \"value\"})");
-		}
-
-		for (int i = 0; i < parms.length; i = i + 2) {
-			String key = parms[i];
-			String value = parms[i + 1];
-			map.put(key, value);
-			if (LOG.isTraceEnabled()) {
-				LOG.trace("Adding parmeter [#0:#1] to interceptor", key, value);
-			}
-		}
-
-		return map;
-	}
-
 	protected List<InterceptorMapping> buildInterceptorList(
 			PackageConfig.Builder builder, InterceptorRef ref, Map params) {
 		return InterceptorBuilder.constructInterceptorReference(builder, ref

Modified: struts/sandbox/trunk/struts2-convention-plugin/src/main/java/org/apache/struts2/convention/DefaultResultMapBuilder.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-convention-plugin/src/main/java/org/apache/struts2/convention/DefaultResultMapBuilder.java?rev=657932&r1=657931&r2=657932&view=diff
==============================================================================
--- struts/sandbox/trunk/struts2-convention-plugin/src/main/java/org/apache/struts2/convention/DefaultResultMapBuilder.java
(original)
+++ struts/sandbox/trunk/struts2-convention-plugin/src/main/java/org/apache/struts2/convention/DefaultResultMapBuilder.java
Mon May 19 12:29:07 2008
@@ -361,7 +361,7 @@
 
         // Handle the annotation
         if (result != null) {
-            params.putAll(createParameterMap(result.params()));
+            params.putAll(StringTools.createParameterMap(result.params()));
         }
 
         // Map the location to the default param for the result or a param named location
@@ -375,28 +375,6 @@
         return new ResultConfig.Builder(info.name, resultTypeConfig.getClassName()).addParams(params).build();
     }
 
-    protected Map<String, String> createParameterMap(String[] parms) {
-        Map<String, String> map = new HashMap<String, String>();
-        int subtract = parms.length % 2;
-        if (subtract != 0) {
-            throw new ConfigurationException("The Result annotation uses an array of strings
for" +
-                " parameters and they must be in a key value pair configuration. It looks
like you" +
-                " have specified an odd number of parameters and there should only be an
even number." +
-                " (e.g. params = {\"key\", \"value\"})");
-        }
-
-        for (int i = 0; i < parms.length; i = i + 2) {
-            String key = parms[i];
-            String value = parms[i + 1];
-            map.put(key, value);
-            if (LOG.isTraceEnabled()) {
-                LOG.trace("Adding parmeter [#0:#1] to result", key, value);
-            }
-        }
-
-        return map;
-    }
-
     class ResultInfo {
         public final String name;
         public final String location;

Modified: struts/sandbox/trunk/struts2-convention-plugin/src/main/java/org/apache/struts2/convention/PackageBasedActionConfigBuilder.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-convention-plugin/src/main/java/org/apache/struts2/convention/PackageBasedActionConfigBuilder.java?rev=657932&r1=657931&r2=657932&view=diff
==============================================================================
--- struts/sandbox/trunk/struts2-convention-plugin/src/main/java/org/apache/struts2/convention/PackageBasedActionConfigBuilder.java
(original)
+++ struts/sandbox/trunk/struts2-convention-plugin/src/main/java/org/apache/struts2/convention/PackageBasedActionConfigBuilder.java
Mon May 19 12:29:07 2008
@@ -501,6 +501,10 @@
         Map<String, ResultConfig> results = resultMapBuilder.build(actionClass, annotation,
actionName, pkgCfg.build());
         actionConfig.addResultConfigs(results);
 
+        //add params
+        if (annotation != null)
+            actionConfig.addParams(StringTools.createParameterMap(annotation.params()));
+
         pkgCfg.addActionConfig(actionName, actionConfig.build());
     }
 

Modified: struts/sandbox/trunk/struts2-convention-plugin/src/main/java/org/apache/struts2/convention/StringTools.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-convention-plugin/src/main/java/org/apache/struts2/convention/StringTools.java?rev=657932&r1=657931&r2=657932&view=diff
==============================================================================
--- struts/sandbox/trunk/struts2-convention-plugin/src/main/java/org/apache/struts2/convention/StringTools.java
(original)
+++ struts/sandbox/trunk/struts2-convention-plugin/src/main/java/org/apache/struts2/convention/StringTools.java
Mon May 19 12:29:07 2008
@@ -20,6 +20,11 @@
  */
 package org.apache.struts2.convention;
 
+import java.util.HashMap;
+import java.util.Map;
+
+import com.opensymphony.xwork2.config.ConfigurationException;
+
 /**
  * <p>
  * This class is a String helper.
@@ -47,4 +52,24 @@
 
         return "";
     }
+
+    public static Map<String, String> createParameterMap(String[] parms) {
+        Map<String, String> map = new HashMap<String, String>();
+        int subtract = parms.length % 2;
+        if (subtract != 0) {
+            throw new ConfigurationException(
+                    "'params' is a string array "
+                            + "and they must be in a key value pair configuration. It looks
like you"
+                            + " have specified an odd number of parameters and there should
only be an even number."
+                            + " (e.g. params = {\"key\", \"value\"})");
+        }
+
+        for (int i = 0; i < parms.length; i = i + 2) {
+            String key = parms[i];
+            String value = parms[i + 1];
+            map.put(key, value);
+        }
+
+        return map;
+    }
 }
\ No newline at end of file

Modified: struts/sandbox/trunk/struts2-convention-plugin/src/main/java/org/apache/struts2/convention/annotation/Action.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-convention-plugin/src/main/java/org/apache/struts2/convention/annotation/Action.java?rev=657932&r1=657931&r2=657932&view=diff
==============================================================================
--- struts/sandbox/trunk/struts2-convention-plugin/src/main/java/org/apache/struts2/convention/annotation/Action.java
(original)
+++ struts/sandbox/trunk/struts2-convention-plugin/src/main/java/org/apache/struts2/convention/annotation/Action.java
Mon May 19 12:29:07 2008
@@ -80,4 +80,11 @@
      * @return Interceptors to be applied to the action
      */
     InterceptorRef[] interceptorRefs() default {};
+
+    /**
+     * @return  The parameters passed to the action. This is a list of strings that form
a name/value
+     *          pair chain since creating a Map for annotations is not possible. An example
would be:
+     *          <code>{"key", "value", "key2", "value2"}</code>.
+     */
+    String[] params() default {};
 }
\ No newline at end of file

Modified: struts/sandbox/trunk/struts2-convention-plugin/src/test/java/org/apache/struts2/convention/PackageBasedActionConfigBuilderTest.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-convention-plugin/src/test/java/org/apache/struts2/convention/PackageBasedActionConfigBuilderTest.java?rev=657932&r1=657931&r2=657932&view=diff
==============================================================================
--- struts/sandbox/trunk/struts2-convention-plugin/src/test/java/org/apache/struts2/convention/PackageBasedActionConfigBuilderTest.java
(original)
+++ struts/sandbox/trunk/struts2-convention-plugin/src/test/java/org/apache/struts2/convention/PackageBasedActionConfigBuilderTest.java
Mon May 19 12:29:07 2008
@@ -49,6 +49,7 @@
 import org.apache.struts2.convention.actions.namespace.ClassLevelNamespaceAction;
 import org.apache.struts2.convention.actions.namespace.PackageLevelNamespaceAction;
 import org.apache.struts2.convention.actions.namespace2.DefaultNamespaceAction;
+import org.apache.struts2.convention.actions.params.ActionParamsMethodLevelAction;
 import org.apache.struts2.convention.actions.parentpackage.ClassLevelParentPackageAction;
 import org.apache.struts2.convention.actions.parentpackage.PackageLevelParentPackageAction;
 import org.apache.struts2.convention.actions.result.ActionLevelResultAction;
@@ -116,6 +117,8 @@
 
         PackageConfig rootPkg = makePackageConfig("org.apache.struts2.convention.actions#struts-default#",
             "", strutsDefault, null);
+        PackageConfig paramsPkg = makePackageConfig("org.apache.struts2.convention.actions.params#struts-default#/params",
+                "/params", strutsDefault, null);
         PackageConfig actionPkg = makePackageConfig("org.apache.struts2.convention.actions.action#struts-default#/action",
             "/action", strutsDefault, null);
         PackageConfig idxPkg = makePackageConfig("org.apache.struts2.convention.actions.idx#struts-default#/idx",
@@ -160,6 +163,9 @@
         expect(resultMapBuilder.build(org.apache.struts2.convention.actions.idx.Index.class,
null, "index", idxPkg)).andReturn(results);
         expect(resultMapBuilder.build(org.apache.struts2.convention.actions.idx.idx2.Index.class,
null, "index", idx2Pkg)).andReturn(results);
 
+        /* org.apache.struts2.convention.actions.params */
+        expect(resultMapBuilder.build(ActionParamsMethodLevelAction.class, getAnnotation(ActionParamsMethodLevelAction.class,
"run1", Action.class), "actionParam1", paramsPkg)).andReturn(results);
+
         /* org.apache.struts2.convention.actions.interceptor */
         expect(resultMapBuilder.build(InterceptorsAction.class, getAnnotation(InterceptorsAction.class,
"run1", Action.class), "action100", interceptorRefsPkg)).andReturn(results);
         expect(resultMapBuilder.build(InterceptorsAction.class, getAnnotation(InterceptorsAction.class,
"run2", Action.class), "action200", interceptorRefsPkg)).andReturn(results);
@@ -247,6 +253,18 @@
         verifyActionConfig(pkgConfig, "action", SingleActionNameAction.class, "run", pkgConfig.getName());
         verifyActionConfig(pkgConfig, "test", TestAction.class, "execute", pkgConfig.getName());
 
+        /* org.apache.struts2.convention.actions.params */
+        pkgConfig = configuration.getPackageConfig("org.apache.struts2.convention.actions.params#struts-default#/params");
+        assertNotNull(pkgConfig);
+        assertEquals(1, pkgConfig.getActionConfigs().size());
+        ActionConfig ac = pkgConfig.getAllActionConfigs().get("actionParam1");
+        assertNotNull(ac);
+        Map<String, String> params = ac.getParams();
+        assertNotNull(params);
+        assertEquals(2, params.size());
+        assertEquals("val1", params.get("param1"));
+        assertEquals("val2", params.get("param2"));
+
         /* org.apache.struts2.convention.actions.idx */
         pkgConfig = configuration.getPackageConfig("org.apache.struts2.convention.actions.idx#struts-default#/idx");
         assertNotNull(pkgConfig);

Added: struts/sandbox/trunk/struts2-convention-plugin/src/test/java/org/apache/struts2/convention/actions/params/ActionParamsMethodLevelAction.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-convention-plugin/src/test/java/org/apache/struts2/convention/actions/params/ActionParamsMethodLevelAction.java?rev=657932&view=auto
==============================================================================
--- struts/sandbox/trunk/struts2-convention-plugin/src/test/java/org/apache/struts2/convention/actions/params/ActionParamsMethodLevelAction.java
(added)
+++ struts/sandbox/trunk/struts2-convention-plugin/src/test/java/org/apache/struts2/convention/actions/params/ActionParamsMethodLevelAction.java
Mon May 19 12:29:07 2008
@@ -0,0 +1,49 @@
+/*
+ * $ID$
+ *
+ * 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.struts2.convention.actions.params;
+
+import org.apache.struts2.convention.annotation.Action;
+
+public class ActionParamsMethodLevelAction {
+    private String param1;
+    private String param2;
+
+    @Action(value = "actionParam1", params = {"param1", "val1", "param2", "val2"})
+    public String run1() throws Exception {
+        return null;
+    }
+
+    public String getParam1() {
+        return param1;
+    }
+
+    public void setParam1(String param1) {
+        this.param1 = param1;
+    }
+
+    public String getParam2() {
+        return param2;
+    }
+
+    public void setParam2(String param2) {
+        this.param2 = param2;
+    }
+}



Mime
View raw message