WW-5544 Marks ReflectionContextFactory as deprecated and uses ActionContext instead (#1254) (#1255)

This commit is contained in:
Lukasz Lenart
2025-04-27 18:43:36 +02:00
committed by GitHub
parent 285d2d3681
commit e326799532
3 changed files with 13 additions and 10 deletions
@@ -23,6 +23,10 @@ import ognl.Ognl;
import java.util.Map;
/**
* @deprecated since 6.8.0, to be removed, see {@link ReflectionContextFactory}
*/
@Deprecated(since = "6.8.0", forRemoval = true)
public class OgnlReflectionContextFactory implements ReflectionContextFactory {
@Override
@@ -20,6 +20,10 @@ package org.apache.struts2.util.reflection;
import java.util.Map;
/**
* @deprecated since 6.8.0, avoid using this interface and any of its implementation, it's going to be removed soon
*/
@Deprecated(since = "6.8.0", forRemoval = true)
public interface ReflectionContextFactory {
/**
* Creates and returns a new standard naming context for evaluating an OGNL
@@ -25,6 +25,7 @@ import org.apache.struts2.util.reflection.ReflectionProvider;
import org.apache.struts2.validator.Validator;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.struts2.ActionContext;
import org.apache.struts2.interceptor.parameter.StrutsParameter;
import java.beans.BeanInfo;
@@ -49,19 +50,13 @@ public class ShowValidatorAction extends ListValidatorsAction {
private Set<PropertyInfo> properties = Collections.emptySet();
private int selected = 0;
ReflectionProvider reflectionProvider;
ReflectionContextFactory reflectionContextFactory;
private ReflectionProvider reflectionProvider;
@Inject
public void setReflectionProvider(ReflectionProvider prov) {
this.reflectionProvider = prov;
}
@Inject
public void setReflectionContextFactory(ReflectionContextFactory fac) {
this.reflectionContextFactory = fac;
}
public int getSelected() {
return selected;
}
@@ -85,7 +80,6 @@ public class ShowValidatorAction extends ListValidatorsAction {
Validator validator = getSelectedValidator();
properties = new TreeSet<>();
try {
Map<String, Object> context = reflectionContextFactory.createDefaultContext(validator);
BeanInfo beanInfoFrom;
try {
beanInfoFrom = Introspector.getBeanInfo(validator.getClass(), Object.class);
@@ -97,6 +91,7 @@ public class ShowValidatorAction extends ListValidatorsAction {
PropertyDescriptor[] pds = beanInfoFrom.getPropertyDescriptors();
Map<String, Object> context = ActionContext.getContext().getContextMap();
for (PropertyDescriptor pd : pds) {
String name = pd.getName();
Object value = null;
@@ -113,9 +108,9 @@ public class ShowValidatorAction extends ListValidatorsAction {
}
} catch (Exception e) {
if (LOG.isWarnEnabled()) {
LOG.warn("Unable to retrieve properties.", e);
LOG.warn("Unable to retrieve properties.", e);
}
addActionError("Unable to retrieve properties: " + e.toString());
addActionError("Unable to retrieve properties: " + e);
}
if (hasErrors()) {