com.partnersoft.system
Class Module

java.lang.Object
  extended by com.partnersoft.system.Module
All Implemented Interfaces:
java.lang.Comparable<Module>

public class Module
extends java.lang.Object
implements java.lang.Comparable<Module>


Constructor Summary
Module(VfsDirectory directory)
           
 
Method Summary
 java.lang.String applyTemplate(java.lang.String name)
          Applies the named template (a script file in the templates/ directory) and returns the result.
 java.lang.String applyTemplate(java.lang.String name, Naming<java.lang.Object> variables)
          Applies the named template (a script file in the templates/ directory) and returns the result.
 java.lang.String applyTemplate(java.lang.String name, java.lang.Object... variables)
          Applies the named template (a script file in the templates/ directory) and returns the result.
 void buildMapsetConfig()
          Same as buildMapsetConfig, but builds the mapset config for the mapset of the same name as this module.
 VfsDirectory buildMapsetConfig(java.lang.String mapsetName)
          Builds a config/FOO/mapsets/BAR directory structure from the defaults in this module.
 VfsDirectory buildModuleConfig()
          Builds a config/FOO/modules/BAR directory structure from the defaults in this module (under the "default/config/" directory).
 void buildModuleConfigDataAndMapsets()
          Builds module config, data, and all mapsets included from defaults.
 VfsDirectory buildModuleData()
          Builds a data/FOO/ directory structure from the defaults in this module (under the "default/data/" directory).
 int compareTo(Module nother)
           
 void createFileFromTemplate(java.lang.String name, Path outputPath, Naming<java.lang.Object> variables)
          Applies the named template (a .st file in the templates/ directory) and writes the result to the file at the given path.
 void createFileFromTemplate(java.lang.String name, Path outputPath, java.lang.Object... variables)
          Applies the named template (a .st file in the templates/ directory) and writes the result to the file at the given path.
 void createFileFromTemplate(java.lang.String name, VfsFile outputFile, Naming<java.lang.Object> variables)
          Applies the named template (a .st file in the templates/ directory) and writes the result to the file given.
 void createFileFromTemplate(java.lang.String name, VfsFile outputFile, java.lang.Object... variables)
          Applies the named template (a .st file in the templates/ directory) and writes the result to the given file.
 SqlDatabase databaseNamed(java.lang.String databaseName)
          Returns the configured SqlDatabase stored with the same name (plus .xml extension) in the databases/ subdirectory of the module.
 ScriptKeeper getAppScripts()
           
 VfsDirectory getConfigDirectory()
          The directory containing configuration associated with the module, generally PARTNERINSTALL/config/CONFIGLEVEL/modules/MODULENAME
 ConfigLevel getConfigLevel()
          Returns the config level this module is at (i.e.
 ScriptKeeper getControlScripts()
           
 VfsDirectory getDataDirectory()
          The directory containing user data associated with the module, generally PARTNERINSTALL/data/MODULENAME
 VfsDirectory getDirectory()
          The directory containing the module's code and resources, generally modules/CONFIGLEVEL/MODULENAME
 ScriptKeeper getEventScripts()
           
 VfsDirectory getLogDirectory()
          The directory containing any module-specific logs.
 java.lang.String getName()
           
 Naming<java.lang.Object> getProfile()
          Returns the module's profile from modules/FOO/THISMODULE/profile.xml.
 CogSchema getSchema()
           
 ScriptKeeper getScripts()
           
 Naming<java.lang.Object> getSettings()
          Returns the settings from config/FOO/modules/THISMODULE/settings.xml.
 VfsDirectory getTempDirectory()
          The directory containing temporary or cache data associated with the module, generally PARTNERINSTALL/temp/MODULENAME
 ScriptKeeper getTemplateScripts()
           
 Naming<java.lang.Object> getVariables()
          Module-level variables.
 Version getVersion()
           
 ScriptKeeper getWorkbenchScripts()
           
 void initialize()
          Initializes the module by running all scripts (must be .bsh) in control/initialize.
 boolean isWatchingForNewFiles()
           
 java.util.List<java.lang.String> listApps()
          Returns a list of named apps supplied by this module.
 java.util.List<Dependency> listDependencies()
          Returns a list of Dependency objects representing other modules this one depends on.
 java.util.List<VfsFile> listJars()
          List jar files in this module, including native ones in os/FOO/jars.
 java.util.List<VfsDirectory> listMapsets()
          Returns a list of available mapset definition directories.
 java.util.List<VfsDirectory> listNativeLibs()
          List native library directories in this module.
 java.util.List<VfsDirectory> listScriptLibs(java.lang.String language)
          Lists the script libraries in this module, for the given scripting language name (e.g.
 VfsDirectory mapsetNamed(java.lang.String name)
          Returns the directory for the named mapset definition, or null if there is none by that name in this module.
 Cog readCogFrom(Path path)
          Loads a Cog from a Cog format XML file given by the path.
 Cog readCogFrom(java.lang.String pathString)
          Loads a Cog from a Cog format XML file given by the named path.
 Cog readCogFrom(VfsFile file)
          Loads a Cog from a Cog format XML file.
 java.lang.Object readObjectFrom(Path path)
          Loads an object from a Cog format XML file given by the path.
 java.lang.Object readObjectFrom(java.lang.String pathString)
          Loads an object from a Cog format XML file given by the named path.
 java.lang.Object readObjectFrom(VfsFile file)
          Loads an object from a Cog format XML file.
 void reloadScripts()
          Completely reloads the scripts and script keepers.
 void runAppScript(java.lang.String name)
          Runs the named app script.
 void runAppScriptAndThrowException(java.lang.String name)
          Runs the named app script.
 void runEventScripts(java.lang.String sourceModule, java.lang.String event, Naming<java.lang.Object> variables)
          Runs all event scripts.
 void runEventScripts(java.lang.String sourceModule, java.lang.String event, java.lang.Object... variables)
          Runs all event scripts.
 void runScript(java.lang.String name)
          Runs the named general script.
 void runScript(java.lang.String name, Naming<java.lang.Object> variables)
          Runs the named general script.
 void runScript(java.lang.String name, java.lang.Object... variables)
          Runs the named general script.
 Script scriptFor(java.lang.String name)
          Runs the named general script.
 void setVersion(Version newValue)
           
 void setWatchingForNewFiles(boolean watchingForNewFiles)
           
 void shutdown()
          Shuts down the module by running all scripts in control/shutdown.
 void startup()
          Starts the module by running all scripts in control/startup.
 java.lang.String toString()
           
 boolean validate()
          Runs a validation check, logs any problems, and returns true if the check passed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Module

public Module(VfsDirectory directory)
       throws java.io.IOException
Throws:
java.io.IOException
Method Detail

reloadScripts

public void reloadScripts()
Completely reloads the scripts and script keepers.


listJars

public java.util.List<VfsFile> listJars()
List jar files in this module, including native ones in os/FOO/jars. Always returns a result, may be empty.


listNativeLibs

public java.util.List<VfsDirectory> listNativeLibs()
List native library directories in this module. Only lists those for the current operating system. Always returns a result, may be empty.


listScriptLibs

public java.util.List<VfsDirectory> listScriptLibs(java.lang.String language)
Lists the script libraries in this module, for the given scripting language name (e.g. ruby, beanshell). Always returns a result, may be empty.


listDependencies

public java.util.List<Dependency> listDependencies()
Returns a list of Dependency objects representing other modules this one depends on. Always returns a result, may be empty.

Returns:

listApps

public java.util.List<java.lang.String> listApps()
Returns a list of named apps supplied by this module.


listMapsets

public java.util.List<VfsDirectory> listMapsets()
Returns a list of available mapset definition directories. These serve as the generic code and defaults for installed mapsets. They are stored in named subdirectories of the mapset/ directory.


mapsetNamed

public VfsDirectory mapsetNamed(java.lang.String name)
Returns the directory for the named mapset definition, or null if there is none by that name in this module. Mapset definitions go in named subdirectories of mapsets/


buildMapsetConfig

public void buildMapsetConfig()
                       throws java.io.IOException
Same as buildMapsetConfig, but builds the mapset config for the mapset of the same name as this module.

Throws:
java.io.IOException

buildMapsetConfig

public VfsDirectory buildMapsetConfig(java.lang.String mapsetName)
                               throws java.io.IOException
Builds a config/FOO/mapsets/BAR directory structure from the defaults in this module. Puts the config at the same config level this module is at. Returns the directory of the newly created mapset.

Throws:
java.io.IOException

buildModuleConfig

public VfsDirectory buildModuleConfig()
                               throws java.io.IOException
Builds a config/FOO/modules/BAR directory structure from the defaults in this module (under the "default/config/" directory). Puts the config at the same config level this module is at. Returns the config directory.

Throws:
java.io.IOException

buildModuleData

public VfsDirectory buildModuleData()
                             throws java.io.IOException
Builds a data/FOO/ directory structure from the defaults in this module (under the "default/data/" directory). Returns the data directory.

Throws:
java.io.IOException

buildModuleConfigDataAndMapsets

public void buildModuleConfigDataAndMapsets()
                                     throws java.io.IOException
Builds module config, data, and all mapsets included from defaults.

Throws:
java.io.IOException

validate

public boolean validate()
Runs a validation check, logs any problems, and returns true if the check passed.


initialize

public void initialize()
Initializes the module by running all scripts (must be .bsh) in control/initialize. This happens BEFORE module jars are loaded.


startup

public void startup()
Starts the module by running all scripts in control/startup. This happens AFTER module jars are loaded.


shutdown

public void shutdown()
Shuts down the module by running all scripts in control/shutdown.


runEventScripts

public void runEventScripts(java.lang.String sourceModule,
                            java.lang.String event,
                            Naming<java.lang.Object> variables)
Runs all event scripts. The sourceModule specifies the module defining and originating the event; the name names the event.


runEventScripts

public void runEventScripts(java.lang.String sourceModule,
                            java.lang.String event,
                            java.lang.Object... variables)
Runs all event scripts. The sourceModule specifies the module defining and originating the event; the name names the event. Supply the variables in name, value, name, value order.


runAppScript

public void runAppScript(java.lang.String name)
Runs the named app script.


runScript

public void runScript(java.lang.String name)
Runs the named general script.


runScript

public void runScript(java.lang.String name,
                      Naming<java.lang.Object> variables)
Runs the named general script.


runScript

public void runScript(java.lang.String name,
                      java.lang.Object... variables)
Runs the named general script.


scriptFor

public Script scriptFor(java.lang.String name)
Runs the named general script.


runAppScriptAndThrowException

public void runAppScriptAndThrowException(java.lang.String name)
                                   throws java.lang.Throwable
Runs the named app script. Throws any exceptions rather than just handling them.

Throws:
java.lang.Throwable

applyTemplate

public java.lang.String applyTemplate(java.lang.String name,
                                      Naming<java.lang.Object> variables)
Applies the named template (a script file in the templates/ directory) and returns the result.


applyTemplate

public java.lang.String applyTemplate(java.lang.String name)
Applies the named template (a script file in the templates/ directory) and returns the result.


applyTemplate

public java.lang.String applyTemplate(java.lang.String name,
                                      java.lang.Object... variables)
Applies the named template (a script file in the templates/ directory) and returns the result.


createFileFromTemplate

public void createFileFromTemplate(java.lang.String name,
                                   Path outputPath,
                                   Naming<java.lang.Object> variables)
Applies the named template (a .st file in the templates/ directory) and writes the result to the file at the given path.


createFileFromTemplate

public void createFileFromTemplate(java.lang.String name,
                                   VfsFile outputFile,
                                   Naming<java.lang.Object> variables)
Applies the named template (a .st file in the templates/ directory) and writes the result to the file given.


createFileFromTemplate

public void createFileFromTemplate(java.lang.String name,
                                   VfsFile outputFile,
                                   java.lang.Object... variables)
Applies the named template (a .st file in the templates/ directory) and writes the result to the given file. Supply arguments as name1, value1, name2, value2, etc. as the last parameters.


createFileFromTemplate

public void createFileFromTemplate(java.lang.String name,
                                   Path outputPath,
                                   java.lang.Object... variables)
Applies the named template (a .st file in the templates/ directory) and writes the result to the file at the given path. Supply arguments as name1, value1, name2, value2, etc. as the last parameters.


compareTo

public int compareTo(Module nother)
Specified by:
compareTo in interface java.lang.Comparable<Module>

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getProfile

public Naming<java.lang.Object> getProfile()
Returns the module's profile from modules/FOO/THISMODULE/profile.xml. Automatically reloads them if the file was changed.


getSettings

public Naming<java.lang.Object> getSettings()
Returns the settings from config/FOO/modules/THISMODULE/settings.xml. Automatically reloads them if the file was changed.


readObjectFrom

public java.lang.Object readObjectFrom(java.lang.String pathString)
                                throws java.io.IOException
Loads an object from a Cog format XML file given by the named path. Looks first in the configuration directory, then in the module directory for the file corresponding to the path. Uses the module's schema.

Throws:
java.io.IOException

readObjectFrom

public java.lang.Object readObjectFrom(Path path)
                                throws java.io.IOException
Loads an object from a Cog format XML file given by the path. Looks first in the configuration directory, then in the module directory for the file corresponding to the path. Uses the module's schema.

Throws:
java.io.IOException

readObjectFrom

public java.lang.Object readObjectFrom(VfsFile file)
                                throws java.io.IOException
Loads an object from a Cog format XML file. Uses the module's schema.

Throws:
java.io.IOException

readCogFrom

public Cog readCogFrom(java.lang.String pathString)
                throws java.io.IOException
Loads a Cog from a Cog format XML file given by the named path. Looks first in the configuration directory, then in the module directory for the file corresponding to the path. Uses the module's schema.

Throws:
java.io.IOException

readCogFrom

public Cog readCogFrom(Path path)
                throws java.io.IOException
Loads a Cog from a Cog format XML file given by the path. Looks first in the configuration directory, then in the module directory for the file corresponding to the path. Uses the module's schema.

Throws:
java.io.IOException

readCogFrom

public Cog readCogFrom(VfsFile file)
                throws java.io.IOException
Loads a Cog from a Cog format XML file. Uses the module's schema.

Throws:
java.io.IOException

getName

public java.lang.String getName()

getDirectory

public VfsDirectory getDirectory()
The directory containing the module's code and resources, generally modules/CONFIGLEVEL/MODULENAME

Returns:

getTempDirectory

public VfsDirectory getTempDirectory()
The directory containing temporary or cache data associated with the module, generally PARTNERINSTALL/temp/MODULENAME

Returns:

getLogDirectory

public VfsDirectory getLogDirectory()
The directory containing any module-specific logs.

Returns:

getDataDirectory

public VfsDirectory getDataDirectory()
The directory containing user data associated with the module, generally PARTNERINSTALL/data/MODULENAME

Returns:

getConfigDirectory

public VfsDirectory getConfigDirectory()
The directory containing configuration associated with the module, generally PARTNERINSTALL/config/CONFIGLEVEL/modules/MODULENAME

Returns:

getVersion

public Version getVersion()

setVersion

public void setVersion(Version newValue)

getVariables

public Naming<java.lang.Object> getVariables()
Module-level variables. Use with care.


getConfigLevel

public ConfigLevel getConfigLevel()
Returns the config level this module is at (i.e. which subdirectory of modules/ it lives in).


getControlScripts

public ScriptKeeper getControlScripts()

getEventScripts

public ScriptKeeper getEventScripts()

getTemplateScripts

public ScriptKeeper getTemplateScripts()

getAppScripts

public ScriptKeeper getAppScripts()

getScripts

public ScriptKeeper getScripts()

getWorkbenchScripts

public ScriptKeeper getWorkbenchScripts()

getSchema

public CogSchema getSchema()

databaseNamed

public SqlDatabase databaseNamed(java.lang.String databaseName)
                          throws java.io.IOException
Returns the configured SqlDatabase stored with the same name (plus .xml extension) in the databases/ subdirectory of the module.

Parameters:
databaseName -
Returns:
Throws:
java.io.IOException

isWatchingForNewFiles

public boolean isWatchingForNewFiles()

setWatchingForNewFiles

public void setWatchingForNewFiles(boolean watchingForNewFiles)