[jboss-cvs] jboss-seam/src/main/org/jboss/seam/util ...
Gavin King
gavin.king at jboss.com
Wed Aug 9 17:39:50 EDT 2006
User: gavin
Date: 06/08/09 17:39:50
Modified: src/main/org/jboss/seam/util Reflections.java
Log:
exception reporting
Revision Changes Path
1.9 +45 -1 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.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- Reflections.java 24 Jul 2006 20:00:42 -0000 1.8
+++ Reflections.java 9 Aug 2006 21:39:50 -0000 1.9
@@ -1,7 +1,8 @@
-//$Id: Reflections.java,v 1.8 2006/07/24 20:00:42 gavin Exp $
+//$Id: Reflections.java,v 1.9 2006/08/09 21:39:50 gavin Exp $
package org.jboss.seam.util;
import java.beans.Introspector;
+import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
@@ -38,6 +39,42 @@
}
}
+ public static Object get(Field field, Object target) throws Exception
+ {
+ try
+ {
+ return field.get(target);
+ }
+ catch (IllegalArgumentException iae)
+ {
+ String message = "Could not get field value by reflection: " + toString(field) +
+ " on: " + target.getClass().getName();
+ throw new IllegalArgumentException(message, iae);
+ }
+ }
+
+ public static void set(Field field, Object target, Object value) throws Exception
+ {
+ try
+ {
+ field.set(target, value);
+ }
+ catch (IllegalArgumentException iae)
+ {
+ String message = "Could not set field value by reflection: " + toString(field) +
+ " on: " + target.getClass().getName();
+ if (value==null)
+ {
+ message += " with null value";
+ }
+ else
+ {
+ message += " with value: " + value.getClass();
+ }
+ throw new IllegalArgumentException(message, iae);
+ }
+ }
+
public static Object invokeAndWrap(Method method, Object target, Object... args)
{
try
@@ -68,6 +105,13 @@
')';
}
+ private static String toString(Field field)
+ {
+ return Strings.unqualify( field.getClass().getName() ) +
+ '.' +
+ field.getName();
+ }
+
public static Class classForName(String name) throws ClassNotFoundException
{
try
More information about the jboss-cvs-commits
mailing list