From 9e218ceda25ff32c94dfdfbdc77135b744b94e34 Mon Sep 17 00:00:00 2001
From: ribeaudc <ribeaudc>
Date: Tue, 15 Jul 2008 02:20:57 +0000
Subject: [PATCH] [LMS-436] add: - 'AuthorizationFailureException' to 'lims'
 and 'lims_webclient'. - 'DatabaseInstanceIdentifierPredicate'. change: -
 Webclient should logout in case of an 'AuthorizationFailureException'.
 remove: - TODO from 'ClassUtils.tryGetInterfaceTypeArgument'. fix: - Some
 problems in authorization.

SVN: 7218
---
 .../cisd/common/utilities/ClassUtils.java     | 24 +++++++------------
 .../cisd/common/utilities/ClassUtilsTest.java |  9 +++++++
 2 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/common/source/java/ch/systemsx/cisd/common/utilities/ClassUtils.java b/common/source/java/ch/systemsx/cisd/common/utilities/ClassUtils.java
index 182d41c1215..16107789578 100644
--- a/common/source/java/ch/systemsx/cisd/common/utilities/ClassUtils.java
+++ b/common/source/java/ch/systemsx/cisd/common/utilities/ClassUtils.java
@@ -16,10 +16,8 @@
 
 package ch.systemsx.cisd.common.utilities;
 
-import java.lang.reflect.Array;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Field;
-import java.lang.reflect.GenericArrayType;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.lang.reflect.ParameterizedType;
@@ -357,13 +355,13 @@ public final class ClassUtils
     }
 
     /**
-     * Returns the type argument found at given <var>index</var> of given generic interface
-     * <var>genericInterfaceClass</var>.
+     * For given <var>clazz</var> tries to retrieve the generic interface of given class, then
+     * returns the type argument found at given <var>index</var>.
      * 
      * @return <code>null</code> if not found.
      */
-    public final static <I> Class<?> tryGetInterfaceTypeArgument(final Class<?> clazz,
-            final Class<I> genericInterfaceClass, final int index)
+    public final static Class<?> tryGetInterfaceTypeArgument(final Class<?> clazz,
+            final Class<?> genericInterfaceClass, final int index)
     {
         assert clazz != null : "Unspecified class";
         assert genericInterfaceClass != null && genericInterfaceClass.isInterface() : "Is not defined or not an interface";
@@ -371,23 +369,19 @@ public final class ClassUtils
         final Type[] genericInterfaces = clazz.getGenericInterfaces();
         for (final Type genericInterface : genericInterfaces)
         {
-            // Only typed interface are instance of ParameterizedType. Other is just a Class.
+            // Only typed interface is an instance of 'ParameterizedType'.
+            // Other is just a 'Class'.
             if (genericInterface instanceof ParameterizedType)
             {
                 final ParameterizedType parameterizedType = (ParameterizedType) genericInterface;
                 if (genericInterfaceClass.isAssignableFrom((Class<?>) parameterizedType
                         .getRawType()))
                 {
-                    Type typeArgument = parameterizedType.getActualTypeArguments()[index];
-                    if (typeArgument instanceof GenericArrayType)
+                    final Type typeArgument = parameterizedType.getActualTypeArguments()[index];
+                    if (typeArgument instanceof Class)
                     {
-                        final GenericArrayType genericArrayType = (GenericArrayType) typeArgument;
-                        // TODO 2008-07-12, Christian Ribeaud: Is there a better way to do this?
-                        return Array.newInstance(
-                                ((Class<?>) genericArrayType.getGenericComponentType()), 0)
-                                .getClass();
+                        return (Class<?>) typeArgument;
                     }
-                    return (Class<?>) typeArgument;
                 }
             }
         }
diff --git a/common/sourceTest/java/ch/systemsx/cisd/common/utilities/ClassUtilsTest.java b/common/sourceTest/java/ch/systemsx/cisd/common/utilities/ClassUtilsTest.java
index 22acebabaa8..1f102295df1 100644
--- a/common/sourceTest/java/ch/systemsx/cisd/common/utilities/ClassUtilsTest.java
+++ b/common/sourceTest/java/ch/systemsx/cisd/common/utilities/ClassUtilsTest.java
@@ -223,6 +223,11 @@ public final class ClassUtilsTest
         typeArgument =
                 ClassUtils.tryGetInterfaceTypeArgument(ExtendingExtendingA.class, IB.class, 0);
         assertNull(typeArgument);
+        // We do not support array type argument
+        typeArgument =
+                ClassUtils
+                        .tryGetInterfaceTypeArgument(ExtendingArrayA.class, IExtendingIA.class, 0);
+        assertNull(typeArgument);
     }
 
     //
@@ -304,6 +309,10 @@ public final class ClassUtilsTest
     {
     }
 
+    private static class ExtendingArrayA extends A implements IExtendingIA<String[]>
+    {
+    }
+
     private static class ExtendingExtendingA extends ExtendingA implements IB, IA<String>
     {
     }
-- 
GitLab