/*
@license.text@
 */
package com.hammurapi.common;

import java.util.Iterator;

import com.hammurapi.extract.Predicate;

/**
 * Execution context.
 * @author Pavel Vlasov
 * @version $Revision: 1.1 $
 */
public interface Context {
	
	/**
	 * Context constructed from all available context services.
	 */
	Context INSTANCE = Util.loadContext();
	
	/**
	 * Looks up object by name.
	 * @param name Object name.
	 * @return named object or null.
	 */
	Object lookup(String name);
	
	/**
	 * Looks up single object (service) by type.
	 * @param <T> Service type.
	 * @param serviceClass Requested service type.
	 * @param selectors Optional service selectors. If more than one, selectors are combined with AND.
	 * @return Service instance or null.
	 */
	<T> T lookup(Class<T> serviceClass, Predicate<T, Context>... selectors);
	
	/**
	 * Looks up all services of given type.
	 * @param <T> Service type.
	 * @param serviceClass Requested service type.
	 * @param selectors Optional service selectors. If more than one, selectors are combined with AND.
	 * @return Iterator over services of requested type.
	 */
	<T> Iterator<T> lookupAll(Class<T> serviceClass, Predicate<T, Context>... selectors);
}
