limpbizkit | 5fb9d92 | 2008-10-14 23:35:56 +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; |
| 18 | |
limpbizkit | 76c24b1 | 2008-12-25 04:32:41 +0000 | [diff] [blame] | 19 | import com.google.inject.internal.BindingImpl; |
limpbizkit | 5fb9d92 | 2008-10-14 23:35:56 +0000 | [diff] [blame] | 20 | import com.google.inject.internal.Errors; |
limpbizkit | 53664a7 | 2009-02-21 00:25:27 +0000 | [diff] [blame] | 21 | import com.google.inject.internal.ImmutableList; |
| 22 | import com.google.inject.internal.ImmutableSet; |
limpbizkit | 5fb9d92 | 2008-10-14 23:35:56 +0000 | [diff] [blame] | 23 | import com.google.inject.internal.MatcherAndConverter; |
limpbizkit | ee79246 | 2009-04-08 23:48:49 +0000 | [diff] [blame] | 24 | import com.google.inject.spi.TypeListenerBinding; |
limpbizkit | 5fb9d92 | 2008-10-14 23:35:56 +0000 | [diff] [blame] | 25 | import java.lang.annotation.Annotation; |
| 26 | import java.util.List; |
| 27 | import 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 | */ |
| 35 | interface 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 | |
limpbizkit | bf0d876 | 2009-02-19 09:06:22 +0000 | [diff] [blame] | 75 | /*if[AOP]*/ |
limpbizkit | 5fb9d92 | 2008-10-14 23:35:56 +0000 | [diff] [blame] | 76 | public void addMethodAspect(MethodAspect methodAspect) { |
| 77 | throw new UnsupportedOperationException(); |
| 78 | } |
| 79 | |
limpbizkit | eb40513 | 2009-04-14 00:50:25 +0000 | [diff] [blame] | 80 | public ImmutableList<MethodAspect> getMethodAspects() { |
limpbizkit | 5fb9d92 | 2008-10-14 23:35:56 +0000 | [diff] [blame] | 81 | return ImmutableList.of(); |
| 82 | } |
limpbizkit | bf0d876 | 2009-02-19 09:06:22 +0000 | [diff] [blame] | 83 | /*end[AOP]*/ |
limpbizkit | 5fb9d92 | 2008-10-14 23:35:56 +0000 | [diff] [blame] | 84 | |
limpbizkit | ee79246 | 2009-04-08 23:48:49 +0000 | [diff] [blame] | 85 | public void addTypeListener(TypeListenerBinding typeListenerBinding) { |
limpbizkit | 03b81a6 | 2009-03-18 05:34:39 +0000 | [diff] [blame] | 86 | throw new UnsupportedOperationException(); |
| 87 | } |
| 88 | |
limpbizkit | ee79246 | 2009-04-08 23:48:49 +0000 | [diff] [blame] | 89 | public List<TypeListenerBinding> getTypeListenerBindings() { |
limpbizkit | 03b81a6 | 2009-03-18 05:34:39 +0000 | [diff] [blame] | 90 | return ImmutableList.of(); |
| 91 | } |
| 92 | |
limpbizkit | 5fb9d92 | 2008-10-14 23:35:56 +0000 | [diff] [blame] | 93 | public void blacklist(Key<?> key) { |
| 94 | } |
| 95 | |
| 96 | public boolean isBlacklisted(Key<?> key) { |
| 97 | return true; |
| 98 | } |
limpbizkit | a8dccb3 | 2008-11-11 22:41:56 +0000 | [diff] [blame] | 99 | |
| 100 | public Object lock() { |
| 101 | throw new UnsupportedOperationException(); |
| 102 | } |
limpbizkit | 5fb9d92 | 2008-10-14 23:35:56 +0000 | [diff] [blame] | 103 | }; |
| 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 | |
limpbizkit | bf0d876 | 2009-02-19 09:06:22 +0000 | [diff] [blame] | 129 | /*if[AOP]*/ |
limpbizkit | 5fb9d92 | 2008-10-14 23:35:56 +0000 | [diff] [blame] | 130 | void addMethodAspect(MethodAspect methodAspect); |
| 131 | |
limpbizkit | eb40513 | 2009-04-14 00:50:25 +0000 | [diff] [blame] | 132 | ImmutableList<MethodAspect> getMethodAspects(); |
limpbizkit | bf0d876 | 2009-02-19 09:06:22 +0000 | [diff] [blame] | 133 | /*end[AOP]*/ |
limpbizkit | 5fb9d92 | 2008-10-14 23:35:56 +0000 | [diff] [blame] | 134 | |
limpbizkit | ee79246 | 2009-04-08 23:48:49 +0000 | [diff] [blame] | 135 | void addTypeListener(TypeListenerBinding typeListenerBinding); |
limpbizkit | 03b81a6 | 2009-03-18 05:34:39 +0000 | [diff] [blame] | 136 | |
limpbizkit | ee79246 | 2009-04-08 23:48:49 +0000 | [diff] [blame] | 137 | List<TypeListenerBinding> getTypeListenerBindings(); |
limpbizkit | 03b81a6 | 2009-03-18 05:34:39 +0000 | [diff] [blame] | 138 | |
limpbizkit | 5fb9d92 | 2008-10-14 23:35:56 +0000 | [diff] [blame] | 139 | /** |
| 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); |
limpbizkit | a8dccb3 | 2008-11-11 22:41:56 +0000 | [diff] [blame] | 151 | |
| 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(); |
limpbizkit | 5fb9d92 | 2008-10-14 23:35:56 +0000 | [diff] [blame] | 157 | } |