diff --git a/core/src/main/java/com/opensymphony/xwork2/interceptor/ValidationAware.java b/core/src/main/java/com/opensymphony/xwork2/interceptor/ValidationAware.java index c959f19d77..aa9e6f5ff4 100644 --- a/core/src/main/java/com/opensymphony/xwork2/interceptor/ValidationAware.java +++ b/core/src/main/java/com/opensymphony/xwork2/interceptor/ValidationAware.java @@ -18,9 +18,89 @@ */ package com.opensymphony.xwork2.interceptor; +import java.util.Collection; +import java.util.List; +import java.util.Map; + /** * @deprecated since 6.7.0, use {@link org.apache.struts2.interceptor.ValidationAware} instead. */ @Deprecated public interface ValidationAware extends org.apache.struts2.interceptor.ValidationAware { + + static ValidationAware adapt(org.apache.struts2.interceptor.ValidationAware actualValidation) { + if (actualValidation instanceof ValidationAware) { + return (ValidationAware) actualValidation; + } + return actualValidation != null ? new LegacyAdapter(actualValidation) : null; + } + + class LegacyAdapter implements ValidationAware { + + private final org.apache.struts2.interceptor.ValidationAware adaptee; + + private LegacyAdapter(org.apache.struts2.interceptor.ValidationAware adaptee) { + this.adaptee = adaptee; + } + + @Override + public void setActionErrors(Collection errorMessages) { + adaptee.setActionErrors(errorMessages); + } + + @Override + public Collection getActionErrors() { + return adaptee.getActionErrors(); + } + + @Override + public void setActionMessages(Collection messages) { + adaptee.setActionMessages(messages); + } + + @Override + public Collection getActionMessages() { + return adaptee.getActionMessages(); + } + + @Override + public void setFieldErrors(Map> errorMap) { + adaptee.setFieldErrors(errorMap); + } + + @Override + public Map> getFieldErrors() { + return adaptee.getFieldErrors(); + } + + @Override + public void addActionError(String anErrorMessage) { + adaptee.addActionError(anErrorMessage); + } + + @Override + public void addActionMessage(String aMessage) { + adaptee.addActionMessage(aMessage); + } + + @Override + public void addFieldError(String fieldName, String errorMessage) { + adaptee.addFieldError(fieldName, errorMessage); + } + + @Override + public boolean hasActionErrors() { + return adaptee.hasActionErrors(); + } + + @Override + public boolean hasActionMessages() { + return adaptee.hasActionMessages(); + } + + @Override + public boolean hasFieldErrors() { + return adaptee.hasFieldErrors(); + } + } } diff --git a/core/src/main/java/com/opensymphony/xwork2/validator/DelegatingValidatorContext.java b/core/src/main/java/com/opensymphony/xwork2/validator/DelegatingValidatorContext.java index bc8c88875c..b0b41e7196 100644 --- a/core/src/main/java/com/opensymphony/xwork2/validator/DelegatingValidatorContext.java +++ b/core/src/main/java/com/opensymphony/xwork2/validator/DelegatingValidatorContext.java @@ -18,13 +18,23 @@ */ package com.opensymphony.xwork2.validator; -import com.opensymphony.xwork2.*; +import com.opensymphony.xwork2.ActionContext; +import com.opensymphony.xwork2.CompositeTextProvider; +import com.opensymphony.xwork2.LocaleProvider; +import com.opensymphony.xwork2.LocaleProviderFactory; +import com.opensymphony.xwork2.StrutsTextProviderFactory; +import com.opensymphony.xwork2.TextProvider; +import com.opensymphony.xwork2.TextProviderFactory; import com.opensymphony.xwork2.interceptor.ValidationAware; import com.opensymphony.xwork2.util.ValueStack; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import java.util.*; +import java.util.Collection; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.ResourceBundle; /** * A default implementation of the {@link ValidatorContext} interface. @@ -233,8 +243,8 @@ protected static LocaleProvider makeLocaleProvider(Object object) { } protected static ValidationAware makeValidationAware(Object object) { - if (object instanceof ValidationAware) { - return (ValidationAware) object; + if (object instanceof org.apache.struts2.interceptor.ValidationAware) { + return ValidationAware.adapt((org.apache.struts2.interceptor.ValidationAware) object); } else { return new LoggingValidationAware(object); }