/*
 * 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
 * Contributor(s):
 *
 * --------------------------------------------------------------------------
 * $Id$
 * --------------------------------------------------------------------------
 */

package org.objectweb.jonas_ejb.container;

import javax.ejb.EJBHome;
import javax.ejb.EJBMetaData;
import java.io.Serializable;
import org.objectweb.jonas_ejb.deployment.api.BeanDesc;
import org.objectweb.jonas_ejb.deployment.api.EntityDesc;
import org.objectweb.jonas_ejb.deployment.api.SessionDesc;
import org.objectweb.jonas_ejb.deployment.api.SessionStatelessDesc;

/**
 * This class is a Serializable class that allows a client to obtain the enterprise 
 * Bean's meta-data information. 
 */
public class JMetaData implements EJBMetaData, Serializable {

    private EJBHome home;
    private Class homeClass;
    private Class remoteClass;
    private Class primaryKeyClass;
    private boolean isSession;
    private boolean isStatelessSession;

    /**
     * Constructor
     */
    public JMetaData(EJBHome home, BeanDesc dd) {
	TraceEjb.debugIc("JMetaData constructor");
	this.home = home;
	homeClass = dd.getHomeClass();
	remoteClass = dd.getRemoteClass();
	if (dd instanceof SessionDesc) {
	    isSession = true;
	    isStatelessSession = (dd instanceof SessionStatelessDesc);
	    primaryKeyClass = null;
	} else if (dd instanceof EntityDesc) {
	    isSession = false;
	    isStatelessSession = false;
	    primaryKeyClass = ((EntityDesc)dd).getPrimaryKeyClass();
	}
    }

    // -----------------------------------------------------------------------
    // EJBMetaData implementation
    // -----------------------------------------------------------------------

    /**
     * Obtains the home interface of the enterprise Bean. 
     */
    public EJBHome getEJBHome() {
	return home;
    }

    /**
     * Obtains the Class object for the enterprise Bean's home interface. 
     */
    public Class getHomeInterfaceClass() {
	return homeClass;
    }

    /**
     * Obtains the Class object for the enterprise Bean's primary key class. 
     */
    public Class getPrimaryKeyClass() {
	return primaryKeyClass;
    }

    /**
     * Obtains the Class object for the enterprise Bean's remote interface. 
     */
    public Class getRemoteInterfaceClass() {
	return remoteClass;
    }
    
    /**
     * Tests if the enterprise Bean's type is "session".
     */
    public boolean isSession() {
	return isSession;
    }

    /**
     * @return True if the type of the enterprise Bean is stateless session.
     */
    public boolean isStatelessSession() {
	return isStatelessSession;
    }


}
