001// Licensed under the Apache License, Version 2.0 (the "License");
002// you may not use this file except in compliance with the License.
003// You may obtain a copy of the License at
005//     http://www.apache.org/licenses/LICENSE-2.0
007// Unless required by applicable law or agreed to in writing, software
008// distributed under the License is distributed on an "AS IS" BASIS,
009// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
010// See the License for the specific language governing permissions and
011// limitations under the License.
013package org.apache.tapestry5.ioc.services;
015import org.apache.tapestry5.ioc.AnnotationProvider;
016import org.apache.tapestry5.ioc.ObjectLocator;
017import org.apache.tapestry5.ioc.ObjectProvider;
018import org.apache.tapestry5.ioc.annotations.UsesOrderedConfiguration;
021 * A service that acts as a chain-of-command over a number of {@link org.apache.tapestry5.ioc.ObjectProvider}, but
022 * allows for the case where no object may be provided.
023 *
024 * This service is itself a key part of Tapestry's general injection mechanism; it is used when instantiating a service
025 * implementation instance, invoking module methods (service builder, decorator, or contribution methods), when
026 * {@linkplain ObjectLocator#autobuild(Class) autobuilding} objects of any type.
027 *
028 * As of Tapestry 5.3, the MasterObjectProvider allows injection of {@link org.apache.tapestry5.ioc.OperationTracker} as a
029 * special case (not based on a contributed ObjectProvider).
030 */
032public interface MasterObjectProvider
034    /**
035     * Provides an object based on an expression. The process of providing objects occurs within a particular
036     * <em>context</em>, which will typically be a service builder method, service contributor method, or service
037     * decorator method. The locator parameter provides access to the services visible <em>to that context</em>.
038     *
039     * When the value is required and no {@link ObjectProvider} provided a non-null value, then {@link
040     * ObjectLocator#getService(Class, Class[])}  is invoked (with no marker annotations),
041     * to provide a uniquely matching service, or throw a failure exception
042     * if no <em>single</em> service can be found.
043     *
044     * @param objectType         the expected object type
045     * @param annotationProvider provides access to annotations (typically, the field or parameter to which an
046     *                           injection-related annotation is attached); annotations on the field or parameter may
047     *                           also be used when resolving the desired object
048     * @param locator            locator for the <em>context</em> in which the provider is being used
049     * @param required           if true (normal case) a value must be provided; if false then it is allowed for no
050     *                           ObjectProvider to provide a value, and this method may return null to indicate the
051     *                           failure
052     * @param <T>
053     * @return the requested object, or null if this object provider can not supply an object
054     * @throws RuntimeException if the expression can not be evaluated, or the type of object identified is not
055     *                          assignable to the type specified by the objectType parameter
056     */
057    <T> T provide(Class<T> objectType, AnnotationProvider annotationProvider, ObjectLocator locator, boolean required);