[jboss-cvs] jboss-seam/src/main/org/jboss/seam/util ...
Peter Muir
peter at bleepbleep.org.uk
Sat Mar 10 14:09:35 EST 2007
User: pmuir
Date: 07/03/10 14:09:35
Modified: src/main/org/jboss/seam/util Reflections.java
Log:
EntityConverter
Revision Changes Path
1.19 +307 -262 jboss-seam/src/main/org/jboss/seam/util/Reflections.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Reflections.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/util/Reflections.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -b -r1.18 -r1.19
--- Reflections.java 14 Feb 2007 05:46:29 -0000 1.18
+++ Reflections.java 10 Mar 2007 19:09:35 -0000 1.19
@@ -1,4 +1,4 @@
-//$Id: Reflections.java,v 1.18 2007/02/14 05:46:29 gavin Exp $
+//$Id: Reflections.java,v 1.19 2007/03/10 19:09:35 pmuir Exp $
package org.jboss.seam.util;
import java.beans.Introspector;
@@ -8,6 +8,8 @@
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.List;
public class Reflections
{
@@ -234,6 +236,23 @@
throw new IllegalArgumentException("no such getter method: " + clazz.getName() + '.' + name);
}
+ /**
+ * Get all the getter methods annotated with the given annotation. Returns an empty list if
+ * none are found
+ */
+ public static List<Method> getGetterMethods(Class clazz, Class annotation)
+ {
+ List<Method> methods = new ArrayList<Method>();
+ for (Method method : clazz.getMethods())
+ {
+ if (method.isAnnotationPresent(annotation))
+ {
+ methods.add(method);
+ }
+ }
+ return methods;
+ }
+
public static Field getField(Class clazz, String name)
{
for ( Class superClass = clazz; superClass!=Object.class; superClass=superClass.getSuperclass() )
@@ -247,6 +266,30 @@
throw new IllegalArgumentException("no such field: " + clazz.getName() + '.' + name);
}
+ /**
+ * Get all the fields which are annotated with the given annotation. Returns an empty list
+ * if none are found
+ */
+ public static List<Field> getFields(Class clazz, Class annotation)
+ {
+ List<Field> fields = null;
+ for (Class superClass = clazz; superClass!=Object.class; superClass=superClass.getSuperclass())
+ {
+ for (Field field : superClass.getDeclaredFields())
+ {
+ if (field.isAnnotationPresent(annotation))
+ {
+ if (fields == null)
+ {
+ fields = new ArrayList<Field>();
+ }
+ fields.add(field);
+ }
+ }
+ }
+ return fields;
+ }
+
public static Method getMethod(Annotation annotation, String name)
{
try
@@ -259,4 +302,6 @@
}
}
+
+
}
More information about the jboss-cvs-commits
mailing list