This is an automated email from the ASF dual-hosted git repository.

kusal pushed a commit to branch WW-5381-method-accessor
in repository https://gitbox.apache.org/repos/asf/struts.git

commit 588d6fcc5c15a200d230ca051f75e87f0cb5c632
Author: Kusal Kithul-Godage <g...@kusal.io>
AuthorDate: Fri Dec 29 14:06:28 2023 +1100

    WW-5381 Introduce extension point for MethodAccessor
---
 .../config/providers/StrutsDefaultConfigurationProvider.java  |  2 +-
 .../com/opensymphony/xwork2/ognl/OgnlValueStackFactory.java   | 11 +++++------
 core/src/main/java/org/apache/struts2/StrutsConstants.java    |  3 +++
 .../apache/struts2/config/StrutsBeanSelectionProvider.java    |  2 ++
 core/src/main/resources/struts-beans.xml                      |  2 +-
 5 files changed, 12 insertions(+), 8 deletions(-)

diff --git 
a/core/src/main/java/com/opensymphony/xwork2/config/providers/StrutsDefaultConfigurationProvider.java
 
b/core/src/main/java/com/opensymphony/xwork2/config/providers/StrutsDefaultConfigurationProvider.java
index bf537899a..fdad8f020 100644
--- 
a/core/src/main/java/com/opensymphony/xwork2/config/providers/StrutsDefaultConfigurationProvider.java
+++ 
b/core/src/main/java/com/opensymphony/xwork2/config/providers/StrutsDefaultConfigurationProvider.java
@@ -142,7 +142,7 @@ public class StrutsDefaultConfigurationProvider implements 
ConfigurationProvider
                 .factory(PropertyAccessor.class, 
HttpParameters.class.getName(), HttpParametersPropertyAccessor.class, 
Scope.SINGLETON)
                 .factory(PropertyAccessor.class, Parameter.class.getName(), 
ParameterPropertyAccessor.class, Scope.SINGLETON)
 
-                .factory(MethodAccessor.class, Object.class.getName(), 
XWorkMethodAccessor.class, Scope.SINGLETON)
+                .factory(MethodAccessor.class, XWorkMethodAccessor.class, 
Scope.SINGLETON)
 
                 .factory(NullHandler.class, Object.class.getName(), 
InstantiatingNullHandler.class, Scope.SINGLETON)
                 .factory(ActionValidatorManager.class, 
AnnotationActionValidatorManager.class, Scope.SINGLETON)
diff --git 
a/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlValueStackFactory.java 
b/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlValueStackFactory.java
index 088caa001..b1d6ea499 100644
--- a/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlValueStackFactory.java
+++ b/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlValueStackFactory.java
@@ -57,6 +57,11 @@ public class OgnlValueStackFactory implements 
ValueStackFactory {
         OgnlRuntime.setMethodAccessor(CompoundRoot.class, 
compoundRootAccessor);
     }
 
+    @Inject
+    protected void setMethodAccessor(MethodAccessor methodAccessor) {
+        OgnlRuntime.setMethodAccessor(Object.class, methodAccessor);
+    }
+
     @Inject("system")
     protected void setTextProvider(TextProvider textProvider) {
         this.textProvider = textProvider;
@@ -87,12 +92,6 @@ public class OgnlValueStackFactory implements 
ValueStackFactory {
             OgnlRuntime.setPropertyAccessor(cls, 
container.getInstance(PropertyAccessor.class, name));
         }
 
-        names = container.getInstanceNames(MethodAccessor.class);
-        for (String name : names) {
-            Class<?> cls = Class.forName(name);
-            OgnlRuntime.setMethodAccessor(cls, 
container.getInstance(MethodAccessor.class, name));
-        }
-
         names = container.getInstanceNames(NullHandler.class);
         for (String name : names) {
             Class<?> cls = Class.forName(name);
diff --git a/core/src/main/java/org/apache/struts2/StrutsConstants.java 
b/core/src/main/java/org/apache/struts2/StrutsConstants.java
index f39258613..939b3bddb 100644
--- a/core/src/main/java/org/apache/struts2/StrutsConstants.java
+++ b/core/src/main/java/org/apache/struts2/StrutsConstants.java
@@ -223,6 +223,9 @@ public final class StrutsConstants {
     /** Extension point for the Struts CompoundRootAccessor */
     public static final String STRUTS_COMPOUND_ROOT_ACCESSOR = 
"struts.compoundRootAccessor";
 
+    /** Extension point for the Struts MethodAccessor */
+    public static final String STRUTS_METHOD_ACCESSOR = 
"struts.methodAccessor";
+
     /** The name of the xwork converter implementation */
     public static final String STRUTS_XWORKCONVERTER = "struts.xworkConverter";
 
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 4895fc6f8..a52a67749 100644
--- 
a/core/src/main/java/org/apache/struts2/config/StrutsBeanSelectionProvider.java
+++ 
b/core/src/main/java/org/apache/struts2/config/StrutsBeanSelectionProvider.java
@@ -61,6 +61,7 @@ import 
com.opensymphony.xwork2.util.location.LocatableProperties;
 import com.opensymphony.xwork2.util.reflection.ReflectionContextFactory;
 import com.opensymphony.xwork2.util.reflection.ReflectionProvider;
 import com.opensymphony.xwork2.validator.ActionValidatorManager;
+import ognl.MethodAccessor;
 import org.apache.struts2.StrutsConstants;
 import org.apache.struts2.components.UrlRenderer;
 import org.apache.struts2.components.date.DateFormatter;
@@ -389,6 +390,7 @@ public class StrutsBeanSelectionProvider extends 
AbstractBeanSelectionProvider {
         alias(FileManagerFactory.class, 
StrutsConstants.STRUTS_FILE_MANAGER_FACTORY, builder, props, Scope.SINGLETON);
 
         alias(RootAccessor.class, 
StrutsConstants.STRUTS_COMPOUND_ROOT_ACCESSOR, builder, props);
+        alias(MethodAccessor.class, StrutsConstants.STRUTS_METHOD_ACCESSOR, 
builder, props);
 
         alias(XWorkConverter.class, StrutsConstants.STRUTS_XWORKCONVERTER, 
builder, props);
         alias(CollectionConverter.class, 
StrutsConstants.STRUTS_CONVERTER_COLLECTION, builder, props);
diff --git a/core/src/main/resources/struts-beans.xml 
b/core/src/main/resources/struts-beans.xml
index 506f9d122..3343b6386 100644
--- a/core/src/main/resources/struts-beans.xml
+++ b/core/src/main/resources/struts-beans.xml
@@ -198,7 +198,7 @@
     <bean type="ognl.PropertyAccessor" 
name="org.apache.struts2.dispatcher.Parameter"
           
class="com.opensymphony.xwork2.ognl.accessor.ParameterPropertyAccessor"/>
 
-    <bean type="ognl.MethodAccessor" name="java.lang.Object"
+    <bean type="ognl.MethodAccessor" name="struts"
           class="com.opensymphony.xwork2.ognl.accessor.XWorkMethodAccessor"/>
 
     <bean type="org.apache.struts2.dispatcher.StaticContentLoader"

Reply via email to