Methods Summary |
---|
private void | ctor(java.lang.String classname)
this.classname = classname;
//if(doExhaustive)
//doReflect = false;
initClasspath();
fixClassname();
String[] locations = findClass();
pr("");//NOI18N
if(locations == null || locations.length <= 0)
{
pr("Can't find class");//NOI18N
return;
}
for(int i = 0; i < locations.length; i++)
pr(classname + " located in " + locations[i]);//NOI18N
//if(doReflect)
//new Reflect(classname);
|
private void | debug(java.lang.String s)
if(debug_)
pr(s);
|
private boolean | findClass(java.lang.String path)
if(path.toLowerCase().endsWith(".jar"))//NOI18N
{
return findClassInJar(path);
}
File f = new File(path + File.separator + classname);
debug("Looking for " + f);//NOI18N
return f.exists();
|
private java.lang.String[] | findClass()
ArrayList names = new ArrayList();
for(int i = 0; i < classpath.length; i++)
{
String path = classpath[i];
if(findClass(path))
{
names.add(path);
debug("FOUND IT: " + path);//NOI18N
}
}
int num = names.size();
debug("Found it in " + num + " places");//NOI18N
if(num <= 0)
{
return null;
}
String[] ss = new String[num];
ss = (String[])names.toArray(ss);
return ss;
|
private boolean | findClassInJar(java.lang.String path)
ZipInputStream zin = null;
try
{
zin = new ZipInputStream(new FileInputStream(path));
ZipEntry entry;
while((entry = zin.getNextEntry()) != null)
{
String name = entry.getName();
zin.closeEntry();
if(name.equals(jarClassname))
{
zin.close();
return true;
}
}
zin.close();
}
catch(IOException e)
{
debug("" + e + " " + path);//NOI18N
}
return false;
|
private void | fixClassname()
// change as follows:
// com.netscape.blizzard.foo --> com\netscape\blizzard\foo
// com/netscape/blizzard/foo --> com\netscape\blizzard\foo
// com/netscape\blizzard.foo --> com\netscape\blizzard\foo
debug("old classname: " + classname);//NOI18N
jarClassname = classname;
classname = classname.replace('.", File.separatorChar);
if(File.separatorChar != '/")
classname = classname.replace('/", File.separatorChar);
if(File.separatorChar != '\\")
classname = classname.replace('\\", File.separatorChar);
// classnames in jars ALWAYS look like: com/foo/goo.class
jarClassname = jarClassname.replace('.", '/");
jarClassname = jarClassname.replace('\\", '/");
classname = classname + ".class";//NOI18N
jarClassname = jarClassname + ".class";//NOI18N
debug("new classname: " + classname);//NOI18N
debug("new jarClassname: " + jarClassname);//NOI18N
|
public java.lang.String | getResult()
return result;
|
private void | initClasspath()
String cp;
if(classpathArg == null)
cp = System.getProperty("java.class.path");//NOI18N
else
cp = classpathArg;
StringTokenizer tokens = new StringTokenizer(cp, ";", false);//NOI18N
int nTokens = tokens.countTokens();
classpath = new String[nTokens];
debug("" + nTokens + " tokens.");//NOI18N
for(int i = 0; tokens.hasMoreTokens(); i++)
{
String s = tokens.nextToken();
debug(s);
classpath[i] = s;
}
|
public static void | main(java.lang.String[] args)
if(args == null || args.length == 0)
{
usage();
return;
}
int argNum = 0;
if(args[0].toLowerCase().equals("-classpath"))//NOI18N
{
if(args.length != 3)
{
usage();
return;
}
new JWhich(args[2], args[1]);
}
else
new JWhich(args[0]);
|
private void | pr(java.lang.String s)
System.out.println(s); //NOI18N
result += s;
|
private static void | usage()
System.out.println("Usage: java " + JWhich.class.getName() + " [-classpath a_classpath] classname");//NOI18N
|