blob: d8cdb348e9fe239e6959d74112156cc753e0be94 [file] [log] [blame]
limpbizkit5fb9d922008-10-14 23:35:56 +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;
18
limpbizkit76c24b12008-12-25 04:32:41 +000019import com.google.inject.internal.BindingImpl;
limpbizkit5fb9d922008-10-14 23:35:56 +000020import com.google.inject.internal.Errors;
limpbizkit53664a72009-02-21 00:25:27 +000021import com.google.inject.internal.ImmutableList;
22import com.google.inject.internal.ImmutableSet;
limpbizkit5fb9d922008-10-14 23:35:56 +000023import com.google.inject.internal.MatcherAndConverter;
limpbizkitee792462009-04-08 23:48:49 +000024import com.google.inject.spi.TypeListenerBinding;
limpbizkit5fb9d922008-10-14 23:35:56 +000025import java.lang.annotation.Annotation;
26import java.util.List;
27import java.util.Map;
28
29/**
30 * The inheritable data within an injector. This class is intended to allow parent and local
31 * injector data to be accessed as a unit.
32 *
33 * @author jessewilson@google.com (Jesse Wilson)
34 */
35interface State {
36
37 static final State NONE = new State() {
38 public State parent() {
39 throw new UnsupportedOperationException();
40 }
41
42 public <T> BindingImpl<T> getExplicitBinding(Key<T> key) {
43 return null;
44 }
45
46 public Map<Key<?>, Binding<?>> getExplicitBindingsThisLevel() {
47 throw new UnsupportedOperationException();
48 }
49
50 public void putBinding(Key<?> key, BindingImpl<?> binding) {
51 throw new UnsupportedOperationException();
52 }
53
54 public Scope getScope(Class<? extends Annotation> scopingAnnotation) {
55 return null;
56 }
57
58 public void putAnnotation(Class<? extends Annotation> annotationType, Scope scope) {
59 throw new UnsupportedOperationException();
60 }
61
62 public void addConverter(MatcherAndConverter matcherAndConverter) {
63 throw new UnsupportedOperationException();
64 }
65
66 public MatcherAndConverter getConverter(String stringValue, TypeLiteral<?> type, Errors errors,
67 Object source) {
68 throw new UnsupportedOperationException();
69 }
70
71 public Iterable<MatcherAndConverter> getConvertersThisLevel() {
72 return ImmutableSet.of();
73 }
74
limpbizkitbf0d8762009-02-19 09:06:22 +000075 /*if[AOP]*/
limpbizkit5fb9d922008-10-14 23:35:56 +000076 public void addMethodAspect(MethodAspect methodAspect) {
77 throw new UnsupportedOperationException();
78 }
79
limpbizkiteb405132009-04-14 00:50:25 +000080 public ImmutableList<MethodAspect> getMethodAspects() {
limpbizkit5fb9d922008-10-14 23:35:56 +000081 return ImmutableList.of();
82 }
limpbizkitbf0d8762009-02-19 09:06:22 +000083 /*end[AOP]*/
limpbizkit5fb9d922008-10-14 23:35:56 +000084
limpbizkitee792462009-04-08 23:48:49 +000085 public void addTypeListener(TypeListenerBinding typeListenerBinding) {
limpbizkit03b81a62009-03-18 05:34:39 +000086 throw new UnsupportedOperationException();
87 }
88
limpbizkitee792462009-04-08 23:48:49 +000089 public List<TypeListenerBinding> getTypeListenerBindings() {
limpbizkit03b81a62009-03-18 05:34:39 +000090 return ImmutableList.of();
91 }
92
limpbizkit5fb9d922008-10-14 23:35:56 +000093 public void blacklist(Key<?> key) {
94 }
95
96 public boolean isBlacklisted(Key<?> key) {
97 return true;
98 }
limpbizkita8dccb32008-11-11 22:41:56 +000099
100 public Object lock() {
101 throw new UnsupportedOperationException();
102 }
limpbizkit5fb9d922008-10-14 23:35:56 +0000103 };
104
105 State parent();
106
107 /** Gets a binding which was specified explicitly in a module, or null. */
108 <T> BindingImpl<T> getExplicitBinding(Key<T> key);
109
110 /** Returns the explicit bindings at this level only. */
111 Map<Key<?>, Binding<?>> getExplicitBindingsThisLevel();
112
113 void putBinding(Key<?> key, BindingImpl<?> binding);
114
115 /** Returns the matching scope, or null. */
116 Scope getScope(Class<? extends Annotation> scopingAnnotation);
117
118 void putAnnotation(Class<? extends Annotation> annotationType, Scope scope);
119
120 void addConverter(MatcherAndConverter matcherAndConverter);
121
122 /** Returns the matching converter for {@code type}, or null if none match. */
123 MatcherAndConverter getConverter(
124 String stringValue, TypeLiteral<?> type, Errors errors, Object source);
125
126 /** Returns all converters at this level only. */
127 Iterable<MatcherAndConverter> getConvertersThisLevel();
128
limpbizkitbf0d8762009-02-19 09:06:22 +0000129 /*if[AOP]*/
limpbizkit5fb9d922008-10-14 23:35:56 +0000130 void addMethodAspect(MethodAspect methodAspect);
131
limpbizkiteb405132009-04-14 00:50:25 +0000132 ImmutableList<MethodAspect> getMethodAspects();
limpbizkitbf0d8762009-02-19 09:06:22 +0000133 /*end[AOP]*/
limpbizkit5fb9d922008-10-14 23:35:56 +0000134
limpbizkitee792462009-04-08 23:48:49 +0000135 void addTypeListener(TypeListenerBinding typeListenerBinding);
limpbizkit03b81a62009-03-18 05:34:39 +0000136
limpbizkitee792462009-04-08 23:48:49 +0000137 List<TypeListenerBinding> getTypeListenerBindings();
limpbizkit03b81a62009-03-18 05:34:39 +0000138
limpbizkit5fb9d922008-10-14 23:35:56 +0000139 /**
140 * Forbids the corresponding injector from creating a binding to {@code key}. Child injectors
141 * blacklist their bound keys on their parent injectors to prevent just-in-time bindings on the
142 * parent injector that would conflict.
143 */
144 void blacklist(Key<?> key);
145
146 /**
147 * Returns true if {@code key} is forbidden from being bound in this injector. This indicates that
148 * one of this injector's descendent's has bound the key.
149 */
150 boolean isBlacklisted(Key<?> key);
limpbizkita8dccb32008-11-11 22:41:56 +0000151
152 /**
153 * Returns the shared lock for all injector data. This is a low-granularity, high-contention lock
154 * to be used when reading mutable data (ie. just-in-time bindings, and binding blacklists).
155 */
156 Object lock();
limpbizkit5fb9d922008-10-14 23:35:56 +0000157}