Commits

Anonymous committed 5fa3735

Method Specification for Validation
Issue number: WW-1093
Obtained from:
Submitted by:
Reviewed by:

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

Comments (0)

Files changed (2)

src/java/com/opensymphony/xwork/interceptor/DefaultWorkflowInterceptor.java

  * </pre>
  *
  * @author Jason Carreira
+ * @author Rainer Hermanns
  */
 public class DefaultWorkflowInterceptor implements Interceptor {
 
     Log log = LogFactory.getLog(this.getClass());
 
     Set excludeMethods = Collections.EMPTY_SET;
+    Set includeMethods = Collections.EMPTY_SET;
 
     public void setExcludeMethods(String excludeMethods) {
         this.excludeMethods = TextParseUtil.commaDelimitedStringToSet(excludeMethods);
     }
 
+    public void setIncludeMethods(String includeMethods) {
+        this.includeMethods = TextParseUtil.commaDelimitedStringToSet(includeMethods);
+    }
+
     public String intercept(ActionInvocation invocation) throws Exception {
     	String method = invocation.getProxy().getMethod();
-        if (excludeMethods.contains(method)) {
-            log.debug("Skipping workflow. Method ["+method+"]found in exclude list.");
+        if (excludeMethods.contains(method) && !includeMethods.contains(method)) {
+            log.debug("Skipping workflow. Method ["+method+"] found in exclude list.");
             return invocation.invoke();
         }
 
-        Object action = invocation.getAction();
+        if ( includeMethods.size() == 0 || includeMethods.contains(method) ) {
+            Object action = invocation.getAction();
 
-        if (action instanceof Validateable) {
-            Validateable validateable = (Validateable) action;
-            validateable.validate();
-        }
+            if (action instanceof Validateable) {
+                Validateable validateable = (Validateable) action;
+                validateable.validate();
+            }
 
-        if (action instanceof ValidationAware) {
-            ValidationAware validationAwareAction = (ValidationAware) action;
+            if (action instanceof ValidationAware) {
+                ValidationAware validationAwareAction = (ValidationAware) action;
 
-            if (validationAwareAction.hasErrors()) {
-                return Action.INPUT;
+                if (validationAwareAction.hasErrors()) {
+                    return Action.INPUT;
+                }
             }
         }
 

src/java/com/opensymphony/xwork/validator/ValidationInterceptor.java

 public class ValidationInterceptor extends AroundInterceptor {
 
     Set excludeMethods = Collections.EMPTY_SET;
+    Set includeMethods = Collections.EMPTY_SET;
 
     public void setExcludeMethods(String excludeMethods) {
         this.excludeMethods = TextParseUtil.commaDelimitedStringToSet(excludeMethods);
     }
 
+    public void setIncludeMethods(String includeMethods) {
+        this.includeMethods = TextParseUtil.commaDelimitedStringToSet(includeMethods);
+    }
+
     protected void after(ActionInvocation dispatcher, String result) throws Exception {
     }
 
      */
     protected void before(ActionInvocation invocation) throws Exception {
     	String method = invocation.getProxy().getMethod();
-        if (excludeMethods.contains(method)) {
+        if (excludeMethods.contains(method) && !includeMethods.contains(method)) {
             log.debug("Skipping validation. Method ["+method+"] found in exclude list.");
             return;
         }
 
-        Object action = invocation.getAction();
-        String context = invocation.getProxy().getActionName();
+        if ( includeMethods.size() == 0 || includeMethods.contains(method) ) {
+            Object action = invocation.getAction();
+            String context = invocation.getProxy().getActionName();
 
-        if (log.isDebugEnabled()) {
-            log.debug("Validating "
-                    + invocation.getProxy().getNamespace() + "/" + invocation.getProxy().getActionName() + ".");
-        }
+            if (log.isDebugEnabled()) {
+                log.debug("Validating "
+                        + invocation.getProxy().getNamespace() + "/" + invocation.getProxy().getActionName() + ".");
+            }
 
-        ActionValidatorManagerFactory.getInstance().validate(action, context);
+            ActionValidatorManagerFactory.getInstance().validate(action, context);
+        }
     }
+
 }