001/*
002@license.text@
003 */
004package com.hammurapi.common;
005
006import java.util.Iterator;
007
008import com.hammurapi.extract.Predicate;
009
010/**
011 * Execution context.
012 * @author Pavel Vlasov
013 * @version $Revision: 1.1 $
014 */
015public interface Context {
016        
017        /**
018         * Context constructed from all available context services.
019         */
020        Context INSTANCE = Util.loadContext();
021        
022        /**
023         * Looks up object by name.
024         * @param name Object name.
025         * @return named object or null.
026         */
027        Object lookup(String name);
028        
029        /**
030         * Looks up single object (service) by type.
031         * @param <T> Service type.
032         * @param serviceClass Requested service type.
033         * @param selectors Optional service selectors. If more than one, selectors are combined with AND.
034         * @return Service instance or null.
035         */
036        <T> T lookup(Class<T> serviceClass, Predicate<T, Context>... selectors);
037        
038        /**
039         * Looks up all services of given type.
040         * @param <T> Service type.
041         * @param serviceClass Requested service type.
042         * @param selectors Optional service selectors. If more than one, selectors are combined with AND.
043         * @return Iterator over services of requested type.
044         */
045        <T> Iterator<T> lookupAll(Class<T> serviceClass, Predicate<T, Context>... selectors);
046}