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.
Inner Class :abstractpublic static class ClassSource
Inner Class :public static class JarClassSource extends ClassSource
Inner Class :public static class DirClassSource extends ClassSource
Inner Class :public static class GeneratedClassSource extends ClassSource
Inner Class :static class UnqualifiedNameTable extends HashMap
Inner Class :public static class AmbiguousName
Inner Class :public static interface MappingFeedback
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...
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".
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.
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 synchronized ClassSource getClassSource(String className)(Code)
Return the source of the specified class which may lie in component
path.
getClassesForPackage
public synchronized Set getClassesForPackage(String pack)(Code)
Return the set of class names in the specified package
including all component paths.
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.
public synchronized void setClassSource(String className, ClassSource cs)(Code)
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.