// Copyright (c) 1995, 1996 Regents of the University of California. // All rights reserved. // // This software was developed by the Arcadia project // at the University of California, Irvine. // // Redistribution and use in source and binary forms are permitted // provided that the above copyright notice and this paragraph are // duplicated in all such forms and that any documentation, // advertising materials, and other materials related to such // distribution and use acknowledge that the software was developed // by the University of California, Irvine. The name of the // University may not be used to endorse or promote products derived // from this software without specific prior written permission. // THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR // IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED // WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. // File: Preloader.java // Classes: Preloader // Original Author: Jason Robbins // $Id: Preloader.java,v 1.2 2000/09/19 21:08:38 dougo Exp $ // Modified by : Kedar Patankar // Last Modified 12 Oct 1997 package edu.neu.ccs.demeter.tools.apstudio.util; import java.util.Vector; import java.util.Enumeration; /** * 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.setVisible(false); _progress.dispose(); return; } } _progress.setVisible(false); _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 */