[jboss-cvs] jbossretro/src/main/org/jboss/lang ...
Kabir Khan
kkhan at jboss.com
Tue Jul 18 04:57:48 EDT 2006
User: kkhan
Date: 06/07/18 04:57:48
Modified: src/main/org/jboss/lang AnnotationHelper.java
Log:
Got a ClassCastException when reading annotations from strongly typed PrivilegedActions. Fix and test for this
Revision Changes Path
1.10 +68 -24 jbossretro/src/main/org/jboss/lang/AnnotationHelper.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: AnnotationHelper.java
===================================================================
RCS file: /cvsroot/jboss/jbossretro/src/main/org/jboss/lang/AnnotationHelper.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -b -r1.9 -r1.10
--- AnnotationHelper.java 17 Jul 2006 17:48:02 -0000 1.9
+++ AnnotationHelper.java 18 Jul 2006 08:57:48 -0000 1.10
@@ -42,7 +42,7 @@
* AnnotationHelper.
*
* @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @version $Revision: 1.9 $
+ * @version $Revision: 1.10 $
*/
public class AnnotationHelper
{
@@ -68,16 +68,16 @@
* @param annotationClass the annotation class
* @return the annotation
*/
- public static Object getAnnotation(Class clazz, Class annotationClass)
+ public static Annotation getAnnotation(Class clazz, Class annotationClass)
{
if (annotationClass == null)
throw new NullPointerException("Null annotation");
String searchName = annotationClass.getName();
- for (Object annotation : getAnnotations(clazz))
+ for (Object annotation : getAnnotationsInternal(clazz))
{
AnnotationImpl impl = (AnnotationImpl) Proxy.getInvocationHandler(annotation);
if (searchName.equals(impl.getTypeName()))
- return annotation;
+ return (Annotation)annotation;
}
return null;
}
@@ -88,7 +88,12 @@
* @param clazz the class
* @return the annotations
*/
- public static Object[] getAnnotations(Class clazz)
+ public static Annotation[] getAnnotations(Class clazz)
+ {
+ return convertAnnotationArray(getAnnotationsInternal(clazz));
+ }
+
+ static Object[] getAnnotationsInternal(Class clazz)
{
return getCtClass(clazz).getAvailableAnnotations();
}
@@ -144,7 +149,7 @@
* @param annotationClass the annotation class
* @return the annotation
*/
- public static Object getAnnotation(AccessibleObject ao, Class annotationClass)
+ public static Annotation getAnnotation(AccessibleObject ao, Class annotationClass)
{
if (ao instanceof Method)
{
@@ -168,7 +173,7 @@
* @param ao the accessible object
* @return the annotations
*/
- public static Object[] getAnnotations(AccessibleObject ao)
+ public static Annotation[] getAnnotations(AccessibleObject ao)
{
if (ao instanceof Method)
{
@@ -207,16 +212,16 @@
* @param annotationClass the annotation class
* @return the annotation
*/
- public static Object getAnnotation(Method method, Class annotationClass)
+ public static Annotation getAnnotation(Method method, Class annotationClass)
{
if (annotationClass == null)
throw new NullPointerException("Null annotation");
String searchName = annotationClass.getName();
- for (Object annotation : getAnnotations(method))
+ for (Object annotation : getAnnotationsInternal(method))
{
AnnotationImpl impl = (AnnotationImpl) Proxy.getInvocationHandler(annotation);
if (searchName.equals(impl.getTypeName()))
- return annotation;
+ return (Annotation)annotation;
}
return null;
}
@@ -227,7 +232,12 @@
* @param method the method
* @return the annotations
*/
- public static Object[] getAnnotations(Method method)
+ public static Annotation[] getAnnotations(Method method)
+ {
+ return convertAnnotationArray(getAnnotationsInternal(method));
+ }
+
+ public static Object[] getAnnotationsInternal(Method method)
{
return getCtMethod(method).getAvailableAnnotations();
}
@@ -238,9 +248,9 @@
* @param method the method
* @return the annotations
*/
- public static Object[][] getParameterAnnotations(Method method)
+ public static Annotation[][] getParameterAnnotations(Method method)
{
- return getCtMethod(method).getAvailableParameterAnnotations();
+ return convertAnnotationArray(getCtMethod(method).getAvailableParameterAnnotations());
}
/**
@@ -290,16 +300,16 @@
* @param annotationClass the annotation class
* @return the annotation
*/
- public static Object getAnnotation(Constructor constructor, Class annotationClass)
+ public static Annotation getAnnotation(Constructor constructor, Class annotationClass)
{
if (annotationClass == null)
throw new NullPointerException("Null annotation");
String searchName = annotationClass.getName();
- for (Object annotation : getAnnotations(constructor))
+ for (Object annotation : getAnnotationsInternal(constructor))
{
AnnotationImpl impl = (AnnotationImpl) Proxy.getInvocationHandler(annotation);
if (searchName.equals(impl.getTypeName()))
- return annotation;
+ return (Annotation)annotation;
}
return null;
}
@@ -310,7 +320,12 @@
* @param constructor the constructor
* @return the annotations
*/
- public static Object[] getAnnotations(Constructor constructor)
+ public static Annotation[] getAnnotations(Constructor constructor)
+ {
+ return convertAnnotationArray(getAnnotationsInternal(constructor));
+ }
+
+ static Object[] getAnnotationsInternal(Constructor constructor)
{
return getCtConstructor(constructor).getAvailableAnnotations();
}
@@ -321,9 +336,9 @@
* @param constructor the constructor
* @return the annotations
*/
- public static Object[][] getParameterAnnotations(Constructor constructor)
+ public static Annotation[][] getParameterAnnotations(Constructor constructor)
{
- return getCtConstructor(constructor).getAvailableParameterAnnotations();
+ return convertAnnotationArray(getCtConstructor(constructor).getAvailableParameterAnnotations());
}
/**
@@ -372,16 +387,16 @@
* @param annotationClass the annotation class
* @return the annotation
*/
- public static Object getAnnotation(Field field, Class annotationClass)
+ public static Annotation getAnnotation(Field field, Class annotationClass)
{
if (annotationClass == null)
throw new NullPointerException("Null annotation");
String searchName = annotationClass.getName();
- for (Object annotation : getAnnotations(field))
+ for (Object annotation : getAnnotationsInternal(field))
{
AnnotationImpl impl = (AnnotationImpl) Proxy.getInvocationHandler(annotation);
if (searchName.equals(impl.getTypeName()))
- return annotation;
+ return (Annotation)annotation;
}
return null;
}
@@ -392,7 +407,12 @@
* @param field the field
* @return the annotations
*/
- public static Object[] getAnnotations(Field field)
+ public static Annotation[] getAnnotations(Field field)
+ {
+ return convertAnnotationArray(getAnnotationsInternal(field));
+ }
+
+ static Object[] getAnnotationsInternal(Field field)
{
return getCtField(field).getAvailableAnnotations();
}
@@ -417,6 +437,30 @@
}
}
+ static Annotation[] convertAnnotationArray(Object[] annotations)
+ {
+ Annotation[] anns = new Annotation[annotations.length];
+ for (int i = 0 ; i < annotations.length ; i++)
+ {
+ anns[i] = (Annotation)annotations[i];
+ }
+ return anns;
+ }
+
+ static Annotation[][] convertAnnotationArray(Object[][] annotations)
+ {
+ Annotation[][] anns = new Annotation[annotations.length][];
+ for (int i = 0 ; i < annotations.length ; i++)
+ {
+ anns[i] = new Annotation[annotations[i].length];
+ for (int j = 0 ; j < annotations[i].length ; j++)
+ {
+ anns[i][j] = (Annotation)annotations[i][j];
+ }
+ }
+ return anns;
+ }
+
/**
* Static helper class
*/
More information about the jboss-cvs-commits
mailing list