openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tandrasc...@apache.org
Subject svn commit: r1464948 - /openwebbeans/branches/owb_1.1.x/webbeans-impl/src/main/java/org/apache/webbeans/annotation/AbstractAnnotationLiteral.java
Date Fri, 05 Apr 2013 12:25:20 GMT
Author: tandraschko
Date: Fri Apr  5 12:25:20 2013
New Revision: 1464948

URL: http://svn.apache.org/r1464948
Log:
#OWB-802

Modified:
    openwebbeans/branches/owb_1.1.x/webbeans-impl/src/main/java/org/apache/webbeans/annotation/AbstractAnnotationLiteral.java

Modified: openwebbeans/branches/owb_1.1.x/webbeans-impl/src/main/java/org/apache/webbeans/annotation/AbstractAnnotationLiteral.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.1.x/webbeans-impl/src/main/java/org/apache/webbeans/annotation/AbstractAnnotationLiteral.java?rev=1464948&r1=1464947&r2=1464948&view=diff
==============================================================================
--- openwebbeans/branches/owb_1.1.x/webbeans-impl/src/main/java/org/apache/webbeans/annotation/AbstractAnnotationLiteral.java
(original)
+++ openwebbeans/branches/owb_1.1.x/webbeans-impl/src/main/java/org/apache/webbeans/annotation/AbstractAnnotationLiteral.java
Fri Apr  5 12:25:20 2013
@@ -20,9 +20,28 @@ package org.apache.webbeans.annotation;
 
 import javax.enterprise.util.AnnotationLiteral;
 import java.lang.annotation.Annotation;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
 
 public class AbstractAnnotationLiteral<T extends Annotation> extends AnnotationLiteral<T>
 {
+    private Class<T> annotationType;
+
+    protected AbstractAnnotationLiteral()
+    {
+        this.annotationType = getAnnotationType(getClass());
+    }
+
+    /**
+     * Implemented for compatibility reasons with other cdi-api jar's.
+     * See OWB-802.
+     */
+    @Override
+    public Class<? extends Annotation> annotationType()
+    {
+        return annotationType;
+    }
+
     @Override
     public int hashCode()
     {
@@ -38,4 +57,45 @@ public class AbstractAnnotationLiteral<T
         return Annotation.class.isInstance(other) &&
                 Annotation.class.cast(other).annotationType().equals(annotationType());
     }
+
+    private Class<T> getAnnotationType(Class<?> definedClazz)
+    {
+        Type superClazz = definedClazz.getGenericSuperclass();
+
+        Class<T> clazz = null;
+
+        if (superClazz.equals(Object.class))
+        {
+            throw new RuntimeException("Super class must be parametrized type!");
+        }
+        else if (superClazz instanceof ParameterizedType)
+        {
+            ParameterizedType paramType = (ParameterizedType) superClazz;
+            Type[] actualArgs = paramType.getActualTypeArguments();
+
+            if (actualArgs.length == 1)
+            {
+                //Actual annotation type
+                Type type = actualArgs[0];
+
+                if (type instanceof Class)
+                {
+                    clazz = (Class<T>) type;
+                    return clazz;
+                }
+                else
+                {
+                    throw new RuntimeException("Not class type!");
+                }
+            }
+            else
+            {
+                throw new RuntimeException("More than one parametric type!");
+            }
+        }
+        else
+        {
+            return getAnnotationType((Class<?>) superClazz);
+        }
+    }
 }



Mime
View raw message