Nice/src/nice/tools/util SelfContainedClassLoader.java,NONE,1.1

Daniel Bonniot <[email protected]> Tue, 12 Apr 2005 13:57:35 +0000
Newsgroups gmane.comp.lang.nice.cvs
Message-ID <[email protected]>
Update of /cvsroot/nice/Nice/src/nice/tools/util
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10113/src/nice/tools/util

Added Files:
	SelfContainedClassLoader.java 
Log Message:
Run generated jars in a self-contained classloader, so that missing classes in the jar lead to errors, instead of being loaded from the parent.

Use "classes" instead of nice.jar so that recent changes immediately affect testcases.

Rethrow the cause exception when a testcase fails.


--- NEW FILE: SelfContainedClassLoader.java ---
/**************************************************************************/
/*                                N I C E                                 */
/*             A high-level object-oriented research language             */
/*                        (c) Daniel Bonniot 2005                         */
/*                                                                        */
/*  This program is free software; you can redistribute it and/or modify  */
/*  it under the terms of the GNU General Public License as published by  */
/*  the Free Software Foundation; either version 2 of the License, or     */
/*  (at your option) any later version.                                   */
/*                                                                        */
/**************************************************************************/

package nice.tools.util;

/**
   A class loader that does not delegate to any parent, except
   java* classes to the system classloader.

   @author Daniel Bonniot ([email protected])
 */

public class SelfContainedClassLoader extends java.net.URLClassLoader
{
  public SelfContainedClassLoader(java.net.URL[] urls)
  {
    super(urls);
  }

  protected Class loadClass(String name, boolean resolve)
    throws ClassNotFoundException
  {
    Class res = this.findLoadedClass(name);

    if (res == null)
      try {
        res = this.findClass(name);
      } catch (ClassNotFoundException e) {}

    if (res == null && name.startsWith("java"))
      {
        res = ClassLoader.getSystemClassLoader().loadClass(name);
      }

    if (res == null)
      throw new ClassNotFoundException(name);

    if (resolve)
      this.resolveClass(res);

    return res;
  }
}



-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click