Package com.inductiveautomation.rm.base
Class RMKeyChain
- java.lang.Object
-
- com.inductiveautomation.rm.base.RMKeyChain
-
public class RMKeyChain extends java.lang.Object
This class evaluates a string expression on a given object: RMKeyChain.getValue(object, expression).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
RMKeyChain.Get
This is interface is implemented by objects that can get key chain values themselves.static class
RMKeyChain.Op
-
Constructor Summary
Constructors Constructor Description RMKeyChain(RMKeyChain.Op anOp)
Node constructor.RMKeyChain(RMKeyChain.Op anOp, java.lang.Object child)
Node constructor.RMKeyChain(RMKeyChain.Op anOp, java.lang.Object left, java.lang.Object right)
Node constructor.RMKeyChain(java.lang.Object cond, java.lang.Object tExp, java.lang.Object fExp)
Node constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addChild(java.lang.Object child)
Adds a child to the end of the keychain's child list.static void
addFunctionClass(java.lang.Class aClass)
Adds a class to the list of classes that RM queries for functions.boolean
anyKeyReferencesKey(java.lang.String aKey)
Returns whether given key is used anywhere in expression.static java.lang.String
getAndResetError()
Returns the last error encountered by the key chain parser and resets parser.static java.util.Map
getAssignments()
Returns a thread-local assignments map.static boolean
getBoolValue(java.lang.Object anObj, java.lang.Object aKeyChain)
Convenience - returns a boolean for an object and key chain.java.lang.Object
getChild(int anIndex)
Returns the child at the given index in the keychain.int
getChildCount()
Returns the number of children in the keychain.RMKeyChain
getChildKeyChain(int i)
Returns the child at the given index in the keychain as a keychain.java.lang.String
getChildString(int i)
Returns the child at the given index in the keychain as a string.static double
getDoubleValue(java.lang.Object anObj, java.lang.Object aKeyChain)
Convenience - returns a double for an object and key chain.static java.lang.String
getError()
Returns the last error encountered by the key chain parser (or null).static float
getFloatValue(java.lang.Object anObj, java.lang.Object aKeyChain)
Convenience - returns a float for an object and key chain.static int
getIntValue(java.lang.Object anObj, java.lang.Object aKeyChain)
Convenience - returns an int for an object and key chain.static RMKeyChain
getKeyChain(java.lang.Object aSource)
Returns a keyChain for aSource (should be a String or existing RMKeyChain).static java.util.List
getListValue(java.lang.Object anObj, java.lang.Object aKeyChain)
Convenience - returns a list for an object and key chain.static java.lang.Number
getNumberValue(java.lang.Object anObj, java.lang.Object aKeyChain)
Convenience - returns a number for an object and key chain.RMKeyChain.Op
getOp()
Returns the top level operator of the keychain.static java.lang.String
getStringValue(java.lang.Object anObj, java.lang.Object aKeyChain)
Convenience - returns a string for an object and key chain.java.lang.Object
getValue()
Returns the value of the keychain.static java.lang.Object
getValue(java.lang.Object anObj, RMKeyChain aKeyChain)
Returns the result of evaluating the given key chain on the given object.static java.lang.Object
getValue(java.lang.Object anObj, java.lang.Object aKeyChain)
Returns the result of evaluating the given key chain on the given object.static java.lang.Object
getValue(java.lang.Object aRoot, java.lang.Object anObj, RMKeyChain aKeyChain)
Returns the result of evaluating the given key chain on the given object.static <T> T
getValue(java.lang.Object anObj, java.lang.Object aKeyChain, java.lang.Class<T> aClass)
Returns a key value if it is of given class (otherwise null).static java.lang.Object
getValueImpl(java.lang.Object aRoot, java.lang.Object anObj, RMKeyChain aKeyChain)
Returns the result of evaluating the given key chain on the given object.static java.lang.Object
getValueList(java.util.List aList, RMKeyChain aKeyChain)
Returns the result of evaluating the given key chain on the given list.java.lang.String
getValueString()
Returns the value of the keychain as a string.boolean
hasOp(RMKeyChain.Op anOp)
Returns whether key contains given op.boolean
hasPageReference()
Returns whether given key has a Page/PageMax key reference.static void
setEnumValue(java.lang.Object anObj, RMKeyChain aKeyChain)
Sets the given value for the given key chain + property.static void
setValue(java.lang.Object anObj, RMKeyChain aKeyChain, java.lang.Object aValue)
Sets the given value for the given key chain + property.static void
setValue(java.lang.Object anObj, java.lang.Object aKeyChain, java.lang.Object aValue)
Sets the given value for the given key chain + property.static void
setValueSafe(java.lang.Object anObj, java.lang.String aKey, java.lang.Object aValue)
Sets the value but only prints a warning if it fails.static void
setValueSilent(java.lang.Object anObj, java.lang.String aKey, java.lang.Object aValue)
Tries to set value in given object, ignoring failure exceptions.RMKeyChain
subchain(int anIndex)
Override to give list chance to implement this.java.lang.String
toString()
Returns a string representation of the key chain.
-
-
-
Constructor Detail
-
RMKeyChain
public RMKeyChain(RMKeyChain.Op anOp)
Node constructor.
-
RMKeyChain
public RMKeyChain(RMKeyChain.Op anOp, java.lang.Object child)
Node constructor.
-
RMKeyChain
public RMKeyChain(RMKeyChain.Op anOp, java.lang.Object left, java.lang.Object right)
Node constructor.
-
RMKeyChain
public RMKeyChain(java.lang.Object cond, java.lang.Object tExp, java.lang.Object fExp)
Node constructor.
-
-
Method Detail
-
getKeyChain
public static RMKeyChain getKeyChain(@Nullable java.lang.Object aSource)
Returns a keyChain for aSource (should be a String or existing RMKeyChain).
-
getAssignments
public static java.util.Map getAssignments()
Returns a thread-local assignments map.
-
getOp
public RMKeyChain.Op getOp()
Returns the top level operator of the keychain.
-
getValue
public java.lang.Object getValue()
Returns the value of the keychain.
-
getValueString
public java.lang.String getValueString()
Returns the value of the keychain as a string.
-
getChildCount
public int getChildCount()
Returns the number of children in the keychain.
-
getChild
public java.lang.Object getChild(int anIndex)
Returns the child at the given index in the keychain.
-
addChild
public void addChild(java.lang.Object child)
Adds a child to the end of the keychain's child list.
-
getChildString
public java.lang.String getChildString(int i)
Returns the child at the given index in the keychain as a string.
-
getChildKeyChain
public RMKeyChain getChildKeyChain(int i)
Returns the child at the given index in the keychain as a keychain.
-
subchain
public RMKeyChain subchain(int anIndex)
Override to give list chance to implement this.
-
getValue
@Nullable public static java.lang.Object getValue(@Nullable java.lang.Object anObj, @Nullable java.lang.Object aKeyChain)
Returns the result of evaluating the given key chain on the given object.
-
getValue
@Nullable public static java.lang.Object getValue(java.lang.Object anObj, RMKeyChain aKeyChain)
Returns the result of evaluating the given key chain on the given object.
-
getValue
public static java.lang.Object getValue(java.lang.Object aRoot, java.lang.Object anObj, RMKeyChain aKeyChain)
Returns the result of evaluating the given key chain on the given object.
-
getValueImpl
public static java.lang.Object getValueImpl(java.lang.Object aRoot, java.lang.Object anObj, RMKeyChain aKeyChain)
Returns the result of evaluating the given key chain on the given object. Broken out so objects can implement custom getKeyChainValue but still have access to default implementation.
-
getValueList
public static java.lang.Object getValueList(java.util.List aList, RMKeyChain aKeyChain)
Returns the result of evaluating the given key chain on the given list.
-
getStringValue
public static java.lang.String getStringValue(java.lang.Object anObj, java.lang.Object aKeyChain)
Convenience - returns a string for an object and key chain.
-
getNumberValue
public static java.lang.Number getNumberValue(java.lang.Object anObj, java.lang.Object aKeyChain)
Convenience - returns a number for an object and key chain.
-
getIntValue
public static int getIntValue(java.lang.Object anObj, java.lang.Object aKeyChain)
Convenience - returns an int for an object and key chain.
-
getFloatValue
public static float getFloatValue(java.lang.Object anObj, java.lang.Object aKeyChain)
Convenience - returns a float for an object and key chain.
-
getDoubleValue
public static double getDoubleValue(java.lang.Object anObj, java.lang.Object aKeyChain)
Convenience - returns a double for an object and key chain.
-
getBoolValue
public static boolean getBoolValue(java.lang.Object anObj, java.lang.Object aKeyChain)
Convenience - returns a boolean for an object and key chain.
-
getListValue
@Nullable public static java.util.List getListValue(java.lang.Object anObj, java.lang.Object aKeyChain)
Convenience - returns a list for an object and key chain.
-
getValue
public static <T> T getValue(java.lang.Object anObj, java.lang.Object aKeyChain, java.lang.Class<T> aClass)
Returns a key value if it is of given class (otherwise null).
-
anyKeyReferencesKey
public boolean anyKeyReferencesKey(java.lang.String aKey)
Returns whether given key is used anywhere in expression. Current version is really hard coded to require key to be isolated (not a part of a key chain).
-
hasPageReference
public boolean hasPageReference()
Returns whether given key has a Page/PageMax key reference.
-
hasOp
public boolean hasOp(RMKeyChain.Op anOp)
Returns whether key contains given op.
-
getError
public static java.lang.String getError()
Returns the last error encountered by the key chain parser (or null).
-
getAndResetError
public static java.lang.String getAndResetError()
Returns the last error encountered by the key chain parser and resets parser.
-
setValue
public static void setValue(java.lang.Object anObj, java.lang.Object aKeyChain, java.lang.Object aValue)
Sets the given value for the given key chain + property. This is a real bogus loser implementation.
-
setValue
public static void setValue(java.lang.Object anObj, RMKeyChain aKeyChain, java.lang.Object aValue)
Sets the given value for the given key chain + property. This is a real bogus loser implementation that only supports Op.Key and Op.Chain.
-
setEnumValue
public static void setEnumValue(java.lang.Object anObj, RMKeyChain aKeyChain)
Sets the given value for the given key chain + property. This is a real bogus loser implementation.
-
setValueSafe
public static void setValueSafe(java.lang.Object anObj, java.lang.String aKey, java.lang.Object aValue)
Sets the value but only prints a warning if it fails.
-
setValueSilent
public static void setValueSilent(java.lang.Object anObj, java.lang.String aKey, java.lang.Object aValue)
Tries to set value in given object, ignoring failure exceptions.
-
toString
public java.lang.String toString()
Returns a string representation of the key chain.- Overrides:
toString
in classjava.lang.Object
-
addFunctionClass
public static void addFunctionClass(java.lang.Class aClass)
Adds a class to the list of classes that RM queries for functions.
-
-