/* Generated by Together */

package cobalt.deployment.descriptor.dist;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import java.util.HashMap;
import java.util.Iterator;

import cobalt.deployment.common.DataContainer;
import cobalt.deployment.common.MustNotNullException;
import cobalt.deployment.descriptor.EjbDescriptor;
import cobalt.deployment.descriptor.EjbReferenceDescriptor;
import cobalt.deployment.descriptor.ResourceReferenceDescriptor;
import cobalt.deployment.descriptor.MethodDescriptor;
import cobalt.deployment.util.CommonUtil;

public class Jeus30EjbDescriptor extends DataContainer {
    public Jeus30EjbDescriptor(EjbDescriptor ejbDesc) {
        super();
        descriptor = ejbDesc;
        cluster = new Jeus30EjbCluster();
        beanPool = new Jeus30PoolConfig();
        ejbRef = new HashMap();
        resRef = new HashMap();
        resEnvRef = new HashMap();

        setExportPort(0);
        setExportIIOP(false);
        setLocalInvocOptimized(true);
        try {
        	setExportName(getEjbName());
        } catch (MustNotNullException e) { }
        setCapacity(2000);
        organize();
    }

    public EjbDescriptor getDescriptor(){ return descriptor; }

    public void setDescriptor(EjbDescriptor descriptor){ this.descriptor = descriptor; }

    public String getJndiName() {
        return descriptor.getJndiName();
    }

    public void setJndiName(String name) {
        descriptor.setJndiName(name);
    }

    public String getEjbName() {
        return descriptor.getEjbName();
    }

    public String getEjbType() {
        return descriptor.getEjbType();
    }

    public int getExportPort(){
        return getInt("export-port", 0);
    }

    public String getExportPortValue(){
        return getString("export-port");
    }

    public void setExportPort(int exportPort){
        setInt("export-port", exportPort);
    }

    public String getExportName(){
        return getString("export-name");
    }

    public void setExportName(String exportName)
    	throws MustNotNullException
    {
        setString("export-name", exportName);
    }

    public boolean isExportIIOP(){
        return getBoolean("export-iiop", false);
    }

    public String isExportIIOPValue(){
        return getString("export-iiop");
    }

    public void setExportIIOP(boolean exportIIOP){
        //setBoolean("export-iiop", exportIIOP, false);
        setBoolean("export-iiop", exportIIOP);
    }

    public int getCapacity(){
        return getInt("capacity", 100000);
    }

    public String getCapacityValue(){
        return getString("capacity");
    }

    public void setCapacity(int capacity){
        setInt("capacity", capacity);
    }

    public boolean isLocalInvocOptimized(){
        return getBoolean("isLocalInvocationOptimized", true);
    }

    public String isLocalInvocOptimizedValue(){
        return getString("isLocalInvocationOptimized");
    }

    public void setLocalInvocOptimized(boolean localInvocOptimized){
        //setBoolean("isLocalInvocationOptimized", localInvocOptimized, true);
        setBoolean("isLocalInvocationOptimized", localInvocOptimized);
    }

    public boolean isRunAsId(){
        return runAsId;
    }

    public void setRunAsId(boolean runAsId){
        this.runAsId = runAsId;
    }

    public String getRunAsRoleName(){
        return getString("run-as-role-name");
    }

    public void setRunAsRoleName(String runAsRoleName)
        throws MustNotNullException
    {
        setString("run-as-role-name", runAsRoleName);
    }

    public String getRunAsPrincipalName(){
        return getString("run-as-principal-name");
    }

    public void setRunAsPrincipalName(String runAsPrincipalName)
        throws MustNotNullException
    {
        setString("run-as-principal-name", runAsPrincipalName);
    }

    public Iterator getMethodDescriptorIterator() {
		return descriptor.getMethodDescriptorIterator();
    }

    public MethodDescriptor getMethod(int index) {
        return descriptor.getMethod(index);
    }

    public Set getEnvs() {
        return descriptor.getEnvs();
    }

    public Jeus30EjbCluster getCluster(){ return cluster; }

    public void setCluster(Jeus30EjbCluster cluster){ this.cluster = cluster; }

    public Jeus30PoolConfig getBeanPool(){ return beanPool; }

    public void setBeanPool(Jeus30PoolConfig beanPool){ this.beanPool = beanPool; }

    public HashMap getEjbRef(){ return ejbRef; }

    public void setEjbRef(java.util.HashMap ejbRef){ this.ejbRef = ejbRef; }

    public HashMap getResRef(){ return resRef; }

    public void setResRef(HashMap resRef){ this.resRef = resRef; }

    public HashMap getResEnvRef(){ return resEnvRef; }

    public void setResEnvRef(HashMap resEnvRef){ this.resEnvRef = resEnvRef; }

    private void organize()
    {
        Jeus30ReferenceDescriptor ref = null;

        Iterator iterator = descriptor.getEjbReferences().values().iterator();
        while ( iterator.hasNext() ) {
            ref = new Jeus30ReferenceDescriptor(iterator.next());
            ejbRef.put(ref.getReferenceName(), ref);
        }
        iterator = descriptor.getResources().iterator();
        while ( iterator.hasNext() ) {
            ref = new Jeus30ReferenceDescriptor(iterator.next());
            resRef.put(ref.getReferenceName(), ref);
        }
    }

    protected EjbDescriptor descriptor;
    private boolean runAsId = false;
    private Jeus30EjbCluster cluster;
    private Jeus30PoolConfig beanPool;
    private HashMap ejbRef;
    private HashMap resRef;
    private HashMap resEnvRef;
}
