// File: Preloader.java // Classes: Preloader // Original Author: Jason Robbins // $Id: Preloader.java,v 1.1.1.1 1997/02/27 20:53:43 chandra Exp $ package uci.util; //import java.lang.*; import java.util.*; /** * Load a set of java classes from an http server and display a * progress dialog when it is happening. This is very useful for large * applets that use many classes if the browser does not support * sending .zip files. * @see Package * @see Progress */ public class Preloader { /** List of classes to load. */ private Vector _classes; /** Progress dialog box */ private Progress _progress; /** Load a Vector of classes by name. Put up a progress dialog box * while the user is waiting. * @param classNames Fully qualified names of the classes to load. */ public static void loadClasses(Vector classNames) { Preloader p = new Preloader(classNames); } /** Define a new Preloader object to load the given classes. * @param classes The classes to load */ public Preloader(Vector classes) { _classes = classes; _progress = new Progress("Loading Classes", classes.size()); _progress.show(); loadClasses(); } /** * Static method to load all classes listed in the given set of * Package objects. * @param packages A Vector of Package objects. * @see Package */ public static void loadPackages(Vector packages) { Vector allClassNames = new Vector(packages.size() * 10); Enumeration packs = packages.elements(); while (packs.hasMoreElements()) { String packName = (String) packs.nextElement(); Package p = null; try { Class packClass = Class.forName(packName); p = (Package) packClass.newInstance(); } catch (java.lang.ClassNotFoundException ignore) { } catch (java.lang.IllegalAccessException ignore) { } catch (java.lang.InstantiationException ignore) { } if (p instanceof Package) { Vector classNames = p.classNames(); Enumeration cls = classNames.elements(); while (cls.hasMoreElements()) { String name = (String) cls.nextElement(); allClassNames.addElement(name); } } } loadClasses(allClassNames); } /** Load all the classes stored in _classes. */ private void loadClasses() { Enumeration cls = _classes.elements(); while (cls.hasMoreElements()) { String className = (String) cls.nextElement(); _progress.setMessage(className); try { Class.forName(className); } catch (java.lang.ClassNotFoundException ignore) { }; _progress.advance(); if (_progress.canceled()) { _progress.hide(); _progress.dispose(); return; } } _progress.hide(); _progress.dispose(); } /** A main() to test out this code. It loads all classes in the * * UCI graph editing framework */ public static void main(String argv[]) { Vector v = new Vector(); v.addElement("uci.graphedit.PackageGraphEdit"); Preloader.loadPackages(v); System.out.println("done"); } } /* end class Preloader */