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


package org.objectweb.jonas_ejb.deployment.api;

import java.lang.Class;

import org.objectweb.jonas_ejb.deployment.xml.ResourceEnvRef;
import org.objectweb.jonas_ejb.deployment.xml.JonasResourceEnv;


/**
 * The ResourceEnvRef class corresponds to the 'resource-env-ref' element in the XML DTD
 * for EJB 2.0 deployment descriptor and its associated 'jonas-resource-env' element.
 *
 * The resource-env-ref element contains a declaration of enterprise bean's reference
 * to an administered object associated with a resource in the enterprise bean's environment.
 * It consists of:
 *   - an optional description (which is not taken into account here),
 *   - the resource environment reference name,
 *   - and an indication of the resource environment refrence type expected by the
 *     enterprise bean code.
 * @author Helene Joanin
 */
public class ResourceEnvRefDesc {

    String name;
    Class type;
    String jndiName;

    /**
     * Package protected constructor used by API
     */
    ResourceEnvRefDesc(ClassLoader classLoader, ResourceEnvRef res, JonasResourceEnv jRes)
            throws DeploymentDescException {
        name = res.getResourceEnvRefName().getValue();
        try {
            type = classLoader.loadClass(res.getResourceEnvRefType().getValue());
        } catch (ClassNotFoundException e) {
            throw new DeploymentDescException("resource-env-ref-type class not found for resource-env-ref "+name,e);
        }
        jndiName = jRes.getJndiName().getValue();
    }

    /**
     * Get resource environment ref. name
     * @return Name of the resource environment ref.
     */
    public String getName() {
            return name;
    }

    /**
     * Get resource environment ref. type
     * @return Class of the resource environment ref.
     */
    public Class getType() {
        return type;
    }

    /**
     * Get the jndi name of the resource environment ref.
     * @return String representation of the JNDI name
     */
    public String getJndiName() {
        return jndiName;
    }
    
    /**
     * String representation of the object for test purpose
     * @return String representation of this object
     */
    public String toString() {
        StringBuffer ret = new StringBuffer();
        ret.append("\ngetName()="+getName());
        ret.append("\ngetType()="+getType());
        ret.append("\ngetJndiName()="+getJndiName());
        return ret.toString();
    }
    
    
}

