EAF 7.6 Util

com.lutris.classloader
Class ClassPathEntry

java.lang.Object
  extended by com.lutris.classloader.ClassPathEntry

public class ClassPathEntry
extends java.lang.Object

Summary:

A class path entry which is a URL representing either a local or a remote directory or zip file. Manages all the details for zip file support. For example, local zip files (once opened) are kept open for the lifetime of the entry for increased performance.

Features:

Note: "zip files" are files with ".zip" or ".jar" extensions.

Class Path Entries:

Example valid class path entries are:

     Files and directories on the local file system
     ../../java/classes
     /users/kristen/java/classes
     /users/kristen/java/classes/
     /users/kristen/java/zipfiles/MyClasses.zip
     /users/kristen/java/jarfiles/MyClasses.jar
     file:///users/kristen/java/classes
     file://localhost/users/kristen/java/classes
     
Files and directories on a remote file system (must be in URL format) ftp://www.foo.com/pub/java/classes file://www.foo.com/pub/java/classes/ http://www.foo.com/web/java/classes/ file://www.foo.com:8080/pub/java/zipfiles/MyClasses.zip http://www.foo.com:8080/web/java/jarfiles/MyClasses.jar

Note that the location of the entry includes the protocol, the host name, and the port while the file name is everything else. For example,

     http://www.foo.com:8080/web/java/jarfiles/MyClasses.jar
 
has the form [location][name] or
     [http://www.foo.com:8080/][/web/java/jarfiles/MyClasses.jar]
 
so the location is "http://www.foo.com:8080/" and the name is "/web/java/jarfiles/MyClasses.jar".

Note that the two references

     /users/kristen/java/classes/
     file:///users/kristen/java/classes/
 
represent the same directory on a Unix machine, and
     C|/windows/java/classes/
     file:///C|/windows/java/classes/
 
are equivalent directories on a Windows box.

But the two references

     /users/kristen/java/classes/
     file://monet.lutris.com/users/kristen/java/classes/
 
are not equivalent even if the directory /users/kristen/java/classes/ lives on the machine named monet.lutris.com and all development is on this machine. Why? Because the web (browser?) protocol is different for URLs with host information and those without. If no host is specified, the file is assumed to be on the local machine and the path is determined from the ROOT of the machine. If the host is specified, then the ftp protocol is used and the path is determined from the ftp ROOT (e.g. /users/ftp/) rather than the machine's ROOT. Thus, on a machine that support's anonymous ftp, the following two directories are the same:
     /users/ftp/pub/classes/
     file://picasso.lutris.com/pub/classes/
 
assuming the development is being done on picasso.lutris.com.

System Class Path Entries

The system class path is the system-dependent path of directories and files (e.g. CLASSPATH on Unix and Windows) used by the system class loader to load classes. Valid system class path entries are directories and zip files, specified by absolute path or relative path on the system. Any valid system class path entry is also valid to create a ClassPathEntry.

Example

Here is an example of how to use a ClassPathEntry:

     ClassPathEntry entry = new ClassPathEntry("/home/java/Test.jar");
     System.out.println("My entry URL is " + entry.get());
     System.out.println("My entry string is " + entry.toString());
     System.out.println("My entry name " + entry.getName());
     System.out.println("My entry location " + entry.getLocation());
     System.out.println("My entry is a zip file? " + entry.isZipFile());
     Resource resource = entry.getResource("foo.gif");
 

Version:
$Revision : 1.0 $
Author:
Kristen Pol, Lutris Technologies
See Also:
Resource, URL

Constructor Summary
ClassPathEntry(java.io.File entry, com.lutris.logging.LogChannel loadLogChannel)
          Constructs class path entry with specified File.
ClassPathEntry(java.lang.String entry, com.lutris.logging.LogChannel loadLogChannel)
          Constructs class path entry with specified String.
ClassPathEntry(java.net.URL entry, com.lutris.logging.LogChannel loadLogChannel)
          Constructs class path entry with specified URL.
 
Method Summary
 boolean equals(java.lang.Object o)
          Determines if specified class path entry is equal to this entry.
 java.lang.String getLocation()
          Gets location of class path entry.
 java.lang.String getName()
          Gets file name of class path entry.
 com.lutris.classloader.Resource getResource(java.lang.String name)
          Gets resource with the specified name from class path entry.
 java.net.URL getURL()
          Gets class path entry set previously by constructor.
 java.util.zip.ZipFile getZipFile()
          Gets zip file associated with class path entry if appropriate.
 boolean isDirectory()
          Determines if class path entry is a directory.
 boolean isLocal()
          Determines if class path entry is local.
 boolean isRemote()
          Determines if class path entry is remote.
 boolean isZipFile()
          Determines if class path entry is a zip file.
 java.lang.String toString()
          Stringifies class path entry set previously by constructor.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ClassPathEntry

public ClassPathEntry(java.lang.String entry,
                      com.lutris.logging.LogChannel loadLogChannel)
Constructs class path entry with specified String. The String is assumed to be either a directory or zip file on the local machine or a remote machine, which can be represented by the absolute file name, the relative file name, or a URL.

Examples:

     ClassPathEntry("../../java/classes");
     ClassPathEntry("/users/kristen/java/classes");
     ClassPathEntry("/users/kristen/java/classes/");
     ClassPathEntry("/users/kristen/java/MyClasses.zip");
     ClassPathEntry("/users/kristen/java/MyClasses.jar");
     ClassPathEntry("ftp://www.foo.com/pub/classes/");
     ClassPathEntry("file://www.foo.com/web/classes/");
     ClassPathEntry("http://www.foo.com/web/classes/");
     ClassPathEntry("http://www.foo.com:8080/web/classes/");
     ClassPathEntry("http://www.foo.com/web/classes/MyClasses.jar");
 

Parameters:
entry - The class path entry.
loadLogChannel - The log channel.

ClassPathEntry

public ClassPathEntry(java.io.File entry,
                      com.lutris.logging.LogChannel loadLogChannel)
Constructs class path entry with specified File. The File can represent a directory or zip file on the local machine.

Examples:

     ClassPathEntry(new File("../../java/classes"));
     ClassPathEntry(new File("/users/kristen/java/classes"));
     ClassPathEntry(new File("/users/kristen/java/classes/"));
     ClassPathEntry(new File("/users/kristen/java/MyClasses.zip"));
     ClassPathEntry(new File("/users/kristen/java/MyClasses.jar"));
 

Parameters:
entry - The class path entry.
loadLogChannel - The log channel.

ClassPathEntry

public ClassPathEntry(java.net.URL entry,
                      com.lutris.logging.LogChannel loadLogChannel)
Constructs class path entry with specified URL. The URL can represent a directory or zip file on the local machine or a remote machine.

Examples:

     ClassPathEntry(new URL("ftp://www.foo.com/pub/classes/"));
     ClassPathEntry(new URL("file://www.foo.com/web/classes/"));
     ClassPathEntry(new URL("http://www.foo.com/web/classes/"));
     ClassPathEntry(new URL("http://www.foo.com:8080/web/classes/"));
     ClassPathEntry(new URL("http://www.foo.com/web/MyClasses.jar"));
 

Parameters:
entry - The class path entry.
loadLogChannel - The log channel.
Method Detail

getURL

public java.net.URL getURL()
Gets class path entry set previously by constructor.

Returns:
the class path entry represented by a URL.

getName

public java.lang.String getName()
Gets file name of class path entry. For example, if the entry is "http://www.foo.com:8080/java/classes/MyClasses.jar", the name is "/java/classes/MyClasses.jar". The beginning slash does not mean that its an absolute file name on its host machine. The file name is always relative to the location.

Returns:
the file name of the class path entry.

getLocation

public java.lang.String getLocation()
Gets location of class path entry. For example, if the entry is "http://www.foo.com:8080/java/classes/MyClasses.jar", the location is "http://www.foo.com:8080/".

Returns:
the file name for the class path entry.

toString

public java.lang.String toString()
Stringifies class path entry set previously by constructor.

Overrides:
toString in class java.lang.Object
Returns:
the class path entry represented by a stringified URL.

getResource

public com.lutris.classloader.Resource getResource(java.lang.String name)
Gets resource with the specified name from class path entry. The result will be null if the resource can not be found.

Parameters:
name - The file name associated with the resource.
Returns:
the resource from the class path entry, or null if it is not found.
See Also:
Resource

isZipFile

public boolean isZipFile()
Determines if class path entry is a zip file. Anything ending in ".zip" or ".jar" is considered a zip file.

Returns:
true if the class path entry is a zip file, false if it is not.

isDirectory

public boolean isDirectory()
Determines if class path entry is a directory. Anything that is not a zip file is considered a directory.

Returns:
true if the class path entry is a directory, false if it is not.
See Also:
isZipFile

isLocal

public boolean isLocal()
Determines if class path entry is local. Anything that has no host name or a host name of "localhost" is considered local.

Returns:
true if the class path entry is remote, false if it is not.

isRemote

public boolean isRemote()
Determines if class path entry is remote. Anything that is not local is considered remote.

Returns:
true if the class path entry is remote, false if it is not.
See Also:
isLocal()

equals

public boolean equals(java.lang.Object o)
Determines if specified class path entry is equal to this entry. The entries are considered equal if the URLs are the same.

Overrides:
equals in class java.lang.Object
Parameters:
cpe - The class path entry to check for equality.
Returns:
true if the class path entry is equal, false if it is not.

getZipFile

public java.util.zip.ZipFile getZipFile()
Gets zip file associated with class path entry if appropriate. If a zip file is not found, null will be returned.

Returns:
the zip file associated with this class path entry if found, null if not.

EAF 7.6 Util