/* 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 java.io.File;
import cobalt.deployment.descriptor.MethodDescriptor;
import cobalt.deployment.util.CommonUtil;

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

public class Weblogic51DbmsBeanDescriptor {
    public static boolean DEBUG = true;
    void info(String msg) {
        if (DEBUG)
        	System.out.println(getClass().toString() + '>' + msg);
    }
    public Weblogic51DbmsBeanDescriptor() {
        finders = new HashSet();
        fieldmap = new HashMap();
        try {
	        cmpFile = File.createTempFile("CMP_WebLogic_CMP_RDBMS", ".xml", new File(CommonUtil.getTempDir()));
	        cmpFile.deleteOnExit();
        } catch (Exception e) { System.err.println(e.getMessage()); }
    }
    public String getEjbName(){
            return ejbName;
        }

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

    public String getSchemaName(){ return schemaName; }

    public void setSchemaName(java.lang.String schemaName){ this.schemaName = schemaName; }

    public String getPoolName(){
            return poolName;
        }

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

    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(Weblogic51Finder finder) {
        finders.add(finder);
    }

    public void removeFinder(Weblogic51Finder 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();
    }

    // Set all finders
    public void initFinders(Iterator iterator) {
        MethodDescriptor method = null;
        Weblogic51Finder 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 Weblogic51Finder();
            finder.setName(method.getMethodName());
            finder.setParams(method.getParams());
            finders.add(finder);
        }
    }

    public File getCmpFile(){ return cmpFile; }

    public void setCmpFile(File cmpFile){ this.cmpFile = cmpFile; }

    private String ejbName;
    private String schemaName;
    private String poolName;
    private String tableName;
    private Set finders;
    private HashMap fieldmap;
    private File cmpFile;
}
