package eu.dnetlib.dlms.jdbc.ast;

import java.sql.SQLException;

import eu.dnetlib.dlms.jdbc.ExecutorContext;
import eu.dnetlib.dlms.jdbc.server.IStatementExecutor;

/**
 * Statement for the declaration and instantiation of a variable.E.g: <code>Object o = new theSet()</code>
 * 
 * @author alessia
 * 
 */
public class DeclInit extends Statement {
	/** Type of the variable. */
	private String type;
	/** Name of the variable. */
	private String varName;
	/** Value to assign to the variable. */
	private Expression expr;

	/**
	 * {@inheritDoc}
	 * 
	 * @see eu.dnetlib.dlms.jdbc.ast.Statement#execute(eu.dnetlib.dlms.jdbc.server.IStatementExecutor)
	 */
	@Override
	public Object execute(final IStatementExecutor executor, final ExecutorContext context) throws SQLException {
		return executor.execute(this, context);
	}

	/**
	 * Constructor.
	 * 
	 * @param t
	 *            type of the variable
	 * @param var
	 *            name of the variable
	 * @param e
	 *            Expression of the value to give to the variable
	 */
	public DeclInit(final String t, final String var, final Expression e) {
		this.type = t;
		this.varName = var;
		this.setExpr(e);
	}

	public String getType() {
		return this.type;
	}

	public void setType(final String type) {
		this.type = type;
	}

	public String getVarName() {
		return this.varName;
	}

	public void setVarName(final String varName) {
		this.varName = varName;
	}

	public void setExpr(final Expression expr) {
		this.expr = expr;
	}

	public Expression getExpr() {
		return this.expr;
	}

	@Override
	public String toString() {
		return "DeclInit [expr=" + this.expr + ", type=" + this.type + ", varName=" + this.varName + "]";
	}

}
