1 /* 2 * Copyright (C) 2010 Google Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.google.inject.spi; 18 19 import com.google.inject.Binding; 20 import com.google.inject.Provider; 21 22 /** 23 * A Provider that is part of an extension which supports a custom BindingTargetVisitor. 24 * 25 * <p>When an extension binds a provider instance, the provider can implement this interface to 26 * allow users using the {@link Binding#acceptTargetVisitor(BindingTargetVisitor)} method to visit a 27 * custom visitor designed for that extension. A typical implementation within the extension would 28 * look like 29 * 30 * <pre> 31 * <V, B> V acceptExtensionVisitor(BindingTargetVisitor<B, V> visitor, ProviderInstanceBinding<? extends B> binding) { 32 * if(visitor instanceof MyCustomExtensionVisitor) { 33 * return ((MyCustomExtensionVisitor<B, V>)visitor).visitCustomExtension(customProperties, binding); 34 * } else { 35 * return visitor.visit(binding); 36 * } 37 * }</pre> 38 * 39 * 'MyCustomExtensionVisitor' in the example above would be an interface the extension provides that 40 * users can implement in order to be notified of custom extension information. These visitor 41 * interfaces must extend from BindingTargetVisitor. 42 * 43 * @since 3.0 44 * @author sameb@google.com (Sam Berlin) 45 */ 46 public interface ProviderWithExtensionVisitor<T> extends Provider<T> { 47 48 /** 49 * Instructs the extension determine if the visitor is an instance of a custom extension visitor, 50 * and if so, visit it using that method. If the visitor is not an instance of the custom 51 * extension visitor, this method <b>MUST</b> call visitor.visit(binding). 52 * 53 * <p>Due to issues with generics, the type parameters of this method do not relate to the type of 54 * the provider. In practice, the 'B' type will always be a supertype of 'T'. 55 */ acceptExtensionVisitor( BindingTargetVisitor<B, V> visitor, ProviderInstanceBinding<? extends B> binding)56 <B, V> V acceptExtensionVisitor( 57 BindingTargetVisitor<B, V> visitor, ProviderInstanceBinding<? extends B> binding); 58 } 59