package org.mandarax.util;

/*
 * Copyright (C) 1999-2004 <a href="mailto:mandarax@jbdietrich.com">Jens Dietrich</a>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
 
import java.util.List;
import java.util.Map;
import org.mandarax.kernel.Derivation;
import org.mandarax.kernel.InferenceException;
import org.mandarax.kernel.ResultSet;
import org.mandarax.kernel.VariableTerm;

/**
 * Abstract result set wrapping another result set and delegating all methods to the
 * wrapped result set. Useful as a superclass when implementingg filters.
 * @author <A HREF="mailto:mandarax@jbdietrich.com">Jens Dietrich</A>
 * @version 3.3.1 <9 August 2004>
 * @since 3.0
 */

public abstract class ResultSetWrapper implements ResultSet {
	protected ResultSet delegate = null;
	/**
	* Constructor.
	* @param delegate the delegate
	*/
	public ResultSetWrapper(ResultSet delegate) {
		super();
		this.delegate = delegate;
	}
	/**
	* Indicates whether the cursor is at the first position.
	* @return a boolean
	*/
	public boolean isFirst() throws InferenceException {
		return delegate.isFirst();
	}
	/**
	* Indicates whether the cursor is at the last position.
	* @return a boolean
	*/
	public boolean isLast() throws InferenceException {
		return delegate.isLast();
	}
	/**
	* Moves the cursor to the first row in this ResultSet object.
	* @return true if the cursor is on a valid row; false if there are no rows in the result set
	*/
	public boolean first() throws InferenceException {
		return delegate.first();
	}
	/**
	* Moves the cursor to the last row in this ResultSet object.
	* @return true if the cursor is on a valid row; false if there are no rows in the results
	*/
	public boolean last() throws InferenceException {
		return delegate.last();
	}
	/**
	* Retrieves the current result number. Numbering starts with 1.
	* @return a number
	*/
	public int getResultNumber() throws InferenceException {
		return delegate.getResultNumber();
	}
	/**
	* Moves the cursor down one row from its current position. A ResultSet cursor is initially positioned
	* before the first row; the first call to the method next makes the first row the current row;
	* the second call makes the second row the current row, and so on.
	* @return true if the new current row is valid; false if there are no more rows
	*/
	public boolean next() throws InferenceException {
		return delegate.next();
	}
	/**
	* Moves the cursor to the previous row in this ResultSet object.
	* @return true if the cursor is on a valid row; false if it is off the result set
	*/
	public boolean previous() throws InferenceException {
		return delegate.previous();
	};

	/**
	* Releases this ResultSet resources.
	*/
	public void close() throws InferenceException {
		delegate.close();
	}
	/**
	* Get a list of all variable terms in the query.
	* @return a list of variable terms
	*/
	public List getQueryVariables() throws InferenceException {
		return delegate.getQueryVariables();
	}
	/**
	* Get the derivation of the current result.
	* Throw an exception if the cursor is not positioned at a result.
	* @return the proof (derivation)
	*/
	public Derivation getProof() throws InferenceException {
		return delegate.getProof();
	}
	/**
	* Get the object that replaces the variable with the given name and type.
	* If there is no such object, return null.
	* Throw an exception if the cursor is not positioned at a result.
	* @return the object that replaced the variable
	* @param type the type of the variable
	* @param name the name of the variable
	* @exception an inference exception
	*/
	public Object getResult(Class type, String name) throws InferenceException {
		return delegate.getResult(type, name);
	}
	/**
	* Get the object that replaces the variable.
	* If there is no such object, return null.
	* Throw an exception if the cursor is not positioned at a result.
	* @return the object that replaced the variable
	* @param term the variable term that is (perhaps) replaced
	* @exception an inference exception
	*/
	public Object getResult(VariableTerm term) throws InferenceException {
		return delegate.getResult(term);
	}
	/**
	* Get the current position of the cursor.
	* @return an integer
	*/
	public int getCursorPosition() throws InferenceException {
		return delegate.getCursorPosition();
	}
	/**
	* Moves the cursor a relative number of results, either positive or negative.
	* @param offset the number of results
	* @return true if the cursor is on the result set; false otherwise.
	*/
	public boolean relative(int offset) throws InferenceException {
		return delegate.relative(offset);
	}
	/**
	* Moves the cursor to the given result number.
	* @param resultNo the number of results.
	* @return true if the cursor is on the result set; false otherwise
	*/
	public boolean absolute(int resultNo) throws InferenceException {
		return delegate.absolute(resultNo);
	}
	/**
	* Moves the cursor to the front of this ResultSet object, just before the first row. 
	* This method has no effect if the result set contains no rows.
	*/
	public void beforeFirst() throws InferenceException {
		delegate.beforeFirst();
	}

	/**
	* Moves the cursor to the end of this ResultSet object, just after the last row. 
	* This method has no effect if the result set contains no rows.
	*/
	public void afterLast() throws InferenceException {
		delegate.afterLast();
	}
	/**
	* Retrieves whether the cursor is before the first row in this ResultSet object.
	* @return true if the cursor is before the first row; false if the cursor is at any other position or the result set contains no rows
	*/
	public boolean isBeforeFirst() throws InferenceException {
		return delegate.isBeforeFirst();
	}

	/**
	* Retrieves whether the cursor is after the last result in this ResultSet object.
	* @return true if the cursor is after the last result; false if the cursor is at any other position or the result set contains no results
	*/
	public boolean isAfterLast() throws InferenceException {
		return delegate.isAfterLast();
	}
	/**
	* Get the replacements as map (term -> term associations).
	* @return a map
	*/
	public Map getResults() throws InferenceException {
		return delegate.getResults();
	}

}
