/* Generated by Together */

package cobalt.deployment.descriptor.dist;

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

import cobalt.deployment.descriptor.EjbDescriptor;
import cobalt.deployment.descriptor.EjbReferenceDescriptor;
import cobalt.deployment.descriptor.EntityEjbDescriptor;
import cobalt.deployment.descriptor.MethodDescriptor;

/**
 * Title:        WebLogic 6.x ejb component descriptor
 * Description:  Represents WebLogic 6.x-specific ejb component for standard ejb component
 * Copyright:    Copyright (c) 2001
 * Company:      ETRI
 * @author Yeon Jun Choi
 * @version 1.0
 */

public class Weblogic60EjbDescriptor {
    public Weblogic60EjbDescriptor(EjbDescriptor ejbDesc) {
        descriptor = ejbDesc;
        elements = new HashMap();
        transactionIsolation = new Weblogic60TransactionIsolation();
    }

    public EjbDescriptor getDescriptor(){ return descriptor; }

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

    protected int getInt(String name, int def) {
        int ret = def;
        try {
            ret = Integer.parseInt((String)elements.get(name));
        } catch (NumberFormatException e) {
        }
        return ret;
    }
    protected boolean getBoolean(String name, boolean def) {
        boolean ret = def;
        try {
            if (elements.get(name) == null)	return ret;
            ret = Boolean.getBoolean((String)elements.get(name));
        } catch (Exception e) {
        }
        return ret;
    }
    protected String getString(String name) {
    	//Object value = elements.get(name);
    	//if (value == null)
    	//	return null;
        return (String)elements.get(name);
    }
    protected void setInt(String name, int value) {
        elements.put(name, String.valueOf(value));
    }
    protected void setBoolean(String name, boolean value) {
        elements.put(name, String.valueOf(value));
    }
    protected void setString(String name, String value) {
        elements.put(name, value);
    }

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

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

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

	// session / entity
    public String getEjbType() {
        return descriptor.getEjbType();
    }

    public int getTransTimeoutSec(){
            return getInt("trans-timeout-seconds", 30);
        }

    public String getTransTimeoutSecValue(){
            return getString("trans-timeout-seconds");
        }

    public void setTransTimeoutSec(int transTimeoutSec){
            setInt("trans-timeout-seconds", transTimeoutSec);
        }

    public boolean isCallByReference(){
            return getBoolean("enable-call-by-reference", true);
        }

    public String isCallByReferenceValue(){
            return getString("enable-call-by-reference");
        }

    public void setCallByReference(boolean callByReference){
            setBoolean("enable-call-by-reference", callByReference);
        }

    public String getRunAsIdentityString(){
            return getString("run-as-identity-principal");
        }

    public void setRunAsIdentity(String runAsIdentity){
            setString("run-as-identity-principal", runAsIdentity);
        }

    public boolean isClusterable(){
            return getBoolean("clusterable", true);
        }

    public String isClusterableValue(){
            return getString("clusterable");
        }

    public void setClusterable(boolean clusterable){
            setBoolean("clusterable", clusterable);
        }

    public String getLoadAlgorithm(){
            return getString("load-algorithm");
        }

    public void setLoadAlgorithm(String loadAlgorithm){
            setString("load-algorithm", loadAlgorithm);
        }

    public String getCallRouterClass(){
            return getString("call-router-class");
        }

    public void setCallRouterClass(String callRouterClass){
            setString("call-router-class", callRouterClass);
        }

    public Weblogic60TransactionIsolation getTransactionIsolation(){
            return transactionIsolation;
        }

    public void setTransactionIsolation(Weblogic60TransactionIsolation transactionIsolation){
            this.transactionIsolation = transactionIsolation;
        }

    public Iterator getResourceIterator() {
        return descriptor.getResources().iterator();
    }

    public Iterator getEnvsIterator() {
        return descriptor.getEnvs().iterator();
    }

    public Iterator getEjbReferenceIterator() {
        return descriptor.getEjbReferences().values().iterator();
    }

    public EjbReferenceDescriptor getEjbReference(String name) {
        return descriptor.getEjbReference(name);
    }

    public Set getEjbReferences() {
        return new HashSet(descriptor.getEjbReferences().values());
    }

    public Set getResourceReferences(){
        return descriptor.getResources();
    }

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

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

    private EjbDescriptor descriptor;
    /*
    private int transTimeoutSec;
    private boolean callByReference;
    private String runAsIdentity;
    private boolean clusterable;
    private String loadAlgorithm;
    private String callRouterClass;
    */
    private HashMap elements;
    public static String[] CLUSTER_LOAD_ALGORITHM = { "RoundRobin","Random","WeightBased" };
    public static String[] PASSIVATION_STRATEGY = { "default", "transaction" };
    //public static String[] WEBLOGIC5_1_CACHE_STRATEGY = { "Read-Write", "Read-Only" };
    private Weblogic60TransactionIsolation transactionIsolation;
}
