/*
 * This java source file is placed into the public domain.
 *
 * The orginal author is Ceki Gulcu, QOS.ch
 *
 * THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY OF ANY KIND, NOT EVEN
 * THE IMPLIED WARRANTY OF MERCHANTABILITY. THE AUTHOR OF THIS SOFTWARE,
 * ASSUMES _NO_ RESPONSIBILITY FOR ANY CONSEQUENCE RESULTING FROM THE
 * USE, MODIFICATION, OR REDISTRIBUTION OF THIS SOFTWARE.
 */
package ch.qos.test;

import box.Box;

import java.net.URL;
import java.net.URLClassLoader;


/**
 * This example demonstates that when the thread context class loader 
 * is explicitly set to the child class loader, then JCL LogFactory 
 * (indirectly loaded by  the parent class loader) cannot find the 
 * log4j classes if if they are visible to the TCCL, i.e. the child 
 * class loader.
 *
 * Usage:
 *
 *   java -cp classes;boxAPI.jar;lib/commons-logging.jar ch.qos.test.ParentFirstTestJCL1
 *
 * @author <a href="http://www.qos.ch/log4j/">Ceki G&uuml;lc&uuml;</a>
 */
public class ParentFirstTestJCL1 {
  public static void main(String[] args) throws Exception {
    URLClassLoader childClassLoader =
      new URLClassLoader(
        new URL[] {
          new URL("file:box1.jar"), 
          new URL("file:lib/commons-logging.jar"),
          new URL("file:lib/log4j.jar")
        });

    Thread.currentThread().setContextClassLoader(childClassLoader);

    Class versionClass1 = childClassLoader.loadClass("box.BoxImplWithJCL");
    Box box = (Box) versionClass1.newInstance();
    box.doOp();
  }
}
