Index: com/opensymphony/xwork/DefaultActionInvocation.java =================================================================== RCS file: /cvs/xwork/src/java/com/opensymphony/xwork/DefaultActionInvocation.java,v retrieving revision 1.44 diff -u -r1.44 DefaultActionInvocation.java --- com/opensymphony/xwork/DefaultActionInvocation.java 5 Mar 2006 20:48:56 -0000 1.44 +++ com/opensymphony/xwork/DefaultActionInvocation.java 6 Mar 2006 17:06:13 -0000 @@ -6,6 +6,7 @@ import com.opensymphony.xwork.config.entities.ActionConfig; import com.opensymphony.xwork.config.entities.ResultConfig; +import com.opensymphony.xwork.config.entities.InterceptorMapping; import com.opensymphony.xwork.interceptor.Interceptor; import com.opensymphony.xwork.interceptor.PreResultListener; import com.opensymphony.xwork.util.OgnlValueStack; @@ -155,7 +156,6 @@ ResultConfig resultConfig = null; - System.out.println("results: " + results); synchronized (config) { try { resultConfig = (ResultConfig) results.get(resultCode); @@ -185,8 +185,8 @@ } if (interceptors.hasNext()) { - Interceptor interceptor = (Interceptor) interceptors.next(); - resultCode = interceptor.intercept(this); + InterceptorMapping interceptor = (InterceptorMapping) interceptors.next(); + resultCode = interceptor.getInterceptor().intercept(this); } else { resultCode = invokeActionOnly(); } Index: com/opensymphony/xwork/config/entities/ActionConfig.java =================================================================== RCS file: /cvs/xwork/src/java/com/opensymphony/xwork/config/entities/ActionConfig.java,v retrieving revision 1.18 diff -u -r1.18 ActionConfig.java --- com/opensymphony/xwork/config/entities/ActionConfig.java 4 Mar 2006 09:59:15 -0000 1.18 +++ com/opensymphony/xwork/config/entities/ActionConfig.java 6 Mar 2006 17:06:13 -0000 @@ -22,7 +22,8 @@ *
interceptor-stack tag.
*
* @author Mike
+ * @author Rainer Hermanns
*/
public class InterceptorStackConfig implements InterceptorListHolder, Serializable {
@@ -47,7 +48,7 @@
return name;
}
- public void addInterceptor(Interceptor interceptor) {
+ public void addInterceptor(InterceptorMapping interceptor) {
this.interceptors.add(interceptor);
}
Index: com/opensymphony/xwork/config/providers/InterceptorBuilder.java
===================================================================
RCS file: /cvs/xwork/src/java/com/opensymphony/xwork/config/providers/InterceptorBuilder.java,v
retrieving revision 1.9
diff -u -r1.9 InterceptorBuilder.java
--- com/opensymphony/xwork/config/providers/InterceptorBuilder.java 4 Mar 2006 09:59:16 -0000 1.9
+++ com/opensymphony/xwork/config/providers/InterceptorBuilder.java 6 Mar 2006 17:06:13 -0000
@@ -5,22 +5,23 @@
package com.opensymphony.xwork.config.providers;
import com.opensymphony.xwork.ObjectFactory;
+import com.opensymphony.xwork.interceptor.Interceptor;
import com.opensymphony.xwork.config.ConfigurationException;
import com.opensymphony.xwork.config.entities.InterceptorConfig;
import com.opensymphony.xwork.config.entities.InterceptorStackConfig;
import com.opensymphony.xwork.config.entities.PackageConfig;
+import com.opensymphony.xwork.config.entities.InterceptorMapping;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
/**
* Builds a list of interceptors referenced by the refName in the supplied PackageConfig.
*
* @author Mike
+ * @author Rainer Hermanns
*/
public class InterceptorBuilder {
@@ -44,17 +45,76 @@
LOG.error("Unable to find interceptor class referenced by ref-name " + refName);
} else {
if (referencedConfig instanceof InterceptorConfig) {
- result.add(ObjectFactory.getObjectFactory().buildInterceptor((InterceptorConfig) referencedConfig, refParams));
+ result.add(new InterceptorMapping(refName, ObjectFactory.getObjectFactory().buildInterceptor((InterceptorConfig) referencedConfig, refParams)));
} else if (referencedConfig instanceof InterceptorStackConfig) {
InterceptorStackConfig stackConfig = (InterceptorStackConfig) referencedConfig;
if ((refParams != null) && (refParams.size() > 0)) {
- LOG.warn("Interceptor-ref params are being ignored because they are applied to an Interceptor-Stack reference. Ref name = " + refName + ", params = " + refParams);
+ result = constructParameterizedInterceptorReferences(packageConfig, stackConfig, refParams);
+ } else {
+ result.addAll(stackConfig.getInterceptors());
}
- result.addAll(stackConfig.getInterceptors());
} else {
LOG.error("Got unexpected type for interceptor " + refName + ". Got " + referencedConfig);
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * Builds a list of interceptors referenced by the refName in the supplied PackageConfig overriding the properties
+ * of the referenced interceptor with refParams.
+ *
+ * @param packageConfig
+ * @param stackConfig
+ * @param refParams The overridden interceptor properies
+ * @return list of interceptors referenced by the refName in the supplied PackageConfig overridden with refParams.
+ */
+ private static List constructParameterizedInterceptorReferences(PackageConfig packageConfig, InterceptorStackConfig stackConfig, Map refParams) {
+ List result;
+ Map params = new HashMap();
+
+ for ( Iterator iter = refParams.keySet().iterator(); iter.hasNext();) {
+ String key = (String) iter.next();
+ String value = (String) refParams.get(key);
+
+ try {
+ String name = key.substring(0, key.indexOf('.'));
+ key = key.substring(key.indexOf('.') + 1);
+
+ Map map;
+ if ( params.containsKey(name)) {
+ map = (Map) params.get(name);
+ } else {
+ map = new HashMap();
+ }
+
+ map.put(key, value);
+ params.put(name, map);
+
+ } catch (Exception e) {
+ LOG.warn("No interceptor found for name = " + key);
+ }
+ }
+
+ result = (ArrayList) stackConfig.getInterceptors();
+
+ for ( Iterator iter = params.keySet().iterator(); iter.hasNext();) {
+
+ String key = (String) iter.next();
+ Map map = (Map) params.get(key);
+
+ InterceptorConfig cfg = (InterceptorConfig) packageConfig.getAllInterceptorConfigs().get(key);
+ Interceptor interceptor = ObjectFactory.getObjectFactory().buildInterceptor(cfg, map);
+
+ InterceptorMapping mapping = new InterceptorMapping(key, interceptor);
+ if ( result != null && result.contains(mapping)) {
+ int index = result.indexOf(mapping);
+ result.set(index, mapping);
+ } else {
+ result.add(mapping);
}
}