blob: 9e59a5cbac9c3040bd4eaf0489bd4ddbe681c931 [file] [log] [blame]
limpbizkit76c24b12008-12-25 04:32:41 +00001/**
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
17package com.google.inject.internal;
18
limpbizkit03b81a62009-03-18 05:34:39 +000019import com.google.inject.Binder;
limpbizkit76c24b12008-12-25 04:32:41 +000020import com.google.inject.Injector;
21import com.google.inject.Key;
22import com.google.inject.spi.BindingTargetVisitor;
23import com.google.inject.spi.Dependency;
24import com.google.inject.spi.ExposedBinding;
limpbizkitc3f92842008-12-30 19:43:47 +000025import com.google.inject.spi.PrivateElements;
limpbizkit76c24b12008-12-25 04:32:41 +000026import java.util.Set;
27
28public class ExposedBindingImpl<T> extends BindingImpl<T> implements ExposedBinding<T> {
29
limpbizkitc3f92842008-12-30 19:43:47 +000030 private final PrivateElements privateElements;
limpbizkit76c24b12008-12-25 04:32:41 +000031
32 public ExposedBindingImpl(Injector injector, Object source, Key<T> key,
limpbizkitc3f92842008-12-30 19:43:47 +000033 InternalFactory<T> factory, PrivateElements privateElements) {
limpbizkit76c24b12008-12-25 04:32:41 +000034 super(injector, key, source, factory, Scoping.UNSCOPED);
limpbizkitc3f92842008-12-30 19:43:47 +000035 this.privateElements = privateElements;
limpbizkit76c24b12008-12-25 04:32:41 +000036 }
37
38 public ExposedBindingImpl(Object source, Key<T> key, Scoping scoping,
limpbizkitc3f92842008-12-30 19:43:47 +000039 PrivateElements privateElements) {
limpbizkit76c24b12008-12-25 04:32:41 +000040 super(source, key, scoping);
limpbizkitc3f92842008-12-30 19:43:47 +000041 this.privateElements = privateElements;
limpbizkit76c24b12008-12-25 04:32:41 +000042 }
43
limpbizkit8996e802008-12-28 01:44:29 +000044 public <V> V acceptTargetVisitor(BindingTargetVisitor<? super T, V> visitor) {
limpbizkit03b81a62009-03-18 05:34:39 +000045 return visitor.visit(this);
limpbizkit76c24b12008-12-25 04:32:41 +000046 }
47
48 public Set<Dependency<?>> getDependencies() {
49 return ImmutableSet.<Dependency<?>>of(Dependency.get(Key.get(Injector.class)));
50 }
51
limpbizkitc3f92842008-12-30 19:43:47 +000052 public PrivateElements getPrivateElements() {
53 return privateElements;
limpbizkit76c24b12008-12-25 04:32:41 +000054 }
55
56 public BindingImpl<T> withScoping(Scoping scoping) {
limpbizkitc3f92842008-12-30 19:43:47 +000057 return new ExposedBindingImpl<T>(getSource(), getKey(), scoping, privateElements);
limpbizkit76c24b12008-12-25 04:32:41 +000058 }
59
60 public ExposedBindingImpl<T> withKey(Key<T> key) {
limpbizkitc3f92842008-12-30 19:43:47 +000061 return new ExposedBindingImpl<T>(getSource(), key, getScoping(), privateElements);
limpbizkit76c24b12008-12-25 04:32:41 +000062 }
63
64 @Override public String toString() {
65 return new ToStringBuilder(ExposedBinding.class)
66 .add("key", getKey())
limpbizkit76c24b12008-12-25 04:32:41 +000067 .add("source", getSource())
limpbizkitc3f92842008-12-30 19:43:47 +000068 .add("privateElements", privateElements)
limpbizkit76c24b12008-12-25 04:32:41 +000069 .toString();
70 }
limpbizkit03b81a62009-03-18 05:34:39 +000071
72 public void applyTo(Binder binder) {
73 throw new UnsupportedOperationException("This element represents a synthetic binding.");
74 }
limpbizkit76c24b12008-12-25 04:32:41 +000075}