Author: pete.muir(a)jboss.org
Date: 2008-06-25 06:44:35 -0400 (Wed, 25 Jun 2008)
New Revision: 12
Modified:
ri/trunk/webbeans-api/src/main/java/javax/webbeans/DynamicBinding.java
Log:
Correct implementation of annotationType() for DynamicBinding
Modified: ri/trunk/webbeans-api/src/main/java/javax/webbeans/DynamicBinding.java
===================================================================
--- ri/trunk/webbeans-api/src/main/java/javax/webbeans/DynamicBinding.java 2008-06-23
17:27:27 UTC (rev 11)
+++ ri/trunk/webbeans-api/src/main/java/javax/webbeans/DynamicBinding.java 2008-06-25
10:44:35 UTC (rev 12)
@@ -1,6 +1,43 @@
package javax.webbeans;
-public class DynamicBinding<T>
+import java.lang.annotation.Annotation;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+
+public abstract class DynamicBinding<T extends Annotation> implements Annotation
{
+ private Class<T> annotationType;
+
+ @SuppressWarnings("unchecked")
+ public DynamicBinding()
+ {
+ Type type = getClass().getGenericSuperclass();
+ if (type instanceof ParameterizedType)
+ {
+ ParameterizedType parameterizedType = (ParameterizedType) type;
+ if (parameterizedType.getActualTypeArguments().length == 1)
+ {
+ annotationType = (Class<T>)
parameterizedType.getActualTypeArguments()[0];
+ }
+ }
+ if (annotationType == null)
+ {
+ throw new RuntimeException("Unable to determine type of dynamic
binding");
+ }
+ }
+
+ public Class<? extends Annotation> annotationType()
+ {
+ return annotationType;
+ }
+
+ @Override
+ public String toString()
+ {
+ // TODO Make this closer to the spec for Annotation
+ String annotationName = "@" + annotationType.getName();
+ return annotationName;
+ }
+
}