package com.eactive.eai.rms.common.datasource;

import java.util.ArrayList;
import java.util.List;

import org.springframework.jndi.JndiObjectFactoryBean;

import com.eactive.eai.rms.common.util.ContainerUtil;


public class DataSourceType extends JndiObjectFactoryBean {
	private String name;
	private String text;
	private String schema;
	private boolean dynamic;
	private boolean online;
	private List<String> renders;

	public void setJndiName(String jndiName) {
        super.setJndiName(jndiName);

        if (ContainerUtil.get() == ContainerUtil.TOMCAT) {
            super.setResourceRef(true);
        } else if (ContainerUtil.get() == ContainerUtil.WEBLOGIC) {
            super.setResourceRef(false);
        } else if (ContainerUtil.get() == ContainerUtil.JBOSS) {
            super.setResourceRef(false);
        } else if (ContainerUtil.get() == ContainerUtil.WEBSPHERE) {
        	super.setResourceRef(false);
        } else {
            super.setResourceRef(false);
        }
    }
    public String getJndiName() {
    	return super.getJndiName();
    }
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getText() {
		return text;
	}
	public void setText(String text) {
		this.text = text;
	}

	public String getSchema() {
		return schema;
	}
	public void setSchema(String schema) {
		this.schema = schema;
	}

	public boolean isDynamic() {
		return dynamic;
	}
	public void setDynamic(boolean dynamic) {
		this.dynamic = dynamic;
	}
	
    public boolean isOnline() {
		return online;
	}
	public void setOnline(boolean online) {
		this.online = online;
	}
	public List<String> getRender() {
		return renders;
	}
	public void setRender(String render) {
		String [] data =render.split(",");
		List<String> list = new ArrayList<String>();
		for(int i=0;i<data.length;i++){
			list.add(data[i]);
		}
		this.renders = list;
	}

	@Override
	public String toString() {
		return "DataSourceType [ dynamic=" + dynamic + ", jndiName="
				+ super.getJndiName() + ", name=" + name + ", schema=" + schema
				+ ", text=" + text + "]";
	}

}
