Package org.cristalise.kernel.scripting
Class Script
java.lang.Object
org.cristalise.kernel.scripting.Script
- All Implemented Interfaces:
DescriptionObject
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionScript()Constructor for castor unmarshallParses a given script xml, instead of loading it from Items.Parses a given script xml, instead of loading it from Items.Creates a script executor for the supplied expression, bypassing the xml parsing bit Output class is forced to an object.Creates a script executor for the supplied expression, bypassing the xml parsing bitScript(String lang, String name, String expr, AgentProxy agent) Creates a script executor requiring an agent to be set.Creates a script executor requiring an agent to be set.Script(String lang, AgentProxy agent, PrintStream out) For consoles -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddIncludedInputParam(String name, Class<?> type) voidaddInputParam(String name, Class<?> type) voidaddInputParam(String name, String type) voidvoidevaluate(ItemPath itemPath, CastorHashMap inputProps, String actContext, boolean actExecEnv, TransactionKey transactionKey) Reads and evaluates input properties, set input parameters from those properties and executes the Scriptevaluate(ItemPath itemPath, CastorHashMap inputProps, String actContext, TransactionKey transactionKey) evaluate(CastorHashMap inputProps) Use this when a Script is executed without an Item or Transaction contextexecute()Executes the script with the submitted parameters.Method for castor marshallstatic ScriptResolves the Script object using its name and version.static ScriptgetScript(String name, Integer version, TransactionKey transactionKey) Resolves the Script object using its name and version.getXml(boolean prettyPrint) static voidmakeDescCollections(TransactionKey transactionKey) voidsetContext(ScriptContext context) voidsetIncludes(ArrayList<Include> includes) Method for castor unmarshallbooleansetInputParamValue(String name, Object value) Submits an input parameter to the script.booleansetInputParamValue(String name, Object value, boolean overwrite) Submits an input parameter to the script.voidsetScriptData(String script) voidsetScriptEngine(String requestedLang) Sets the languagetoString()toXml()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.cristalise.kernel.utils.DescriptionObject
exists, export, getItemPath, getName, getNamespace, getVersion, getXml, makeDescCollection, setItemPath, setName, setNamespace, setVersion, toOutcome
-
Field Details
-
PARAMETER_AGENT
- See Also:
-
PARAMETER_DB
- See Also:
-
PARAMETER_ITEM
- See Also:
-
PARAMETER_JOB
- See Also:
-
PARAMETER_LOCKER
- See Also:
-
PARAMETER_LOOKUP
- See Also:
-
PARAMETER_OUTPUT
- See Also:
-
PARAMETER_VERTX
- See Also:
-
PARAMETER_STORAGE
- See Also:
-
SYSTEM_USER
- See Also:
-
-
Constructor Details
-
Script
public Script()Constructor for castor unmarshall -
Script
public Script(String name, Integer version, ItemPath path, String xml) throws ScriptParsingException, ParameterException Parses a given script xml, instead of loading it from Items.- Parameters:
name- the name of the Scriptversion- the version of the Scriptpath- the Itempath if the Script (can be null)xml- the marshalled Script- Throws:
ScriptParsingException- there was an error parsing the xmlParameterException- there was an error parsing the parameters
-
Script
public Script(String name, Integer version, ItemPath path, String xml, boolean lateBind) throws ScriptParsingException, ParameterException Parses a given script xml, instead of loading it from Items.- Parameters:
name- the name of the Scriptversion- the version of the Scriptpath- the Itempath if the Script (can be null)xml- the marshalled ScriptlateBind- do not try to resolve the Items of the included scripts during the XML parse- Throws:
ScriptParsingException- there was an error parsing the xmlParameterException- there was an error parsing the parameters
-
Script
Creates a script executor for the supplied expression, bypassing the xml parsing bit- Parameters:
lang- - script languageexpr- - the script to runreturnType- Class of the return of the Script- Throws:
ScriptingEngineException
-
Script
public Script(String lang, String name, String expr, AgentProxy agent) throws ScriptingEngineException Creates a script executor requiring an agent to be set. Used by module event scripts.- Parameters:
lang- - script languagename- - script name for debuggingexpr- - the script to runagent- - the agentproxy to pass into the script as 'agent'- Throws:
ScriptingEngineException
-
Script
public Script(String lang, String name, String expr, AgentProxy agent, Class<?> returnType) throws ScriptingEngineException Creates a script executor requiring an agent to be set. Used by module event scripts.- Parameters:
lang- - script languagename- - script name for debuggingexpr- - the script to runagent- - the agentproxy to pass into the script as 'agent'- Throws:
ScriptingEngineException
-
Script
Creates a script executor for the supplied expression, bypassing the xml parsing bit Output class is forced to an object.- Parameters:
lang- - script languageexpr- - the script to run- Throws:
ScriptingEngineException
-
Script
For consoles- Parameters:
lang- - script languageagent- - Proxy of the console Agent(user)out- - the output PrintStream for reporting results that don't go to the log- Throws:
Exception
-
-
Method Details
-
setScriptEngine
Sets the language- Parameters:
requestedLang- the language- Throws:
ScriptingEngineException
-
setContext
- Parameters:
context-ScriptContext
-
getContext
- Returns:
ScriptContext
-
addInputParam
- Parameters:
name-type-- Throws:
ParameterException
-
addInputParam
- Throws:
ParameterException
-
addIncludedInputParam
- Parameters:
name-type-- Throws:
ParameterException
-
addOutput
- Parameters:
name-type-- Throws:
ParameterException
-
addOutput
- Parameters:
name-type-- Throws:
ParameterException
-
setInputParamValue
Submits an input parameter to the script. Must be declared by name and type in the script XML. The value will be overwritten even if it was set before.- Parameters:
name- - input parameter name from the script xmlvalue- - object to use for this parameter- Returns:
- if the input parameter was used or not
- Throws:
ParameterException- - name not found or wrong type
-
setInputParamValue
public boolean setInputParamValue(String name, Object value, boolean overwrite) throws ParameterException Submits an input parameter to the script. Must be declared by name and type in the script XML.- Parameters:
name- - input parameter name from the script xmlvalue- - object to use for this parameteroverwrite- - if the value should be overwritten even if it was set before- Returns:
- if the input parameter was used or not
- Throws:
ParameterException- - name not found or wrong type
-
evaluate
Use this when a Script is executed without an Item or Transaction context- Parameters:
inputProps- the inputs of the script- Returns:
- the result of the execution
- Throws:
ScriptingEngineException- something went wrong during the execution
-
evaluate
public Object evaluate(ItemPath itemPath, CastorHashMap inputProps, String actContext, TransactionKey transactionKey) throws ScriptingEngineException - Parameters:
itemPath-inputProps-actContext-transactionKey-- Returns:
- Throws:
ScriptingEngineException
-
evaluate
public Object evaluate(ItemPath itemPath, CastorHashMap inputProps, String actContext, boolean actExecEnv, TransactionKey transactionKey) throws ScriptingEngineException Reads and evaluates input properties, set input parameters from those properties and executes the Script- Parameters:
itemPath- the Item contextinputProps- input propertiesactContext- activity pathtransactionKey- transaction transactionKey- Returns:
- the values returned by the Script
- Throws:
ScriptingEngineException
-
execute
Executes the script with the submitted parameters. All declared input parameters should have been set first. It executes the included scripts first because they might set input parameters, for the actual Script. NOT thread-safe!!!!- Returns:
- The return value depends on the way the output type was declared in the script xml.
- If there was no output class declared then null is returned
- If a class was declared, but not named, then the object returned by the script is checked to be of that type, then returned.
- If the output value was named and typed, then an object of that class is created and passed to the script as an input parameter. The script should set this before it returns.
- Throws:
ScriptingEngineException- - input parameters weren't set, there was an error executing the script, or the output was invalid
-
setScriptData
- Throws:
ScriptParsingException
-
getScriptData
-
getItemID
- Specified by:
getItemIDin interfaceDescriptionObject
-
getScript
public static Script getScript(String name, Integer version) throws ScriptingEngineException, ObjectNotFoundException, InvalidDataException Resolves the Script object using its name and version. If Version is null tries to interpret the name as an expression- Parameters:
name- the name of the Script Item or an expressionversion- the version of the Script. If set to null- Returns:
Script- Throws:
ScriptingEngineExceptionObjectNotFoundExceptionInvalidDataException- See Also:
-
getScript
public static Script getScript(String name, Integer version, TransactionKey transactionKey) throws ScriptingEngineException, ObjectNotFoundException, InvalidDataException Resolves the Script object using its name and version. If Version is null tries to interpret the name as an expression- Parameters:
name- the name of the Script Item or an expressionversion- the version of the Script. If set to nulltransactionKey- key of the transaction- Returns:
Script- Throws:
ScriptingEngineExceptionObjectNotFoundExceptionInvalidDataException- See Also:
-
getIncludes
Method for castor marshall- Returns:
- list of Include objects
-
setIncludes
public void setIncludes(ArrayList<Include> includes) throws ObjectNotFoundException, InvalidDataException, ParameterException, ScriptParsingException Method for castor unmarshall- Parameters:
includes- included Scripts- Throws:
ObjectNotFoundExceptionInvalidDataExceptionParameterExceptionScriptParsingException
-
makeDescCollections
public CollectionArrayList makeDescCollections(TransactionKey transactionKey) throws InvalidDataException, ObjectNotFoundException - Specified by:
makeDescCollectionsin interfaceDescriptionObject- Throws:
InvalidDataExceptionObjectNotFoundException
-
getXml
- Specified by:
getXmlin interfaceDescriptionObject- Throws:
InvalidDataException
-
getResourceType
- Specified by:
getResourceTypein interfaceDescriptionObject
-
main
-
toXml
- Throws:
IOException
-
toString
-