Class KeyValueAdaptor

java.lang.Object
xal.tools.data.KeyValueAdaptor

public class KeyValueAdaptor extends Object
Provides methods to set and get an object's values for its named properties
  • Constructor Details

    • KeyValueAdaptor

      public KeyValueAdaptor()
      Constructor
  • Method Details

    • valueForKey

      public Object valueForKey(Object target, String key)
      Get the target's value for the specified accessor key. Accessor methods are searched by first looking for a method with the name specified by the key. If no such method is found, then a method name is generated by raising the case of the first character of the key and then prepending "get". For example, if the key is "betaX" it will first look for a method called "betaX" and if none is found then look for a method of name "getBetaX". If no such method can be found, then if the target implements the java.util.Map interface, the get method is called on the target with the specified key passed as an argument.
      Parameters:
      target - object from which to get the value
      key - string indicating an accessor method (or Map key)
    • valueForKeyPath

      public Object valueForKeyPath(Object target, String keyPath)
      Get the target's value for the specified key path, but return null if any object along the key path is null.
      Parameters:
      target - object from which to get the value
      keyPath - series of keys joined by "." in between.
    • setValueForKey

      public void setValueForKey(Object target, String key, Object value)
      Set the target's value for the specified accessor key. Setter methods are searched by looking for a method with the name specified by generating a name raising the case of the first character of the key and then prepending "set". For example, if the key is "betaX" it will look for a method called "setBetaX". If no match is found and the target implements the java.util.Map interface, then put method is called on the target with the specified key and value passed as arguments.
      Parameters:
      target - object from which to get the value
      key - string indicating a setter method (or Map key)
      value - the value to set
    • setValueForKeyPath

      public void setValueForKeyPath(Object target, String keyPath, Object value)
      Set the target's value for the specified key path.
      Parameters:
      target - object from which to get the value
      keyPath - series of keys joined by "." in between.
      value - the value to set
    • valueForInvalidAccessor

      protected Object valueForInvalidAccessor(Object target, String key)
      Hook to allow subclasses to provide a value for an invalid key. The current implementation simply throws an exception.
      Parameters:
      target - object from which to get the value
      key - string indicating the accessor which could not be found
    • setValueForInvalidSetter

      protected Object setValueForInvalidSetter(Object target, String key, Object value)
      Hook to allow subclasses to set a value for an invalid key. The current implementation simply throws an exception.
      Parameters:
      target - object from which to get the value
      key - string indicating the setter which could not be found
      value - the value to set