This is an automated email from the ASF dual-hosted git repository. kusal pushed a commit to branch kusal-depr-apis-2 in repository https://gitbox.apache.org/repos/asf/struts.git
commit e7da68ac47b8b96ca5de4af1f8b79db3c03f896f Author: Kusal Kithul-Godage <g...@kusal.io> AuthorDate: Thu Oct 17 14:03:44 2024 +1100 WW-3714 Deprecate and migrate ActionFactory --- .../com/opensymphony/xwork2/ObjectFactory.java | 15 ++++++++----- .../opensymphony/xwork2/factory/ActionFactory.java | 26 +++++----------------- .../config/AbstractBeanSelectionProvider.java | 10 ++++++++- .../config/StrutsBeanSelectionProvider.java | 3 ++- .../apache/struts2}/factory/ActionFactory.java | 2 +- core/src/main/resources/struts-beans.xml | 2 ++ 6 files changed, 29 insertions(+), 29 deletions(-) diff --git a/core/src/main/java/com/opensymphony/xwork2/ObjectFactory.java b/core/src/main/java/com/opensymphony/xwork2/ObjectFactory.java index 3a5c8f266..9ea62bb9d 100644 --- a/core/src/main/java/com/opensymphony/xwork2/ObjectFactory.java +++ b/core/src/main/java/com/opensymphony/xwork2/ObjectFactory.java @@ -23,7 +23,11 @@ import com.opensymphony.xwork2.config.entities.ActionConfig; import com.opensymphony.xwork2.config.entities.InterceptorConfig; import com.opensymphony.xwork2.config.entities.ResultConfig; import com.opensymphony.xwork2.conversion.TypeConverter; -import com.opensymphony.xwork2.factory.*; +import com.opensymphony.xwork2.factory.ConverterFactory; +import com.opensymphony.xwork2.factory.InterceptorFactory; +import com.opensymphony.xwork2.factory.ResultFactory; +import com.opensymphony.xwork2.factory.UnknownHandlerFactory; +import com.opensymphony.xwork2.factory.ValidatorFactory; import com.opensymphony.xwork2.inject.Container; import com.opensymphony.xwork2.inject.Inject; import com.opensymphony.xwork2.interceptor.Interceptor; @@ -32,16 +36,17 @@ import com.opensymphony.xwork2.validator.Validator; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.struts2.StrutsConstants; +import org.apache.struts2.factory.ActionFactory; import java.io.Serializable; import java.util.Map; /** - * ObjectFactory is responsible for building the core framework objects. Users may register their + * ObjectFactory is responsible for building the core framework objects. Users may register their * own implementation of the ObjectFactory to control instantiation of these Objects. * * <p> - * This default implementation uses the {@link #buildBean(Class,java.util.Map) buildBean} + * This default implementation uses the {@link #buildBean(Class,java.util.Map) buildBean} * method to create all classes (interceptors, actions, results, etc). * </p> * @@ -178,7 +183,7 @@ public class ObjectFactory implements Serializable { public Object buildBean(String className, Map<String, Object> extraContext) throws Exception { return buildBean(className, extraContext, true); } - + /** * Build a generic Java object of the given type. * @@ -260,5 +265,5 @@ public class ObjectFactory implements Serializable { public UnknownHandler buildUnknownHandler(String unknownHandlerName, Map<String, Object> extraContext) throws Exception { return unknownHandlerFactory.buildUnknownHandler(unknownHandlerName, extraContext); } - + } diff --git a/core/src/main/java/com/opensymphony/xwork2/factory/ActionFactory.java b/core/src/main/java/com/opensymphony/xwork2/factory/ActionFactory.java index 15a0f780f..c920faa97 100644 --- a/core/src/main/java/com/opensymphony/xwork2/factory/ActionFactory.java +++ b/core/src/main/java/com/opensymphony/xwork2/factory/ActionFactory.java @@ -18,28 +18,12 @@ */ package com.opensymphony.xwork2.factory; -import com.opensymphony.xwork2.config.entities.ActionConfig; - -import java.util.Map; - /** - * Used by {@link com.opensymphony.xwork2.ObjectFactory} to build actions + * {@inheritDoc} + * + * @deprecated since 6.7.0, use {@link org.apache.struts2.factory.ActionFactory} instead. */ -public interface ActionFactory { - - /** - * Builds action instance - * - * @param actionName name of the action - * @param namespace namespace for the action - * @param config action config - * @param extraContext extra context map - * - * @return action object - * - * @throws Exception in case of any errors - */ - Object buildAction(String actionName, String namespace, ActionConfig config, Map<String, Object> extraContext) throws Exception; - +@Deprecated +public interface ActionFactory extends org.apache.struts2.factory.ActionFactory { } diff --git a/core/src/main/java/org/apache/struts2/config/AbstractBeanSelectionProvider.java b/core/src/main/java/org/apache/struts2/config/AbstractBeanSelectionProvider.java index f672ae041..037558c4e 100644 --- a/core/src/main/java/org/apache/struts2/config/AbstractBeanSelectionProvider.java +++ b/core/src/main/java/org/apache/struts2/config/AbstractBeanSelectionProvider.java @@ -22,7 +22,11 @@ import com.opensymphony.xwork2.ObjectFactory; import com.opensymphony.xwork2.config.BeanSelectionProvider; import com.opensymphony.xwork2.config.Configuration; import com.opensymphony.xwork2.config.ConfigurationException; -import com.opensymphony.xwork2.inject.*; +import com.opensymphony.xwork2.inject.Container; +import com.opensymphony.xwork2.inject.ContainerBuilder; +import com.opensymphony.xwork2.inject.Context; +import com.opensymphony.xwork2.inject.Factory; +import com.opensymphony.xwork2.inject.Scope; import com.opensymphony.xwork2.util.ClassLoaderUtil; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -67,6 +71,10 @@ public abstract class AbstractBeanSelectionProvider implements BeanSelectionProv } else { try { Class cls = ClassLoaderUtil.loadClass(foundName, this.getClass()); + if (!type.isAssignableFrom(cls)) { + LOG.debug("Skipping aliasing as bean ({}) does not implement the interface ({})", foundName, type.getName()); + return; + } LOG.trace("Choosing bean ({}) for ({})", cls.getName(), type.getName()); builder.factory(type, cls, scope); } catch (ClassNotFoundException ex) { diff --git a/core/src/main/java/org/apache/struts2/config/StrutsBeanSelectionProvider.java b/core/src/main/java/org/apache/struts2/config/StrutsBeanSelectionProvider.java index a52a67749..a5ccc52c6 100644 --- a/core/src/main/java/org/apache/struts2/config/StrutsBeanSelectionProvider.java +++ b/core/src/main/java/org/apache/struts2/config/StrutsBeanSelectionProvider.java @@ -39,7 +39,6 @@ import com.opensymphony.xwork2.conversion.impl.DateConverter; import com.opensymphony.xwork2.conversion.impl.NumberConverter; import com.opensymphony.xwork2.conversion.impl.StringConverter; import com.opensymphony.xwork2.conversion.impl.XWorkConverter; -import com.opensymphony.xwork2.factory.ActionFactory; import com.opensymphony.xwork2.factory.ConverterFactory; import com.opensymphony.xwork2.factory.InterceptorFactory; import com.opensymphony.xwork2.factory.ResultFactory; @@ -69,6 +68,7 @@ import org.apache.struts2.dispatcher.DispatcherErrorHandler; import org.apache.struts2.dispatcher.StaticContentLoader; import org.apache.struts2.dispatcher.mapper.ActionMapper; import org.apache.struts2.dispatcher.multipart.MultiPartRequest; +import org.apache.struts2.factory.ActionFactory; import org.apache.struts2.interceptor.exec.ExecutorProvider; import org.apache.struts2.ognl.OgnlGuard; import org.apache.struts2.url.QueryStringBuilder; @@ -381,6 +381,7 @@ public class StrutsBeanSelectionProvider extends AbstractBeanSelectionProvider { public void register(ContainerBuilder builder, LocatableProperties props) { alias(ObjectFactory.class, StrutsConstants.STRUTS_OBJECTFACTORY, builder, props); alias(ActionFactory.class, StrutsConstants.STRUTS_OBJECTFACTORY_ACTIONFACTORY, builder, props); + alias(com.opensymphony.xwork2.factory.ActionFactory.class, StrutsConstants.STRUTS_OBJECTFACTORY_ACTIONFACTORY, builder, props); alias(ResultFactory.class, StrutsConstants.STRUTS_OBJECTFACTORY_RESULTFACTORY, builder, props); alias(ConverterFactory.class, StrutsConstants.STRUTS_OBJECTFACTORY_CONVERTERFACTORY, builder, props); alias(InterceptorFactory.class, StrutsConstants.STRUTS_OBJECTFACTORY_INTERCEPTORFACTORY, builder, props); diff --git a/core/src/main/java/com/opensymphony/xwork2/factory/ActionFactory.java b/core/src/main/java/org/apache/struts2/factory/ActionFactory.java similarity index 97% copy from core/src/main/java/com/opensymphony/xwork2/factory/ActionFactory.java copy to core/src/main/java/org/apache/struts2/factory/ActionFactory.java index 15a0f780f..43458d65e 100644 --- a/core/src/main/java/com/opensymphony/xwork2/factory/ActionFactory.java +++ b/core/src/main/java/org/apache/struts2/factory/ActionFactory.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package com.opensymphony.xwork2.factory; +package org.apache.struts2.factory; import com.opensymphony.xwork2.config.entities.ActionConfig; diff --git a/core/src/main/resources/struts-beans.xml b/core/src/main/resources/struts-beans.xml index 5c3121f77..22ae11985 100644 --- a/core/src/main/resources/struts-beans.xml +++ b/core/src/main/resources/struts-beans.xml @@ -39,6 +39,8 @@ <bean class="com.opensymphony.xwork2.ObjectFactory" name="struts"/> <bean type="com.opensymphony.xwork2.factory.ResultFactory" name="struts" class="org.apache.struts2.factory.StrutsResultFactory"/> + <bean type="org.apache.struts2.factory.ActionFactory" name="struts" + class="com.opensymphony.xwork2.factory.DefaultActionFactory"/> <bean type="com.opensymphony.xwork2.factory.ActionFactory" name="struts" class="com.opensymphony.xwork2.factory.DefaultActionFactory"/> <bean type="com.opensymphony.xwork2.factory.ConverterFactory" name="struts"