com.partnersoft.scripting
Class ScriptKeeper

java.lang.Object
  extended by com.partnersoft.scripting.ScriptKeeper

public class ScriptKeeper
extends java.lang.Object

Organizer for a filesystem hierarchy containing scripts.

The Partner system depends heavily on scripts to customize and extend an installation. While in some cases a single script is run for a specific task, more often we run an entire directory of scripts. This can serve as a sort of event-listener model, where when something happens in the software, one or more scripts in one or more modules can be run. For example, ModuleManager handles such events for active modules, but passes the actual running of scripts off to this class.

Copyright 2007 Partner Software, Inc.

Version:
$Id: ScriptKeeper.java 2328 2010-01-06 15:38:22Z paul $
Author:
Brad Gray

Constructor Summary
ScriptKeeper()
          Creates a new, empty ScriptKeeper.
ScriptKeeper(VfsDirectory directory)
          Creates a new ScriptKeeper and registers scripts based on the filesystem hierarchy under the given directory.
 
Method Summary
 boolean isWatchingForNewFiles()
           
 java.util.List<Script> listScriptsIn(Path path)
          Returns the scripts in the given directory path.
 Naming<Script> nameScriptsIn(Path path)
          Returns a naming of the scripts in the given directory path.
 void registerScriptHierarchy(VfsDirectory directory)
          Register script directories with paths based on the filesystem hierarchy.
 void registerScripts(Path path, VfsDirectory directory)
          Register a script path with a directory of script files.
 void registerScripts(java.lang.String pathString, VfsDirectory directory)
           
 java.lang.Object runScript(Path path, Naming<java.lang.Object> variables)
          Run a specific script (defined by its path) and return the result.
 java.lang.Object runScript(Path path, java.lang.Object... variables)
          Run a specific script (defined by its path) and return the result.
 void runScripts(Path path, Naming<java.lang.Object> variables)
          Handle a pathed event by running all the scripts in the registered directory.
 void runScripts(Path path, java.lang.Object... variables)
          Handle a pathed event by running all the scripts in the registered directory.
 Script scriptFor(Path path)
          Returns the script with the given path, or null if none is found.
 Script scriptFor(java.lang.String pathString)
          Returns the script at the given path, or null if none is found.
 void setLibraries(ScriptKeeper libraries)
          Sets a separate ScriptKeeper object to manage libraries.
 void setWatchingForNewFiles(boolean watchingForNewFiles)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ScriptKeeper

public ScriptKeeper()
Creates a new, empty ScriptKeeper.


ScriptKeeper

public ScriptKeeper(VfsDirectory directory)
Creates a new ScriptKeeper and registers scripts based on the filesystem hierarchy under the given directory.

Method Detail

setLibraries

public void setLibraries(ScriptKeeper libraries)
Sets a separate ScriptKeeper object to manage libraries. Do this before you register scripts.


registerScripts

public void registerScripts(java.lang.String pathString,
                            VfsDirectory directory)

registerScripts

public void registerScripts(Path path,
                            VfsDirectory directory)
Register a script path with a directory of script files. If you do this more than once, it "layers" the directories, combining the available scripts, and replacing ones of the same name with the ones added last.


runScripts

public void runScripts(Path path,
                       java.lang.Object... variables)
Handle a pathed event by running all the scripts in the registered directory. Sets the given variables in each script, specify them in name, value, name, value order.


runScripts

public void runScripts(Path path,
                       Naming<java.lang.Object> variables)
Handle a pathed event by running all the scripts in the registered directory. Sets the given variables in each script.


registerScriptHierarchy

public void registerScriptHierarchy(VfsDirectory directory)
Register script directories with paths based on the filesystem hierarchy. Called more than once, it will "layer" directories as described in registerScripts().


scriptFor

public Script scriptFor(java.lang.String pathString)
Returns the script at the given path, or null if none is found.


scriptFor

public Script scriptFor(Path path)
Returns the script with the given path, or null if none is found.


listScriptsIn

public java.util.List<Script> listScriptsIn(Path path)
Returns the scripts in the given directory path.


nameScriptsIn

public Naming<Script> nameScriptsIn(Path path)
Returns a naming of the scripts in the given directory path.


runScript

public java.lang.Object runScript(Path path,
                                  Naming<java.lang.Object> variables)
Run a specific script (defined by its path) and return the result.


runScript

public java.lang.Object runScript(Path path,
                                  java.lang.Object... variables)
Run a specific script (defined by its path) and return the result. Variables are specified as name, value, name, value...


isWatchingForNewFiles

public boolean isWatchingForNewFiles()

setWatchingForNewFiles

public void setWatchingForNewFiles(boolean watchingForNewFiles)