package eu.dnetlib.xml.database.exist;

import org.xmldb.api.base.ResourceSet;
import org.xmldb.api.base.XMLDBException;

import eu.dnetlib.xml.database.XMLDBResultSet;

/**
 * Wraps an eXist resourceset as an abstract XMLDBResultSet.
 * 
 * @author marko
 * 
 */
public class ExistResultSet implements XMLDBResultSet {

	/**
	 * underlying exist resourceset.
	 */
	private ResourceSet res;

	/**
	 * construct an exist resultset from an exist resourceset.
	 * 
	 * @param res
	 *            eXist resourceset
	 */
	public ExistResultSet(final ResourceSet res) {
		setRes(res);
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see eu.dnetlib.xml.database.XMLDBResultSet#get(int)
	 */
	public String get(final int index) throws XMLDBException {
		return (String) getRes().getResource(index).getContent();
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see eu.dnetlib.xml.database.XMLDBResultSet#getSize()
	 */
	public long getSize() throws XMLDBException {
		return getRes().getSize();
	}

	protected ResourceSet getRes() {
		return res;
	}

	private void setRes(final ResourceSet res) {
		this.res = res;
	}

}
