dan.halem | 5d18743 | 2008-02-22 22:52:28 +0000 | [diff] [blame] | 1 | /* |
| 2 | Copyright (C) 2007 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; |
| 18 | |
limpbizkit | 2b93168 | 2008-04-21 00:59:34 +0000 | [diff] [blame] | 19 | import com.google.inject.internal.ToStringBuilder; |
dan.halem | 5d18743 | 2008-02-22 22:52:28 +0000 | [diff] [blame] | 20 | import com.google.inject.spi.BindingVisitor; |
| 21 | import com.google.inject.spi.Dependency; |
limpbizkit | 2b93168 | 2008-04-21 00:59:34 +0000 | [diff] [blame] | 22 | import com.google.inject.spi.ProviderInstanceBinding; |
| 23 | |
dan.halem | 5d18743 | 2008-02-22 22:52:28 +0000 | [diff] [blame] | 24 | import java.util.Collection; |
| 25 | |
| 26 | /** |
| 27 | * |
| 28 | */ |
| 29 | class ProviderInstanceBindingImpl<T> extends BindingImpl<T> |
| 30 | implements ProviderInstanceBinding<T> { |
| 31 | |
| 32 | final Provider<? extends T> providerInstance; |
| 33 | |
| 34 | ProviderInstanceBindingImpl(InjectorImpl injector, Key<T> key, |
| 35 | Object source, |
| 36 | InternalFactory<? extends T> internalFactory, Scope scope, |
| 37 | Provider<? extends T> providerInstance) { |
| 38 | super(injector, key, source, internalFactory, scope); |
| 39 | this.providerInstance = providerInstance; |
| 40 | } |
| 41 | |
| 42 | public void accept(BindingVisitor<? super T> bindingVisitor) { |
| 43 | bindingVisitor.visit(this); |
| 44 | } |
| 45 | |
| 46 | public Provider<? extends T> getProviderInstance() { |
| 47 | return this.providerInstance; |
| 48 | } |
| 49 | |
| 50 | public Collection<Dependency<?>> getDependencies() { |
| 51 | return injector.getFieldAndMethodDependenciesFor( |
| 52 | providerInstance.getClass()); |
| 53 | } |
| 54 | |
| 55 | @Override |
| 56 | public String toString() { |
| 57 | return new ToStringBuilder(ProviderInstanceBinding.class) |
| 58 | .add("key", key) |
| 59 | .add("provider", providerInstance) |
| 60 | .add("scope", scope) |
| 61 | .add("source", source) |
| 62 | .toString(); |
| 63 | } |
| 64 | } |