1. opensymphony
  2. xwork

Commits

mrdon  committed b90a94b

Adding wildcard replacement for all action subelements except interceptor-ref
XW-390

git-svn-id: http://svn.opensymphony.com/svn/xwork/trunk@1036e221344d-f017-0410-9bd5-d282ab1896d7

  • Participants
  • Parent commits 2786212
  • Branches master

Comments (0)

Files changed (2)

File src/java/com/opensymphony/xwork/config/impl/ActionConfigMatcher.java

View file
 import org.apache.commons.logging.LogFactory;
 import com.opensymphony.xwork.util.WildcardHelper;
 import com.opensymphony.xwork.config.entities.ActionConfig;
+import com.opensymphony.xwork.config.entities.ExceptionMappingConfig;
+import com.opensymphony.xwork.config.entities.ExternalReference;
+import com.opensymphony.xwork.config.entities.ResultConfig;
 
 import java.io.Serializable;
 
         String methodName = convertParam(orig.getMethodName(), vars);
         String pkgName = convertParam(orig.getPackageName(), vars);
         
-        Map<String,Object> params = new LinkedHashMap<String,Object>();
-        replaceParameters(orig.getParams(), params, vars);
+        Map<String,Object> params = replaceParameters(orig.getParams(), vars);
+        
+        Map<String,ResultConfig> results = new LinkedHashMap<String,ResultConfig>();
+        for (String name : orig.getResults().keySet()) {
+            ResultConfig result = orig.getResults().get(name);
+            name = convertParam(name, vars);
+            String resultClassName = convertParam(result.getClassName(), vars);
+            Map<String,Object> resultParams = replaceParameters(result.getParams(), vars);
+            ResultConfig r = new ResultConfig(name, resultClassName, resultParams);
+            results.put(name, r);
+        }
+        
+        List<ExceptionMappingConfig> exs = new ArrayList<ExceptionMappingConfig>();
+        for (ExceptionMappingConfig ex : orig.getExceptionMappings()) {
+            String name = convertParam(ex.getName(), vars);
+            String exClassName = convertParam(ex.getExceptionClassName(), vars);
+            String exResult = convertParam(ex.getResult(), vars);
+            Map<String,Object> exParams = replaceParameters(ex.getParams(), vars);
+            ExceptionMappingConfig e = new ExceptionMappingConfig(name, exClassName, exResult, exParams);
+            exs.add(e);
+        }
+        
+        List<ExternalReference> refs = new ArrayList<ExternalReference>();
+        for (ExternalReference ex : orig.getExternalRefs()) {
+            String name = convertParam(ex.getName(), vars);
+            String refName = convertParam(ex.getExternalRef(), vars);
+            ExternalReference e = new ExternalReference(name, refName, ex.isRequired());
+            refs.add(e);
+        }
+        
         
         ActionConfig config = new ActionConfig(methodName, className, pkgName, 
-                params, orig.getResults(), orig.getInterceptors(), 
-                orig.getExternalRefs(), orig.getExceptionMappings());
+                params, results, orig.getInterceptors(), refs, exs);
         
         return config;
     }
      * @param map The target parameters to store the processed values
      * @param vars  A Map of wildcard-matched strings
      */
-    protected void replaceParameters(Map<String, Object> orig, 
-            Map<String, Object> map, Map vars) {
-
+    protected Map<String,Object> replaceParameters(Map<String, Object> orig, Map vars) {
+        Map<String,Object> map = new LinkedHashMap<String,Object>();
         for (String key : orig.keySet()) {
             map.put(key, convertParam(String.valueOf(orig.get(key)), vars));
         }
+        return map;
     }
 
     /**

File src/test/com/opensymphony/xwork/config/impl/ActionConfigMatcherTest.java

View file
         ActionConfig matched = matcher.match("foo/class/method");
 
         assertNotNull("ActionConfig should be matched", matched);
-        assertTrue("ActionConfig should have properties",
-            matched.getParams().size() == 2);
+        assertTrue("ActionConfig should have properties, had " +
+                matched.getParams().size(), matched.getParams().size() == 2);
         assertTrue("ActionConfig should have interceptors",
                 matched.getInterceptors().size() == 1);
         assertTrue("ActionConfig should have ex mappings",
 
         assertTrue("First param isn't correct", "class".equals(m.getParams().get("first")));
         assertTrue("Second param isn't correct", "method".equals(m.getParams().get("second")));
+        
+        ExceptionMappingConfig ex = m.getExceptionMappings().get(0);
+        assertTrue("Wrong name, was "+ex.getName(), "fooclass".equals(ex.getName()));
+        assertTrue("Wrong result", "successclass".equals(ex.getResult()));
+        assertTrue("Wrong exception", 
+                "java.lang.methodException".equals(ex.getExceptionClassName()));
+        assertTrue("First param isn't correct", "class".equals(ex.getParams().get("first")));
+        assertTrue("Second param isn't correct", "method".equals(ex.getParams().get("second")));
+        
+        ResultConfig result = m.getResults().get("successclass");
+        assertTrue("Wrong name, was "+result.getName(), "successclass".equals(result.getName()));
+        assertTrue("Wrong classname", "foo.method".equals(result.getClassName()));
+        assertTrue("First param isn't correct", "class".equals(result.getParams().get("first")));
+        assertTrue("Second param isn't correct", "method".equals(result.getParams().get("second")));
+        
+        ExternalReference ref = m.getExternalRefs().get(0);
+        assertTrue("Wrong name", "fooclass".equals(ref.getName()));
+        assertTrue("Wrong ref", "barmethod".equals(ref.getExternalRef()));
+        assertTrue("Wrong required", ref.isRequired());
     }
 
     public void testCheckMultipleSubstitutions() {
         config.setParams(params);
         map.put("foo/*/*", config);
         
-        config.addExceptionMapping(new ExceptionMappingConfig());
-        config.addExternalRef(new ExternalReference());
+        config.addExceptionMapping(new ExceptionMappingConfig(
+                "foo{1}", "java.lang.{2}Exception", "success{1}", new HashMap(params)));
+        
+        config.addExternalRef(new ExternalReference("foo{1}", "bar{2}", true));
+        
         config.addInterceptor(new InterceptorMapping());
-        config.addResultConfig(new ResultConfig());
+        
+        config.addResultConfig(new ResultConfig("success{1}", "foo.{2}", new HashMap(params)));
         
         config = new ActionConfig();