/* Generated by Together */

package cobalt.deployment.descriptor.xml;

import java.util.ArrayList;
import java.util.Iterator;

import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.apache.xerces.dom.NodeImpl;
import org.w3c.dom.Element;
import org.apache.xerces.dom.ElementImpl;
import org.w3c.dom.Document;
import org.apache.xerces.dom.DocumentImpl;

import cobalt.deployment.descriptor.*;
import cobalt.deployment.descriptor.dist.*;
import cobalt.deployment.util.CommonUtil;
import cobalt.deployment.util.XmlUtil;

/**
 * Title:        for deployment information descriptor
 * Description:
 * Copyright:    Copyright (c) 2001
 * Company:      ETRI
 * @author YeonJun Choi
 * @version 1.0
 */

public class Websphere30EjbNode extends ElementNode {
	public Websphere30EjbNode(Document doc, String type) {
        super((DocumentImpl)doc, type);
    }
/*
    public static EjbDescriptor getEjbDescriptor(Node node) {
        //EjbDescriptor ejb = new EjbDescriptor();
        if (((Element)node).getTagName().equals("session"))
            return getSessionEjbDescriptor(node);
        return getEntityEjbDescriptor(node);
    }
    public static SessionEjbDescriptor getSessionEjbDescriptor(Node parent) {
        SessionEjbDescriptor ejb = new SessionEjbDescriptor();
        NodeList nodelist = parent.getChildNodes();
        Node node = null;
        String tag;
        for ( int i=0 ; i<nodelist.getLength() ; i++) {
            node = nodelist.item(i);
            if ( !(node instanceof Element) ) continue;
            tag = ((Element)node).getTagName();
            if ( tag.equals("description") )
                ejb.setDescription(XmlUtil.getNodeTextValue(node));
            else if ( tag.equals("display-name") )
                ejb.setName(XmlUtil.getNodeTextValue(node));
            else if ( tag.equals("small-icon") )
                ejb.setSmallIcon(XmlUtil.getNodeTextValue(node));
            else if ( tag.equals("large-icon") )
                ejb.setLargeIcon(XmlUtil.getNodeTextValue(node));
            else if ( tag.equals("home") )
                ejb.setHomeInterface(XmlUtil.getNodeTextValue(node));
            else if ( tag.equals("remote") )
                ejb.setRemoteInterface(XmlUtil.getNodeTextValue(node));
            else if ( tag.equals("ejb-class") )
                ejb.setBeanClass(XmlUtil.getNodeTextValue(node));
            else if ( tag.equals("session-type") )
                ejb.setSessionType(XmlUtil.getNodeTextValue(node));
            else if ( tag.equals("transaction-type") )
                ejb.setTransactionType(XmlUtil.getNodeTextValue(node));
            else if ( tag.equals("env-entry") )
                ejb.addEnv(XmlUtil.getEnvFromNode(node));
            else if ( tag.equals("ejb-ref") )
                ejb.addEjbReference(XmlUtil.getEjbReferenceFromNode(node));
            else if ( tag.equals("security-role-ref") )
                ejb.addSecurityRole(XmlUtil.getSecurityRoleFromNode(node));
            else if ( tag.equals("resource-ref") )
                ejb.addResource(XmlUtil.getResourceReferenceFromNode(node));
        }
        return ejb;
    }
    public static EntityEjbDescriptor getEntityEjbDescriptor(Node parent) {
        EntityEjbDescriptor ejb = new EntityEjbDescriptor();
        NodeList nodelist = parent.getChildNodes();
        Node node = null;
        String tag;
        for ( int i=0 ; i<nodelist.getLength() ; i++) {
            node = nodelist.item(i);
            if ( !(node instanceof Element) ) continue;
            tag = ((Element)node).getTagName();
            if ( tag.equals("description") )
                ejb.setDescription(XmlUtil.getNodeTextValue(node));
            else if ( tag.equals("display-name") )
                ejb.setName(XmlUtil.getNodeTextValue(node));
            else if ( tag.equals("small-icon") )
                ejb.setSmallIcon(XmlUtil.getNodeTextValue(node));
            else if ( tag.equals("large-icon") )
                ejb.setLargeIcon(XmlUtil.getNodeTextValue(node));
            else if ( tag.equals("home") )
                ejb.setHomeInterface(XmlUtil.getNodeTextValue(node));
            else if ( tag.equals("remote") )
                ejb.setRemoteInterface(XmlUtil.getNodeTextValue(node));
            else if ( tag.equals("ejb-class") )
                ejb.setBeanClass(XmlUtil.getNodeTextValue(node));
            else if ( tag.equals("persistence-type") )
                ejb.setTransactionType(XmlUtil.getNodeTextValue(node));
            else if ( tag.equals("prim-key-class") )
                ejb.setPrimaryKeyClassName(XmlUtil.getNodeTextValue(node));
            else if ( tag.equals("reentrant") )
                ejb.setReentrant(Boolean.getBoolean(XmlUtil.getNodeTextValue(node)));
            else if ( tag.equals("cmp-field") )
                ejb.putContainerManagedField(XmlUtil.getContainerManagedFieldFromNode(node));
            else if ( tag.equals("prim-key-field") )
                ejb.setPrimaryKeyField(XmlUtil.getNodeTextValue(node));
            else if ( tag.equals("env-entry") )
                ejb.addEnv(XmlUtil.getEnvFromNode(node));
            else if ( tag.equals("ejb-ref") )
                ejb.addEjbReference(XmlUtil.getEjbReferenceFromNode(node));
            else if ( tag.equals("security-role-ref") )
                ejb.addSecurityRole(XmlUtil.getSecurityRoleFromNode(node));
            else if ( tag.equals("resource-ref") )
                ejb.addResource(XmlUtil.getResourceReferenceFromNode(node));
        }
        return ejb;
    }
*/
    public void setEjbDescriptor(Websphere30EjbDescriptor descriptor) {
        Document doc = getOwnerDocument();
        Element root = doc.getDocumentElement();
        this.setAttribute("dname", descriptor.getSerName());
        if ( descriptor instanceof Websphere30SessionEjbDescriptor) {
            Websphere30SessionEjbDescriptor se = (Websphere30SessionEjbDescriptor)descriptor;
            XmlUtil.addNode(this, XmlUtil.getNewTextNode((DocumentImpl)doc, "session-timeout", se.getTimeOutValue() ));
            XmlUtil.addNode(this, XmlUtil.getNewTextNode((DocumentImpl)doc, "state-management", se.getStateMgt() ));
        }
        else {
            Websphere30EntityEjbDescriptor ee = (Websphere30EntityEjbDescriptor)descriptor;
            XmlUtil.addNode(this, XmlUtil.getNewTextNode((DocumentImpl)doc, "primary-key", ee.getPrimaryKey() ));
            XmlUtil.addNode(this, XmlUtil.getNewTextNode((DocumentImpl)doc, "reentrant", ee.getReentrantValue() ));
            ArrayList cm = ee.getCmpFieldNameList();
            for ( int i=0 ; i<cm.size() ; i++ )
                XmlUtil.addNode(this, XmlUtil.getNewTextNode((DocumentImpl)doc, "container-managed", (String)cm.get(i) ));
        }
        XmlUtil.addNode(this, XmlUtil.getNewTextNode((DocumentImpl)doc, "home-interface", descriptor.getHomeInterface()));
        XmlUtil.addNode(this, XmlUtil.getNewTextNode((DocumentImpl)doc, "remote-interface", descriptor.getRemoteInterface()));
        XmlUtil.addNode(this, XmlUtil.getNewTextNode((DocumentImpl)doc, "enterprise-bean", descriptor.getEnterpriseBean()));
        XmlUtil.addNode(this, XmlUtil.getNewTextNode((DocumentImpl)doc, "jndi-name", descriptor.getJndiName()));
        XmlUtil.addNode(this, XmlUtil.getNewTextNode((DocumentImpl)doc, "transaction-attr", descriptor.getTransactionAttr()));
        XmlUtil.addNode(this, XmlUtil.getNewTextNode((DocumentImpl)doc, "isolation-level", descriptor.getIsolationLevel()));
        XmlUtil.addNode(this, XmlUtil.getNewTextNode((DocumentImpl)doc, "run-as-mode", descriptor.getRunAsMode()));
        XmlUtil.addNode(this, XmlUtil.getNewTextNode((DocumentImpl)doc, "run-as-id", descriptor.getRunAsId()));
        // method control
        Node newNode;
        Websphere30MethodControl mc = descriptor.getMethodControl();
        Iterator iterator = mc.getMethodIterator();
        while ( iterator.hasNext() ) {
            newNode = XmlUtil.getNewElementNode((DocumentImpl)doc,"method-control");
        }
        // env
        //XmlUtil.addNode(this, XmlUtil.getNewTextNode((DocumentImpl)doc, "", descriptor.getHomeInterface()));
        // deplendency
        /*XmlUtil.addNode(this, XmlUtil.getNewTextNode((DocumentImpl)doc, "ejb-name", descriptor.getEjbName()));
        XmlUtil.appendTransactionDescriptorNode((DocumentImpl)doc, this, descriptor);
        XmlUtil.appendReferenceDescriptorNode((DocumentImpl)doc, this, descriptor);
        XmlUtil.addNode(this, XmlUtil.getNewTextNode((DocumentImpl)doc, "enable-call-by-reference", descriptor.isCallByReferenceString()));
        //XmlUtil.addNode(this, XmlUtil.getNewTextNode((DocumentImpl)doc, "run-as-identity-principal", descriptor.getRunAsIdentityString()));
        XmlUtil.addNode(this, XmlUtil.getNewTextNode((DocumentImpl)doc, "jndi-name", descriptor.getJndiName()));
        */
    }
}
