public class DefaultScriptService extends AbstractSingletonService<ScriptLanguage> implements ScriptService
SCRIPTS_PATH_PROPERTY, SCRIPTS_RESOURCE_DIR
Constructor and Description |
---|
DefaultScriptService() |
Modifier and Type | Method and Description |
---|---|
void |
addAlias(String alias,
Class<?> type)
TODO
|
void |
addScriptDirectory(File scriptDirectory)
Adds a base directory to scan for scripts.
|
void |
addScriptDirectory(File scriptDirectory,
MenuPath menuPrefix)
Adds a base directory to scan for scripts, placing discovered scripts
beneath the given menu path prefix.
|
Map<String,Class<?>> |
getAliases()
TODO
|
ScriptLanguageIndex |
getIndex()
Gets the index of available scripting languages.
|
MenuPath |
getMenuPrefix(File scriptDirectory)
Gets the menu path prefix for the given script directory, or null if none.
|
ScriptInfo |
getScript(File scriptFile)
Gets the cached
ScriptInfo metadata for the script at the given
file, creating it if it does not already exist. |
List<File> |
getScriptDirectories()
Gets the base directories to scan for scripts.
|
Collection<ScriptInfo> |
getScripts()
Gets all available scripts.
|
void |
initialize()
Performs any needed initialization when the service is first loaded.
|
Class<?> |
lookupClass(String alias)
TODO
|
void |
removeScriptDirectory(File scriptDirectory)
Removes a base directory to scan for scripts.
|
Future<ScriptModule> |
run(File file,
boolean process,
Map<String,Object> inputMap)
Executes the script in the given file.
|
Future<ScriptModule> |
run(File file,
boolean process,
Object... inputs)
Executes the script in the given file.
|
Future<ScriptModule> |
run(ScriptInfo info,
boolean process,
Map<String,Object> inputMap)
Executes the given script.
|
Future<ScriptModule> |
run(ScriptInfo info,
boolean process,
Object... inputs)
Executes the given script.
|
getInstance, getInstances, objectService, onEvent, onEvent
pluginService
getContext, setContext, toString
getInfo, getPriority, setInfo, setPriority
context
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
addAlias, canHandleFile, canHandleFile, getLanguageByExtension, getLanguageByName, getLanguages, getPluginType, run, run, run, run
create, filterInstances, getInstance, getInstances, objectService
getPlugins, getPluginService, pluginService
registerEventHandlers
getIdentifier, log
context, getContext, setContext
compareTo, getPriority, setPriority
getInfo, setInfo
getLocation
getVersion
dispose
public ScriptLanguageIndex getIndex()
ScriptService
getIndex
in interface ScriptService
public List<File> getScriptDirectories()
ScriptService
getScriptDirectories
in interface ScriptService
public MenuPath getMenuPrefix(File scriptDirectory)
ScriptService
getMenuPrefix
in interface ScriptService
public void addScriptDirectory(File scriptDirectory)
ScriptService
addScriptDirectory
in interface ScriptService
public void addScriptDirectory(File scriptDirectory, MenuPath menuPrefix)
ScriptService
addScriptDirectory
in interface ScriptService
public void removeScriptDirectory(File scriptDirectory)
ScriptService
removeScriptDirectory
in interface ScriptService
public Collection<ScriptInfo> getScripts()
ScriptService
getScripts
in interface ScriptService
public ScriptInfo getScript(File scriptFile)
ScriptService
ScriptInfo
metadata for the script at the given
file, creating it if it does not already exist.getScript
in interface ScriptService
public Future<ScriptModule> run(File file, boolean process, Object... inputs)
ScriptService
run
in interface ScriptService
file
- File containing the script to execute.process
- If true, executes the script with pre- and postprocessing
steps from all available PreprocessorPlugin
s and
PostprocessorPlugin
s in the plugin index; if false,
executes the script with no pre- or postprocessing.inputs
- List of input parameter names and values. The expected order
is in pairs: an input name followed by its value, for each desired
input to populate. Leaving some inputs unpopulated is allowed.
Passing the name of an input that is not valid for the plugin, or
passing a value of a type incompatible with the associated input
parameter, will issue an error and ignore that name/value pair.Future
of the module instance being executed. Calling
Future.get()
will block until execution is complete.public Future<ScriptModule> run(File file, boolean process, Map<String,Object> inputMap)
ScriptService
run
in interface ScriptService
file
- File containing the script to execute.process
- If true, executes the script with pre- and postprocessing
steps from all available PreprocessorPlugin
s and
PostprocessorPlugin
s in the plugin index; if false,
executes the script with no pre- or postprocessing.inputMap
- Table of input parameter values, with keys matching the
plugin's input parameter names. Passing a value of a type
incompatible with the associated input parameter will issue an
error and ignore that value.Future
of the module instance being executed. Calling
Future.get()
will block until execution is complete.public Future<ScriptModule> run(ScriptInfo info, boolean process, Object... inputs)
ScriptService
run
in interface ScriptService
info
- The script to instantiate and run.process
- If true, executes the script with pre- and postprocessing
steps from all available PreprocessorPlugin
s and
PostprocessorPlugin
s in the plugin index; if false,
executes the script with no pre- or postprocessing.inputs
- List of input parameter names and values. The expected order
is in pairs: an input name followed by its value, for each desired
input to populate. Leaving some inputs unpopulated is allowed.
Passing the name of an input that is not valid for the plugin, or
passing a value of a type incompatible with the associated input
parameter, will issue an error and ignore that name/value pair.Future
of the module instance being executed. Calling
Future.get()
will block until execution is complete.public Future<ScriptModule> run(ScriptInfo info, boolean process, Map<String,Object> inputMap)
ScriptService
run
in interface ScriptService
info
- The script to instantiate and run.process
- If true, executes the script with pre- and postprocessing
steps from all available PreprocessorPlugin
s and
PostprocessorPlugin
s in the plugin index; if false,
executes the script with no pre- or postprocessing.inputMap
- Table of input parameter values, with keys matching the
plugin's input parameter names. Passing a value of a type
incompatible with the associated input parameter will issue an
error and ignore that value.Future
of the module instance being executed. Calling
Future.get()
will block until execution is complete.public void addAlias(String alias, Class<?> type)
ScriptService
addAlias
in interface ScriptService
public Map<String,Class<?>> getAliases()
ScriptService
getAliases
in interface ScriptService
public Class<?> lookupClass(String alias) throws ScriptException
ScriptService
lookupClass
in interface ScriptService
ScriptException
public void initialize()
Service
NB: This method is not intended to be called directly. It is called by
the service framework itself (specifically by the ServiceHelper
)
when initializing the service. It should not be called a second time.
initialize
in interface Initializable
initialize
in interface SingletonService<ScriptLanguage>
initialize
in interface Service
Copyright © 2015–2022 SciJava. All rights reserved.