/* JFox, the OpenSource J2EE Application Server
 *
 * Distributable under GNU LGPL license by gun.org
 * more details please visit http://www.huihoo.org/jfox
 */
package org.jfox.ejb.meta;

import org.w3c.dom.Node;

/**
 * @author <a href="mailto:young_yy@hotmail.com">Young Yang</a>
 */

public class EJBReferenceDescriptor extends EJBDescriptorBase {
    private String type;
    private String refName;

    public EJBReferenceDescriptor() {

    }

    public void processXML(Node node) throws EJBDescriptionException {
        super.processXML(node);
        setRefName(XmlUtil.getChildNodeValueOf(node, "ejb-ref-name"));
        setType(XmlUtil.getChildNodeValueOf(node, "ejb-ref-type"));
        setHomeClassName(XmlUtil.getChildNodeValueOf(node, "home"));
        setRemoteClassName(XmlUtil.getChildNodeValueOf(node, "remote"));
        //ejb-link is the link ejb name, not the link ejb jndi name
        setEjbName(XmlUtil.getChildNodeValueOf(node, "ejb-link"));
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getRefName() {
        return refName;
    }

    public void setRefName(String refName) {
        this.refName = refName;
    }

    public void setLinkName(String linkedEjbName) {
        setJndiName(linkedEjbName);
    }

    public String getLinkName() {
        return getJndiName();
    }

    public boolean isResolved() {
        return !getJndiName().equals("");
    }

    public boolean equals(Object obj) {
        if(obj instanceof EJBReferenceDescriptor)
            return refName.equals(((EJBReferenceDescriptor) obj).refName);
        else
            return false;
    }

    public int hashCode() {
        return refName.hashCode();
    }

    public static void main(String[] args) {

    }
}

