limpbizkit | 76c24b1 | 2008-12-25 04:32:41 +0000 | [diff] [blame] | 1 | /** |
| 2 | * Copyright (C) 2008 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.internal; |
| 18 | |
limpbizkit | 03b81a6 | 2009-03-18 05:34:39 +0000 | [diff] [blame] | 19 | import com.google.inject.Binder; |
limpbizkit | 76c24b1 | 2008-12-25 04:32:41 +0000 | [diff] [blame] | 20 | import com.google.inject.Injector; |
| 21 | import com.google.inject.Key; |
| 22 | import com.google.inject.spi.BindingTargetVisitor; |
| 23 | import com.google.inject.spi.Dependency; |
| 24 | import com.google.inject.spi.ExposedBinding; |
limpbizkit | c3f9284 | 2008-12-30 19:43:47 +0000 | [diff] [blame] | 25 | import com.google.inject.spi.PrivateElements; |
limpbizkit | 76c24b1 | 2008-12-25 04:32:41 +0000 | [diff] [blame] | 26 | import java.util.Set; |
| 27 | |
limpbizkit | 5ae41eb | 2009-06-06 17:51:27 +0000 | [diff] [blame^] | 28 | public final class ExposedBindingImpl<T> extends BindingImpl<T> implements ExposedBinding<T> { |
limpbizkit | 76c24b1 | 2008-12-25 04:32:41 +0000 | [diff] [blame] | 29 | |
limpbizkit | c3f9284 | 2008-12-30 19:43:47 +0000 | [diff] [blame] | 30 | private final PrivateElements privateElements; |
limpbizkit | 76c24b1 | 2008-12-25 04:32:41 +0000 | [diff] [blame] | 31 | |
limpbizkit | 5ae41eb | 2009-06-06 17:51:27 +0000 | [diff] [blame^] | 32 | public ExposedBindingImpl(InjectorImpl injector, Object source, Key<T> key, |
limpbizkit | c3f9284 | 2008-12-30 19:43:47 +0000 | [diff] [blame] | 33 | InternalFactory<T> factory, PrivateElements privateElements) { |
limpbizkit | 76c24b1 | 2008-12-25 04:32:41 +0000 | [diff] [blame] | 34 | super(injector, key, source, factory, Scoping.UNSCOPED); |
limpbizkit | c3f9284 | 2008-12-30 19:43:47 +0000 | [diff] [blame] | 35 | this.privateElements = privateElements; |
limpbizkit | 76c24b1 | 2008-12-25 04:32:41 +0000 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | public ExposedBindingImpl(Object source, Key<T> key, Scoping scoping, |
limpbizkit | c3f9284 | 2008-12-30 19:43:47 +0000 | [diff] [blame] | 39 | PrivateElements privateElements) { |
limpbizkit | 76c24b1 | 2008-12-25 04:32:41 +0000 | [diff] [blame] | 40 | super(source, key, scoping); |
limpbizkit | c3f9284 | 2008-12-30 19:43:47 +0000 | [diff] [blame] | 41 | this.privateElements = privateElements; |
limpbizkit | 76c24b1 | 2008-12-25 04:32:41 +0000 | [diff] [blame] | 42 | } |
| 43 | |
limpbizkit | 8996e80 | 2008-12-28 01:44:29 +0000 | [diff] [blame] | 44 | public <V> V acceptTargetVisitor(BindingTargetVisitor<? super T, V> visitor) { |
limpbizkit | 03b81a6 | 2009-03-18 05:34:39 +0000 | [diff] [blame] | 45 | return visitor.visit(this); |
limpbizkit | 76c24b1 | 2008-12-25 04:32:41 +0000 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | public Set<Dependency<?>> getDependencies() { |
| 49 | return ImmutableSet.<Dependency<?>>of(Dependency.get(Key.get(Injector.class))); |
| 50 | } |
| 51 | |
limpbizkit | c3f9284 | 2008-12-30 19:43:47 +0000 | [diff] [blame] | 52 | public PrivateElements getPrivateElements() { |
| 53 | return privateElements; |
limpbizkit | 76c24b1 | 2008-12-25 04:32:41 +0000 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | public BindingImpl<T> withScoping(Scoping scoping) { |
limpbizkit | c3f9284 | 2008-12-30 19:43:47 +0000 | [diff] [blame] | 57 | return new ExposedBindingImpl<T>(getSource(), getKey(), scoping, privateElements); |
limpbizkit | 76c24b1 | 2008-12-25 04:32:41 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | public ExposedBindingImpl<T> withKey(Key<T> key) { |
limpbizkit | c3f9284 | 2008-12-30 19:43:47 +0000 | [diff] [blame] | 61 | return new ExposedBindingImpl<T>(getSource(), key, getScoping(), privateElements); |
limpbizkit | 76c24b1 | 2008-12-25 04:32:41 +0000 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | @Override public String toString() { |
| 65 | return new ToStringBuilder(ExposedBinding.class) |
| 66 | .add("key", getKey()) |
limpbizkit | 76c24b1 | 2008-12-25 04:32:41 +0000 | [diff] [blame] | 67 | .add("source", getSource()) |
limpbizkit | c3f9284 | 2008-12-30 19:43:47 +0000 | [diff] [blame] | 68 | .add("privateElements", privateElements) |
limpbizkit | 76c24b1 | 2008-12-25 04:32:41 +0000 | [diff] [blame] | 69 | .toString(); |
| 70 | } |
limpbizkit | 03b81a6 | 2009-03-18 05:34:39 +0000 | [diff] [blame] | 71 | |
| 72 | public void applyTo(Binder binder) { |
| 73 | throw new UnsupportedOperationException("This element represents a synthetic binding."); |
| 74 | } |
limpbizkit | 76c24b1 | 2008-12-25 04:32:41 +0000 | [diff] [blame] | 75 | } |