diff options
Diffstat (limited to 'src/com/vaadin/tools/ReflectTools.java')
-rw-r--r-- | src/com/vaadin/tools/ReflectTools.java | 71 |
1 files changed, 22 insertions, 49 deletions
diff --git a/src/com/vaadin/tools/ReflectTools.java b/src/com/vaadin/tools/ReflectTools.java index 03c5b8be92..240adccb73 100644 --- a/src/com/vaadin/tools/ReflectTools.java +++ b/src/com/vaadin/tools/ReflectTools.java @@ -56,9 +56,14 @@ public class ReflectTools { * @return The value of the field in the object * @throws FormBuilderException * If the field value cannot be determined + * @throws InvocationTargetException + * @throws IllegalAccessException + * @throws IllegalArgumentException */ public static Object getJavaFieldValue(Object object, - java.lang.reflect.Field field) throws FormBuilderException { + java.lang.reflect.Field field) throws FormBuilderException, + IllegalArgumentException, IllegalAccessException, + InvocationTargetException { PropertyDescriptor pd; try { pd = new PropertyDescriptor(field.getName(), object.getClass()); @@ -66,26 +71,16 @@ public class ReflectTools { if (getter != null) { return getter.invoke(object, (Object[]) null); } - } catch (Exception e) { - // Ignore all problems with getter and try to get the value directly - // from the field + } catch (IntrospectionException e1) { + // Ignore this and try to get directly using the field } - try { - if (!field.isAccessible()) { - // Try to gain access even if field is private - field.setAccessible(true); - } - return field.get(object); - } catch (IllegalArgumentException e) { - throw new FormBuilderException("Could not get value for field '" - + field.getName() + "'", e.getCause()); - } catch (IllegalAccessException e) { - throw new FormBuilderException( - "Access denied while assigning built component to field '" - + field.getName() + "' in " - + object.getClass().getName(), e); + // Try to get the value or throw an exception + if (!field.isAccessible()) { + // Try to gain access even if field is private + field.setAccessible(true); } + return field.get(object); } /** @@ -105,47 +100,25 @@ public class ReflectTools { */ public static void setJavaFieldValue(Object object, java.lang.reflect.Field field, Object value) - throws FormBuilderException { + throws IllegalAccessException, IllegalArgumentException, + InvocationTargetException { PropertyDescriptor pd; try { pd = new PropertyDescriptor(field.getName(), object.getClass()); Method setter = pd.getWriteMethod(); if (setter != null) { - try { - setter.invoke(object, value); - } catch (IllegalArgumentException e) { - throw new FormBuilderException( - "Could not assign value to field '" - + field.getName() + "'", e); - } catch (IllegalAccessException e) { - throw new FormBuilderException( - "Access denied while assigning value to field using " - + setter.getName() + " in " - + object.getClass().getName(), e); - } catch (InvocationTargetException e) { - throw new FormBuilderException( - "Could not assign value to field '" - + field.getName() + "'", e.getCause()); - } + // Exceptions are thrown forward if this fails + setter.invoke(object, value); } } catch (IntrospectionException e1) { // Ignore this and try to set directly using the field } - try { - if (!field.isAccessible()) { - // Try to gain access even if field is private - field.setAccessible(true); - } - field.set(object, value); - } catch (IllegalArgumentException e) { - throw new FormBuilderException("Could not assign value to field '" - + field.getName() + "'", e.getCause()); - } catch (IllegalAccessException e) { - throw new FormBuilderException( - "Access denied while assigning value to field '" - + field.getName() + "' in " - + object.getClass().getName(), e); + // Try to set the value directly to the field or throw an exception + if (!field.isAccessible()) { + // Try to gain access even if field is private + field.setAccessible(true); } + field.set(object, value); } } |