/* Generated by Together */

package cobalt.deployment.descriptor.xml;

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.Weblogic51XmlUtil;

/**
 * Title:        WebLogic 5.1 ejb component xml
 * Description:  WebLogic 5.1-specific module xml description of ejb component
 * Copyright:    Copyright (c) 2001
 * Company:      ETRI
 * @author YeonJun Choi
 * @version 1.0
 */

public class Weblogic51EjbNode extends ElementNode {
	public Weblogic51EjbNode(Document doc) {
        super((DocumentImpl)doc, "weblogic-enterprise-bean");
    }
/*
    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(Weblogic51EjbDescriptor descriptor) {
        Document doc = getOwnerDocument();
        Weblogic51XmlUtil.addNode(this, Weblogic51XmlUtil.getNewTextNode((DocumentImpl)doc, "ejb-name", descriptor.getEjbName()));
        if (descriptor instanceof Weblogic51StatelessEjbDescriptor ) {
            Weblogic51XmlUtil.appendStateless((DocumentImpl)doc, this, (Weblogic51StatelessEjbDescriptor)descriptor);
       	}
        else if (descriptor instanceof Weblogic51StatefulEjbDescriptor ) {
            Weblogic51XmlUtil.appendStateful((DocumentImpl)doc, this, (Weblogic51StatefulEjbDescriptor)descriptor);
        }
        else {
            Weblogic51XmlUtil.appendEntity((DocumentImpl)doc, this, (Weblogic51EntityEjbDescriptor)descriptor);
            // Setting Entity Descriptor
        	/*
            Weblogic51XmlUtil.addNode(this, XmlUtil.getNewTextNode((DocumentImpl)doc, "persistence-type", descriptor.getTransactionType()));
        	Weblogic51XmlUtil.addNode(this, XmlUtil.getNewTextNode((DocumentImpl)doc, "prim-key-class", ((EntityEjbDescriptor)descriptor).getPrimaryKeyClassName()));
        	Weblogic51XmlUtil.addNode(this, XmlUtil.getNewTextNode((DocumentImpl)doc, "reentrant", ((EntityEjbDescriptor)descriptor).reentrantString()));
            Weblogic51XmlUtil.appendContainerManagedFieldNode((DocumentImpl)doc, this,((EntityEjbDescriptor)descriptor).getAllContainerManagedFields());
        	Weblogic51XmlUtil.addNode(this, XmlUtil.getNewTextNode((DocumentImpl)doc, "prim-key-field", ((EntityEjbDescriptor)descriptor).getPrimaryKeyField()));
            */
        }
        Weblogic51XmlUtil.appendTransactionDescriptorNode((DocumentImpl)doc, this, descriptor);
        Weblogic51XmlUtil.appendReferenceDescriptorNode((DocumentImpl)doc, this, descriptor);
        Weblogic51XmlUtil.addNode(this, Weblogic51XmlUtil.getNewTextNode((DocumentImpl)doc, "enable-call-by-reference", descriptor.isCallByReferenceString()));
        //Weblogic51XmlUtil.addNode(this, Weblogic51XmlUtil.getNewTextNode((DocumentImpl)doc, "run-as-identity-principal", descriptor.getRunAsIdentityString()));
        Weblogic51XmlUtil.addNode(this, Weblogic51XmlUtil.getNewTextNode((DocumentImpl)doc, "jndi-name", descriptor.getJndiName()));
        //Weblogic51XmlUtil.appendEnvDescriptorNode((DocumentImpl)doc, this, descriptor.getEnvs().iterator());
        //Weblogic51XmlUtil.appendEjbReferenceNode((DocumentImpl)doc, this, descriptor.getEjbReferences().values().iterator());
        //Weblogic51XmlUtil.appendSecurityRoleNode((DocumentImpl)doc, this, descriptor.getSecurityRoles().iterator());
        //Weblogic51XmlUtil.appendResourceReferenceDescriptorNode((DocumentImpl)doc, this, descriptor.getResources().iterator());
    }
}
