FileDocCategorySizeDatePackage
ClassPath.javaAPI DocGlassfish v2 API9011Fri May 04 22:34:38 BST 2007com.sun.jdo.api.persistence.enhancer.util

ClassPath

public class ClassPath extends Object
ClassPath provides class file lookup according to a classpath specification.

Fields Summary
private String
theClassPathSpec
private ClassPathElement
theClassPath
Constructors Summary
public ClassPath(String path)
Construct a class path from the input String argument. The path is expected to be in the form appropriate for the current execution environment.

    theClassPathSpec = path;
    parsePath();
  
Methods Summary
public voidappend(ClassPathElement anElement)
Append a class path element to the classpath.

    if (theClassPath == null)
      theClassPath = anElement;
    else
      theClassPath.append(anElement);
  
public voidappend(java.io.File directory)
Append a directory to the classpath.

    append(ClassPathElement.create(directory.getPath()));
  
public static java.lang.StringclassNameOf(java.lang.String fileName)
Return the vm class name which corresponds to the input file name. The file name is expected to be a "./" relative path. Returns null if the file name doesn't end in ".class"

    int fnlen = fileName.length();
    if (fnlen > 6 && fileName.regionMatches(true, fnlen - 6, ".class", 0, 6)) {//NOI18N
      /* the file name ends with .class */
      fileName = fileName.substring(0, fileName.length()-6);
      StringBuffer className = new StringBuffer();
      StringTokenizer parser = new StringTokenizer(fileName, "\\/", false);//NOI18N
      for (boolean first = true; parser.hasMoreElements(); first = false) {
	if (!first)
	  className.append('/");
	className.append(parser.nextToken());
      }
      return className.toString();
    }
    return null;
  
public java.util.EnumerationclassesInPackage(java.lang.String packageName)
Return an enumeration of all of the class files in the specified package in this class path.

param
packageName specifies the VM format package name to which class files must belong.
returns
an Enumeration of the VM format class names which can be found. Note that the Enumeration value is of type String and duplicate entries may be returned as the result of finding a class through more than one class path element. Note also that the class name returned might not correspond the the name of the class in the file.

    return new ClassPackageEnumeration(this, packageName);
  
public static java.lang.StringfileNameOf(java.lang.String className, char separator)
Return a file name which might reasonably identify a file containing the specified class. The name is a "./" relative path.

    StringBuffer path = new StringBuffer();
    StringTokenizer parser = new StringTokenizer(className, "./", false);//NOI18N
    for (boolean first = true; parser.hasMoreElements(); first = false) {
      if (!first)
	path.append(separator);
      path.append(parser.nextToken());
    }
    path.append(".class");//NOI18N
    return path.toString();
  
public static java.lang.StringfileNameOf(java.lang.String className)
Return a file name which might reasonably identify a file containing the specified class. The name is a "./" relative path.

    return fileNameOf(className, File.separatorChar);
  
public ClassFileSourcefindClass(java.lang.String className)
locate a class file given a fully qualified class name

    return findClass(className, theClassPath);
  
static ClassFileSourcefindClass(java.lang.String className, ClassPathElement path)
locate a class file given a fully qualified class name starting at the specified class path element

    for (ClassPathElement e = path; e != null; e = e.next()) {
      ClassFileSource source = e.sourceOf(className);
      if (source != null) {
	source.setSourceElement(e);
	return source;
      }
    }

    return null;
  
ClassPathElementgetPathElements()

    return theClassPath;
  
private voidparsePath()

    StringTokenizer parser = 
      new StringTokenizer(theClassPathSpec,
			  java.io.File.pathSeparator,
			  false /* dont return delimiters */
			  );
    
    ClassPathElement lastElement = null;
    while (parser.hasMoreElements()) {
      ClassPathElement anElement = ClassPathElement.create(parser.nextToken());

      if (lastElement == null)
	theClassPath = anElement;
      else
	lastElement.append(anElement);

      lastElement = anElement;
    }
  
public booleanremove(java.io.File directory)
Remove any class path elements which match directory

    boolean matched = false;
    ClassPathElement firstElement = theClassPath;
    ClassPathElement prevElement = null;
    for (ClassPathElement cpe = firstElement; cpe != null; cpe = cpe.next()) {
      if (cpe.matches(directory)) {
	matched = true;
	if (prevElement == null)
	  firstElement = cpe.next();
	else
	  prevElement.setNext(cpe.next());
      } else {
	prevElement = cpe;
      }
    }
    theClassPath = firstElement;
    return matched;
  
public static java.lang.StringzipFileNameOf(java.lang.String className)
Return a file name which might reasonably identify a file containing the specified class in a zip file.

    return fileNameOf(className, '/");