org.scijava.script
Class ScriptInfo

java.lang.Object
  extended by org.scijava.AbstractBasicDetails
      extended by org.scijava.AbstractUIDetails
          extended by org.scijava.module.AbstractModuleInfo
              extended by org.scijava.script.ScriptInfo
All Implemented Interfaces:
Comparable<Prioritized>, BasicDetails, Contextual, Identifiable, ModuleInfo, Prioritized, UIDetails, Validated

public class ScriptInfo
extends AbstractModuleInfo
implements Contextual

Metadata about a script.

This class is responsible for parsing the script for parameters. See parseParameters() for details.

Author:
Curtis Rueden, Johannes Schindelin

Field Summary
 
Fields inherited from interface org.scijava.UIDetails
APPLICATION_MENU_ROOT
 
Constructor Summary
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.
 
Method Summary
 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 getPath()
          Gets the path to the script on disk.
 BufferedReader getReader()
          Gets the reader which delivers the script's content.
 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.
 
Methods inherited from class org.scijava.module.AbstractModuleInfo
canCancel, canPreview, canRunHeadless, clearParameters, getInitializer, getInput, getInput, getOutput, getOutput, getProblems, getTitle, inputList, inputMap, inputs, isInteractive, isValid, outputList, outputMap, outputs, registerInput, registerOutput, update
 
Methods inherited from class org.scijava.AbstractUIDetails
compareTo, getIconPath, getMenuPath, getMenuRoot, getPriority, getSelectionGroup, isEnabled, isSelectable, isSelected, isVisible, setEnabled, setIconPath, setMenuPath, setMenuRoot, setPriority, setSelectable, setSelected, setSelectionGroup, setVisible, toString
 
Methods inherited from class org.scijava.AbstractBasicDetails
get, getDescription, getLabel, getName, is, set, setDescription, setLabel, setName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.scijava.UIDetails
getIconPath, getMenuPath, getMenuRoot, getSelectionGroup, isEnabled, isSelectable, isSelected, isVisible, setEnabled, setIconPath, setMenuPath, setMenuRoot, setSelectable, setSelected, setSelectionGroup, setVisible
 
Methods inherited from interface org.scijava.BasicDetails
get, getDescription, getLabel, getName, is, set, setDescription, setLabel, setName
 
Methods inherited from interface org.scijava.Prioritized
getPriority, setPriority
 
Methods inherited from interface java.lang.Comparable
compareTo
 

Constructor Detail

ScriptInfo

public ScriptInfo(Context context,
                  File file)
Creates a script metadata object which describes the given script file.

Parameters:
context - The ImageJ application context to use when populating service inputs.
file - The script file.

ScriptInfo

public ScriptInfo(Context context,
                  String path)
Creates a script metadata object which describes the given script file.

Parameters:
context - The ImageJ application context to use when populating service inputs.
path - Path to the script file.

ScriptInfo

public ScriptInfo(Context context,
                  String path,
                  Reader reader)
Creates a script metadata object which describes a script provided by the given Reader.

Parameters:
context - The ImageJ 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).
Method Detail

getPath

public String getPath()
Gets the path to the script on disk.

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().


getReader

public BufferedReader getReader()
Gets the reader which delivers the script's content.

This might be null, in which case the content is stored in a file on disk given by getPath().


parseParameters

public void parseParameters()
Parses the script's input and output parameters from the script header.

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.

ImageJ'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:

Where:

See the @Parameter annotation for a list of valid attributes.

Here are a few examples:

Overrides:
parseParameters in class AbstractModuleInfo

getDelegateClassName

public String getDelegateClassName()
Description copied from interface: ModuleInfo
Gets the fully qualified name of the class containing the module's actual implementation. By definition, this is the same value returned by 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()).

Specified by:
getDelegateClassName in interface ModuleInfo

loadDelegateClass

public Class<?> loadDelegateClass()
Description copied from interface: ModuleInfo
Loads the class containing the module's actual implementation. The name of the loaded class will match the value returned by ModuleInfo.getDelegateClassName().

Specified by:
loadDelegateClass in interface ModuleInfo
See Also:
Instantiable.loadClass()

createModule

public ScriptModule createModule()
                          throws ModuleException
Description copied from interface: ModuleInfo
Instantiates the module described by this module info.

Specified by:
createModule in interface ModuleInfo
Throws:
ModuleException

context

public Context context()
Description copied from interface: Contextual
Gets the application context to which the object belongs.

Specified by:
context in interface Contextual
See Also:
Contextual.getContext()

getContext

public Context getContext()
Description copied from interface: Contextual
Gets the application context to which the object belongs, or null if Contextual.setContext(Context) has not yet been called on this object.

Specified by:
getContext in interface Contextual
See Also:
Contextual.context()

setContext

public void setContext(Context context)
Description copied from interface: Contextual
Sets the application context to which the object belongs.

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.

Specified by:
setContext in interface Contextual
See Also:
Context.inject(Object), for an example of how to implement this interface

getIdentifier

public String getIdentifier()
Description copied from interface: Identifiable
Gets a string intended to function as an identifier for the object.

Specified by:
getIdentifier in interface Identifiable
Overrides:
getIdentifier in class AbstractModuleInfo


Copyright © 2009–2014 SciJava. All rights reserved.