Class RMKey.KeyAccessor

java.lang.Object
com.inductiveautomation.rm.base.RMKey.KeyAccessor
Enclosing class:
RMKey

public static class RMKey.KeyAccessor extends Object
KeyAccessor - enclosed class for actually getting/setting values for a given object (class) and key.
  • Constructor Details

    • KeyAccessor

      public KeyAccessor(Object anObj, String aKey)
      Creates a new getter for given object and key (caches type).
  • Method Details

    • get

      public Object get(Object anObj)
      This method actually retrieves a value for an object and a key.
    • getGetMethod

      public Method getGetMethod()
      Searches for a get method for given key then caches and returns result.
    • set

      public void set(Object anObj, Object aValue) throws Exception
      Coerces aValue to this accessor's setter parameter type and invokes that setter on anObj. Coercion is keyed on the setter's parameter type (the type the setter declares for its argument), not the value's type — so setName(String) stringifies an Integer 42, while setCount(int) parses the String "42". The conversion applied for each parameter type (numeric, String, Number, and Date route through RMUtils; the rest convert inline). The parameter type and how it's coerced is as follows:

      A List value is treated by the setter's type: a scalar setter receives the list's first element (an empty list is passed as-is), while a List-typed setter receives the whole list. So setName(String) with ["a","b"] stores "a", but setItems(List) stores ["a","b"].

      Parameters:
      anObj - the object whose setter is invoked
      aValue - the value to coerce and set
      Throws:
      NoSuchMethodException - if no setter can be resolved for this accessor's key
      Exception - if the setter throws, or rejects the (uncoerced) value's type
    • getSetMethod

      public Method getSetMethod() throws Exception
      Searches for a set method for given key then caches and returns result.
      Throws:
      Exception