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