struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lukaszlen...@apache.org
Subject git commit: WW-4167 Renames based class to match the rest based classes and marks extending validators as final to avoid users' confusion
Date Fri, 11 Jul 2014 20:21:59 GMT
Repository: struts
Updated Branches:
  refs/heads/develop 1dcf58537 -> 351263a67


WW-4167 Renames based class to match the rest based classes
and marks extending validators as final to avoid users' confusion


Project: http://git-wip-us.apache.org/repos/asf/struts/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/351263a6
Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/351263a6
Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/351263a6

Branch: refs/heads/develop
Commit: 351263a679dd72dc30e700d7eeed77f89e5bafac
Parents: 1dcf585
Author: Lukasz Lenart <lukaszlenart@apache.org>
Authored: Fri Jul 11 22:21:36 2014 +0200
Committer: Lukasz Lenart <lukaszlenart@apache.org>
Committed: Fri Jul 11 22:21:36 2014 +0200

----------------------------------------------------------------------
 .../validators/AbstractRangeValidator.java      | 110 -------------------
 .../validators/DateRangeFieldValidator.java     |   2 +-
 .../validators/IntRangeFieldValidator.java      |   2 +-
 .../validators/LongRangeFieldValidator.java     |   2 +-
 .../validators/RangeValidatorSupport.java       | 106 ++++++++++++++++++
 .../validators/ShortRangeFieldValidator.java    |   2 +-
 6 files changed, 110 insertions(+), 114 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/351263a6/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/AbstractRangeValidator.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/AbstractRangeValidator.java
b/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/AbstractRangeValidator.java
deleted file mode 100644
index aa17a0e..0000000
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/AbstractRangeValidator.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Copyright 2002-2006,2009 The Apache Software Foundation.
- * 
- * Licensed 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 com.opensymphony.xwork2.validator.validators;
-
-import com.opensymphony.xwork2.util.logging.Logger;
-import com.opensymphony.xwork2.util.logging.LoggerFactory;
-import com.opensymphony.xwork2.validator.ValidationException;
-import org.apache.commons.lang3.StringUtils;
-
-
-/**
- * Base class for range based validators.
- *
- * @author Jason Carreira
- * @author Cameron Braid
- */
-public abstract class AbstractRangeValidator<T extends Comparable> extends FieldValidatorSupport
{
-
-    private static final Logger LOG = LoggerFactory.getLogger(AbstractRangeValidator.class);
-
-    private final Class<T> type;
-
-    private T min;
-    private String minExpression;
-    private T max;
-    private String maxExpression;
-
-    protected AbstractRangeValidator(Class<T> type) {
-        this.type = type;
-    }
-
-    public void validate(Object object) throws ValidationException {
-        Object obj = getFieldValue(getFieldName(), object);
-        Comparable<T> value = (Comparable<T>) obj;
-
-        // if there is no value - don't do comparison
-        // if a value is required, a required validator should be added to the field
-        if (value == null) {
-            return;
-        }
-
-        // only check for a minimum value if the min parameter is set
-        T minComparatorValue = getMin();
-        if ((minComparatorValue != null) && (value.compareTo(minComparatorValue)
< 0)) {
-            addFieldError(getFieldName(), object);
-        }
-
-        // only check for a maximum value if the max parameter is set
-        T maxComparatorValue = getMax();
-        if ((maxComparatorValue != null) && (value.compareTo(maxComparatorValue)
> 0)) {
-            addFieldError(getFieldName(), object);
-        }
-    }
-
-    public void setMin(T min) {
-        this.min = min;
-    }
-
-    public T getMin() {
-        if (min != null) {
-            return min;
-        } else if (StringUtils.isNotEmpty(minExpression)) {
-            return (T) parse(minExpression, type);
-        } else {
-            return null;
-        }
-    }
-
-    public void setMinExpression(String minExpression) {
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("${minExpression} was defined as [#0]", minExpression);
-        }
-        this.minExpression = minExpression;
-    }
-
-    public void setMax(T max) {
-        this.max = max;
-    }
-
-    public T getMax() {
-        if (max != null) {
-            return max;
-        } else if (StringUtils.isNotEmpty(maxExpression)) {
-            return (T) parse(maxExpression, type);
-        } else {
-            return null;
-        }
-    }
-
-    public void setMaxExpression(String maxExpression) {
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("${maxExpression} was defined as [#0]", maxExpression);
-        }
-        this.maxExpression = maxExpression;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/struts/blob/351263a6/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/DateRangeFieldValidator.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/DateRangeFieldValidator.java
b/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/DateRangeFieldValidator.java
index cee2987..572d307 100644
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/DateRangeFieldValidator.java
+++ b/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/DateRangeFieldValidator.java
@@ -86,7 +86,7 @@ import java.util.Date;
  * @author Jason Carreira
  * @version $Date$ $Id$
  */
-public class DateRangeFieldValidator extends AbstractRangeValidator<Date> {
+public final class DateRangeFieldValidator extends RangeValidatorSupport<Date> {
 
     public DateRangeFieldValidator() {
         super(Date.class);

http://git-wip-us.apache.org/repos/asf/struts/blob/351263a6/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/IntRangeFieldValidator.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/IntRangeFieldValidator.java
b/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/IntRangeFieldValidator.java
index dd3252f..bcc95d4 100644
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/IntRangeFieldValidator.java
+++ b/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/IntRangeFieldValidator.java
@@ -74,7 +74,7 @@ package com.opensymphony.xwork2.validator.validators;
  * @author Jason Carreira
  * @version $Date$ $Id$
  */
-public class IntRangeFieldValidator extends AbstractRangeValidator<Integer> {
+public final class IntRangeFieldValidator extends RangeValidatorSupport<Integer> {
 
     public IntRangeFieldValidator() {
         super(Integer.class);

http://git-wip-us.apache.org/repos/asf/struts/blob/351263a6/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/LongRangeFieldValidator.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/LongRangeFieldValidator.java
b/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/LongRangeFieldValidator.java
index a743aa9..d5503c3 100644
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/LongRangeFieldValidator.java
+++ b/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/LongRangeFieldValidator.java
@@ -73,7 +73,7 @@ package com.opensymphony.xwork2.validator.validators;
  *
  * @version $Date$
  */
-public class LongRangeFieldValidator extends AbstractRangeValidator<Long> {
+public final class LongRangeFieldValidator extends RangeValidatorSupport<Long> {
 
     public LongRangeFieldValidator() {
         super(Long.class);

http://git-wip-us.apache.org/repos/asf/struts/blob/351263a6/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/RangeValidatorSupport.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/RangeValidatorSupport.java
b/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/RangeValidatorSupport.java
new file mode 100644
index 0000000..22eb341
--- /dev/null
+++ b/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/RangeValidatorSupport.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright 2002-2006,2009 The Apache Software Foundation.
+ * 
+ * Licensed 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 com.opensymphony.xwork2.validator.validators;
+
+import com.opensymphony.xwork2.util.logging.Logger;
+import com.opensymphony.xwork2.util.logging.LoggerFactory;
+import com.opensymphony.xwork2.validator.ValidationException;
+import org.apache.commons.lang3.StringUtils;
+
+/**
+ * Base class for range based validators. Use this class to develop any other custom range
validators.
+ */
+public abstract class RangeValidatorSupport<T extends Comparable> extends FieldValidatorSupport
{
+
+    private static final Logger LOG = LoggerFactory.getLogger(RangeValidatorSupport.class);
+
+    private final Class<T> type;
+
+    private T min;
+    private String minExpression;
+    private T max;
+    private String maxExpression;
+
+    protected RangeValidatorSupport(Class<T> type) {
+        this.type = type;
+    }
+
+    public void validate(Object object) throws ValidationException {
+        Object obj = getFieldValue(getFieldName(), object);
+        Comparable<T> value = (Comparable<T>) obj;
+
+        // if there is no value - don't do comparison
+        // if a value is required, a required validator should be added to the field
+        if (value == null) {
+            return;
+        }
+
+        // only check for a minimum value if the min parameter is set
+        T minComparatorValue = getMin();
+        if ((minComparatorValue != null) && (value.compareTo(minComparatorValue)
< 0)) {
+            addFieldError(getFieldName(), object);
+        }
+
+        // only check for a maximum value if the max parameter is set
+        T maxComparatorValue = getMax();
+        if ((maxComparatorValue != null) && (value.compareTo(maxComparatorValue)
> 0)) {
+            addFieldError(getFieldName(), object);
+        }
+    }
+
+    public void setMin(T min) {
+        this.min = min;
+    }
+
+    public T getMin() {
+        if (min != null) {
+            return min;
+        } else if (StringUtils.isNotEmpty(minExpression)) {
+            return (T) parse(minExpression, type);
+        } else {
+            return null;
+        }
+    }
+
+    public void setMinExpression(String minExpression) {
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("${minExpression} was defined as [#0]", minExpression);
+        }
+        this.minExpression = minExpression;
+    }
+
+    public void setMax(T max) {
+        this.max = max;
+    }
+
+    public T getMax() {
+        if (max != null) {
+            return max;
+        } else if (StringUtils.isNotEmpty(maxExpression)) {
+            return (T) parse(maxExpression, type);
+        } else {
+            return null;
+        }
+    }
+
+    public void setMaxExpression(String maxExpression) {
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("${maxExpression} was defined as [#0]", maxExpression);
+        }
+        this.maxExpression = maxExpression;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/struts/blob/351263a6/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/ShortRangeFieldValidator.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/ShortRangeFieldValidator.java
b/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/ShortRangeFieldValidator.java
index b4bf866..24a20e2 100644
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/ShortRangeFieldValidator.java
+++ b/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/ShortRangeFieldValidator.java
@@ -73,7 +73,7 @@ package com.opensymphony.xwork2.validator.validators;
  *
  * @version $Date$
  */
-public class ShortRangeFieldValidator extends AbstractRangeValidator<Short> {
+public final class ShortRangeFieldValidator extends RangeValidatorSupport<Short> {
 
     public ShortRangeFieldValidator() {
         super(Short.class);


Mime
View raw message