bsh.classpath

Class BshClassPath

Implemented Interfaces:
ClassPathListener, NameSource

public class BshClassPath
extends java.lang.Object
implements ClassPathListener, NameSource

A BshClassPath encapsulates knowledge about a class path of URLs. It can maps all classes the path which may include: jar/zip files and base dirs A BshClassPath may composite other BshClassPaths as components of its path and will reflect changes in those components through its methods and listener interface. Classpath traversal is done lazily when a call is made to getClassesForPackage() or getClassSource() or can be done explicitily through insureInitialized(). Feedback on mapping progress is provided through the MappingFeedback interface. Design notes: Several times here we traverse ourselves and our component paths to produce a composite view of some thing relating to the path. This would be an opportunity for a visitor pattern.

Nested Class Summary

static class
BshClassPath.AmbiguousName
static class
BshClassPath.ClassSource
static class
BshClassPath.DirClassSource
static class
BshClassPath.GeneratedClassSource
static class
BshClassPath.JarClassSource
static interface
BshClassPath.MappingFeedback

Constructor Summary

BshClassPath(String name)
BshClassPath(String name, URL[] urls)

Method Summary

void
add(URL url)
void
add(URL[] urls)
void
addComponent(BshClassPath bcp)
Add the specified BshClassPath as a component of our path.
void
addListener(ClassPathListener l)
static void
addMappingFeedback(BshClassPath.MappingFeedback mf)
void
addNameSourceListener(NameSource.Listener listener)
Implements NameSource Add a listener who is notified upon changes to names in this space.
static String
canonicalizeClassName(String name)
Create a proper class name from a messy thing.
void
classPathChanged()
String[]
getAllNames()
static BshClassPath
getBootClassPath()
Get the boot path including the lib/rt.jar if possible.
String
getClassNameByUnqName(String name)
Support for super import "*"; Get the full name associated with the unqualified name in this classpath.
BshClassPath.ClassSource
getClassSource(String className)
Return the source of the specified class which may lie in component path.
Set
getClassesForPackage(String pack)
Return the set of class names in the specified package including all component paths.
protected List
getFullPath()
Get the full path including component paths.
Set
getPackagesSet()
Get a list of all of the known packages
URL[]
getPathComponents()
Get the path components including any component paths.
static BshClassPath
getUserClassPath()
A BshClassPath initialized to the user path from java.class.path
static URL[]
getUserClassPathComponents()
void
insureInitialized()
If the claspath map is not initialized, do it now.
protected void
insureInitialized(boolean topPath)
static boolean
isArchiveFileName(String name)
static boolean
isClassFileName(String name)
static void
main(String[] args)
static Collection
removeInnerClassNames(Collection col)
Return a new collection without any inner class names
void
removeListener(ClassPathListener l)
void
setClassSource(String className, BshClassPath.ClassSource cs)
Explicitly set a class source.
void
setPath(URL[] urls)
static String[]
splitClassname(String classname)
Split class name into package and name
String
toString()

Constructor Details

BshClassPath

public BshClassPath(String name)

BshClassPath

public BshClassPath(String name,
                    URL[] urls)

Method Details

add

public void add(URL url)
            throws IOException

add

public void add(URL[] urls)

addComponent

public void addComponent(BshClassPath bcp)
Add the specified BshClassPath as a component of our path. Changes in the bcp will be reflected through us.

addListener

public void addListener(ClassPathListener l)

addMappingFeedback

public static void addMappingFeedback(BshClassPath.MappingFeedback mf)

addNameSourceListener

public void addNameSourceListener(NameSource.Listener listener)
Implements NameSource Add a listener who is notified upon changes to names in this space.
Specified by:
addNameSourceListener in interface NameSource

canonicalizeClassName

public static String canonicalizeClassName(String name)
Create a proper class name from a messy thing. Turn / or \ into ., remove leading class and trailing .class Note: this makes lots of strings... could be faster.

classPathChanged

public void classPathChanged()
Specified by:
classPathChanged in interface ClassPathListener

getAllNames

public String[] getAllNames()
Specified by:
getAllNames in interface NameSource

getBootClassPath

public static BshClassPath getBootClassPath()
            throws ClassPathException
Get the boot path including the lib/rt.jar if possible.

getClassNameByUnqName

public String getClassNameByUnqName(String name)
            throws ClassPathException
Support for super import "*"; Get the full name associated with the unqualified name in this classpath. Returns either the String name or an AmbiguousName object encapsulating the various names.

getClassSource

public BshClassPath.ClassSource getClassSource(String className)
Return the source of the specified class which may lie in component path.

getClassesForPackage

public Set getClassesForPackage(String pack)
Return the set of class names in the specified package including all component paths.

getFullPath

protected List getFullPath()
Get the full path including component paths. (component paths listed first, in order) Duplicate path components are removed.

getPackagesSet

public Set getPackagesSet()
Get a list of all of the known packages

getPathComponents

public URL[] getPathComponents()
Get the path components including any component paths.

getUserClassPath

public static BshClassPath getUserClassPath()
            throws ClassPathException
A BshClassPath initialized to the user path from java.class.path

getUserClassPathComponents

public static URL[] getUserClassPathComponents()
            throws ClassPathException

insureInitialized

public void insureInitialized()
If the claspath map is not initialized, do it now. If component maps are not do them as well... Random note: Should this be "insure" or "ensure". I know I've seen "ensure" used in the JDK source. Here's what Webster has to say: Main Entry:ensure Pronunciation:in-'shur Function:transitive verb Inflected Form(s):ensured; ensuring : to make sure, certain, or safe : GUARANTEE synonyms ENSURE, INSURE, ASSURE, SECURE mean to make a thing or person sure. ENSURE, INSURE, and ASSURE are interchangeable in many contexts where they indicate the making certain or inevitable of an outcome, but INSURE sometimes stresses the taking of necessary measures beforehand, and ASSURE distinctively implies the removal of doubt and suspense from a person's mind. SECURE implies action taken to guard against attack or loss.

insureInitialized

protected void insureInitialized(boolean topPath)
Parameters:
topPath - indicates that this is the top level classpath component and it should send the startClassMapping message

isArchiveFileName

public static boolean isArchiveFileName(String name)

isClassFileName

public static boolean isClassFileName(String name)

main

public static void main(String[] args)
            throws Exception

removeInnerClassNames

public static Collection removeInnerClassNames(Collection col)
Return a new collection without any inner class names

removeListener

public void removeListener(ClassPathListener l)

setClassSource

public void setClassSource(String className,
                           BshClassPath.ClassSource cs)
Explicitly set a class source. This is used for generated classes, but could potentially be used to allow a user to override which version of a class from the classpath is located.

setPath

public void setPath(URL[] urls)

splitClassname

public static String[] splitClassname(String classname)
Split class name into package and name

toString

public String toString()

B) 2000-2005 pat@pat.net :-)