package eu.dnetlib.dlms.jdbc.ast;

import java.sql.SQLException;

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

/**
 * A SimplePredicate is an xPath to filter objects based on their connected/reachable objects.
 * <p>
 * E.g. <code>select A[./B/C]</code> selects objects in Set A such that they are sources of relation B whose targets are
 * sources of relation C.
 * </p>
 * 
 * @author alessia
 * 
 */
public class SimplePredicate extends Predicate {
	/** XPath instance. */
	private XPath xPath;

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

	/**
	 * Constructor.
	 * 
	 * @param xp
	 *            XPath
	 */
	public SimplePredicate(final XPath xp) {
		this.setXPath(xp);
	}

	@Override
	public String toString() {
		return "SimplePredicate [xPath=" + this.xPath + "]";
	}

	public void setXPath(final XPath xPath) {
		this.xPath = xPath;
	}

	public XPath getXPath() {
		return this.xPath;
	}

}
