Package com.identityworksllc.iiq.common
Class BeanshellUtilities
- java.lang.Object
-
- com.identityworksllc.iiq.common.BeanshellUtilities
-
public class BeanshellUtilities extends Object
Utilities for working with Beanshell at a language level
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Object
coerce(bsh.This bshThis, Class<?>... types)
Create a Proxy implementing the given interface which will invoke a similarly named Beanshell method for any function call to the interface.static <T> T
coerce(Class<T> type, bsh.This bshThis, String methodName)
Create a Proxy implementing the given class which will invoke the given Beanshell function for any method call.static <T> T
coerce(Class<T> type, bsh.This bshThis, String targetMethod, String methodName)
Create a Proxy implementing the given class which will invoke the given Beanshell function for any method call.static void
dump(bsh.This namespace, org.apache.commons.logging.Log logger)
Dumps the beanshell namespace passed to this method to the given loggerstatic boolean
exists(Object bshThis, String variableName)
An indirect reference toexists(bsh.This, String)
that will allow the Eclipse plugin to compile rules properly.static <T> T
get(bsh.This bshThis, String variableName, Class<T> expectedType)
Gets the value of the Beanshell variable, if it exists and is the expected object type, otherwise null.static <T> T
get(Object bshThis, String variableName, Class<T> expectedType)
Gets the value of the Beanshell variable, if it exists and is the expected object type, otherwise null.static org.apache.bsf.BSFManager
getBSFManager(org.apache.bsf.util.BSFFunctions bsf)
Extracts the BSFManager from the current Beanshell context using reflectionstatic void
importStatic(bsh.This bshThis, Class<?> target)
Imports static methods from the given target class into the namespacestatic boolean
runRuleTerminated(bsh.This bshThis)
Intended to be invoked from a Run Rule task (or code that may be invoked from one), will check whether the task has been stopped.static void
safe(Object bshThis, String variableName)
If the given variable does not exist, sets it to null, enabling ordinary null checks.static void
safe(Object bshThis, String variableName, Object defaultValue)
If the given variable does not exist, sets it to null, enabling ordinary null checks.static boolean
safeEquals(Object bshThis, String variableName, Object expectedValue)
Returns true if the variable exists and is equal to the expected value.
-
-
-
Method Detail
-
coerce
public static Object coerce(bsh.This bshThis, Class<?>... types)
Create a Proxy implementing the given interface which will invoke a similarly named Beanshell method for any function call to the interface.- Parameters:
bshThis
- The ‘this’ instance in Beanshelltypes
- The interface types that the Beanshell context ought to proxy- Returns:
- the proxy implementing the interface
-
coerce
public static <T> T coerce(Class<T> type, bsh.This bshThis, String methodName)
Create a Proxy implementing the given class which will invoke the given Beanshell function for any method call.This should be used mainly for “functional” interfaces with a single abstract method, like Runnable or Callable or the various event handlers.
- Type Parameters:
T
- the interface type to implement- Parameters:
type
- The proxy typebshThis
- The ‘this’ instance in BeanshellmethodName
- The method name to invoke on method call- Returns:
- the proxy implementing the interface
-
coerce
public static <T> T coerce(Class<T> type, bsh.This bshThis, String targetMethod, String methodName)
Create a Proxy implementing the given class which will invoke the given Beanshell function for any method call.This should be used mainly for “functional” interfaces with a single abstract method, like Runnable or Callable or the various event handlers.
- Type Parameters:
T
- the interface type to implement- Parameters:
type
- The proxy typebshThis
- The ‘this’ instance in BeanshelltargetMethod
- The method to intercept on the interface (e.g. ‘run’ on a Runnable)methodName
- The Beanshell method name to invoke on method call- Returns:
- the proxy implementing the interface
-
dump
public static void dump(bsh.This namespace, org.apache.commons.logging.Log logger) throws bsh.UtilEvalError, sailpoint.tools.GeneralException
Dumps the beanshell namespace passed to this method to the given logger- Parameters:
namespace
- The beanshell namespace to dump- Throws:
bsh.UtilEvalError
- On errors getting the variable valuesailpoint.tools.GeneralException
- If a Sailpoint exception occurs
-
exists
public static boolean exists(Object bshThis, String variableName)
An indirect reference toexists(bsh.This, String)
that will allow the Eclipse plugin to compile rules properly.If the bshThis passed is not a This object, this method will silently return false.
- Parameters:
bshThis
- The Beanshell this variablevariableName
- The variable name to check- Returns:
- True if the variable exists, false otherwise
-
getBSFManager
public static org.apache.bsf.BSFManager getBSFManager(org.apache.bsf.util.BSFFunctions bsf) throws sailpoint.tools.GeneralException
Extracts the BSFManager from the current Beanshell context using reflection- Parameters:
bsf
- The ‘bsf’ variable passed to all Beanshell scripts- Returns:
- The BSFManager
- Throws:
sailpoint.tools.GeneralException
- if any issues occur retrieving the value using reflection
-
get
public static <T> T get(Object bshThis, String variableName, Class<T> expectedType)
Gets the value of the Beanshell variable, if it exists and is the expected object type, otherwise null.- Type Parameters:
T
- The expected object type- Parameters:
bshThis
- The beanshell ‘this’ objectvariableName
- The variable name to retrieveexpectedType
- The expected type of the variable- Returns:
- The value of the given variable, or null
-
get
public static <T> T get(bsh.This bshThis, String variableName, Class<T> expectedType)
Gets the value of the Beanshell variable, if it exists and is the expected object type, otherwise null.- Type Parameters:
T
- The expected object type- Parameters:
bshThis
- The beanshell ‘this’ objectvariableName
- The variable name to retrieveexpectedType
- The expected type of the variable- Returns:
- The value of the given variable, or null
-
importStatic
public static void importStatic(bsh.This bshThis, Class<?> target)
Imports static methods from the given target class into the namespace- Parameters:
bshThis
- The ‘this’ reference from Beanshelltarget
- The target class to import
-
runRuleTerminated
public static boolean runRuleTerminated(bsh.This bshThis)
Intended to be invoked from a Run Rule task (or code that may be invoked from one), will check whether the task has been stopped.- Parameters:
bshThis
- The ‘this’ object from Beanshell- Returns:
- True if the task has been terminated
-
safe
public static void safe(Object bshThis, String variableName, Object defaultValue) throws sailpoint.tools.GeneralException
If the given variable does not exist, sets it to null, enabling ordinary null checks.If the “this” reference is not a Beanshell context, this method will have no effect.
- Parameters:
bshThis
- The current Beanshell namespacevariableName
- The variable namedefaultValue
- The default value- Throws:
sailpoint.tools.GeneralException
- if any failures occur
-
safe
public static void safe(Object bshThis, String variableName) throws sailpoint.tools.GeneralException
If the given variable does not exist, sets it to null, enabling ordinary null checks.If the “this” reference is not a Beanshell context, this method will have no effect.
- Parameters:
bshThis
- The current Beanshell namespacevariableName
- The variable name- Throws:
sailpoint.tools.GeneralException
- if any failures occur
-
safeEquals
public static boolean safeEquals(Object bshThis, String variableName, Object expectedValue) throws sailpoint.tools.GeneralException
Returns true if the variable exists and is equal to the expected value.If the variable is null or void, it will match an expected value of null. If the variable is not null or void, it will be passed to
Util.nullSafeEq(Object, Object)
.- Parameters:
bshThis
- The ‘this’ object from BeanshellvariableName
- The variable name to extractexpectedValue
- The value we expect the variable to have- Returns:
- True if the variable’s value is equal to the expected value
- Throws:
sailpoint.tools.GeneralException
- if reading the variable fails
-
-