[seam-commits] Seam SVN: r12867 - modules/security/trunk/impl/src/main/java/org/jboss/seam/security/util.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Thu May 27 05:27:24 EDT 2010
Author: shane.bryzak at jboss.com
Date: 2010-05-27 05:27:23 -0400 (Thu, 27 May 2010)
New Revision: 12867
Modified:
modules/security/trunk/impl/src/main/java/org/jboss/seam/security/util/AnnotatedBeanProperty.java
Log:
improve exceptions, make class non-abstract
Modified: modules/security/trunk/impl/src/main/java/org/jboss/seam/security/util/AnnotatedBeanProperty.java
===================================================================
--- modules/security/trunk/impl/src/main/java/org/jboss/seam/security/util/AnnotatedBeanProperty.java 2010-05-27 08:45:53 UTC (rev 12866)
+++ modules/security/trunk/impl/src/main/java/org/jboss/seam/security/util/AnnotatedBeanProperty.java 2010-05-27 09:27:23 UTC (rev 12867)
@@ -16,7 +16,7 @@
*
* @author Shane Bryzak
*/
-public abstract class AnnotatedBeanProperty<T extends Annotation>
+public class AnnotatedBeanProperty<T extends Annotation>
{
private Field propertyField;
private Method propertyGetter;
@@ -114,14 +114,17 @@
}
/**
- * This method must be provided by a concrete implementation of this class. It
- * may be used to scan for an annotation with one or more particular attribute
- * values.
+ * This method may be overridden by a subclass. It can be used to scan
+ * for an annotation with particular attribute values, or to allow a match
+ * based on more complex logic.
*
* @param annotation The potential match
* @return true if the specified annotation is a match
*/
- protected abstract boolean isMatch(T annotation);
+ protected boolean isMatch(T annotation)
+ {
+ return true;
+ }
/**
* This method sets the property value for a specified bean to the specified
@@ -228,25 +231,30 @@
private Object getFieldValue(Field field, Object obj)
{
+ field.setAccessible(true);
try
{
return field.get(obj);
}
- catch (Exception e)
+ catch (IllegalAccessException e)
{
- if (e instanceof RuntimeException)
- {
- throw (RuntimeException) e;
- }
- else
- {
- throw new IllegalArgumentException(
- String.format("Exception reading [%s] field from object [%s].",
- field.getName(), obj), e);
- }
- }
+ throw new RuntimeException(buildGetFieldValueErrorMessage(field, obj), e);
+ }
+ catch (NullPointerException ex)
+ {
+ NullPointerException ex2 = new NullPointerException(
+ buildGetFieldValueErrorMessage(field, obj));
+ ex2.initCause(ex.getCause());
+ throw ex2;
+ }
}
+ private String buildGetFieldValueErrorMessage(Field field, Object obj)
+ {
+ return String.format("Exception reading [%s] field from object [%s].",
+ field.getName(), obj);
+ }
+
private void setFieldValue(Field field, Object obj, Object value)
{
field.setAccessible(true);
@@ -254,21 +262,25 @@
{
field.set(obj, value);
}
- catch (Exception e)
+ catch (IllegalAccessException e)
{
- if (e instanceof RuntimeException)
- {
- throw (RuntimeException) e;
- }
- else
- {
- throw new IllegalArgumentException(
- String.format("Exception setting [%s] field on object [%s] to value [%s]",
- field.getName(), obj, value), e);
- }
- }
+ throw new RuntimeException(buildSetFieldValueErrorMessage(field, obj, value), e);
+ }
+ catch (NullPointerException ex)
+ {
+ NullPointerException ex2 = new NullPointerException(
+ buildSetFieldValueErrorMessage(field, obj, value));
+ ex2.initCause(ex.getCause());
+ throw ex2;
+ }
}
+ private String buildSetFieldValueErrorMessage(Field field, Object obj, Object value)
+ {
+ return String.format("Exception setting [%s] field on object [%s] to value [%s]",
+ field.getName(), obj, value);
+ }
+
private Object invokeMethod(Method method, Object obj, Object... args)
{
try
More information about the seam-commits
mailing list