/* Generated by Together */

package cobalt.deployment.descriptor.dist;

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

import cobalt.deployment.descriptor.MethodDescriptor;

/**
 * Title:        WebLogic 6.x dbms configure description
 * Description:  Represents WebLogic 6.x-specific dmbs configuration desciptor
 * Copyright:    Copyright (c) 2001
 * Company:      ETRI
 * @author Yeon Jun Choi
 * @version 1.0
 */

public class Weblogic60DbmsBeanDescriptor {
    public Weblogic60DbmsBeanDescriptor() {
        finders = new HashSet();
        fieldmap = new HashMap();
    }
    public String getEjbName(){
            return ejbName;
        }

    public void setEjbName(String ejbName){
            this.ejbName = ejbName;
        }

    public String getDsName(){
            return dsName;
        }

    public void setDsName(String dsName){
            this.dsName = dsName;
            poolName = null;
        }

    public String getPoolName(){
            return poolName;
        }

    public void setPoolName(String poolName){
            this.poolName = poolName;
            dsName = null;
        }

    public String getTableName(){
            return tableName;
        }

    public void setTableName(String tableName){
            this.tableName = tableName;
        }

    public int getFinderSize(){
            return finders.size();
        }

    public Set getFinders(){
            return finders;
        }

    public void setFinders(Set finders){
            this.finders = finders;
        }

    public void putFinder(Weblogic60Finder finder) {
        finders.add(finder);
    }

    public void removeFinder(Weblogic60Finder finder) {
        finders.remove(finder);
    }

    public Iterator getFinderIterator() {
        return finders.iterator();
    }

    public int getFieldmapSize(){
            return fieldmap.size();
        }

    public HashMap getFieldmap(){
            return fieldmap;
        }

    public Object getField(Object name){
            return fieldmap.get(name);
        }

    public void setFieldmap(HashMap fieldmap){
            this.fieldmap = fieldmap;
        }

    public String getColumn(String field) {
        return (String)fieldmap.get(field);
    }
    public void putField(String field, String column) {
        fieldmap.put(field, column);
    }

    public void removeField(String field) {
        fieldmap.remove(field);
    }

    public Iterator getFieldIterator() {
        return fieldmap.keySet().iterator();
    }

    public String isTunedUpdateString(){
            return tunedUpdate;
        }

    public boolean isTunedUpdate(){
        	if (tunedUpdate == null || tunedUpdate.equals(""))
                return true;
            return Boolean.getBoolean(tunedUpdate);
        }

    public void setTunedUpdate(String tunedUpdate){
            this.tunedUpdate = tunedUpdate;
        }

    public void initFinders(Iterator iterator) {
        MethodDescriptor method = null;
        Weblogic60Finder finder = null;
        while ( iterator.hasNext() ) {
            method = (MethodDescriptor)iterator.next();
//info(method.toString());
            if (method.getMethodIntf().equals(MethodDescriptor.getMethodIntfType()[1]))
                continue;
            if (method.getMethodName().equals("*"))
                continue;
            //if (method.getMethodName().equals("findByPrimaryKey"))
            //    continue;
            if (!method.getMethodName().startsWith("find"))
                continue;
//info(method.methodString());
            finder = new Weblogic60Finder();
            finder.setName(method.getMethodName());
            finder.setParams(method.getParams());
            finders.add(finder);
        }
    }

    private String ejbName;
    private String dsName;
    private String poolName;
    private String tableName;
    private Set finders;
    private HashMap fieldmap;
    private String tunedUpdate;
}
