code.loader
Class CurryModulePath

java.lang.Object
  extended by code.loader.CurryModulePath

public class CurryModulePath
extends java.lang.Object

This class encapsulates PATHS where source files can be located. one initializes CurryModulePath by appending "paths" to it. then one can "ask" the CurryModulePath object to provide a complete path to some fileName.

Currently all members of this class will be static. This implies that there is exactly one CurryModulePath. Primary user of this class LoadManager. Other user is the Command class in loop package.

Since:
Aug 7, 2004 Modified by Sunita Marathe on Jul 15, 2005
Author:
Pravin Damle

Field Summary
static int CURRYPATH
           
private static java.util.Vector<java.lang.String> curryPaths
          A Static data member that holds all the normalized paths that should be searched when loading a module.
static int NATIVEPATH
           
private static java.util.Vector<java.lang.String> nativePaths
           
static int NATIVEPKG
           
private static java.util.Vector<java.lang.String> nativePkgs
           
 
Constructor Summary
private CurryModulePath()
           
 
Method Summary
private static void append(java.lang.String[] paths)
          Appends each element of the paths array to ModulePath.
static void append(java.lang.String path, int pathType)
          Add the specified path(s) to the CurryModulePath.
static void appendPkgs(java.lang.String path)
           
static java.lang.String getFilePath(java.lang.String moduleName)
          Search the CurryModulePath for file containing this module and return the complete path of that file.
private static java.lang.String getNormalizedPath(java.lang.String somePath)
          Returns the normalized path of the specified path.
private static boolean pathExists(java.lang.String path, int pathType)
          Returns true if the specified path already exists in the CurryModulePath.
static void remove(java.lang.String path)
          Removes the specified path(s) from CurryModulePath.
static void set(java.lang.String path)
          Set the CurryModulePath to the specified path.
static void show(java.io.Writer out)
          Shows/Prints the contents of the CurryModulePath on the specified PrintStream.
static java.lang.String showPaths()
           
private static java.lang.String[] splitPath(java.lang.String path, int pathType)
          Split a colon (:) separated string into an array of strings.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

curryPaths

private static java.util.Vector<java.lang.String> curryPaths
A Static data member that holds all the normalized paths that should be searched when loading a module. A normalized path is independent of the "current working directory" of the FLVM.


nativePaths

private static java.util.Vector<java.lang.String> nativePaths

nativePkgs

private static java.util.Vector<java.lang.String> nativePkgs

CURRYPATH

public static final int CURRYPATH
See Also:
Constant Field Values

NATIVEPATH

public static final int NATIVEPATH
See Also:
Constant Field Values

NATIVEPKG

public static final int NATIVEPKG
See Also:
Constant Field Values
Constructor Detail

CurryModulePath

private CurryModulePath()
Method Detail

append

public static void append(java.lang.String path,
                          int pathType)
                   throws java.io.IOException
Add the specified path(s) to the CurryModulePath. The paths are colon (:) separated. Any legal path (from the Operating System perspective) can be specified. Requesting to add a nonexisting or null path to CurryModulePath, prints an error message on stderr. Requesting to add a path that is not a readable directory to CurryModulePath, prints an error message on stderr. All specified paths are converted to their Normalized representation before adding them. Normalized representation is independent of the "current working directory". If a path has already been added, then a warning is printed on the stderr.

This method will be called by Main and Read-Eval-Print loop.

Parameters:
path - A Colon separated list of paths.
Throws:
java.io.IOException

appendPkgs

public static void appendPkgs(java.lang.String path)
                       throws java.io.IOException
Throws:
java.io.IOException

getFilePath

public static java.lang.String getFilePath(java.lang.String moduleName)
                                    throws ModFileNotFoundException,
                                           ModFileDuplicatedException
Search the CurryModulePath for file containing this module and return the complete path of that file. If some path in the CurryModulePath is not accessible, then it should be reported as a warning on stderr and the search should continue. If multiple files containing the specified module exists, then it should be reported as an exception. This method will be called by LoadManager to obtain the complete file path of the module file that needs to be loaded.

Returns:
The nonnull path String
Throws:
ModFileNotFoundException
ModFileDuplicatedException

show

public static void show(java.io.Writer out)
Shows/Prints the contents of the CurryModulePath on the specified PrintStream. The paths are printed in sorted order, so that repeated tests print the paths in the same order.

Parameters:
out - a PrintStream on which to show the contents of CurryModulePath.

showPaths

public static java.lang.String showPaths()

set

public static void set(java.lang.String path)
Set the CurryModulePath to the specified path.

This is implemented by assigning a new Vector to the ModulePath static data member and then appending the specified path.


remove

public static void remove(java.lang.String path)
Removes the specified path(s) from CurryModulePath. Several paths can be specified as a colon (:) separated list. If the specified path is not found in the CurryModulePath, then a warning is printed on stderr.

Parameters:
path - The path(s) that should be removed from CurryModulePath

append

private static void append(java.lang.String[] paths)
                    throws java.io.IOException
Appends each element of the paths array to ModulePath. This method must use the public append method to do the actual task.

Parameters:
paths - An array of paths, each of which is assumed to be not Colon separated.
Throws:
java.io.IOException

splitPath

private static java.lang.String[] splitPath(java.lang.String path,
                                            int pathType)
                                     throws java.io.IOException
Split a colon (:) separated string into an array of strings.

Parameters:
path - A Colon Separated Path
Returns:
An array of String
Throws:
java.io.IOException

getNormalizedPath

private static java.lang.String getNormalizedPath(java.lang.String somePath)
                                           throws java.io.IOException
Returns the normalized path of the specified path. Normalized representation is independent of the "current working directory". Currently the canonical path is the normalized path.

ToDo: Enhance the functionality of getNormalizedPath method to interpret some META CHARACTERS and TAGS and replace them with actual path fragments. For example: we could have a path like ~/curry/lib which could translate to /home/pravin/curry/lib Another example: we could have a path like $FLVMHOME/test1 which could translate to /home/pravin/curry/test1 if $FLVMHOME environment variable's value is /home/pravin/curry

Parameters:
somePath - Some path whose Normalized path is desired.
Returns:
The normalized path
Throws:
java.io.IOException

pathExists

private static boolean pathExists(java.lang.String path,
                                  int pathType)
Returns true if the specified path already exists in the CurryModulePath. Otherwise it returns false.

Parameters:
path - The path that should be checked for existance in CurryModulePath
Returns:
A boolean indicating if the specified path exists (true) or not (false)