//----------------------------BEGIN LICENSE----------------------------
/* 
 * Willow : the Open Source WorkFlow Project
 * Distributable under GNU LGPL license by gun.org
 *
 * Copyright (C) 2004-2010  huihoo.org 
 * Copyright (C) 2004-2010  ZosaTapo <dertyang@hotmail.com> 
 * 
 * ====================================================================
 * Project Homepage : http://www.huihoo.org/willow
 * Source Forge     : http://sourceforge.net/projects/huihoo
 * Mailing list     : willow@lists.sourceforge.net 
 */
//----------------------------END  LICENSE----------------------------
package org.huihoo.willow.util;

import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectStreamClass;

public final class CustomObjectInputStream extends ObjectInputStream
{

	/**
	 * The class loader we will use to resolve classes.
	 */
	private ClassLoader classLoader = null;

	/**
	 * Construct a new instance of CustomObjectInputStream
	 *
	 * @param stream The input stream we will read from
	 * @param classLoader The class loader used to instantiate objects
	 *
	 * @exception IOException if an input/output error occurs
	 */
	public CustomObjectInputStream(InputStream stream, ClassLoader classLoader) throws IOException
	{

		super(stream);
		this.classLoader = classLoader;
	}

	/**
	 * Load the local class equivalent of the specified stream class
	 * description, by using the class loader assigned to this Context.
	 *
	 * @param classDesc Class description from the input stream
	 *
	 * @exception ClassNotFoundException if this class cannot be found
	 * @exception IOException if an input/output error occurs
	 */
	public Class resolveClass(ObjectStreamClass classDesc) throws ClassNotFoundException, IOException
	{
		return Class.forName(classDesc.getName(), false, classLoader);
	}

}