Commits

jcarreira  committed db5b5c5

XW-69: Removed dependence on Action Interface by Validator framework

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

  • Participants
  • Parent commits 97fbdc3

Comments (0)

Files changed (9)

File src/java/com/opensymphony/xwork/validator/Validator.java

  */
 package com.opensymphony.xwork.validator;
 
-import com.opensymphony.xwork.Action;
-
 
 /**
  * Validator
 
     String getDefaultMessage();
 
-    String getMessage(Action action);
+    String getMessage(Object object);
 
     void setMessageKey(String key);
 
     String getMessageKey();
 
-    void validate(Action action) throws ValidationException;
+    void validate(Object object) throws ValidationException;
 }

File src/java/com/opensymphony/xwork/validator/validators/AbstractRangeValidator.java

  */
 package com.opensymphony.xwork.validator.validators;
 
-import com.opensymphony.xwork.Action;
 import com.opensymphony.xwork.validator.ValidationException;
 
 
 public abstract class AbstractRangeValidator extends FieldValidatorSupport {
     //~ Methods ////////////////////////////////////////////////////////////////
 
-    public void validate(Action action) throws ValidationException {
-        Comparable value = (Comparable) this.getFieldValue(getFieldName(), action);
+    public void validate(Object object) throws ValidationException {
+        Comparable value = (Comparable) this.getFieldValue(getFieldName(), object);
 
         // if there is no value - don't do comparison
         // if a value is required, a required validator should be added to the field
 
         // only check for a minimum value if the min parameter is set
         if ((getMinComparatorValue() != null) && (value.compareTo(getMinComparatorValue()) < 0)) {
-            addFieldError(getFieldName(), action);
+            addFieldError(getFieldName(), object);
         }
 
         // only check for a maximum value if the max parameter is set
         if ((getMaxComparatorValue() != null) && (value.compareTo(getMaxComparatorValue()) > 0)) {
-            addFieldError(getFieldName(), action);
+            addFieldError(getFieldName(), object);
         }
     }
 

File src/java/com/opensymphony/xwork/validator/validators/EmailValidator.java

 
 import com.opensymphony.util.TextUtils;
 
-import com.opensymphony.xwork.Action;
 import com.opensymphony.xwork.validator.ValidationException;
 
 
 public class EmailValidator extends FieldValidatorSupport {
     //~ Methods ////////////////////////////////////////////////////////////////
 
-    public void validate(Action action) throws ValidationException {
+    public void validate(Object object) throws ValidationException {
         String fieldName = getFieldName();
-        Object value = this.getFieldValue(fieldName, action);
+        Object value = this.getFieldValue(fieldName, object);
 
         if (!(value instanceof String) || !TextUtils.verifyEmail((String) value)) {
-            addFieldError(fieldName, action);
+            addFieldError(fieldName, object);
         }
     }
 }

File src/java/com/opensymphony/xwork/validator/validators/ExpressionValidator.java

  */
 package com.opensymphony.xwork.validator.validators;
 
-import com.opensymphony.xwork.Action;
 import com.opensymphony.xwork.ActionContext;
 import com.opensymphony.xwork.util.OgnlValueStack;
 import com.opensymphony.xwork.validator.ValidationException;
         return expression;
     }
 
-    public void validate(Action action) throws ValidationException {
+    public void validate(Object object) throws ValidationException {
         Boolean answer = Boolean.FALSE;
         OgnlValueStack stack = ActionContext.getContext().getValueStack();
         Object obj = stack.findValue(expression);
         }
 
         if (!answer.booleanValue()) {
-            addActionError(action);
+            addActionError(object);
         }
     }
 }

File src/java/com/opensymphony/xwork/validator/validators/FieldExpressionValidator.java

  */
 package com.opensymphony.xwork.validator.validators;
 
-import com.opensymphony.xwork.Action;
 import com.opensymphony.xwork.ActionContext;
 import com.opensymphony.xwork.util.OgnlValueStack;
 import com.opensymphony.xwork.validator.ValidationException;
         return expression;
     }
 
-    public void validate(Action action) throws ValidationException {
+    public void validate(Object object) throws ValidationException {
         String fieldName = getFieldName();
 
         Boolean answer = Boolean.FALSE;
         }
 
         if (!answer.booleanValue()) {
-            addFieldError(fieldName, action);
+            addFieldError(fieldName, object);
         }
     }
 }

File src/java/com/opensymphony/xwork/validator/validators/RequiredFieldValidator.java

  */
 package com.opensymphony.xwork.validator.validators;
 
-import com.opensymphony.xwork.Action;
 import com.opensymphony.xwork.validator.ValidationException;
 
 
 public class RequiredFieldValidator extends FieldValidatorSupport {
     //~ Methods ////////////////////////////////////////////////////////////////
 
-    public void validate(Action action) throws ValidationException {
+    public void validate(Object object) throws ValidationException {
         String fieldName = getFieldName();
-        Object value = this.getFieldValue(fieldName, action);
+        Object value = this.getFieldValue(fieldName, object);
 
         if (value == null) {
-            addFieldError(fieldName, action);
+            addFieldError(fieldName, object);
         }
     }
 }

File src/java/com/opensymphony/xwork/validator/validators/RequiredStringValidator.java

 
 import com.opensymphony.util.TextUtils;
 
-import com.opensymphony.xwork.Action;
 import com.opensymphony.xwork.validator.ValidationException;
 
 
 public class RequiredStringValidator extends FieldValidatorSupport {
     //~ Methods ////////////////////////////////////////////////////////////////
 
-    public void validate(Action action) throws ValidationException {
+    public void validate(Object object) throws ValidationException {
         String fieldName = getFieldName();
-        Object value = this.getFieldValue(fieldName, action);
+        Object value = this.getFieldValue(fieldName, object);
 
         if (!(value instanceof String) || !TextUtils.stringSet((String) value)) {
-            addFieldError(fieldName, action);
+            addFieldError(fieldName, object);
         }
     }
 }

File src/java/com/opensymphony/xwork/validator/validators/URLValidator.java

 
 import com.opensymphony.util.TextUtils;
 
-import com.opensymphony.xwork.Action;
 import com.opensymphony.xwork.validator.ValidationException;
 
 
 public class URLValidator extends FieldValidatorSupport {
     //~ Methods ////////////////////////////////////////////////////////////////
 
-    public void validate(Action action) throws ValidationException {
+    public void validate(Object object) throws ValidationException {
         String fieldName = getFieldName();
-        Object value = this.getFieldValue(fieldName, action);
+        Object value = this.getFieldValue(fieldName, object);
 
         if (!(value instanceof String) || !TextUtils.verifyUrl((String) value)) {
-            addFieldError(fieldName, action);
+            addFieldError(fieldName, object);
         }
     }
 }

File src/java/com/opensymphony/xwork/validator/validators/ValidatorSupport.java

  */
 package com.opensymphony.xwork.validator.validators;
 
-import com.opensymphony.xwork.Action;
 import com.opensymphony.xwork.ActionContext;
 import com.opensymphony.xwork.LocaleAware;
 import com.opensymphony.xwork.ValidationAware;
         return defaultMessage;
     }
 
-    public String getMessage(Action action) {
+    public String getMessage(Object object) {
         String message;
 
-        if ((messageKey != null) && (action instanceof LocaleAware)) {
+        if ((messageKey != null) && (object instanceof LocaleAware)) {
             try {
-                LocaleAware localeAware = (LocaleAware) action;
+                LocaleAware localeAware = (LocaleAware) object;
                 message = localeAware.getText(messageKey);
             } catch (MissingResourceException e) {
                 message = defaultMessage;
         return messageKey;
     }
 
-    protected Object getFieldValue(String name, Action action) throws ValidationException {
+    protected Object getFieldValue(String name, Object object) throws ValidationException {
         try {
-            return Ognl.getValue(name, action);
+            return Ognl.getValue(name, object);
         } catch (OgnlException e) {
             final String msg = "Caught exception while getting value for field " + name;
             log.error(msg, e);
         }
     }
 
-    protected void addActionError(Action action) {
-        if (action instanceof ValidationAware) {
-            ValidationAware validationAware = (ValidationAware) action;
-            validationAware.addActionError(getMessage(action));
+    protected void addActionError(Object object) {
+        if (object instanceof ValidationAware) {
+            ValidationAware validationAware = (ValidationAware) object;
+            validationAware.addActionError(getMessage(object));
         } else {
-            log.error("Validation error: " + getMessage(action));
+            log.error("Validation error: " + getMessage(object));
         }
     }
 
-    protected void addFieldError(String propertyName, Action action) {
-        if (action instanceof ValidationAware) {
-            ValidationAware validationAction = (ValidationAware) action;
-            validationAction.addFieldError(propertyName, getMessage(action));
+    protected void addFieldError(String propertyName, Object object) {
+        if (object instanceof ValidationAware) {
+            ValidationAware validationAction = (ValidationAware) object;
+            validationAction.addFieldError(propertyName, getMessage(object));
         } else {
-            log.error("Validation error for " + propertyName + ":" + getMessage(action));
+            log.error("Validation error for " + propertyName + ":" + getMessage(object));
         }
     }
 }