Package xal.tools.data
Class KeyValueAdaptor
java.lang.Object
xal.tools.data.KeyValueAdaptor
Provides methods to set and get an object's values for its named properties
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Exception thrown to indicate that an accessor cannot be found for the specified target/key pair.static class
Exception thrown to indicate that a setter cannot be found for the specified target/key/value group. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected Object
setValueForInvalidSetter
(Object target, String key, Object value) Hook to allow subclasses to set a value for an invalid key.void
setValueForKey
(Object target, String key, Object value) Set the target's value for the specified accessor key.void
setValueForKeyPath
(Object target, String keyPath, Object value) Set the target's value for the specified key path.protected Object
valueForInvalidAccessor
(Object target, String key) Hook to allow subclasses to provide a value for an invalid key.valueForKey
(Object target, String key) Get the target's value for the specified accessor key.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.
-
Constructor Details
-
KeyValueAdaptor
public KeyValueAdaptor()Constructor
-
-
Method Details
-
valueForKey
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 valuekey
- string indicating an accessor method (or Map key)
-
valueForKeyPath
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 valuekeyPath
- series of keys joined by "." in between.
-
setValueForKey
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 valuekey
- string indicating a setter method (or Map key)value
- the value to set
-
setValueForKeyPath
Set the target's value for the specified key path.- Parameters:
target
- object from which to get the valuekeyPath
- series of keys joined by "." in between.value
- the value to set
-
valueForInvalidAccessor
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 valuekey
- string indicating the accessor which could not be found
-
setValueForInvalidSetter
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 valuekey
- string indicating the setter which could not be foundvalue
- the value to set
-