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;
016 * Object providers represent an alternate way to locate an object provided somewhere in the {@link
017 * org.apache.tapestry5.ioc.Registry}. Instead of using a just the service id to gain access to a service within the
018 * Registry, object providers in different flavors are capable of vending, or even creating, objects of disparate types
019 * from disparate sources.
020 *
021 * Object providers are consulted in a strict order, and the first non-null result is taken.
022 *
023 * In many cases, an object provider searches for additional annotations on the element (usually a parameter, or perhaps
024 * a field) for which a value is required.
025 */
026public interface ObjectProvider
028    /**
029     * Provides an object based on an expression. The process of providing objects occurs within a particular
030     * <em>context</em>, which will typically be a service builder method, service contributor method, or service
031     * decorator method. The locator parameter provides access to the services visible <em>to that context</em>.
032     *
033     * @param objectType         the expected object type
034     * @param annotationProvider provides access to annotations (typically, the field or parameter to which an
035     *                           injection-related annotation is attached); annotations on the field or parameter may
036     *                           also be used when resolving the desired object
037     * @param locator            locator for the <em>context</em> in which the provider is being used
038     * @param <T>
039     * @return the requested object, or null if this object provider can not supply an object
040     * @throws RuntimeException if the expression can not be evaluated, or the type of object identified is not
041     *                          assignable to the type specified by the objectType parameter
042     */
043    <T> T provide(Class<T> objectType, AnnotationProvider annotationProvider, ObjectLocator locator);