Merge pull request #407 from apache/WW-5017-drop-validation

[WW-5017] Drops deprecated Validation annotation as not needed
This commit is contained in:
Lukasz Lenart
2020-05-03 12:01:07 +02:00
committed by GitHub
7 changed files with 21 additions and 189 deletions
@@ -73,16 +73,6 @@ public class AnnotationValidationConfigurationBuilder {
if (a instanceof Validations) {
processValidationAnnotation(a, fieldName, methodName, result);
}
// Process single custom validator
if (a instanceof Validation) {
Validation v = (Validation) a;
if (v.validations() != null) {
for (Validations val : v.validations()) {
processValidationAnnotation(val, fieldName, methodName, result);
}
}
}
// Process single custom validator
else if (a instanceof ExpressionValidator) {
ExpressionValidator v = (ExpressionValidator) a;
@@ -1,141 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* <!-- START SNIPPET: description -->
* This annotation has been deprecated since 2.1 as its previous purpose, to define classes that support annotation validations,
* is no longer necessary.
* <!-- END SNIPPET: description -->
*
* <p><u>Annotation usage:</u></p>
*
* <!-- START SNIPPET: usage -->
* <p>The Validation annotation must be applied at Type level.</p>
* <!-- END SNIPPET: usage -->
*
* <p><u>Annotation parameters:</u></p>
*
* <!-- START SNIPPET: parameters -->
* <table class='confluenceTable' summary=''>
* <tr>
* <th class='confluenceTh'> Parameter </th>
* <th class='confluenceTh'> Required </th>
* <th class='confluenceTh'> Default </th>
* <th class='confluenceTh'> Notes </th>
* </tr>
* <tr>
* <td class='confluenceTd'>validations</td>
* <td class='confluenceTd'>yes</td>
* <td class='confluenceTd'>&nbsp;</td>
* <td class='confluenceTd'></td>
* </tr>
* </table>
* <!-- END SNIPPET: parameters -->
*
* <p><u>Example code:</u></p>
*
* <u>An Annotated Interface</u>
* <pre>
* <!-- START SNIPPET: example -->
* &#64;Validation()
* public interface AnnotationDataAware {
*
* void setBarObj(Bar b);
*
* Bar getBarObj();
*
* &#64;RequiredFieldValidator(message = "You must enter a value for data.")
* &#64;RequiredStringValidator(message = "You must enter a value for data.")
* void setData(String data);
*
* String getData();
* }
* <!-- END SNIPPET: example -->
* </pre>
*
* <p><u>Example code:</u></p>
*
* <u>An Annotated Class</u>
* <pre>
* <!-- START SNIPPET: example2 -->
* &#64;Validation()
* public class SimpleAnnotationAction extends ActionSupport {
*
* &#64;RequiredFieldValidator(type = ValidatorType.FIELD, message = "You must enter a value for bar.")
* &#64;IntRangeFieldValidator(type = ValidatorType.FIELD, min = "6", max = "10", message = "bar must be between ${min} and ${max}, current value is ${bar}.")
* public void setBar(int bar) {
* this.bar = bar;
* }
*
* public int getBar() {
* return bar;
* }
*
* &#64;Validations(
* requiredFields =
* {&#64;RequiredFieldValidator(type = ValidatorType.SIMPLE, fieldName = "customfield", message = "You must enter a value for field.")},
* requiredStrings =
* {&#64;RequiredStringValidator(type = ValidatorType.SIMPLE, fieldName = "stringisrequired", message = "You must enter a value for string.")},
* emails =
* { &#64;EmailValidator(type = ValidatorType.SIMPLE, fieldName = "emailaddress", message = "You must enter a value for email.")},
* urls =
* { &#64;UrlValidator(type = ValidatorType.SIMPLE, fieldName = "hreflocation", message = "You must enter a value for email.")},
* stringLengthFields =
* {&#64;StringLengthFieldValidator(type = ValidatorType.SIMPLE, trim = true, minLength="10" , maxLength = "12", fieldName = "needstringlength", message = "You must enter a stringlength.")},
* intRangeFields =
* { @IntRangeFieldValidator(type = ValidatorType.SIMPLE, fieldName = "intfield", min = "6", max = "10", message = "bar must be between ${min} and ${max}, current value is ${bar}.")},
* dateRangeFields =
* {&#64;DateRangeFieldValidator(type = ValidatorType.SIMPLE, fieldName = "datefield", min = "-1", max = "99", message = "bar must be between ${min} and ${max}, current value is ${bar}.")},
* expressions = {
* &#64;ExpressionValidator(expression = "foo &gt; 1", message = "Foo must be greater than Bar 1. Foo = ${foo}, Bar = ${bar}."),
* &#64;ExpressionValidator(expression = "foo &gt; 2", message = "Foo must be greater than Bar 2. Foo = ${foo}, Bar = ${bar}."),
* &#64;ExpressionValidator(expression = "foo &gt; 3", message = "Foo must be greater than Bar 3. Foo = ${foo}, Bar = ${bar}."),
* &#64;ExpressionValidator(expression = "foo &gt; 4", message = "Foo must be greater than Bar 4. Foo = ${foo}, Bar = ${bar}."),
* &#64;ExpressionValidator(expression = "foo &gt; 5", message = "Foo must be greater than Bar 5. Foo = ${foo}, Bar = ${bar}.")
* }
* )
* public String execute() throws Exception {
* return SUCCESS;
* }
* }
*
* <!-- END SNIPPET: example2 -->
* </pre>
*
* @author Rainer Hermanns
* @deprecated Since Struts 2.1 because it isn't necessary anymore
*/
@Deprecated
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface Validation {
/**
* Used for class or interface validation rules.
*
* @return array of validations
*/
Validations[] validations() default {};
}
@@ -26,12 +26,8 @@ import java.util.Properties;
/**
* Simple Test Action for annotaton processing.
*
* @author Rainer Hermanns
* @version $Revision$
* Simple Test Action for annotation processing.
*/
@Validation()
public class SimpleAnnotationAction extends ActionSupport {
//~ Static fields/initializers /////////////////////////////////////////////
@@ -24,7 +24,6 @@ import com.opensymphony.xwork2.conversion.impl.FooBarConverter;
import com.opensymphony.xwork2.util.Bar;
import com.opensymphony.xwork2.validator.annotations.RequiredFieldValidator;
import com.opensymphony.xwork2.validator.annotations.RequiredStringValidator;
import com.opensymphony.xwork2.validator.annotations.Validation;
/**
@@ -21,7 +21,11 @@ package com.opensymphony.xwork2.test;
import com.opensymphony.xwork2.conversion.annotations.ConversionRule;
import com.opensymphony.xwork2.conversion.annotations.TypeConversion;
import com.opensymphony.xwork2.util.KeyProperty;
import com.opensymphony.xwork2.validator.annotations.*;
import com.opensymphony.xwork2.validator.annotations.EmailValidator;
import com.opensymphony.xwork2.validator.annotations.ExpressionValidator;
import com.opensymphony.xwork2.validator.annotations.FieldExpressionValidator;
import com.opensymphony.xwork2.validator.annotations.RequiredFieldValidator;
import com.opensymphony.xwork2.validator.annotations.Validations;
import java.util.Collection;
import java.util.List;
@@ -30,17 +34,12 @@ import java.util.Map;
/**
* Test bean.
*
* @author Mark Woon
* @author Rainer Hermanns
*/
@Validation(
validations = @Validations(
expressions = {
@ExpressionValidator(expression = "email.startsWith('mark')", message = "Email does not start with mark"),
@ExpressionValidator(expression = "email2.startsWith('mark')", message = "Email2 does not start with mark")
}
)
@Validations(
expressions = {
@ExpressionValidator(expression = "email.startsWith('mark')", message = "Email does not start with mark"),
@ExpressionValidator(expression = "email2.startsWith('mark')", message = "Email2 does not start with mark")
}
)
public class AnnotationUser implements AnnotationUserMarker {
@@ -84,7 +83,7 @@ public class AnnotationUser implements AnnotationUserMarker {
list = l;
}
@KeyProperty( value = "name")
@KeyProperty(value = "name")
@TypeConversion(converterClass = String.class, rule = ConversionRule.COLLECTION)
public List getList() {
return list;
@@ -20,25 +20,19 @@ package com.opensymphony.xwork2.test;
import com.opensymphony.xwork2.validator.annotations.ExpressionValidator;
import com.opensymphony.xwork2.validator.annotations.RequiredFieldValidator;
import com.opensymphony.xwork2.validator.annotations.Validation;
import com.opensymphony.xwork2.validator.annotations.Validations;
/**
* Marker interface to help test hierarchy traversal.
*
* @author Mark Woon
* @author Rainer Hermanns
*/
@Validation(
validations = @Validations(
requiredFields = {
@RequiredFieldValidator(fieldName = "email", shortCircuit = true, message = "You must enter a value for email."),
@RequiredFieldValidator(fieldName = "email2", shortCircuit = true, message = "You must enter a value for email2.")
},
expressions = {
@ExpressionValidator(shortCircuit = true, expression = "email.equals(email2)", message = "Email not the same as email2" )
}
)
@Validations(
requiredFields = {
@RequiredFieldValidator(fieldName = "email", shortCircuit = true, message = "You must enter a value for email."),
@RequiredFieldValidator(fieldName = "email2", shortCircuit = true, message = "You must enter a value for email2.")
},
expressions = {
@ExpressionValidator(shortCircuit = true, expression = "email.equals(email2)", message = "Email not the same as email2")
}
)
public interface AnnotationUserMarker {
}
@@ -20,15 +20,10 @@ package com.opensymphony.xwork2.test.annotations;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.validator.annotations.ExpressionValidator;
import com.opensymphony.xwork2.validator.annotations.Validation;
/**
* <code>ValidateAnnotatedMethodOnlyAction</code>
*
* @author <a href="mailto:hermanns@aixcept.de">Rainer Hermanns</a>
* @version $Id$
*/
@Validation
public class ValidateAnnotatedMethodOnlyAction extends ActionSupport {
String param1;
@@ -52,7 +47,7 @@ public class ValidateAnnotatedMethodOnlyAction extends ActionSupport {
}
@ExpressionValidator(expression = "(param1 != null) || (param2 != null)",
message = "Need param1 or param2.")
message = "Need param1 or param2.")
public String annotatedMethod() {
try {
// do search