=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ReflectionUtils.java' --- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ReflectionUtils.java 2012-04-13 14:11:00 +0000 +++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ReflectionUtils.java 2012-04-14 06:48:32 +0000 @@ -38,11 +38,10 @@ public class ReflectionUtils { - /** - * Invokes method getId() for this object and returns the return value. An int - * return type is expected. If the operation fails -1 is returned. - * + * Invokes method getId() for this object and returns the return value. An + * int return type is expected. If the operation fails -1 is returned. + * * @param object object to call getId() on. * @return The identifier. */ @@ -53,7 +52,8 @@ Method method = object.getClass().getMethod( "getId" ); return (Integer) method.invoke( object ); - } catch ( Exception ex ) + } + catch ( Exception ex ) { return -1; } @@ -61,8 +61,8 @@ /** * Fetch a property off the object. Returns null if the operation fails. - * - * @param object the object. + * + * @param object the object. * @param property name of the property to get. * @return the value of the property or null. */ @@ -75,25 +75,26 @@ Method method = object.getClass().getMethod( "get" + property ); return (String) method.invoke( object ); - } catch ( Exception ex ) + } + catch ( Exception ex ) { return null; } } /** - * Sets a property for the supplied object. Throws an UnsupportedOperationException - * if the operation fails. - * + * Sets a property for the supplied object. Throws an + * UnsupportedOperationException if the operation fails. + * * @param object Object to modify - * @param name Name of property to set - * @param value Value the property will be set to + * @param name Name of property to set + * @param value Value the property will be set to */ public static void setProperty( Object object, String name, String value ) { - Object[] arguments = new Object[]{value}; + Object[] arguments = new Object[] { value }; - Class[] parameterTypes = new Class[]{String.class}; + Class[] parameterTypes = new Class[] { String.class }; if ( name.length() > 0 ) { @@ -104,7 +105,8 @@ Method concatMethod = object.getClass().getMethod( name, parameterTypes ); concatMethod.invoke( object, arguments ); - } catch ( Exception ex ) + } + catch ( Exception ex ) { throw new UnsupportedOperationException( "Failed to set property", ex ); } @@ -112,13 +114,13 @@ } /** - * Sets a property for the supplied object. Throws an UnsupportedOperationException - * if the operation fails. - * - * @param object Object to modify + * Sets a property for the supplied object. Throws an + * UnsupportedOperationException if the operation fails. + * + * @param object Object to modify * @param namePrefix prefix of the property name to set - * @param name Name of property to set - * @param value Value the property will be set to + * @param name Name of property to set + * @param value Value the property will be set to */ public static void setProperty( Object object, String namePrefix, String name, String value ) { @@ -130,7 +132,7 @@ /** * Returns the name of the class that the object is an instance of * org.hisp.dhis.indicator.Indicactor returns Indicator. - * + * * @param object object to determine className for. * @return String containing the class name. */ @@ -141,7 +143,7 @@ /** * Test whether the object is an array or a Collection. - * + * * @param value the object. * @return true if the object is an array or a Collection, false otherwise. */ @@ -165,7 +167,8 @@ try { field = object.getClass().getDeclaredField( fieldName ); - } catch ( NoSuchFieldException e ) + } + catch ( NoSuchFieldException e ) { return false; } @@ -186,7 +189,8 @@ } } - } catch ( ClassCastException e ) + } + catch ( ClassCastException e ) { return false; } @@ -199,7 +203,8 @@ try { return object.getClass().getMethod( "get" + StringUtils.capitalize( fieldName ) ); - } catch ( NoSuchMethodException e ) + } + catch ( NoSuchMethodException e ) { return null; } @@ -210,12 +215,14 @@ try { return object.getClass().getMethod( "set" + StringUtils.capitalize( fieldName ) ); - } catch ( NoSuchMethodException e ) + } + catch ( NoSuchMethodException e ) { return null; } } + @SuppressWarnings("unchecked") public static T invokeGetterMethod( String fieldName, Object object ) { Method method = findGetterMethod( fieldName, object ); @@ -228,15 +235,18 @@ try { return (T) method.invoke( object ); - } catch ( InvocationTargetException e ) + } + catch ( InvocationTargetException e ) { return null; - } catch ( IllegalAccessException e ) + } + catch ( IllegalAccessException e ) { return null; } } + @SuppressWarnings("unchecked") public static T invokeSetterMethod( String fieldName, Object object, Object... objects ) { Method method = findSetterMethod( fieldName, object ); @@ -249,10 +259,12 @@ try { return (T) method.invoke( object, objects ); - } catch ( InvocationTargetException e ) + } + catch ( InvocationTargetException e ) { return null; - } catch ( IllegalAccessException e ) + } + catch ( IllegalAccessException e ) { return null; }