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. |
ScriptInfo(Context context,
URL url,
String path)
Creates a script metadata object which describes a script at the given URL.
|
| 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.
|
URL |
getURL()
Gets the URL of the script.
|
String |
getVersion()
Gets the version of the object.
|
boolean |
isReturnValueAppended()
Gets whether the return value is appended as an additional output.
|
boolean |
isReturnValueDeclared()
Deprecated.
Use
isReturnValueAppended() instead. |
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.
|
clearParameters, getInput, getInput, getOutput, getOutput, inputList, inputMap, inputs, outputList, outputMap, outputs, registerInput, registerOutputgetIconPath, getMenuPath, getMenuRoot, getPriority, getSelectionGroup, isEnabled, isSelectable, isSelected, isVisible, setEnabled, setIconPath, setMenuPath, setMenuRoot, setPriority, setSelectable, setSelected, setSelectionGroup, setVisible, toStringget, getDescription, getLabel, getName, is, set, setDescription, setLabel, setNameclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitcanCancel, canPreview, canRunHeadless, getInitializer, getProblems, getTitle, isInteractive, isValid, updatecompareTo, getIconPath, getMenuPath, getMenuRoot, getSelectionGroup, isEnabled, isSelectable, isSelected, isVisible, setEnabled, setIconPath, setMenuPath, setMenuRoot, setSelectable, setSelected, setSelectionGroup, setVisibleget, getDescription, getLabel, is, set, setDescription, setLabelgetPriority, setPrioritypublic 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, URL url, String path) throws IOException
context - The SciJava application context to use when populating
service inputs.url - URL which references the script.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.IOExceptionpublic 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 URL getURL()
If the actual source of the script is a URL (provided via
ScriptInfo(Context, URL, String)), then this will return it.
Alternately, if the path (from getPath()) is a real file on disk
(provided via ScriptInfo(Context, File) or
ScriptInfo(Context, String)), then the URL returned here will be a
file:// one reference to it.
Otherwise, this method will return null.
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:
// @Dataset dataset// @double(type=OUTPUT) result// @BOTH ImageDisplay display// @INPUT(persist=false, visibility=INVISIBLE) boolean verbose
Parameters will be parsed and filled just like @Parameter-annotated
fields in Commands.
parseParameters in class AbstractModuleInfopublic boolean isReturnValueAppended()
public String getDelegateClassName()
ModuleInfocreateModule().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 ModuleInfopublic Class<?> loadDelegateClass()
ModuleInfoModuleInfo.getDelegateClassName().loadDelegateClass in interface ModuleInfoInstantiable.loadClass()public ScriptModule createModule() throws ModuleException
ModuleInfocreateModule in interface ModuleInfoModuleExceptionpublic Context context()
Contextualcontext in interface ContextualContextual.getContext()public Context getContext()
ContextualContextual.setContext(Context) has not yet been called on this object.getContext in interface ContextualContextual.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 ContextualContext.inject(Object)public String getIdentifier()
IdentifiablegetIdentifier in interface IdentifiablegetIdentifier in interface ModuleInfopublic String getLocation()
LocatablegetLocation in interface LocatablegetLocation in interface ModuleInfopublic String getVersion()
VersionedgetVersion in interface ModuleInfogetVersion in interface Versioned@Deprecated public boolean isReturnValueDeclared()
isReturnValueAppended() instead.Copyright © 2009–2017 SciJava. All rights reserved.