com.digi.config.util
Class PathLocater

java.lang.Object
  extended bycom.digi.config.util.PathLocater

public class PathLocater
extends java.lang.Object

A helper class for determining path names.


Field Summary
(package private) static java.net.URL documentBase
          If loaded from the network, this identifies where to find network resources
(package private) static int numDirInClasspath
          Number of directories in the classpath.
 
Constructor Summary
PathLocater()
           
 
Method Summary
static void createPathToFile(java.io.File file)
          Ensures that the directory path portion of the specified file exists.
static void createPathToFile(java.lang.String fullName)
          Ensures that the directory path portion of the specified full file name exists.
static java.lang.String getDefaultSaveFileName(java.lang.String fileName)
          Creates a fully qualified file name of the Persistance file.
static java.net.URL getDocumentBase()
          Returns the document base currently in use
static int getNumDirInClasspath()
          Returns the number of directories in the classpath.
static java.lang.String locateFile(java.lang.String fileName)
          This method returns the absolute path name of a file.
static java.lang.String locateFullClassFileName(java.lang.String name)
          Returns the fully qualified file name of the provided class.
static java.lang.String locateFullPath(java.lang.String name)
          Returns the name of the path from where the provided class was loaded.
static void setDocumentBase(java.net.URL documentBase)
          Sets the document base currently in use
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

documentBase

static java.net.URL documentBase
If loaded from the network, this identifies where to find network resources


numDirInClasspath

static int numDirInClasspath
Number of directories in the classpath. This is saved after the first time it is calculated as a trade off between using 4 bytes of storage versus the cost to re-calc the number. NOTE: Obviously, if the application ever is in a situation where the classpath can dynamically be updated during runtime, caching this number is not a good idea.

Constructor Detail

PathLocater

public PathLocater()
Method Detail

setDocumentBase

public static void setDocumentBase(java.net.URL documentBase)
Sets the document base currently in use


getDocumentBase

public static java.net.URL getDocumentBase()
Returns the document base currently in use


locateFullClassFileName

public static java.lang.String locateFullClassFileName(java.lang.String name)
Returns the fully qualified file name of the provided class.

Parameters:
name - Name of the class. Use package qualified name e.g.com.digi.config.util.PathLocater
Returns:
the fully qualified file name for the class file. Such as d:\\config\\com\\digi\\util\\PathLocater.class

locateFullPath

public static java.lang.String locateFullPath(java.lang.String name)
Returns the name of the path from where the provided class was loaded.

Parameters:
name - Name of the class. Use package qualified name such as com.digi.config.util.PathLocator
Returns:
the name of the path from where the specified class was loaded. Such as d:\\config NOTE: there is no trailing path separator character on the returned value.

getNumDirInClasspath

public static int getNumDirInClasspath()
Returns the number of directories in the classpath.

Returns:
the number of directories in the classpath

locateFile

public static java.lang.String locateFile(java.lang.String fileName)
This method returns the absolute path name of a file. The file must be located in the directory specified by the "user.home" or "user.dir" system properties or somewhere along the classpath.

Parameters:
fileName - Name of the file to locate.
Returns:
Absoulte path for the file.

getDefaultSaveFileName

public static java.lang.String getDefaultSaveFileName(java.lang.String fileName)
Creates a fully qualified file name of the Persistance file. The path to the file is generated as follows: If user.home is specified, then that path is used as the default path otherwise the classpath directory containing the config class files will be used. The subdirectory "Data" will be appended to whichever path is found above.


createPathToFile

public static void createPathToFile(java.lang.String fullName)
Ensures that the directory path portion of the specified full file name exists. If directories in the path do not exist, then this method will create them if possible.

Parameters:
fullName - the fully qualified file name whose path is to be created as needed.
Throws:
java.lang.SecurityException - If a security manager exists and its SecurityManager.checkWrite(java.lang.String) method does not permit the named directory and all necessary parent directories and to be created

createPathToFile

public static void createPathToFile(java.io.File file)
Ensures that the directory path portion of the specified file exists. If directories in the path do not exist, then this method will create them if possible.

Parameters:
file - the file whose path is to be created as needed.
Throws:
java.lang.SecurityException - If a security manager exists and its SecurityManager.checkWrite(java.lang.String) method does not permit the named directory and all necessary parent directories and to be created


Copyright © 2001-2002 Digi International. All Rights Reserved.