limpbizkit | 3d58d6b | 2008-03-08 16:11:47 +0000 | [diff] [blame] | 1 | /** |
| 2 | * Copyright (C) 2006 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 | |
kevinb9n | 1601ae5 | 2008-06-03 22:21:04 +0000 | [diff] [blame] | 19 | import static com.google.common.base.Preconditions.checkNotNull; |
limpbizkit | b3a8f0b | 2008-09-05 22:30:40 +0000 | [diff] [blame^] | 20 | import com.google.common.collect.ImmutableSet; |
limpbizkit | 9dc32d4 | 2008-06-15 11:29:10 +0000 | [diff] [blame] | 21 | import com.google.common.collect.Iterables; |
| 22 | import com.google.common.collect.Lists; |
| 23 | import com.google.inject.Reflection.Factory; |
limpbizkit | 3d58d6b | 2008-03-08 16:11:47 +0000 | [diff] [blame] | 24 | import static com.google.inject.Scopes.SINGLETON; |
limpbizkit | 9dc32d4 | 2008-06-15 11:29:10 +0000 | [diff] [blame] | 25 | import com.google.inject.internal.Errors; |
limpbizkit | 163c48a | 2008-06-16 02:58:08 +0000 | [diff] [blame] | 26 | import com.google.inject.internal.ErrorsException; |
limpbizkit | 6663d02 | 2008-06-19 07:57:55 +0000 | [diff] [blame] | 27 | import com.google.inject.internal.SourceProvider; |
limpbizkit | 2b93168 | 2008-04-21 00:59:34 +0000 | [diff] [blame] | 28 | import com.google.inject.internal.Stopwatch; |
limpbizkit | a98bc7a | 2008-08-29 16:52:44 +0000 | [diff] [blame] | 29 | import com.google.inject.spi.Dependency; |
limpbizkit | 477f9f9 | 2008-07-28 07:05:14 +0000 | [diff] [blame] | 30 | import com.google.inject.spi.Element; |
| 31 | import com.google.inject.spi.Elements; |
limpbizkit | 163c48a | 2008-06-16 02:58:08 +0000 | [diff] [blame] | 32 | import com.google.inject.spi.InjectionPoint; |
limpbizkit | f44e9cc | 2008-03-26 06:33:29 +0000 | [diff] [blame] | 33 | import java.util.List; |
limpbizkit | 8eef998 | 2008-08-03 00:45:52 +0000 | [diff] [blame] | 34 | import java.util.Map; |
limpbizkit | 3d58d6b | 2008-03-08 16:11:47 +0000 | [diff] [blame] | 35 | import java.util.logging.Logger; |
| 36 | |
| 37 | /** |
| 38 | * Builds a dependency injection {@link Injector}. |
| 39 | * |
| 40 | * @author crazybob@google.com (Bob Lee) |
| 41 | * @author jessewilson@google.com (Jesse Wilson) |
| 42 | */ |
| 43 | class InjectorBuilder { |
| 44 | |
| 45 | private final Stopwatch stopwatch = new Stopwatch(); |
| 46 | |
| 47 | private Injector parent; |
| 48 | private Stage stage; |
limpbizkit | 9dc32d4 | 2008-06-15 11:29:10 +0000 | [diff] [blame] | 49 | private Factory reflectionFactory = new RuntimeReflectionFactory(); |
| 50 | private final List<Module> modules = Lists.newLinkedList(); |
limpbizkit | 3d58d6b | 2008-03-08 16:11:47 +0000 | [diff] [blame] | 51 | |
limpbizkit | 3d58d6b | 2008-03-08 16:11:47 +0000 | [diff] [blame] | 52 | private InjectorImpl injector; |
limpbizkit | 9dc32d4 | 2008-06-15 11:29:10 +0000 | [diff] [blame] | 53 | private Errors errors = new Errors(); |
limpbizkit | 3d58d6b | 2008-03-08 16:11:47 +0000 | [diff] [blame] | 54 | |
limpbizkit | 477f9f9 | 2008-07-28 07:05:14 +0000 | [diff] [blame] | 55 | private final List<Element> elements = Lists.newArrayList(); |
limpbizkit | 3d58d6b | 2008-03-08 16:11:47 +0000 | [diff] [blame] | 56 | |
limpbizkit | 00ca9f7 | 2008-08-02 17:56:17 +0000 | [diff] [blame] | 57 | private BindingProcessor bindCommandProcesor; |
| 58 | private InjectionRequestProcessor injectionCommandProcessor; |
limpbizkit | 3d58d6b | 2008-03-08 16:11:47 +0000 | [diff] [blame] | 59 | |
| 60 | /** |
limpbizkit | 9dc32d4 | 2008-06-15 11:29:10 +0000 | [diff] [blame] | 61 | * @param stage we're running in. If the stage is {@link Stage#PRODUCTION}, we will eagerly load |
| 62 | * singletons. |
limpbizkit | 3d58d6b | 2008-03-08 16:11:47 +0000 | [diff] [blame] | 63 | */ |
| 64 | InjectorBuilder stage(Stage stage) { |
| 65 | this.stage = stage; |
| 66 | return this; |
| 67 | } |
| 68 | |
limpbizkit | 9dc32d4 | 2008-06-15 11:29:10 +0000 | [diff] [blame] | 69 | InjectorBuilder usingReflectionFactory(Factory reflectionFactory) { |
limpbizkit | 916f548 | 2008-04-16 20:51:14 +0000 | [diff] [blame] | 70 | this.reflectionFactory = reflectionFactory; |
| 71 | return this; |
| 72 | } |
| 73 | |
limpbizkit | 3d58d6b | 2008-03-08 16:11:47 +0000 | [diff] [blame] | 74 | InjectorBuilder parentInjector(Injector parent) { |
| 75 | this.parent = parent; |
| 76 | return this; |
| 77 | } |
| 78 | |
| 79 | InjectorBuilder addModules(Iterable<? extends Module> modules) { |
| 80 | for (Module module : modules) { |
| 81 | this.modules.add(module); |
| 82 | } |
| 83 | return this; |
| 84 | } |
| 85 | |
| 86 | Injector build() { |
| 87 | if (injector != null) { |
| 88 | throw new AssertionError("Already built, builders are not reusable."); |
| 89 | } |
| 90 | |
limpbizkit | 9dc32d4 | 2008-06-15 11:29:10 +0000 | [diff] [blame] | 91 | injector = new InjectorImpl(parent); |
limpbizkit | 7f8eda0 | 2008-03-26 01:11:16 +0000 | [diff] [blame] | 92 | |
limpbizkit | 3d58d6b | 2008-03-08 16:11:47 +0000 | [diff] [blame] | 93 | modules.add(0, new BuiltInModule(injector, stage)); |
| 94 | |
limpbizkit | 477f9f9 | 2008-07-28 07:05:14 +0000 | [diff] [blame] | 95 | elements.addAll(Elements.getElements(stage, modules)); |
limpbizkit | 3d58d6b | 2008-03-08 16:11:47 +0000 | [diff] [blame] | 96 | |
limpbizkit | 3d58d6b | 2008-03-08 16:11:47 +0000 | [diff] [blame] | 97 | buildCoreInjector(); |
| 98 | |
| 99 | validate(); |
| 100 | |
limpbizkit | 9dc32d4 | 2008-06-15 11:29:10 +0000 | [diff] [blame] | 101 | errors.throwCreationExceptionIfErrorsExist(); |
limpbizkit | 3d58d6b | 2008-03-08 16:11:47 +0000 | [diff] [blame] | 102 | |
| 103 | // If we're in the tool stage, stop here. Don't eagerly inject or load |
| 104 | // anything. |
| 105 | if (stage == Stage.TOOL) { |
limpbizkit | 8eef998 | 2008-08-03 00:45:52 +0000 | [diff] [blame] | 106 | return new ToolStageInjector(injector); |
limpbizkit | 3d58d6b | 2008-03-08 16:11:47 +0000 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | fulfillInjectionRequests(); |
| 110 | |
limpbizkit | 477f9f9 | 2008-07-28 07:05:14 +0000 | [diff] [blame] | 111 | if (!elements.isEmpty()) { |
| 112 | throw new AssertionError("Failed to execute " + elements); |
limpbizkit | 3d58d6b | 2008-03-08 16:11:47 +0000 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | return injector; |
| 116 | } |
| 117 | |
limpbizkit | 9dc32d4 | 2008-06-15 11:29:10 +0000 | [diff] [blame] | 118 | /** Builds the injector. */ |
limpbizkit | 3d58d6b | 2008-03-08 16:11:47 +0000 | [diff] [blame] | 119 | private void buildCoreInjector() { |
limpbizkit | 00ca9f7 | 2008-08-02 17:56:17 +0000 | [diff] [blame] | 120 | new MessageProcessor(errors) |
limpbizkit | 477f9f9 | 2008-07-28 07:05:14 +0000 | [diff] [blame] | 121 | .processCommands(elements); |
limpbizkit | 3d58d6b | 2008-03-08 16:11:47 +0000 | [diff] [blame] | 122 | |
limpbizkit | 00ca9f7 | 2008-08-02 17:56:17 +0000 | [diff] [blame] | 123 | InterceptorBindingProcessor interceptorCommandProcessor |
| 124 | = new InterceptorBindingProcessor(errors); |
| 125 | interceptorCommandProcessor.processCommands(elements); |
| 126 | ConstructionProxyFactory proxyFactory = interceptorCommandProcessor.createProxyFactory(); |
limpbizkit | 9dc32d4 | 2008-06-15 11:29:10 +0000 | [diff] [blame] | 127 | injector.reflection = reflectionFactory.create(proxyFactory); |
limpbizkit | 3d58d6b | 2008-03-08 16:11:47 +0000 | [diff] [blame] | 128 | stopwatch.resetAndLog("Interceptors creation"); |
| 129 | |
limpbizkit | 00ca9f7 | 2008-08-02 17:56:17 +0000 | [diff] [blame] | 130 | new ScopeBindingProcessor(errors, injector.scopes).processCommands(elements); |
limpbizkit | 3d58d6b | 2008-03-08 16:11:47 +0000 | [diff] [blame] | 131 | stopwatch.resetAndLog("Scopes creation"); |
| 132 | |
limpbizkit | 00ca9f7 | 2008-08-02 17:56:17 +0000 | [diff] [blame] | 133 | new TypeConverterBindingProcessor(errors, injector.converters).processCommands(elements); |
limpbizkit | 3d58d6b | 2008-03-08 16:11:47 +0000 | [diff] [blame] | 134 | stopwatch.resetAndLog("Converters creation"); |
| 135 | |
limpbizkit | 150d677 | 2008-04-25 17:34:25 +0000 | [diff] [blame] | 136 | bindLogger(); |
limpbizkit | 00ca9f7 | 2008-08-02 17:56:17 +0000 | [diff] [blame] | 137 | bindCommandProcesor = new BindingProcessor(errors, |
limpbizkit | ecbb080 | 2008-06-02 07:02:11 +0000 | [diff] [blame] | 138 | injector, injector.scopes, injector.explicitBindings, |
limpbizkit | 7a2341b | 2008-07-08 05:49:55 +0000 | [diff] [blame] | 139 | injector.memberInjector); |
limpbizkit | 477f9f9 | 2008-07-28 07:05:14 +0000 | [diff] [blame] | 140 | bindCommandProcesor.processCommands(elements); |
limpbizkit | f44e9cc | 2008-03-26 06:33:29 +0000 | [diff] [blame] | 141 | bindCommandProcesor.createUntargettedBindings(); |
limpbizkit | 3d58d6b | 2008-03-08 16:11:47 +0000 | [diff] [blame] | 142 | stopwatch.resetAndLog("Binding creation"); |
| 143 | |
| 144 | injector.index(); |
| 145 | stopwatch.resetAndLog("Binding indexing"); |
| 146 | |
limpbizkit | 00ca9f7 | 2008-08-02 17:56:17 +0000 | [diff] [blame] | 147 | injectionCommandProcessor |
| 148 | = new InjectionRequestProcessor(errors, injector.memberInjector); |
| 149 | injectionCommandProcessor.processCommands(elements); |
limpbizkit | 3d58d6b | 2008-03-08 16:11:47 +0000 | [diff] [blame] | 150 | stopwatch.resetAndLog("Static injection"); |
| 151 | } |
| 152 | |
limpbizkit | 9dc32d4 | 2008-06-15 11:29:10 +0000 | [diff] [blame] | 153 | /** Validate everything that we can validate now that the injector is ready for use. */ |
limpbizkit | 3d58d6b | 2008-03-08 16:11:47 +0000 | [diff] [blame] | 154 | private void validate() { |
| 155 | bindCommandProcesor.runCreationListeners(injector); |
| 156 | stopwatch.resetAndLog("Validation"); |
| 157 | |
limpbizkit | 00ca9f7 | 2008-08-02 17:56:17 +0000 | [diff] [blame] | 158 | injectionCommandProcessor.validate(injector); |
limpbizkit | 3d58d6b | 2008-03-08 16:11:47 +0000 | [diff] [blame] | 159 | stopwatch.resetAndLog("Static validation"); |
| 160 | |
limpbizkit | 7a2341b | 2008-07-08 05:49:55 +0000 | [diff] [blame] | 161 | injector.memberInjector.validateOustandingInjections(errors); |
limpbizkit | 3d58d6b | 2008-03-08 16:11:47 +0000 | [diff] [blame] | 162 | stopwatch.resetAndLog("Instance member validation"); |
| 163 | |
limpbizkit | 00ca9f7 | 2008-08-02 17:56:17 +0000 | [diff] [blame] | 164 | new ProviderLookupProcessor(errors, injector).processCommands(elements); |
limpbizkit | 3d58d6b | 2008-03-08 16:11:47 +0000 | [diff] [blame] | 165 | stopwatch.resetAndLog("Provider verification"); |
| 166 | |
limpbizkit | 9dc32d4 | 2008-06-15 11:29:10 +0000 | [diff] [blame] | 167 | errors.throwCreationExceptionIfErrorsExist(); |
limpbizkit | 3d58d6b | 2008-03-08 16:11:47 +0000 | [diff] [blame] | 168 | } |
| 169 | |
limpbizkit | 9532e62 | 2008-06-18 08:20:54 +0000 | [diff] [blame] | 170 | /** Inject everything that can be injected. */ |
limpbizkit | 3d58d6b | 2008-03-08 16:11:47 +0000 | [diff] [blame] | 171 | private void fulfillInjectionRequests() { |
limpbizkit | 00ca9f7 | 2008-08-02 17:56:17 +0000 | [diff] [blame] | 172 | injectionCommandProcessor.injectMembers(injector); |
limpbizkit | 3d58d6b | 2008-03-08 16:11:47 +0000 | [diff] [blame] | 173 | stopwatch.resetAndLog("Static member injection"); |
limpbizkit | 9532e62 | 2008-06-18 08:20:54 +0000 | [diff] [blame] | 174 | |
limpbizkit | 7a2341b | 2008-07-08 05:49:55 +0000 | [diff] [blame] | 175 | injector.memberInjector.injectAll(errors); |
limpbizkit | 3d58d6b | 2008-03-08 16:11:47 +0000 | [diff] [blame] | 176 | stopwatch.resetAndLog("Instance injection"); |
limpbizkit | 9532e62 | 2008-06-18 08:20:54 +0000 | [diff] [blame] | 177 | errors.throwCreationExceptionIfErrorsExist(); |
limpbizkit | 3d58d6b | 2008-03-08 16:11:47 +0000 | [diff] [blame] | 178 | |
limpbizkit | ecbb080 | 2008-06-02 07:02:11 +0000 | [diff] [blame] | 179 | loadEagerSingletons(); |
limpbizkit | 3d58d6b | 2008-03-08 16:11:47 +0000 | [diff] [blame] | 180 | stopwatch.resetAndLog("Preloading"); |
limpbizkit | 9532e62 | 2008-06-18 08:20:54 +0000 | [diff] [blame] | 181 | errors.throwCreationExceptionIfErrorsExist(); |
limpbizkit | 3d58d6b | 2008-03-08 16:11:47 +0000 | [diff] [blame] | 182 | } |
| 183 | |
limpbizkit | ecbb080 | 2008-06-02 07:02:11 +0000 | [diff] [blame] | 184 | public void loadEagerSingletons() { |
| 185 | // load eager singletons, or all singletons if we're in Stage.PRODUCTION. |
limpbizkit | e81cf1b | 2008-06-02 16:41:22 +0000 | [diff] [blame] | 186 | for (final BindingImpl<?> binding |
kevinb9n | 1601ae5 | 2008-06-03 22:21:04 +0000 | [diff] [blame] | 187 | : Iterables.concat(injector.explicitBindings.values(), injector.jitBindings.values())) { |
limpbizkit | 5789ef4 | 2008-08-04 06:44:30 +0000 | [diff] [blame] | 188 | if ((stage == Stage.PRODUCTION && binding.getScope() == SINGLETON) |
limpbizkit | e81cf1b | 2008-06-02 16:41:22 +0000 | [diff] [blame] | 189 | || binding.getLoadStrategy() == LoadStrategy.EAGER) { |
limpbizkit | 9dc32d4 | 2008-06-15 11:29:10 +0000 | [diff] [blame] | 190 | try { |
| 191 | injector.callInContext(new ContextualCallable<Void>() { |
| 192 | public Void call(InternalContext context) { |
limpbizkit | a98bc7a | 2008-08-29 16:52:44 +0000 | [diff] [blame] | 193 | Dependency<?> dependency = Dependency.get(binding.key); |
| 194 | context.setDependency(dependency); |
limpbizkit | a6e0e78 | 2008-09-03 06:19:56 +0000 | [diff] [blame] | 195 | errors.pushSource(dependency); |
limpbizkit | 9dc32d4 | 2008-06-15 11:29:10 +0000 | [diff] [blame] | 196 | try { |
limpbizkit | a98bc7a | 2008-08-29 16:52:44 +0000 | [diff] [blame] | 197 | binding.internalFactory.get(errors, context, dependency); |
limpbizkit | 163c48a | 2008-06-16 02:58:08 +0000 | [diff] [blame] | 198 | } catch (ErrorsException e) { |
limpbizkit | 9dc32d4 | 2008-06-15 11:29:10 +0000 | [diff] [blame] | 199 | errors.merge(e.getErrors()); |
| 200 | } finally { |
limpbizkit | a98bc7a | 2008-08-29 16:52:44 +0000 | [diff] [blame] | 201 | context.setDependency(null); |
limpbizkit | a6e0e78 | 2008-09-03 06:19:56 +0000 | [diff] [blame] | 202 | errors.popSource(dependency); |
limpbizkit | 9dc32d4 | 2008-06-15 11:29:10 +0000 | [diff] [blame] | 203 | } |
| 204 | |
limpbizkit | ecbb080 | 2008-06-02 07:02:11 +0000 | [diff] [blame] | 205 | return null; |
limpbizkit | ecbb080 | 2008-06-02 07:02:11 +0000 | [diff] [blame] | 206 | } |
limpbizkit | 9dc32d4 | 2008-06-15 11:29:10 +0000 | [diff] [blame] | 207 | }); |
limpbizkit | 163c48a | 2008-06-16 02:58:08 +0000 | [diff] [blame] | 208 | } catch (ErrorsException e) { |
limpbizkit | 9dc32d4 | 2008-06-15 11:29:10 +0000 | [diff] [blame] | 209 | throw new AssertionError(); |
| 210 | } |
limpbizkit | ecbb080 | 2008-06-02 07:02:11 +0000 | [diff] [blame] | 211 | } |
| 212 | } |
| 213 | } |
| 214 | |
limpbizkit | 7d9991e | 2008-06-17 02:49:18 +0000 | [diff] [blame] | 215 | private static class BuiltInModule implements Module { |
limpbizkit | 3d58d6b | 2008-03-08 16:11:47 +0000 | [diff] [blame] | 216 | final Injector injector; |
| 217 | final Stage stage; |
| 218 | |
| 219 | private BuiltInModule(Injector injector, Stage stage) { |
kevinb9n | 1601ae5 | 2008-06-03 22:21:04 +0000 | [diff] [blame] | 220 | this.injector = checkNotNull(injector, "injector"); |
| 221 | this.stage = checkNotNull(stage, "stage"); |
limpbizkit | 3d58d6b | 2008-03-08 16:11:47 +0000 | [diff] [blame] | 222 | } |
| 223 | |
limpbizkit | 7d9991e | 2008-06-17 02:49:18 +0000 | [diff] [blame] | 224 | public void configure(Binder binder) { |
limpbizkit | 9532e62 | 2008-06-18 08:20:54 +0000 | [diff] [blame] | 225 | binder = binder.withSource(SourceProvider.UNKNOWN_SOURCE); |
limpbizkit | 3d58d6b | 2008-03-08 16:11:47 +0000 | [diff] [blame] | 226 | |
limpbizkit | 7d9991e | 2008-06-17 02:49:18 +0000 | [diff] [blame] | 227 | binder.bind(Stage.class).toInstance(stage); |
| 228 | binder.bindScope(Singleton.class, SINGLETON); |
| 229 | // Create default bindings. |
| 230 | // We use toProvider() instead of toInstance() to avoid infinite recursion |
| 231 | // in toString(). |
| 232 | binder.bind(Injector.class).toProvider(new InjectorProvider(injector)); |
limpbizkit | 3d58d6b | 2008-03-08 16:11:47 +0000 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | class InjectorProvider implements Provider<Injector> { |
| 236 | final Injector injector; |
| 237 | |
| 238 | InjectorProvider(Injector injector) { |
| 239 | this.injector = injector; |
| 240 | } |
| 241 | |
| 242 | public Injector get() { |
| 243 | return injector; |
| 244 | } |
| 245 | |
| 246 | public String toString() { |
| 247 | return "Provider<Injector>"; |
| 248 | } |
| 249 | } |
limpbizkit | 2b93168 | 2008-04-21 00:59:34 +0000 | [diff] [blame] | 250 | } |
limpbizkit | 3d58d6b | 2008-03-08 16:11:47 +0000 | [diff] [blame] | 251 | |
limpbizkit | 2b93168 | 2008-04-21 00:59:34 +0000 | [diff] [blame] | 252 | /** |
limpbizkit | 9dc32d4 | 2008-06-15 11:29:10 +0000 | [diff] [blame] | 253 | * The Logger is a special case because it knows the injection point of the injected member. It's |
| 254 | * the only binding that does this. |
limpbizkit | 2b93168 | 2008-04-21 00:59:34 +0000 | [diff] [blame] | 255 | */ |
| 256 | private void bindLogger() { |
| 257 | Key<Logger> key = Key.get(Logger.class); |
| 258 | LoggerFactory loggerFactory = new LoggerFactory(); |
| 259 | injector.explicitBindings.put(key, |
| 260 | new ProviderInstanceBindingImpl<Logger>(injector, key, |
limpbizkit | 9532e62 | 2008-06-18 08:20:54 +0000 | [diff] [blame] | 261 | SourceProvider.UNKNOWN_SOURCE, loggerFactory, Scopes.NO_SCOPE, |
limpbizkit | b3a8f0b | 2008-09-05 22:30:40 +0000 | [diff] [blame^] | 262 | loggerFactory, LoadStrategy.LAZY, ImmutableSet.<InjectionPoint>of())); |
limpbizkit | 2b93168 | 2008-04-21 00:59:34 +0000 | [diff] [blame] | 263 | } |
limpbizkit | 3d58d6b | 2008-03-08 16:11:47 +0000 | [diff] [blame] | 264 | |
limpbizkit | 2b93168 | 2008-04-21 00:59:34 +0000 | [diff] [blame] | 265 | static class LoggerFactory implements InternalFactory<Logger>, Provider<Logger> { |
limpbizkit | a98bc7a | 2008-08-29 16:52:44 +0000 | [diff] [blame] | 266 | public Logger get(Errors errors, InternalContext context, Dependency<?> dependency) { |
| 267 | InjectionPoint injectionPoint = dependency.getInjectionPoint(); |
| 268 | return injectionPoint == null |
limpbizkit | 2b93168 | 2008-04-21 00:59:34 +0000 | [diff] [blame] | 269 | ? Logger.getAnonymousLogger() |
limpbizkit | a98bc7a | 2008-08-29 16:52:44 +0000 | [diff] [blame] | 270 | : Logger.getLogger(injectionPoint.getMember().getDeclaringClass().getName()); |
limpbizkit | 2b93168 | 2008-04-21 00:59:34 +0000 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | public Logger get() { |
| 274 | return Logger.getAnonymousLogger(); |
| 275 | } |
| 276 | |
| 277 | public String toString() { |
| 278 | return "Provider<Logger>"; |
limpbizkit | 3d58d6b | 2008-03-08 16:11:47 +0000 | [diff] [blame] | 279 | } |
| 280 | } |
| 281 | |
limpbizkit | 8eef998 | 2008-08-03 00:45:52 +0000 | [diff] [blame] | 282 | /** {@link Injector} exposed to users in {@link Stage#TOOL}. */ |
| 283 | static class ToolStageInjector implements Injector { |
| 284 | private final Injector delegateInjector; |
| 285 | |
| 286 | ToolStageInjector(Injector delegateInjector) { |
| 287 | this.delegateInjector = delegateInjector; |
| 288 | } |
| 289 | public void injectMembers(Object o) { |
| 290 | throw new UnsupportedOperationException( |
| 291 | "Injector.injectMembers(Object) is not supported in Stage.TOOL"); |
| 292 | } |
| 293 | public Map<Key<?>, Binding<?>> getBindings() { |
| 294 | return this.delegateInjector.getBindings(); |
| 295 | } |
| 296 | public <T> Binding<T> getBinding(Key<T> key) { |
| 297 | return this.delegateInjector.getBinding(key); |
| 298 | } |
| 299 | public <T> Binding<T> getBinding(Class<T> type) { |
| 300 | return this.delegateInjector.getBinding(type); |
| 301 | } |
| 302 | public <T> List<Binding<T>> findBindingsByType(TypeLiteral<T> type) { |
| 303 | return this.delegateInjector.findBindingsByType(type); |
| 304 | } |
| 305 | public <T> Provider<T> getProvider(Key<T> key) { |
| 306 | throw new UnsupportedOperationException( |
| 307 | "Injector.getProvider(Key<T>) is not supported in Stage.TOOL"); |
| 308 | } |
| 309 | public <T> Provider<T> getProvider(Class<T> type) { |
| 310 | throw new UnsupportedOperationException( |
| 311 | "Injector.getProvider(Class<T>) is not supported in Stage.TOOL"); |
| 312 | } |
| 313 | public <T> T getInstance(Key<T> key) { |
| 314 | throw new UnsupportedOperationException( |
| 315 | "Injector.getInstance(Key<T>) is not supported in Stage.TOOL"); |
| 316 | } |
| 317 | public <T> T getInstance(Class<T> type) { |
| 318 | throw new UnsupportedOperationException( |
| 319 | "Injector.getInstance(Class<T>) is not supported in Stage.TOOL"); |
| 320 | } |
| 321 | } |
limpbizkit | 3d58d6b | 2008-03-08 16:11:47 +0000 | [diff] [blame] | 322 | } |