package eu.dnetlib.dlms.jdbc.ast;

import java.sql.SQLException;
import java.util.List;

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

/**
 * Expression to represent invocation of methods, such as cast, import, drop.
 * 
 * @author alessia
 * 
 */
public class Call extends Expression {

	/** Target of the call. */
	private Ref target;
	/** Name of the method to call on target. */
	private String method;
	/** Arguments of the method as List of Expression instances. */
	private List<Expression> args;

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

	/**
	 * Constructor.
	 * 
	 * @param target
	 *            variable name, target of the call
	 * @param method
	 *            name of the method to call
	 * @param args
	 *            arguments of the method as List of Expression
	 */
	public Call(final Ref target, final String method, final List<Expression> args) {
		this.target = target;
		this.method = method;
		this.args = args;
	}

	public Ref getTarget() {
		return this.target;
	}

	public void setTarget(final Ref target) {
		this.target = target;
	}

	public String getMethod() {
		return this.method;
	}

	public void setMethod(final String method) {
		this.method = method;
	}

	public List<Expression> getArgs() {
		return this.args;
	}

	public void setArgs(final List<Expression> args) {
		this.args = args;
	}

	@Override
	public String toString() {
		return "Call [args=" + this.args + ", method=" + this.method + ", target=" + this.target + "]";
	}

}
