net.craftforge.reflection.utils
Class PropertyUtils

java.lang.Object
  extended by net.craftforge.reflection.utils.PropertyUtils

public class PropertyUtils
extends Object

Since:
02.12.2010
Author:
Christian Bick

Constructor Summary
PropertyUtils()
           
 
Method Summary
static Object getProperty(Object owner, Field field)
          Gets the value of an object's property.
static Object setProperty(Object owner, Field field, Object value)
          Sets the value of an object's property.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PropertyUtils

public PropertyUtils()
Method Detail

setProperty

public static Object setProperty(Object owner,
                                 Field field,
                                 Object value)
                          throws NoSuchMethodException,
                                 InvocationTargetException,
                                 IllegalAccessException
Sets the value of an object's property.

If the field is public, the new value will be assigned to field directly.
Otherwise, a setter method will be looked up and invoked with the value to set.

Parameters:
owner - The object that owns the property
field - The property field
value - The value to set
Returns:
The modified object
Throws:
IllegalAccessException - Failed to access field or setter method
NoSuchMethodException - Setter method not found
InvocationTargetException - Failed to invoke setter method

getProperty

public static Object getProperty(Object owner,
                                 Field field)
                          throws IllegalAccessException,
                                 NoSuchMethodException,
                                 InvocationTargetException
Gets the value of an object's property.

Parameters:
owner - The object
field - The property field
Returns:
The value of the property
Throws:
IllegalAccessException - Failed to access field or getter method
NoSuchMethodException - Getter method not found
InvocationTargetException - Failed to invoke getter method


Copyright © 2011. All Rights Reserved.