|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.jode.bytecode.ClassPath
public class ClassPath
A path in which class files are searched for. Class files can be loaded from several different locations, these locations can be:
JarURLConnection
), useful if
the jar file is not packed correctly.reflection:/
. This is a
special location, which fills the ClassInfo with the information
from the java reflection API. Obviously it can't load any files
nor the full bytecode. It only loads declarations of classes. If a
security manager is present, it can only load public
declarations. .class
extension. For example if the class path points to
/home/java
, the class java.lang.Object
is
loaded from /home/java/java/lang/Object.class
. Of course
you can write your own ClassPath.Location
s that break this rule.
A class path can have another ClassPath as fallback. If
ClassInfo.loadInfo is called and the class isn't found the fallback
ClassPath is searched instead. This repeats until there is no
further fallback. The fallback is not used when listing classes or
files.
The main method for creating classes is getClassInfo(java.lang.String)
. The
other available methods are useful to find other files in the
ClassPath and to get a listing of all available files and classes.
A ClassPath handles some IOException
s and
SecurityException
s skipping the path that produced
them.
Nested Class Summary | |
---|---|
static class |
ClassPath.Location
A location is a single component of the ClassPath. |
Field Summary | |
---|---|
static char |
altPathSeparatorChar
We need a different pathSeparatorChar, since ':' (used for UNIX systems) is also used as protocol separator in URLs. |
Constructor Summary | |
---|---|
ClassPath(ClassPath.Location[] locs)
Creates a new class path for the given path. |
|
ClassPath(ClassPath.Location[] locs,
ClassPath fallback)
Creates a new class path for the given path. |
|
ClassPath(String path)
Creates a new class path for the given path. |
|
ClassPath(String[] paths)
Creates a new class path for the given path. |
|
ClassPath(String[] paths,
ClassPath fallback)
Creates a new class path for the given path. |
|
ClassPath(String path,
ClassPath fallback)
Creates a new class path for the given path. |
Method Summary | |
---|---|
static ClassPath.Location |
createLocation(String path)
Creates a location for a given path component. |
boolean |
existsClass(String classname)
Checks, if a class with the given name exists somewhere in this path. |
boolean |
existsFile(String filename)
Checks, if a file with the given name exists somewhere in this path. |
ClassInfo |
getClassInfo(String classname)
Creates a new class info for a class residing in this search path. |
ClassInfo |
getClassInfoFromStream(InputStream stream)
Creates a new class info from an input stream containing the bytecode. |
List<String> |
getClassPath()
|
InputStream |
getFile(String filename)
Searches for a file in the class path. |
boolean |
isDirectory(String filename)
Searches for a filename in the class path and tells if it is a directory. |
boolean |
isPackage(String fqn)
Searches for a filename in the class path and tells if it is a package. |
Enumeration |
listClassesAndPackages(String packageName)
Get a list of all classes and packages in the given package. |
Enumeration |
listFiles(String dirName)
Get a list of all files in a given directory. |
String |
toString()
Returns a string representation of this classpath. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final char altPathSeparatorChar
altPathSeparator
, or better yet the
ClassPath(String[]) or ClassPath(Location[]) constructors.
Constructor Detail |
---|
public ClassPath(String[] paths, ClassPath fallback)
paths
- An array of paths.fallback
- The fallback classpath.public ClassPath(String[] paths)
paths
- An array of paths.public ClassPath(ClassPath.Location[] locs, ClassPath fallback)
locs
- An array of locations.fallback
- The fallback classpath.public ClassPath(ClassPath.Location[] locs)
locs
- An array of locations.public ClassPath(String path, ClassPath fallback)
path
- One or more paths. They should be separated by the
altPathSeparatorChar or pathSeparatorChar, but the latter is
deprecated since it may give problems for UNIX machines.ClassPath(String[] paths)
public ClassPath(String path)
path
- One or more paths. They should be separated by the
altPathSeparatorChar or pathSeparatorChar, but the latter is
deprecated since it may give problems for UNIX machines.ClassPath(String[] paths)
Method Detail |
---|
public static ClassPath.Location createLocation(String path) throws IOException, SecurityException
path
- the path component.
NullPointerException
- if path is null.
IOException
- if an io exception occured while accessing the
path component.
SecurityException
- if a security exception occured
while accessing the path component.public ClassInfo getClassInfo(String classname)
classname
- the dot-separated full qualified name of the class.
For inner classes you must use the bytecode name with $,
e.g. java.util.Map$Entry
.
IllegalArgumentException
- if class name isn't valid.public List<String> getClassPath()
public ClassInfo getClassInfoFromStream(InputStream stream) throws IOException, ClassFormatException
ClassInfo.ALL
) when you use this
method.
stream
- the input stream containing the bytecode.
IOException
- if an io exception occurs.
ClassFormatException
- if bytecode isn't valid.public boolean existsClass(String classname)
classname
- the class name.
IllegalArgumentException
- if class name isn't valid.public boolean existsFile(String filename)
filename
- the file name.existsClass(java.lang.String)
public InputStream getFile(String filename) throws IOException
filename
- the filename. The path components should be separated
by "/".
IOException
public boolean isDirectory(String filename)
filename
- the filename. The path components should be separated
by "/".
public boolean isPackage(String fqn)
fqn
- the full qualified name. The components should be dot
separated.
isDirectory(java.lang.String)
public Enumeration listFiles(String dirName)
dirName
- the directory name. The path components must
be separated by "/".
public Enumeration listClassesAndPackages(String packageName)
packageName
- a dot-separated package name.
public String toString()
toString
in class Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |