int toolboxIndex = 0; // the scalaSciToolbox class keeps the name of the .jar file of each toolbox and a Vector that holds the bytecodes of its classes
scalaExec.scalaLab.scalaSciToolbox ssciToolbox = new scalaExec.scalaLab.scalaSciToolbox();
ssciToolbox.toolboxName = jarFileName;
JarEntry je;
JarInputStream jis = new JarInputStream(new BufferedInputStream (new FileInputStream(jarFileName)));
// scan first the jar for the file "AvoidClassPatterns.txt" and for the startup code
while ((je = jis.getNextJarEntry()) != null) {
String nameOfEntry = je.toString();
if (nameOfEntry.contains("AvoidClassPatterns.txt")) {
patternsToAvoid = readTextFromJar(jarFileName, nameOfEntry); // get the patterns to avoid from the .jar file
StringTokenizer strTok = new StringTokenizer(patternsToAvoid, " \n,\t;");
numOfPatternsToAvoid =strTok.countTokens();
while (strTok.hasMoreElements())
avoidClassPatterns.add(strTok.nextToken());
break;
}
}
jis.close();
jis = new JarInputStream(new BufferedInputStream (new FileInputStream(jarFileName)));
while ((je = jis.getNextJarEntry()) != null)
{ // while jar file has entries unprocessed
String nameOfEntry = je.toString();
if (nameOfEntry.contains("startup.ssci")) {
startupCode = readTextFromJar(jarFileName, nameOfEntry); // get the startup code from the .jar file
}
// make sure we have only slashes, i.e. use Unix path conventions
String name ='/'+je.getName().replace('\\', '/');
String javaName = name.replace('/','.');
int idx = javaName.lastIndexOf(".class");
int javaNameLen = javaName.length();
boolean classStringIsWithinName = javaNameLen > ( idx+".class".length() );
if (idx != -1 && !classStringIsWithinName) { // a class file
javaName = javaName.substring(1, idx); // remove the first '.'
if (checkAllowed(javaName) == true) { // not a class name that we should avoid to load
Object foundClass=null;
try {
foundClass = GlobalValues.extensionClassLoader.loadClass(javaName);
}
catch (Exception e) {
foundClass = null;
}
boolean classIsPublic = false;
if (foundClass != null) {
int modifier = ((Class) foundClass).getModifiers();
if (Modifier.isAbstract(modifier)==false && Modifier.isInterface(modifier)== false && Modifier.isStatic(modifier)==false) { // class is not abstract or interface
if ( Modifier.isPublic(modifier) ) { // class is public
classIsPublic = true;
ssciToolbox.toolboxClasses.add(foundClass);
AutoCompletionScalaSci.scanMethodsScalaSci.add(((Class)foundClass).getName());
numJarAutoCompletionItems++;
if (numJarAutoCompletionItems % 100 == 0) { // update visual progress
dots += ".";
String classCntDots = "Classes: "+ numJarAutoCompletionItems+" "+dots;
g2d.clearRect(0, 0, 400, 100);
g2d.drawString(classCntDots, 20, 10);
}
} // class is public
if (GlobalValues.retrieveAlsoMethods && classIsPublic) { // classIsPublic
Method [] classMethods=null;
try {
classMethods = ((Class)foundClass).getDeclaredMethods();
if (classMethods != null)
if (classMethods.length > 0)
for (Method currentMethod: classMethods) {
if (Modifier.isPublic(currentMethod.getModifiers() )) {
String methodName = currentMethod.getName()+GlobalValues.smallNameFullPackageSeparator+javaName;
if (AutoCompletionScalaSci.scanMethodsScalaSci.indexOf(methodName)==-1) {
AutoCompletionScalaSci.scanMethodsScalaSci.add(methodName);
numJarAutoCompletionItems++;
}
}
}
}
catch (SecurityException e) {
System.out.println("Security Exception in getDeclaredMethods");
}
catch (Exception e) {
System.out.println("Exception in getDeclaredMethods");
}
} // classIsPublic
if (javaName.indexOf("$") == -1) {
String smallName = javaName.substring(javaName.lastIndexOf(".")+1, javaName.length());
String nameToInsert = smallName+GlobalValues.smallNameFullPackageSeparator+javaName;
//String elemToInsert = nameToInsert+" #Toolbox class";
if (AutoCompletionScalaSci.scanMethodsScalaSci.indexOf(nameToInsert) == -1) {
AutoCompletionScalaSci.scanMethodsScalaSci.add(nameToInsert);
numJarAutoCompletionItems++;
numJarClasses++;
}
} // class is public
} // class is not abstract or interface
} // foundClasss != null
} // a class file
} //
} // while jar file has entries unprocessed
//System.out.println("Found in toolbox "+jarFileName+" #classes = "+JarClassLoader.classesFnt);
// construct a new AutoCompletion Object (needed in order to sort the list of methods, and to permit the access of the new methods)
scalaExec.Interpreter.GlobalValues.autoCompletionScalaSci = new scalaExec.gui.AutoCompletionScalaSci(); // create the autocompletion object
jis.close();
System.out.println("number of Toolbox LoadedClasses = "+numJarClasses);
System.out.println("number of Toolbox AutoCompletion Items = "+numJarAutoCompletionItems);
System.out.println("Total items of ScalaSci Autocompletion = "+ scalaExec.Interpreter.GlobalValues.autoCompletionScalaSci.scanMethodsScalaSci.size());
scalaExec.scalaLab.scalaSciToolboxes.ssciToolboxes.add(ssciToolbox);