001// Copyright 2006, 2008 The Apache Software Foundation
002//
003// Licensed under the Apache License, Version 2.0 (the "License");
004// you may not use this file except in compliance with the License.
005// You may obtain a copy of the License at
006//
007//     http://www.apache.org/licenses/LICENSE-2.0
008//
009// Unless required by applicable law or agreed to in writing, software
010// distributed under the License is distributed on an "AS IS" BASIS,
011// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012// See the License for the specific language governing permissions and
013// limitations under the License.
014
015package org.apache.tapestry5.ioc.services;
016
017import org.apache.tapestry5.ioc.util.StrategyRegistry;
018
019import java.util.Map;
020
021/**
022 * A service implementation builder that operates around a {@link StrategyRegistry}, implementing a version of the Gang
023 * of Four Strategy pattern.
024 * <p/>
025 * The constructed service is configured with a number of adapters (that implement the same service interface). Method
026 * invocations on the service are routed to one of the adapters.
027 * <p/>
028 * The first parameter of each method is used to select the appropriate adapter.
029 * <p/>
030 * The ideal interface for use with this builder has only one method.
031 */
032public interface StrategyBuilder
033{
034    /**
035     * Given a number of adapters implementing the service interface, builds a "dispatcher" implementations that
036     * delegates to the one of the adapters. It is an error if any of the methods takes no parameters.
037     *
038     * @param <S>      the service interface type
039     * @param registry defines the adapters based on parameter type (of the first parameter)
040     * @return a service implementation
041     */
042    <S> S build(StrategyRegistry<S> registry);
043
044    /**
045     * @param registrations map frm class to the adapter type
046     * @param <S>
047     * @return the dispatcher
048     * @since 5.1.0.0
049     */
050    <S> S build(Class<S> adapterType, Map<Class, S> registrations);
051}