/*
 * JOnAS: Java(TM) Open Application Server
 * Copyright (C) 1999 Bull S.A.
 * Contact: jonas-team@objectweb.org
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 * USA
 *
 * Initial developer(s): Philippe Coq, Philippe Durieux
 * Contributor(s):
 *
 * --------------------------------------------------------------------------
 * $Id$
 * --------------------------------------------------------------------------
 */

package org.objectweb.jonas_ejb.container;

import java.io.Serializable;
import java.rmi.RemoteException;
import java.util.Hashtable;
import javax.ejb.EJBHome;
import javax.ejb.HomeHandle;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;


/**
 * This class implements javax.ejb.HomeHandle interface.
 * A handle is an abstraction of a network reference to a home object.
 * A handle is intended to be used as a "robust" persistent
 * reference to a home object.
 */
public class JHomeHandle implements HomeHandle, Serializable {
    
    private String homename = null;
    private Hashtable jndiprop = null;

    /**
     * constructor
     */
    public JHomeHandle(String hname, Hashtable jndi) {
	homename = hname;
	jndiprop = jndi;
    }

    // -----------------------------------------------------------------------
    // HomeHandle implementation
    // -----------------------------------------------------------------------

    /** 
     * Obtains the home object represented by this handle. 
     * @Throws RemoteException: The home object could not be obtained because of a 
     * system-level failure. 
     */
    public EJBHome getEJBHome() throws RemoteException {
	TraceEjb.debugIc("JHomeHandle getEJBHome");
	EJBHome ejbh = null;
	try {
	    Context ic = new InitialContext(jndiprop);
	    ejbh = (EJBHome) PortableRemoteObject.narrow(ic.lookup(homename), EJBHome.class);
	} catch (NamingException e) {
	    throw new RemoteException("getEJBHome:"+e);
	}
	return ejbh;
    }
}

    
