org.scijava.script
Class DefaultScriptService

java.lang.Object
  extended by org.scijava.AbstractContextual
      extended by org.scijava.plugin.AbstractRichPlugin
          extended by org.scijava.service.AbstractService
              extended by org.scijava.plugin.AbstractPTService<PT>
                  extended by org.scijava.plugin.AbstractSingletonService<ScriptLanguage>
                      extended by org.scijava.script.DefaultScriptService
All Implemented Interfaces:
Comparable<Prioritized>, Contextual, Disposable, HasPluginInfo, PTService<ScriptLanguage>, RichPlugin, SciJavaPlugin, SingletonService<ScriptLanguage>, Prioritized, ScriptService, SciJavaService, Service

public class DefaultScriptService
extends AbstractSingletonService<ScriptLanguage>
implements ScriptService

Default service for working with scripting languages.

Author:
Johannes Schindelin, Curtis Rueden

Field Summary
 
Fields inherited from interface org.scijava.script.ScriptService
SCRIPTS_PATH_PROPERTY
 
Constructor Summary
DefaultScriptService()
           
 
Method Summary
 void addAlias(Class<?> type)
          TODO
 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.
 boolean canHandleFile(File file)
          TODO
 boolean canHandleFile(String fileName)
          TODO
 ScriptLanguageIndex getIndex()
          Gets the index of available scripting languages.
 ScriptLanguage getLanguageByExtension(String extension)
          Gets the scripting language that handles the given file extension.
 ScriptLanguage getLanguageByName(String name)
          Gets the scripting language with the given name.
 List<ScriptLanguage> getLanguages()
          Gets the available scripting languages, including wrapped ScriptEngineFactory instances available from the Java scripting framework itself.
 MenuPath getMenuPrefix(File scriptDirectory)
          Gets the menu path prefix for the given script directory, or null if none.
 Class<ScriptLanguage> getPluginType()
          Gets the type of plugins managed by this service.
 ScriptInfo getScript(File scriptFile)
          Gets the ScriptInfo metadata for the script at the given file, or null if none.
 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.
 Future<ScriptModule> run(String path, Reader reader, boolean process, Map<String,Object> inputMap)
          Executes the given script.
 Future<ScriptModule> run(String path, Reader reader, boolean process, Object... inputs)
          Executes the given script.
 Future<ScriptModule> run(String path, String script, boolean process, Map<String,Object> inputMap)
          Executes the given script.
 Future<ScriptModule> run(String path, String script, boolean process, Object... inputs)
          Executes the given script.
 
Methods inherited from class org.scijava.plugin.AbstractSingletonService
filterInstances, getInstance, getInstances
 
Methods inherited from class org.scijava.plugin.AbstractPTService
getPlugins, getPluginService
 
Methods inherited from class org.scijava.service.AbstractService
dispose, getContext, registerEventHandlers, setContext, toString
 
Methods inherited from class org.scijava.plugin.AbstractRichPlugin
compareTo, getInfo, getPriority, setInfo, setPriority
 
Methods inherited from class org.scijava.AbstractContextual
context
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.scijava.plugin.SingletonService
getInstance, getInstances
 
Methods inherited from interface org.scijava.plugin.PTService
getPlugins, getPluginService
 
Methods inherited from interface org.scijava.service.Service
registerEventHandlers
 
Methods inherited from interface org.scijava.Contextual
context, getContext, setContext
 
Methods inherited from interface org.scijava.Prioritized
getPriority, setPriority
 
Methods inherited from interface java.lang.Comparable
compareTo
 
Methods inherited from interface org.scijava.plugin.HasPluginInfo
getInfo, setInfo
 
Methods inherited from interface org.scijava.Disposable
dispose
 

Constructor Detail

DefaultScriptService

public DefaultScriptService()
Method Detail

getIndex

public ScriptLanguageIndex getIndex()
Description copied from interface: ScriptService
Gets the index of available scripting languages.

Specified by:
getIndex in interface ScriptService

getLanguages

public List<ScriptLanguage> getLanguages()
Description copied from interface: ScriptService
Gets the available scripting languages, including wrapped ScriptEngineFactory instances available from the Java scripting framework itself.

This method is similar to SingletonService.getInstances(), except that SingletonService.getInstances() only returns ScriptLanguage subclasses annotated with @Plugin.

Specified by:
getLanguages in interface ScriptService

getLanguageByExtension

public ScriptLanguage getLanguageByExtension(String extension)
Description copied from interface: ScriptService
Gets the scripting language that handles the given file extension.

Specified by:
getLanguageByExtension in interface ScriptService

getLanguageByName

public ScriptLanguage getLanguageByName(String name)
Description copied from interface: ScriptService
Gets the scripting language with the given name.

Specified by:
getLanguageByName in interface ScriptService

getScriptDirectories

public List<File> getScriptDirectories()
Description copied from interface: ScriptService
Gets the base directories to scan for scripts.

Specified by:
getScriptDirectories in interface ScriptService

getMenuPrefix

public MenuPath getMenuPrefix(File scriptDirectory)
Description copied from interface: ScriptService
Gets the menu path prefix for the given script directory, or null if none.

Specified by:
getMenuPrefix in interface ScriptService

addScriptDirectory

public void addScriptDirectory(File scriptDirectory)
Description copied from interface: ScriptService
Adds a base directory to scan for scripts.

Specified by:
addScriptDirectory in interface ScriptService

addScriptDirectory

public void addScriptDirectory(File scriptDirectory,
                               MenuPath menuPrefix)
Description copied from interface: ScriptService
Adds a base directory to scan for scripts, placing discovered scripts beneath the given menu path prefix.

Specified by:
addScriptDirectory in interface ScriptService

removeScriptDirectory

public void removeScriptDirectory(File scriptDirectory)
Description copied from interface: ScriptService
Removes a base directory to scan for scripts.

Specified by:
removeScriptDirectory in interface ScriptService

getScripts

public Collection<ScriptInfo> getScripts()
Description copied from interface: ScriptService
Gets all available scripts.

Specified by:
getScripts in interface ScriptService

getScript

public ScriptInfo getScript(File scriptFile)
Description copied from interface: ScriptService
Gets the ScriptInfo metadata for the script at the given file, or null if none.

Specified by:
getScript in interface ScriptService

run

public Future<ScriptModule> run(File file,
                                boolean process,
                                Object... inputs)
Description copied from interface: ScriptService
Executes the script in the given file.

Specified by:
run in interface ScriptService
Parameters:
file - File containing the script to execute.
process - If true, executes the script with pre- and postprocessing steps from all available PreprocessorPlugins and PostprocessorPlugins 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.
Returns:
Future of the module instance being executed. Calling Future.get() will block until execution is complete.

run

public Future<ScriptModule> run(File file,
                                boolean process,
                                Map<String,Object> inputMap)
Description copied from interface: ScriptService
Executes the script in the given file.

Specified by:
run in interface ScriptService
Parameters:
file - File containing the script to execute.
process - If true, executes the script with pre- and postprocessing steps from all available PreprocessorPlugins and PostprocessorPlugins 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.
Returns:
Future of the module instance being executed. Calling Future.get() will block until execution is complete.

run

public Future<ScriptModule> run(String path,
                                String script,
                                boolean process,
                                Object... inputs)
Description copied from interface: ScriptService
Executes the given script.

Specified by:
run in interface ScriptService
Parameters:
path - Pseudo-path to the script. This is important mostly for the path's file extension, which provides an important hint as to the language of the script.
script - The script itself to execute.
process - If true, executes the script with pre- and postprocessing steps from all available PreprocessorPlugins and PostprocessorPlugins 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.
Returns:
Future of the module instance being executed. Calling Future.get() will block until execution is complete.

run

public Future<ScriptModule> run(String path,
                                String script,
                                boolean process,
                                Map<String,Object> inputMap)
Description copied from interface: ScriptService
Executes the given script.

Specified by:
run in interface ScriptService
Parameters:
path - Pseudo-path to the script. This is important mostly for the path's file extension, which provides an important hint as to the language of the script.
script - The script itself to execute.
process - If true, executes the script with pre- and postprocessing steps from all available PreprocessorPlugins and PostprocessorPlugins 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.
Returns:
Future of the module instance being executed. Calling Future.get() will block until execution is complete.

run

public Future<ScriptModule> run(String path,
                                Reader reader,
                                boolean process,
                                Object... inputs)
Description copied from interface: ScriptService
Executes the given script.

Specified by:
run in interface ScriptService
Parameters:
path - Pseudo-path to the script. This is important mostly for the path's file extension, which provides an important hint as to the language of the script.
reader - A stream providing the script contents.
process - If true, executes the script with pre- and postprocessing steps from all available PreprocessorPlugins and PostprocessorPlugins 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.
Returns:
Future of the module instance being executed. Calling Future.get() will block until execution is complete.

run

public Future<ScriptModule> run(String path,
                                Reader reader,
                                boolean process,
                                Map<String,Object> inputMap)
Description copied from interface: ScriptService
Executes the given script.

Specified by:
run in interface ScriptService
Parameters:
path - Pseudo-path to the script. This is important mostly for the path's file extension, which provides an important hint as to the language of the script.
reader - A stream providing the script contents.
process - If true, executes the script with pre- and postprocessing steps from all available PreprocessorPlugins and PostprocessorPlugins 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.
Returns:
Future of the module instance being executed. Calling Future.get() will block until execution is complete.

run

public Future<ScriptModule> run(ScriptInfo info,
                                boolean process,
                                Object... inputs)
Description copied from interface: ScriptService
Executes the given script.

Specified by:
run in interface ScriptService
Parameters:
info - The script to instantiate and run.
process - If true, executes the script with pre- and postprocessing steps from all available PreprocessorPlugins and PostprocessorPlugins 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.
Returns:
Future of the module instance being executed. Calling Future.get() will block until execution is complete.

run

public Future<ScriptModule> run(ScriptInfo info,
                                boolean process,
                                Map<String,Object> inputMap)
Description copied from interface: ScriptService
Executes the given script.

Specified by:
run in interface ScriptService
Parameters:
info - The script to instantiate and run.
process - If true, executes the script with pre- and postprocessing steps from all available PreprocessorPlugins and PostprocessorPlugins 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.
Returns:
Future of the module instance being executed. Calling Future.get() will block until execution is complete.

canHandleFile

public boolean canHandleFile(File file)
Description copied from interface: ScriptService
TODO

Specified by:
canHandleFile in interface ScriptService

canHandleFile

public boolean canHandleFile(String fileName)
Description copied from interface: ScriptService
TODO

Specified by:
canHandleFile in interface ScriptService

addAlias

public void addAlias(Class<?> type)
Description copied from interface: ScriptService
TODO

Specified by:
addAlias in interface ScriptService

addAlias

public void addAlias(String alias,
                     Class<?> type)
Description copied from interface: ScriptService
TODO

Specified by:
addAlias in interface ScriptService

lookupClass

public Class<?> lookupClass(String alias)
                     throws ScriptException
Description copied from interface: ScriptService
TODO

Specified by:
lookupClass in interface ScriptService
Throws:
ScriptException

getPluginType

public Class<ScriptLanguage> getPluginType()
Description copied from interface: PTService
Gets the type of plugins managed by this service.

Specified by:
getPluginType in interface PTService<ScriptLanguage>

initialize

public void initialize()
Description copied from interface: Service
Performs any needed initialization when the service is first loaded.

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.

Specified by:
initialize in interface Service
Overrides:
initialize in class AbstractSingletonService<ScriptLanguage>


Copyright © 2009–2014 SciJava. All rights reserved.