crazyboblee | abc4dd0 | 2007-02-01 01:44:36 +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 | */ |
crazyboblee | 7289ac1 | 2007-02-01 00:28:09 +0000 | [diff] [blame] | 16 | |
| 17 | package com.google.inject; |
| 18 | |
kevinb9n | cad2c2b | 2007-05-15 17:28:03 +0000 | [diff] [blame] | 19 | import com.google.inject.internal.Objects; |
kevinb9n | a312d7a | 2007-03-01 10:57:35 +0000 | [diff] [blame] | 20 | import com.google.inject.spi.SourceProviders; |
kevinb9n | a312d7a | 2007-03-01 10:57:35 +0000 | [diff] [blame] | 21 | |
crazyboblee | 7289ac1 | 2007-02-01 00:28:09 +0000 | [diff] [blame] | 22 | /** |
| 23 | * @author crazybob@google.com (Bob Lee) |
| 24 | */ |
crazyboblee | bd9544e | 2007-02-25 20:32:11 +0000 | [diff] [blame] | 25 | class InternalFactoryToProviderAdapter<T> implements InternalFactory<T> { |
crazyboblee | 7289ac1 | 2007-02-01 00:28:09 +0000 | [diff] [blame] | 26 | |
crazyboblee | bd9544e | 2007-02-25 20:32:11 +0000 | [diff] [blame] | 27 | private final Provider<? extends T> provider; |
kevinb9n | a312d7a | 2007-03-01 10:57:35 +0000 | [diff] [blame] | 28 | private final Object source; |
crazyboblee | 7289ac1 | 2007-02-01 00:28:09 +0000 | [diff] [blame] | 29 | |
crazyboblee | bd9544e | 2007-02-25 20:32:11 +0000 | [diff] [blame] | 30 | public InternalFactoryToProviderAdapter(Provider<? extends T> provider) { |
kevinb9n | a312d7a | 2007-03-01 10:57:35 +0000 | [diff] [blame] | 31 | this(provider, SourceProviders.UNKNOWN_SOURCE); |
| 32 | } |
| 33 | |
| 34 | public InternalFactoryToProviderAdapter( |
| 35 | Provider<? extends T> provider, Object source) { |
| 36 | this.provider = Objects.nonNull(provider, "provider"); |
| 37 | this.source = Objects.nonNull(source, "source"); |
crazyboblee | 7289ac1 | 2007-02-01 00:28:09 +0000 | [diff] [blame] | 38 | } |
limpbizkit | 51515b5 | 2008-03-11 03:46:25 +0000 | [diff] [blame^] | 39 | |
limpbizkit | fcf2b8c | 2007-10-21 18:23:43 +0000 | [diff] [blame] | 40 | public T get(InternalContext context, InjectionPoint<?> injectionPoint) { |
limpbizkit | 51515b5 | 2008-03-11 03:46:25 +0000 | [diff] [blame^] | 41 | context.ensureMemberInjected(provider); |
kevinb9n | a312d7a | 2007-03-01 10:57:35 +0000 | [diff] [blame] | 42 | T provided = provider.get(); |
limpbizkit | fcf2b8c | 2007-10-21 18:23:43 +0000 | [diff] [blame] | 43 | return injectionPoint.checkForNull(provided, source); |
crazyboblee | 7289ac1 | 2007-02-01 00:28:09 +0000 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | public String toString() { |
crazyboblee | bd9544e | 2007-02-25 20:32:11 +0000 | [diff] [blame] | 47 | return provider.toString(); |
crazyboblee | 7289ac1 | 2007-02-01 00:28:09 +0000 | [diff] [blame] | 48 | } |
crazyboblee | 7289ac1 | 2007-02-01 00:28:09 +0000 | [diff] [blame] | 49 | } |