Package com.inductiveautomation.rm.base
Class RMKey.KeyAccessor
java.lang.Object
com.inductiveautomation.rm.base.RMKey.KeyAccessor
- Enclosing class:
- RMKey
KeyAccessor - enclosed class for actually getting/setting values for a given object (class) and
key.
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionKeyAccessor(Object anObj, String aKey) Creates a new getter for given object and key (caches type). -
Method Summary
Modifier and TypeMethodDescriptionThis method actually retrieves a value for an object and a key.Searches for a get method for given key then caches and returns result.Searches for a set method for given key then caches and returns result.voidCoercesaValueto this accessor's setter parameter type and invokes that setter onanObj.
-
Constructor Details
-
KeyAccessor
Creates a new getter for given object and key (caches type).
-
-
Method Details
-
get
This method actually retrieves a value for an object and a key. -
getGetMethod
Searches for a get method for given key then caches and returns result. -
set
CoercesaValueto this accessor's setter parameter type and invokes that setter onanObj. Coercion is keyed on the setter's parameter type (the type the setter declares for its argument), not the value's type — sosetName(String)stringifies anInteger42, whilesetCount(int)parses the String"42". The conversion applied for each parameter type (numeric,String,Number, andDateroute throughRMUtils; the rest convert inline). The parameter type and how it's coerced is as follows:- numeric primitives/wrappers — passed through if the value is already that wrapper class
(
Integerfor anint/Integersetter,Longforlong, etc.; note a value reaches here boxed, sinceaValueis anObject), else coerced (e.g."42" -> 42,5L -> 5);byte/shortnarrow and may wrap String— alwaysRMUtils.stringValue(java.lang.Object)(e.g.42 -> "42")- other
Numbersubtypes —RMUtils.numberValue(java.lang.Object);Date—RMUtils.getDate(java.lang.Object) - an
enum— only aStringvalue is resolved, by name viaEnum.valueOf(java.lang.Class<T>, java.lang.String)(the enum constant itself also works; other types are passed through unchanged) ColorfromRMColorand vice-versa;Filefrom a String path- any type with no matching rule — passed through unchanged
A
Listvalue is treated by the setter's type: a scalar setter receives the list's first element (an empty list is passed as-is), while aList-typed setter receives the whole list. SosetName(String)with["a","b"]stores"a", butsetItems(List)stores["a","b"].- Parameters:
anObj- the object whose setter is invokedaValue- the value to coerce and set- Throws:
NoSuchMethodException- if no setter can be resolved for this accessor's keyException- if the setter throws, or rejects the (uncoerced) value's type
- numeric primitives/wrappers — passed through if the value is already that wrapper class
(
-
getSetMethod
Searches for a set method for given key then caches and returns result.- Throws:
Exception
-