public final class ScriptVars extends Object
The global variables are meant to be accessible by all scripts and the script variables are meant to be accessible by just a given script (identified by its name).
Note: While it's possible to a script to access the variables of another script that usage is discouraged.
The keys and (string) values of the variables have restrictions on its character length:
There's a maximum number of global/script variables:
Modifier and Type | Method and Description |
---|---|
static void |
clear()
Clears all variables, global and script.
|
static void |
clearGlobalVars()
Clears the global variables.
|
static void |
clearScriptVars(String scriptName)
Clears the variables of the script with the given name.
|
static Object |
getGlobalCustomVar(String key)
Gets a global custom variable.
|
static Map<String,Object> |
getGlobalCustomVars()
Gets an unmodifiable map, variable key to value, containing the global custom variables.
|
static String |
getGlobalVar(String key)
Gets a global variable.
|
static Map<String,String> |
getGlobalVars()
Gets an unmodifiable map, variable key to value, containing the global variables.
|
static Object |
getScriptCustomVar(ScriptContext context,
String key)
Gets a script custom variable.
|
static Object |
getScriptCustomVar(String scriptName,
String key)
Gets a custom variable from the script with the given name.
|
static Map<String,Object> |
getScriptCustomVars(String scriptName)
Gets an unmodifiable map, variable key to value, containing the custom variables of the
script with the given name.
|
static String |
getScriptVar(ScriptContext context,
String key)
Gets a script variable.
|
static String |
getScriptVar(String scriptName,
String key)
Gets a variable from the script with the given name.
|
static Map<String,String> |
getScriptVars(String scriptName)
Gets an unmodifiable map, variable key to value, containing the variables of the script with
the given name.
|
static void |
setGlobalCustomVar(String key,
Object value)
Sets or removes a global custom variable.
|
static void |
setGlobalVar(String key,
String value)
Sets or removes a global variable.
|
static void |
setScriptCustomVar(ScriptContext context,
String key,
Object value)
Sets or removes a script custom variable.
|
static void |
setScriptCustomVar(String scriptName,
String key,
Object value)
Sets or removes a script custom variable.
|
static void |
setScriptVar(ScriptContext context,
String key,
String value)
Sets or removes a script variable.
|
static void |
setScriptVar(String scriptName,
String key,
String value)
Sets or removes a script variable.
|
public static void setGlobalVar(String key, String value)
The variable is removed when the value
is null
.
key
- the key of the variable.value
- the value of the variable.IllegalArgumentException
- if one of the following conditions is met:
key
is null
or its length is higher than the maximum allowed
();
value
's length is higher than the maximum allowed ();
public static String getGlobalVar(String key)
key
- the key of the variable.null
if no value was previously set.public static Map<String,String> getGlobalVars()
Iterations should be done in a synchronised block using the returned map.
null
.public static void setGlobalCustomVar(String key, Object value)
The variable is removed when the value
is null
.
key
- the key of the variable.value
- the value of the variable.IllegalArgumentException
- if one of the following conditions is met:
key
is null
or its length is higher than the maximum allowed
();
public static Object getGlobalCustomVar(String key)
key
- the key of the variable.null
if no value was previously set.public static Map<String,Object> getGlobalCustomVars()
Iterations should be done in a synchronised block using the returned map.
null
.public static void setScriptVar(ScriptContext context, String key, String value)
The variable is removed when the value
is null
.
context
- the context of the script.key
- the key of the variable.value
- the value of the variable.IllegalArgumentException
- if one of the following conditions is met:
context
is null
or it does not contain the name of the script;
key
is null
or its length is higher than the maximum allowed
();
value
's length is higher than the maximum allowed ();
public static void setScriptVar(String scriptName, String key, String value)
The variable is removed when the value
is null
.
scriptName
- the name of the script.key
- the key of the variable.value
- the value of the variable.IllegalArgumentException
- if one of the following conditions is met:
scriptName
is null
;
key
is null
or its length is higher than the maximum allowed
();
value
's length is higher than the maximum allowed ();
public static String getScriptVar(ScriptContext context, String key)
context
- the context of the script.key
- the key of the variable.null
if no value was previously set.IllegalArgumentException
- if the context
is null
or it does not
contain the name of the script.public static String getScriptVar(String scriptName, String key)
scriptName
- the name of the script.key
- the key of the variable.null
if no value was previously set.IllegalArgumentException
- if the scriptName
is null
.public static Map<String,String> getScriptVars(String scriptName)
Iterations should be done in a synchronised block using the returned map.
scriptName
- the name of the script.null
.public static void setScriptCustomVar(ScriptContext context, String key, Object value)
The variable is removed when the value
is null
.
context
- the context of the script.key
- the key of the variable.value
- the value of the variable.IllegalArgumentException
- if one of the following conditions is met:
context
is null
or it does not contain the name of the script;
key
is null
or its length is higher than the maximum allowed
();
public static void setScriptCustomVar(String scriptName, String key, Object value)
The variable is removed when the value
is null
.
scriptName
- the name of the script.key
- the key of the variable.value
- the value of the variable.IllegalArgumentException
- if one of the following conditions is met:
scriptName
is null
;
key
is null
or its length is higher than the maximum allowed
();
public static Object getScriptCustomVar(ScriptContext context, String key)
context
- the context of the script.key
- the key of the variable.null
if no value was previously set.IllegalArgumentException
- if the context
is null
or it does not
contain the name of the script.public static Object getScriptCustomVar(String scriptName, String key)
scriptName
- the name of the script.key
- the key of the variable.null
if no value was previously set.IllegalArgumentException
- if the scriptName
is null
.public static Map<String,Object> getScriptCustomVars(String scriptName)
Iterations should be done in a synchronised block using the returned map.
scriptName
- the name of the script.null
.public static void clearGlobalVars()
clear()
,
clearScriptVars(String)
public static void clearScriptVars(String scriptName)
scriptName
- the name of the script.clear()
,
clearGlobalVars()
public static void clear()
clearGlobalVars()
,
clearScriptVars(String)