public class Script extends Object implements ObjectStorage, Serializable
| Modifier and Type | Field and Description |
|---|---|
static Set<String> |
JAVA_SCRIPT_KEYWORDS |
static String |
JAVA_SCRIPT_LANG |
static Set<String> |
LEFT_EXCEPTIONS |
static String |
PYTHON_SCRIPT_LANG |
static Set<String> |
RIGHT_EXCEPTIONS |
| Constructor and Description |
|---|
Script()
Instantiates new Script object.
|
| Modifier and Type | Method and Description |
|---|---|
static String |
any2Js(String code)
Converts any script to javascript.
|
static String |
any2Js(String code,
String importStr)
Converts any script to javascript.
|
void |
clear()
Clears the storage.
|
boolean |
compile(ObjectStorage objectStorage,
String name,
String code,
String lang,
Boolean... compatible)
Compiles script if it is possible.
|
Object |
eval(ObjectStorage objectStorage,
Bindings bindings,
String name,
String lang)
Evaluates script.
|
static TypedKeyValue<String,TypedKeyValue<Integer,Integer>> |
findBestOperand(String value,
String[] ops)
Find best operand.
|
Bindings |
getBindings(ObjectStorage objectStorage,
String lang)
Returns an uninitialized
Bindings for the script engine
defined by lang. |
Bindings |
getBindings(ObjectStorage objectStorage,
String lang,
String key)
Gets the bindings.
|
String |
getString(String key)
Gets the string representation of the value by the key.
|
Object |
getValue(String key)
Gets the value by the key.
|
LinkedHashMap<String,String> |
getVariables(ObjectStorage objectStorage,
String code)
Gets the variables.
|
static LinkedHashMap<String,String> |
getVariables(String code)
Returns list of potential variables from the code.
|
boolean |
hasCompiledCode(ObjectStorage objectStorage,
String name)
Checks if code has been compiled.
|
static boolean |
hasVarsToBind(String code)
Checks if script has for potential variables to bind.
|
static Script |
insatnce() |
static List<String> |
parseExpression(String value,
String[] connectors)
Parse the expression.
|
static String[] |
parseExpressionLine(String value,
String[] ops,
String[] connectors)
Parses string and return parts of the expression.
|
static String |
parseFunctions(String code,
Map<String,String> patterns)
Parses the functions.
|
void |
setValue(String key,
Object value)
Associates value with the key.
|
static String |
sql2Java(String code)
Replaces SQL like boolean operations.
|
public static String JAVA_SCRIPT_LANG
public static String PYTHON_SCRIPT_LANG
public static Set<String> JAVA_SCRIPT_KEYWORDS
public static final Set<String> LEFT_EXCEPTIONS
public static final Set<String> RIGHT_EXCEPTIONS
public static String any2Js(String code)
code - the scriptpublic static String any2Js(String code,
String importStr)
code - the scriptimportStr - the import stringpublic static TypedKeyValue<String,TypedKeyValue<Integer,Integer>> findBestOperand(String value, String[] ops)
value - the string to parseops - the operandspublic static LinkedHashMap<String,String> getVariables(String code)
code - the codepublic static boolean hasVarsToBind(String code)
code - the codepublic static List<String> parseExpression(String value,
String[] connectors)
value - the expression to parseconnectors - the connectorspublic static String[] parseExpressionLine(String value,
String[] ops,
String[] connectors)
value - the string to parseops - the operandsconnectors - the connectorspublic static String parseFunctions(String code,
Map<String,String> patterns)
Example: sum(abc) + avg(xyz) -- com.toolsverse.function.Stat.sum(abc, context) + com.toolsverse.function.Stat.avg(xyz, context)
code - the codepatterns - the patternspublic static String sql2Java(String code)
or -> || and -> && not -> ! == -> =
code - the codepublic static Script insatnce()
public void clear()
public boolean compile(ObjectStorage objectStorage, String name, String code, String lang, Boolean... compatible) throws Exception
objectStorage - the storage for the compiled scriptsname - the name of the scriptcode - the scriptlang - the script language namecompatible - if true script is compatible with all versions of JSException - in case of any errorpublic Object eval(ObjectStorage objectStorage, Bindings bindings, String name, String lang) throws ScriptException
objectStorage - the storage for the compiled scriptsbindings - the bindingsname - the name of the scriptlang - the script language nameScriptException - in case of any errorpublic Bindings getBindings(ObjectStorage objectStorage, String lang)
Bindings for the script engine
defined by lang.objectStorage - the object storagelang - the script languagepublic Bindings getBindings(ObjectStorage objectStorage, String lang, String key)
objectStorage - the object storagelang - the languagekey - the cache keypublic LinkedHashMap<String,String> getVariables(ObjectStorage objectStorage, String code)
objectStorage - the object storagecode - the codepublic String getString(String key)
ObjectStoragegetString in interface ObjectStoragekey - the keypublic Object getValue(String key)
ObjectStoragegetValue in interface ObjectStoragekey - the keypublic boolean hasCompiledCode(ObjectStorage objectStorage, String name)
objectStorage - the object storagename - the namepublic void setValue(String key,
Object value)
ObjectStoragesetValue in interface ObjectStoragekey - the keyvalue - the valueCopyright © 2010-2020 Toolsverse. All Rights Reserved.