public class ScriptInfo extends AbstractModuleInfo implements Contextual
This class is responsible for parsing the script for parameters. See
parseParameters()
for details.
APPLICATION_MENU_ROOT
Constructor and Description |
---|
ScriptInfo(Context context,
File file)
Creates a script metadata object which describes the given script file.
|
ScriptInfo(Context context,
String path)
Creates a script metadata object which describes the given script file.
|
ScriptInfo(Context context,
String path,
Reader reader)
Creates a script metadata object which describes a script provided by the
given
Reader . |
Modifier and Type | Method and Description |
---|---|
Context |
context()
Gets the application context to which the object belongs.
|
ScriptModule |
createModule()
Instantiates the module described by this module info.
|
Context |
getContext()
Gets the application context to which the object belongs, or null if
Contextual.setContext(Context) has not yet been called on this object. |
String |
getDelegateClassName()
Gets the fully qualified name of the class containing the module's actual
implementation.
|
String |
getIdentifier()
Gets a string intended to function as an identifier for the object.
|
String |
getLocation()
Gets the URL string defining the object's location.
|
String |
getPath()
Gets the path to the script on disk.
|
BufferedReader |
getReader()
Gets a reader which delivers the script's content.
|
String |
getVersion()
Gets the version of the object.
|
boolean |
isReturnValueDeclared()
Gets whether the return value is explicitly declared as an output.
|
Class<?> |
loadDelegateClass()
Loads the class containing the module's actual implementation.
|
void |
parseParameters()
Parses the script's input and output parameters from the script header.
|
void |
setContext(Context context)
Sets the application context to which the object belongs.
|
canCancel, canPreview, canRunHeadless, clearParameters, getInitializer, getInput, getInput, getOutput, getOutput, getProblems, getTitle, inputList, inputMap, inputs, isInteractive, isValid, outputList, outputMap, outputs, registerInput, registerOutput, update
compareTo, getIconPath, getMenuPath, getMenuRoot, getPriority, getSelectionGroup, isEnabled, isSelectable, isSelected, isVisible, setEnabled, setIconPath, setMenuPath, setMenuRoot, setPriority, setSelectable, setSelected, setSelectionGroup, setVisible, toString
get, getDescription, getLabel, getName, is, set, setDescription, setLabel, setName
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getIconPath, getMenuPath, getMenuRoot, getSelectionGroup, isEnabled, isSelectable, isSelected, isVisible, setEnabled, setIconPath, setMenuPath, setMenuRoot, setSelectable, setSelected, setSelectionGroup, setVisible
get, getDescription, getLabel, is, set, setDescription, setLabel
getPriority, setPriority
compareTo
public ScriptInfo(Context context, File file)
context
- The SciJava application context to use when populating
service inputs.file
- The script file.public ScriptInfo(Context context, String path)
context
- The SciJava application context to use when populating
service inputs.path
- Path to the script file.public ScriptInfo(Context context, String path, Reader reader)
Reader
.context
- The SciJava application context to use when populating
service inputs.path
- Pseudo-path to the script file. This file does not actually
need to exist, but rather provides a name for the script with file
extension.reader
- Reader which provides the script itself (i.e., its contents).public String getPath()
If the path doesn't actually exist on disk, then this is a pseudo-path
merely for the purpose of naming the script with a file extension, and the
actual script content is delivered by the BufferedReader
given by
getReader()
.
public BufferedReader getReader()
This might be null, in which case the content is stored in a file on disk
given by getPath()
.
public void parseParameters()
This method is called automatically the first time any parameter accessor
method is called (AbstractModuleInfo.getInput(java.lang.String)
, AbstractModuleInfo.getOutput(java.lang.String)
, AbstractModuleInfo.inputs()
,
AbstractModuleInfo.outputs()
, etc.). Subsequent calls will reparse the parameters.
SciJava's scripting framework supports specifying @Parameter
-style
inputs and outputs in a preamble. The format is a simplified version of the
Java @Parameter
annotation syntax. The following syntaxes are
supported:
// @<type> <varName>
// @<type>(<attr1>=<value1>, ..., <attrN>=<valueN>) <varName>
// @<IOType> <type> <varName>
// @<IOType>(<attr1>=<value1>, ..., <attrN>=<valueN>) <type> <varName>
Where:
//
= the comment style of the scripting language, so that the
parameter line is ignored by the script engine itself.<IOType>
= one of INPUT
, OUTPUT
, or
BOTH
.<varName>
= the name of the input or output variable.<type>
= the Java Class
of the variable.<attr*>
= an attribute key.<value*>
= an attribute value.
See the @Parameter
annotation for a list of valid attributes.
Here are a few examples:
parseParameters
in class AbstractModuleInfo
public boolean isReturnValueDeclared()
public String getDelegateClassName()
ModuleInfo
createModule().getDelegateObject().getClass().getName()
, and hence
is also the class containing any callback methods specified by
ModuleItem.getCallback()
.
The nature of this method is implementation-specific; for example, a
CommandModule
will return the class name of its associated
Command
. For modules that are not commands, the result may be
something else.
If you are implementing this interface directly, a good rule of thumb is to
return the class name of the associated Module
(i.e., the same
value given by createModule().getClass().getName()
).
getDelegateClassName
in interface ModuleInfo
public Class<?> loadDelegateClass()
ModuleInfo
ModuleInfo.getDelegateClassName()
.loadDelegateClass
in interface ModuleInfo
Instantiable.loadClass()
public ScriptModule createModule() throws ModuleException
ModuleInfo
createModule
in interface ModuleInfo
ModuleException
public Context context()
Contextual
context
in interface Contextual
Contextual.getContext()
public Context getContext()
Contextual
Contextual.setContext(Context)
has not yet been called on this object.getContext
in interface Contextual
Contextual.context()
public void setContext(Context context)
Contextual
Typically this method simply delegates to Context.inject(Object)
,
and should be called only once to populate the context. Most contextual
objects do not support later alteration of the context, and will throw
IllegalStateException
if this method is invoked again.
setContext
in interface Contextual
Context.inject(Object)
,
for an example of how to implement this interface
public String getIdentifier()
Identifiable
getIdentifier
in interface Identifiable
getIdentifier
in class AbstractModuleInfo
public String getLocation()
Locatable
getLocation
in interface Locatable
getLocation
in class AbstractModuleInfo
public String getVersion()
Versioned
getVersion
in interface Versioned
getVersion
in class AbstractModuleInfo
Copyright © 2009–2015 SciJava. All rights reserved.