blob: 81263b1e410227da05c422a083e5d0f8684b7d0b [file] [log] [blame]
dan.halem5d187432008-02-22 22:52:28 +00001/*
2Copyright (C) 2007 Google Inc.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17package com.google.inject;
18
limpbizkit2b931682008-04-21 00:59:34 +000019import com.google.inject.internal.ToStringBuilder;
dan.halem5d187432008-02-22 22:52:28 +000020import com.google.inject.spi.BindingVisitor;
21import com.google.inject.spi.Dependency;
limpbizkit2b931682008-04-21 00:59:34 +000022import com.google.inject.spi.ProviderInstanceBinding;
23
dan.halem5d187432008-02-22 22:52:28 +000024import java.util.Collection;
25
26/**
27 *
28 */
29class 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}