Top Description Inners Fields Constructors Methods
bsh.classpath

public Class BshClassPath

extends Object
implements ClassPathListener, NameSource
Class Inheritance
All Implemented Interfaces
bsh.NameSource, bsh.classpath.ClassPathListener
Imports
java.util.*, java.util.zip.*, java.io.*, .File, java.net.*, bsh.ConsoleInterface, .StringUtil, .ClassPathException, .NameSource, java.lang.ref.WeakReference

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 and Inner Type Summary

Modifier and TypeClass and Description
public static class
public abstract static class
public static class
public static class
public static class
public static interface
pack-priv static class

Field Summary

Modifier and TypeField and Description
pack-priv static BshClassPath
private Map<K, V>
classSource

Map of source (URL or File dir) of every clas

private List<E>
compPaths

Ordered list of components BshClassPaths

pack-priv Vector<E>
pack-priv static BshClassPath.MappingFeedback
mappingFeedbackListener

only allow one for now

private boolean
mapsInitialized

The packageMap and classSource maps have been built.

pack-priv String
private boolean
nameCompletionIncludesUnqNames

This used to be configurable, but now we always include them.

pack-priv List<E>
private Map<K, V>
packageMap

Set of classes in a package mapped by package name

private List<E>
path

The URL path components

private BshClassPath.UnqualifiedNameTable
pack-priv static BshClassPath
pack-priv static URL[]
userClassPathComp

The user classpath from system property java.class.path

Constructor Summary

AccessConstructor and Description
public
public
BshClassPath(String name, URL[] urls)

Method Summary

Modifier and TypeMethod and Description
public void
add(URL[] urls)

public void
add(URL url)

public void
addComponent(BshClassPath bcp)

Add the specified BshClassPath as a component of our path.

public void
public static void
public void
addNameSourceListener(NameSource.Listener listener)

Implements bsh.NameSource.addNameSourceListener.

Implements NameSource Add a listener who is notified upon changes to names in this space.
private BshClassPath.UnqualifiedNameTable
public static String
canonicalizeClassName(String name)

Create a proper class name from a messy thing.

pack-priv void
public void
private synchronized void
clearCachedStructures()

Clear anything cached.

pack-priv void
pack-priv void
public String[]
public static BshClassPath
getBootClassPath()

Get the boot path including the lib/rt.jar if possible.

public synchronized Set<E>
getClassesForPackage(String pack)

Return the set of class names in the specified package including all component paths.

public String
getClassNameByUnqName(String name)

Support for super import "*"; Get the full name associated with the unqualified name in this classpath.

public synchronized BshClassPath.ClassSource
getClassSource(String className)

Return the source of the specified class which may lie in component path.

protected List<E>
getFullPath()

Get the full path including component paths.

public Set<E>
getPackagesSet()

Get a list of all of the known packages

public URL[]
getPathComponents()

Get the path components including any component paths.

private static String
private BshClassPath.UnqualifiedNameTable
public static BshClassPath
getUserClassPath()

A BshClassPath initialized to the user path from java.class.path

public static URL[]
public void
insureInitialized()

If the claspath map is not initialized, do it now.

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

public static boolean
public static boolean
public static void
main(String[] args)

pack-priv synchronized void
map(URL[] urls)

call map(url) for each url in the array

pack-priv synchronized void
map(URL url)

private void
map(String[] classes, Object source)

private void
mapClass(String className, Object source)

pack-priv void
nameSpaceChanged()

Fire the NameSourceListeners

pack-priv void
public static Collection<E>
removeInnerClassNames(Collection<E> col)

Return a new collection without any inner class names

public void
private synchronized void
reset()

Clear everything and reset the path to empty.

pack-priv static String[]
searchJarForClasses(URL jar)

Get the class file entries from the Jar

public synchronized void
setClassSource(String className, BshClassPath.ClassSource cs)

Explicitly set a class source.

public void
setPath(URL[] urls)

public static String[]
splitClassname(String classname)

Split class name into package and name

pack-priv void
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
pack-priv static String[]
pack-priv static List<E>
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

bootClassPathback to summary
pack-priv static BshClassPath bootClassPath
classSourceback to summary
private Map<K, V> classSource

Map of source (URL or File dir) of every clas

compPathsback to summary
private List<E> compPaths

Ordered list of components BshClassPaths

listenersback to summary
pack-priv Vector<E> listeners
mappingFeedbackListenerback to summary
pack-priv static BshClassPath.MappingFeedback mappingFeedbackListener

only allow one for now

mapsInitializedback to summary
private boolean mapsInitialized

The packageMap and classSource maps have been built.

nameback to summary
pack-priv String name
nameCompletionIncludesUnqNamesback to summary
private boolean nameCompletionIncludesUnqNames

This used to be configurable, but now we always include them.

nameSourceListenersback to summary
pack-priv List<E> nameSourceListeners
packageMapback to summary
private Map<K, V> packageMap

Set of classes in a package mapped by package name

pathback to summary
private List<E> path

The URL path components

unqNameTableback to summary
private BshClassPath.UnqualifiedNameTable unqNameTable
userClassPathback to summary
pack-priv static BshClassPath userClassPath
userClassPathCompback to summary
pack-priv static URL[] userClassPathComp

The user classpath from system property java.class.path

Constructor Detail

BshClassPathback to summary
public BshClassPath(String name)
BshClassPathback to summary
public BshClassPath(String name, URL[] urls)

Method Detail

addback to summary
public void add(URL[] urls)
addback to summary
public void add(URL url) throws IOException
addComponentback to summary
public void addComponent(BshClassPath bcp)

Add the specified BshClassPath as a component of our path. Changes in the bcp will be reflected through us.

addListenerback to summary
public void addListener(ClassPathListener l)
addMappingFeedbackback to summary
public static void addMappingFeedback(BshClassPath.MappingFeedback mf)
addNameSourceListenerback to summary
public void addNameSourceListener(NameSource.Listener listener)

Implements bsh.NameSource.addNameSourceListener.

Implements NameSource Add a listener who is notified upon changes to names in this space.

buildUnqualifiedNameTableback to summary
private BshClassPath.UnqualifiedNameTable buildUnqualifiedNameTable()
canonicalizeClassNameback to summary
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.

classMappingback to summary
pack-priv void classMapping(String msg)
classPathChangedback to summary
public void classPathChanged()

Implements bsh.classpath.ClassPathListener.classPathChanged.

clearCachedStructuresback to summary
private synchronized void clearCachedStructures()

Clear anything cached. All will be reconstructed as necessary.

endClassMappingback to summary
pack-priv void endClassMapping()
errorWhileMappingback to summary
pack-priv void errorWhileMapping(String s)
getAllNamesback to summary
public String[] getAllNames()

Implements bsh.NameSource.getAllNames.

getBootClassPathback to summary
public static BshClassPath getBootClassPath() throws ClassPathException

Get the boot path including the lib/rt.jar if possible.

getClassesForPackageback to summary
public synchronized Set<E> getClassesForPackage(String pack)

Return the set of class names in the specified package including all component paths.

getClassNameByUnqNameback to summary
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.

getClassSourceback to summary
public synchronized BshClassPath.ClassSource getClassSource(String className)

Return the source of the specified class which may lie in component path.

getFullPathback to summary
protected List<E> getFullPath()

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

getPackagesSetback to summary
public Set<E> getPackagesSet()

Get a list of all of the known packages

getPathComponentsback to summary
public URL[] getPathComponents()

Get the path components including any component paths.

getRTJarPathback to summary
private static String getRTJarPath()
getUnqualifiedNameTableback to summary
private BshClassPath.UnqualifiedNameTable getUnqualifiedNameTable()
getUserClassPathback to summary
public static BshClassPath getUserClassPath() throws ClassPathException

A BshClassPath initialized to the user path from java.class.path

getUserClassPathComponentsback to summary
public static URL[] getUserClassPathComponents() throws ClassPathException
insureInitializedback to summary
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.

insureInitializedback to summary
protected synchronized void insureInitialized(boolean topPath)
Parameters
topPath:boolean

indicates that this is the top level classpath component and it should send the startClassMapping message

isArchiveFileNameback to summary
public static boolean isArchiveFileName(String name)
isClassFileNameback to summary
public static boolean isClassFileName(String name)
mainback to summary
public static void main(String[] args) throws Exception
mapback to summary
pack-priv synchronized void map(URL[] urls)

call map(url) for each url in the array

mapback to summary
pack-priv synchronized void map(URL url) throws IOException
mapback to summary
private void map(String[] classes, Object source)
mapClassback to summary
private void mapClass(String className, Object source)
nameSpaceChangedback to summary
pack-priv void nameSpaceChanged()

Fire the NameSourceListeners

notifyListenersback to summary
pack-priv void notifyListeners()
removeInnerClassNamesback to summary
public static Collection<E> removeInnerClassNames(Collection<E> col)

Return a new collection without any inner class names

removeListenerback to summary
public void removeListener(ClassPathListener l)
resetback to summary
private synchronized void reset()

Clear everything and reset the path to empty.

searchJarForClassesback to summary
pack-priv static String[] searchJarForClasses(URL jar) throws IOException

Get the class file entries from the Jar

setClassSourceback to summary
public synchronized 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.

setPathback to summary
public void setPath(URL[] urls)
splitClassnameback to summary
public static String[] splitClassname(String classname)

Split class name into package and name

startClassMappingback to summary
pack-priv void startClassMapping()
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

traverseDirForClassesback to summary
pack-priv static String[] traverseDirForClasses(File dir) throws IOException
traverseDirForClassesAuxback to summary
pack-priv static List<E> traverseDirForClassesAux(File topDir, File dir) throws IOException
bsh.classpath back to summary

public Class BshClassPath.AmbiguousName

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv List<E>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
add(String name)

public List<E>
get()

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

listback to summary
pack-priv List<E> list

Constructor Detail

AmbiguousNameback to summary
public AmbiguousName()

Method Detail

addback to summary
public void add(String name)
getback to summary
public List<E> get()
bsh.classpath back to summary

public abstract Class BshClassPath.ClassSource

extends Object
Class Inheritance
Known Direct Subclasses
bsh.classpath.BshClassPath.JarClassSource, bsh.classpath.BshClassPath.DirClassSource, bsh.classpath.BshClassPath.GeneratedClassSource

Field Summary

Modifier and TypeField and Description
pack-priv Object

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
pack-priv abstract byte[]
getCode(String className)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

sourceback to summary
pack-priv Object source

Constructor Detail

ClassSourceback to summary
public ClassSource()

Method Detail

getCodeback to summary
pack-priv abstract byte[] getCode(String className)
bsh.classpath back to summary

public Class BshClassPath.DirClassSource

extends ClassSource
Class Inheritance

Field Summary

Inherited from bsh.classpath.BshClassPath.ClassSource:
source

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public byte[]
public File
public static byte[]
readBytesFromFile(File base, String className)

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Constructor Detail

DirClassSourceback to summary
pack-priv DirClassSource(File dir)

Method Detail

getCodeback to summary
public byte[] getCode(String className)

Implements abstract bsh.classpath.BshClassPath.ClassSource.getCode.

getDirback to summary
public File getDir()
readBytesFromFileback to summary
public static byte[] readBytesFromFile(File base, String className)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

bsh.classpath back to summary

public Class BshClassPath.GeneratedClassSource

extends ClassSource
Class Inheritance

Field Summary

Inherited from bsh.classpath.BshClassPath.ClassSource:
source

Constructor Summary

AccessConstructor and Description
pack-priv
GeneratedClassSource(byte[] bytecode)

Method Summary

Modifier and TypeMethod and Description
public byte[]

Constructor Detail

GeneratedClassSourceback to summary
pack-priv GeneratedClassSource(byte[] bytecode)

Method Detail

getCodeback to summary
public byte[] getCode(String className)

Implements abstract bsh.classpath.BshClassPath.ClassSource.getCode.

bsh.classpath back to summary

public Class BshClassPath.JarClassSource

extends ClassSource
Class Inheritance

Field Summary

Inherited from bsh.classpath.BshClassPath.ClassSource:
source

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public byte[]
public URL
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Constructor Detail

JarClassSourceback to summary
pack-priv JarClassSource(URL url)

Method Detail

getCodeback to summary
public byte[] getCode(String className)

Implements abstract bsh.classpath.BshClassPath.ClassSource.getCode.

getURLback to summary
public URL getURL()
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

bsh.classpath back to summary

public Interface BshClassPath.MappingFeedback


Method Summary

Modifier and TypeMethod and Description
public void
classMapping(String msg)

Provide feedback on the progress of mapping the classpath

public void
public void
public void

Method Detail

classMappingback to summary
public void classMapping(String msg)

Provide feedback on the progress of mapping the classpath

endClassMappingback to summary
public void endClassMapping()
errorWhileMappingback to summary
public void errorWhileMapping(String msg)
startClassMappingback to summary
public void startClassMapping()
bsh.classpath back to summary

pack-priv Class BshClassPath.UnqualifiedNameTable

extends HashMap
Class Inheritance

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv void
add(String fullname)

Inherited from java.util.HashMap:
clearclonecomputecomputeIfAbsentcomputeIfPresentcontainsKeycontainsValueentrySetforEachgetgetOrDefaultisEmptykeySetmergenewHashMapputputAllputIfAbsentremoveremovereplacereplacereplaceAllsizevalues

Constructor Detail

UnqualifiedNameTableback to summary
pack-priv UnqualifiedNameTable()

Method Detail

addback to summary
pack-priv void add(String fullname)