blob: 3e410e249f74ce4d5d16d3590ab608b0f6f9b0fe [file] [log] [blame]
limpbizkit76c24b12008-12-25 04:32:41 +00001/*
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
17package com.google.inject.internal;
18
19import com.google.inject.Injector;
20import com.google.inject.Key;
limpbizkit03b81a62009-03-18 05:34:39 +000021import com.google.inject.Binder;
limpbizkit76c24b12008-12-25 04:32:41 +000022import com.google.inject.spi.BindingTargetVisitor;
23import com.google.inject.spi.Dependency;
24import com.google.inject.spi.UntargettedBinding;
25
26public class UntargettedBindingImpl<T> extends BindingImpl<T> implements UntargettedBinding<T> {
27
28 public UntargettedBindingImpl(Injector injector, Key<T> key, Object source) {
29 super(injector, key, source, new InternalFactory<T>() {
30 public T get(Errors errors, InternalContext context, Dependency<?> dependency) {
31 throw new AssertionError();
32 }
33 }, Scoping.UNSCOPED);
34 }
35
36 public UntargettedBindingImpl(Object source, Key<T> key, Scoping scoping) {
37 super(source, key, scoping);
38 }
39
limpbizkit8996e802008-12-28 01:44:29 +000040 public <V> V acceptTargetVisitor(BindingTargetVisitor<? super T, V> visitor) {
limpbizkit03b81a62009-03-18 05:34:39 +000041 return visitor.visit(this);
limpbizkit76c24b12008-12-25 04:32:41 +000042 }
43
44 public BindingImpl<T> withScoping(Scoping scoping) {
45 return new UntargettedBindingImpl<T>(getSource(), getKey(), scoping);
46 }
47
48 public BindingImpl<T> withKey(Key<T> key) {
49 return new UntargettedBindingImpl<T>(getSource(), key, getScoping());
50 }
51
limpbizkit03b81a62009-03-18 05:34:39 +000052 public void applyTo(Binder binder) {
53 getScoping().applyTo(binder.withSource(getSource()).bind(getKey()));
54 }
55
limpbizkit76c24b12008-12-25 04:32:41 +000056 @Override public String toString() {
57 return new ToStringBuilder(UntargettedBinding.class)
58 .add("key", getKey())
59 .add("source", getSource())
60 .toString();
61 }
62}