struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lukaszlen...@apache.org
Subject [2/6] struts git commit: Hides Spring concepts behind ProxyUtil
Date Tue, 20 Jun 2017 10:45:21 GMT
Hides Spring concepts behind ProxyUtil


Project: http://git-wip-us.apache.org/repos/asf/struts/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/56f31bec
Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/56f31bec
Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/56f31bec

Branch: refs/heads/master
Commit: 56f31bec42365c31788739a14c89343b9db65605
Parents: 2a8a686
Author: Yasser Zamani <yasser.zamani@live.com>
Authored: Wed Jun 14 15:35:29 2017 +0430
Committer: Yasser Zamani <yasser.zamani@live.com>
Committed: Wed Jun 14 15:35:29 2017 +0430

----------------------------------------------------------------------
 .../xwork2/interceptor/ChainingInterceptor.java |  4 +--
 .../xwork2/ognl/SecurityMemberAccess.java       |  4 +--
 .../com/opensymphony/xwork2/util/ProxyUtil.java | 32 ++++++++++++++++++--
 .../xwork2/spring/SpringProxyUtilTest.java      | 28 ++++++++---------
 4 files changed, 48 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/56f31bec/core/src/main/java/com/opensymphony/xwork2/interceptor/ChainingInterceptor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/com/opensymphony/xwork2/interceptor/ChainingInterceptor.java
b/core/src/main/java/com/opensymphony/xwork2/interceptor/ChainingInterceptor.java
index 430edcc..67f5939 100644
--- a/core/src/main/java/com/opensymphony/xwork2/interceptor/ChainingInterceptor.java
+++ b/core/src/main/java/com/opensymphony/xwork2/interceptor/ChainingInterceptor.java
@@ -164,8 +164,8 @@ public class ChainingInterceptor extends AbstractInterceptor {
             if (shouldCopy(object)) {
                 Object action = invocation.getAction();
                 Class<?> editable = null;
-                if(ProxyUtil.isSpringAopProxy(action)) {
-                    editable = ProxyUtil.springUltimateTargetClass(action);
+                if(ProxyUtil.isProxy(action)) {
+                    editable = ProxyUtil.ultimateTargetClass(action);
                 }
                 reflectionProvider.copy(object, action, ctxMap, prepareExcludes(), includes,
editable);
             }

http://git-wip-us.apache.org/repos/asf/struts/blob/56f31bec/core/src/main/java/com/opensymphony/xwork2/ognl/SecurityMemberAccess.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/com/opensymphony/xwork2/ognl/SecurityMemberAccess.java b/core/src/main/java/com/opensymphony/xwork2/ognl/SecurityMemberAccess.java
index 9b03881..02c53d8 100644
--- a/core/src/main/java/com/opensymphony/xwork2/ognl/SecurityMemberAccess.java
+++ b/core/src/main/java/com/opensymphony/xwork2/ognl/SecurityMemberAccess.java
@@ -108,9 +108,9 @@ public class SecurityMemberAccess extends DefaultMemberAccess {
     }
 
     protected boolean isProxyAccess(Object target, Member member) {
-        if (!ProxyUtil.isSpringAopProxy(target))
+        if (!ProxyUtil.isProxy(target))
             return false;
-        Class<?> clazz = ProxyUtil.springUltimateTargetClass(target);
+        Class<?> clazz = ProxyUtil.ultimateTargetClass(target);
         if (member instanceof Method) {
             return null == MethodUtils.getMatchingMethod(clazz, member.getName(), ((Method)
member).getParameterTypes());
         }

http://git-wip-us.apache.org/repos/asf/struts/blob/56f31bec/core/src/main/java/com/opensymphony/xwork2/util/ProxyUtil.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/com/opensymphony/xwork2/util/ProxyUtil.java b/core/src/main/java/com/opensymphony/xwork2/util/ProxyUtil.java
index a3f8740..afda508 100644
--- a/core/src/main/java/com/opensymphony/xwork2/util/ProxyUtil.java
+++ b/core/src/main/java/com/opensymphony/xwork2/util/ProxyUtil.java
@@ -33,6 +33,34 @@ public class ProxyUtil {
     private static final String SPRING_TARGETCLASSAWARE_CLASS_NAME = "org.springframework.aop.TargetClassAware";
 
     /**
+     * Determine the ultimate target class of the given instance, traversing
+     * not only a top-level proxy but any number of nested proxies as well &mdash;
+     * as long as possible without side effects.
+     * @param candidate the instance to check (might be a proxy)
+     * @return the ultimate target class (or the plain class of the given
+     * object as fallback; never {@code null})
+     */
+    public static Class<?> ultimateTargetClass(Object candidate) {
+        Class<?> result = null;
+        if (isSpringAopProxy(candidate))
+            result = springUltimateTargetClass(candidate);
+
+        if (result == null) {
+            result = candidate.getClass();
+        }
+
+        return result;
+    }
+
+    /**
+     * Check whether the given object is a proxy.
+     * @param object the object to check
+     */
+    public static boolean isProxy(Object object) {
+        return isSpringAopProxy(object);
+    }
+
+    /**
      * Determine the ultimate target class of the given spring bean instance, traversing
      * not only a top-level spring proxy but any number of nested spring proxies as well
&mdash;
      * as long as possible without side effects, that is, just for singleton targets.
@@ -40,7 +68,7 @@ public class ProxyUtil {
      * @return the ultimate target class (or the plain class of the given
      * object as fallback; never {@code null})
      */
-    public static Class<?> springUltimateTargetClass(Object candidate) {
+    private static Class<?> springUltimateTargetClass(Object candidate) {
         Object current = candidate;
         Class<?> result = null;
         while (null != current && implementsInterface(current.getClass(), SPRING_TARGETCLASSAWARE_CLASS_NAME))
{
@@ -61,7 +89,7 @@ public class ProxyUtil {
      * Check whether the given object is a Spring proxy.
      * @param object the object to check
      */
-    public static boolean isSpringAopProxy(Object object) {
+    private static boolean isSpringAopProxy(Object object) {
         Class<?> clazz = object.getClass();
         return (implementsInterface(clazz, SPRING_SPRINGPROXY_CLASS_NAME) && (Proxy.isProxyClass(clazz)
                 || isCglibProxyClass(clazz)));

http://git-wip-us.apache.org/repos/asf/struts/blob/56f31bec/core/src/test/java/com/opensymphony/xwork2/spring/SpringProxyUtilTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/com/opensymphony/xwork2/spring/SpringProxyUtilTest.java b/core/src/test/java/com/opensymphony/xwork2/spring/SpringProxyUtilTest.java
index 7ae9883..106e62d 100644
--- a/core/src/test/java/com/opensymphony/xwork2/spring/SpringProxyUtilTest.java
+++ b/core/src/test/java/com/opensymphony/xwork2/spring/SpringProxyUtilTest.java
@@ -37,49 +37,49 @@ public class SpringProxyUtilTest extends XWorkTestCase {
         appContext = ((SpringObjectFactory)container.getInstance(ObjectFactory.class)).appContext;
     }
 
-    public void testIsSpringAopProxy() throws Exception {
+    public void testIsProxy() throws Exception {
         Object simpleAction = appContext.getBean("simple-action");
-        assertFalse(ProxyUtil.isSpringAopProxy(simpleAction));
+        assertFalse(ProxyUtil.isProxy(simpleAction));
 
         Object proxiedAction = appContext.getBean("proxied-action");
-        assertTrue(ProxyUtil.isSpringAopProxy(proxiedAction));
+        assertTrue(ProxyUtil.isProxy(proxiedAction));
 
         Object autoProxiedAction = appContext.getBean("auto-proxied-action");
-        assertTrue(ProxyUtil.isSpringAopProxy(autoProxiedAction));
+        assertTrue(ProxyUtil.isProxy(autoProxiedAction));
 
         Object pointcuttedTestBean = appContext.getBean("pointcutted-test-bean");
-        assertTrue(ProxyUtil.isSpringAopProxy(pointcuttedTestBean));
+        assertTrue(ProxyUtil.isProxy(pointcuttedTestBean));
 
         Object pointcuttedTestSubBean = appContext.getBean("pointcutted-test-sub-bean");
-        assertTrue(ProxyUtil.isSpringAopProxy(pointcuttedTestSubBean));
+        assertTrue(ProxyUtil.isProxy(pointcuttedTestSubBean));
 
         Object testAspect = appContext.getBean("test-aspect");
-        assertFalse(ProxyUtil.isSpringAopProxy(testAspect));
+        assertFalse(ProxyUtil.isProxy(testAspect));
     }
 
-    public void testSpringUltimateTargetClass() throws Exception {
+    public void testUltimateTargetClass() throws Exception {
         Object simpleAction = appContext.getBean("simple-action");
-        Class<?> simpleActionUltimateTargetClass = ProxyUtil.springUltimateTargetClass(simpleAction);
+        Class<?> simpleActionUltimateTargetClass = ProxyUtil.ultimateTargetClass(simpleAction);
         assertEquals(SimpleAction.class, simpleActionUltimateTargetClass);
 
         Object proxiedAction = appContext.getBean("proxied-action");
-        Class<?> proxiedActionUltimateTargetClass = ProxyUtil.springUltimateTargetClass(proxiedAction);
+        Class<?> proxiedActionUltimateTargetClass = ProxyUtil.ultimateTargetClass(proxiedAction);
         assertEquals(SimpleAction.class, proxiedActionUltimateTargetClass);
 
         Object autoProxiedAction = appContext.getBean("auto-proxied-action");
-        Class<?> autoProxiedActionUltimateTargetClass = ProxyUtil.springUltimateTargetClass(autoProxiedAction);
+        Class<?> autoProxiedActionUltimateTargetClass = ProxyUtil.ultimateTargetClass(autoProxiedAction);
         assertEquals(SimpleAction.class, autoProxiedActionUltimateTargetClass);
 
         Object pointcuttedTestBean = appContext.getBean("pointcutted-test-bean");
-        Class<?> pointcuttedTestBeanUltimateTargetClass = ProxyUtil.springUltimateTargetClass(pointcuttedTestBean);
+        Class<?> pointcuttedTestBeanUltimateTargetClass = ProxyUtil.ultimateTargetClass(pointcuttedTestBean);
         assertEquals(TestBean.class, pointcuttedTestBeanUltimateTargetClass);
 
         Object pointcuttedTestSubBean = appContext.getBean("pointcutted-test-sub-bean");
-        Class<?> pointcuttedTestSubBeanUltimateTargetClass = ProxyUtil.springUltimateTargetClass(pointcuttedTestSubBean);
+        Class<?> pointcuttedTestSubBeanUltimateTargetClass = ProxyUtil.ultimateTargetClass(pointcuttedTestSubBean);
         assertEquals(TestSubBean.class, pointcuttedTestSubBeanUltimateTargetClass);
 
         Object testAspect = appContext.getBean("test-aspect");
-        Class<?> testAspectUltimateTargetClass = ProxyUtil.springUltimateTargetClass(testAspect);
+        Class<?> testAspectUltimateTargetClass = ProxyUtil.ultimateTargetClass(testAspect);
         assertEquals(TestAspect.class, testAspectUltimateTargetClass);
     }
 }


Mime
View raw message