home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 November / Chip_1998-11_cd.bin / tema / Cafe / main.bin / RMIClassLoader.java < prev    next >
Text File  |  1997-05-20  |  4KB  |  104 lines

  1. /*
  2.  * @(#)RMIClassLoader.java    1.10 97/01/06
  3.  * 
  4.  * Copyright (c) 1995, 1996 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  * CopyrightVersion 1.1_beta
  20.  */
  21.  
  22. package java.rmi.server;
  23.  
  24. import java.net.MalformedURLException;
  25. import java.net.URL;
  26.  
  27. /**
  28.  * The RMIClassLoader class provides static methods for loading classes
  29.  * over the network.  Classes can be loaded from either a particular URL,
  30.  * or from the URL specified in the <b>java.rmi.server.codebase</b>
  31.  * system property.
  32.  * 
  33.  * @version    1.10, 01/06/97
  34.  * @author Ann Wollrath
  35.  */
  36. public class RMIClassLoader {
  37.     /*
  38.      * Disallow anyone from creating one of these.
  39.      */
  40.     private RMIClassLoader() {}
  41.  
  42.     private static LoaderHandler handler = null;
  43.  
  44.     private static synchronized LoaderHandler getHandler() 
  45.     {
  46.     if (handler == null) {
  47.         try {
  48.         Class cl = Class.forName(LoaderHandler.packagePrefix +
  49.                      ".LoaderHandler");
  50.         handler = (LoaderHandler)cl.newInstance();
  51.         } catch (Exception e) {
  52.         throw new Error("No LoaderHandler present");
  53.         }
  54.     }
  55.     return handler;
  56.     }
  57.  
  58.     /**
  59.      * Load a class from the URL specified in the
  60.      * <b>java.rmi.server.codebase</b> property.
  61.      * @param name  the name of the class to load
  62.      * @return the Class object representing the loaded class
  63.      * @exception MalformedURLException
  64.      *            The system property <b>java.rmi.server.codebase</b>
  65.      *            does not contain a valid URL.
  66.      * @exception ClassNotFoundException
  67.      *            A definition for the class could not
  68.      *            be found at the codebase URL.
  69.      */
  70.     public static Class loadClass(String name)
  71.     throws MalformedURLException, ClassNotFoundException
  72.     {
  73.     return getHandler().loadClass(name);
  74.     }
  75.     
  76.     /**
  77.      * Load a class from a URL.
  78.      * @param codebase  the URL from which to load the class
  79.      * @param name      the name of the class to load
  80.      * @return the Class object representing the loaded class
  81.      * @exception MalformedURLException
  82.      *            The codebase paramater was null.
  83.      * @exception ClassNotFoundException
  84.      *            A definition for the class could not
  85.      *            be found at the specified URL.
  86.      */
  87.     public static Class loadClass(URL codebase, String name)
  88.     throws MalformedURLException, ClassNotFoundException
  89.     {
  90.     return getHandler().loadClass(codebase, name);
  91.     }
  92.  
  93.     /**
  94.      * Returns the security context of the given class loader
  95.      * @param loader a class loader from which to get the security
  96.      *           context
  97.      * @return the security context (e.g., a URL)
  98.      */
  99.     public static Object getSecurityContext(ClassLoader loader)
  100.     {
  101.     return getHandler().getSecurityContext(loader);
  102.     }
  103. }
  104.