package ws.prova.calc;

/*
 * Copyright (C) 2002-2007 <a href="mailto:a.kozlenkov@city.ac.uk">Alex Kozlenkov</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 org.mandarax.kernel.Predicate;
import org.mandarax.kernel.Session;
import org.mandarax.kernel.Term;
import org.mandarax.util.logging.LogCategories;

import java.lang.reflect.Method;

/**
 * Predicate corresponding to Java calls in Prova
 * <p>Title: Prova</p>
 * <p>Description: Predicate corresponding to Java calls</p>
 * <p>Copyright: Copyright (c) 20022005</p>
 * <p>Company: City University, London, United Kingdom</p>
 *
 * @author Alex Kozlenkov
 * @version 2.0 <25 March 2007>
 */
public class CalcPredicate implements Predicate, LogCategories {

	private String name = null;
	private Class[] structure = null;
	private Method method = null;

	public CalcPredicate() {
		super();
	}

	/**
	 * Get the name of the predicate.
	 *
	 * @return the name of the predicate
	 */
	public String getName() {
		return name;
	}

	/**
	 * Set the name.
	 *
	 * @param n a name
	 */
	public void setName(String n) {
		name = n;
	}

	public Method getMethod() {
		return method;
	}

	public void setMethod(Method m) {
		method = m;
	}

	/**
	 * Convert the object to a string.
	 *
	 * @return a string
	 */
	public String toString() {
		return (name == null) ? super.toString() : name;
	}

	/**
	 * Get the type structure of the object, e.g. the types of terms
	 * that can be used with this constructor.
	 *
	 * @return an array of classes
	 */
	public Class[] getStructure() {
		return structure;
	}

	/**
	 * Set the structure of the predicates, i.e. the types of the terms.
	 * Should be handled with care since it must be consistent with the type mapping
	 * used and the (SQL) type and number of columns in the result set.
	 *
	 * @param an array of classes
	 */
	public void setStructure(Class[] struct) {
		structure = struct;
	}

	public Object perform(Term[] parameter) throws IllegalArgumentException, UnsupportedOperationException {
		throw new java.lang.UnsupportedOperationException("Method perform() is not applicable.");
	}

	/**
	 * Indicates whether the object (usually a term or a clause set) can be performed
	 * using the java semantics.
	 *
	 * @return false
	 */
	public boolean isExecutable() {
		return false;
	}

	public CalcPredicate copy() {
		CalcPredicate clone = new CalcPredicate();
		clone.name = name;
		clone.structure = structure;
		clone.method = method;

		return clone;
	}

	/**
	 * perform
	 *
	 * @param parameter Term[]
	 * @param session   Session
	 * @return Object
	 */
	public Object perform(Term[] parameter, Session session) {
		return "";
	}

	/**
	 * getSlotNames
	 *
	 * @return String[]
	 */
	public String[] getSlotNames() {
		return null;
	}

	/**
	 * setSlotNames
	 *
	 * @param names String[]
	 */
	public void setSlotNames(String[] names) {
	}

	/**
	 * slotNamesCanBeEdited
	 *
	 * @return boolean
	 */
	public boolean slotNamesCanBeEdited() {
		return false;
	}
}
