crazyboblee | 07e4182 | 2006-11-21 01:27:08 +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 | |
limpbizkit | 5ae41eb | 2009-06-06 17:51:27 +0000 | [diff] [blame] | 17 | package com.google.inject.internal; |
crazyboblee | 07e4182 | 2006-11-21 01:27:08 +0000 | [diff] [blame] | 18 | |
sberlin | d9c913a | 2011-06-26 21:02:54 +0000 | [diff] [blame^] | 19 | import com.google.common.base.Objects; |
limpbizkit | a98bc7a | 2008-08-29 16:52:44 +0000 | [diff] [blame] | 20 | import com.google.inject.spi.Dependency; |
crazyboblee | 235d068 | 2007-01-31 02:25:21 +0000 | [diff] [blame] | 21 | |
crazyboblee | 07e4182 | 2006-11-21 01:27:08 +0000 | [diff] [blame] | 22 | /** |
| 23 | * @author crazybob@google.com (Bob Lee) |
| 24 | */ |
limpbizkit | 5ae41eb | 2009-06-06 17:51:27 +0000 | [diff] [blame] | 25 | final class ConstantFactory<T> implements InternalFactory<T> { |
crazyboblee | 07e4182 | 2006-11-21 01:27:08 +0000 | [diff] [blame] | 26 | |
limpbizkit | 5fb9d92 | 2008-10-14 23:35:56 +0000 | [diff] [blame] | 27 | private final Initializable<T> initializable; |
crazyboblee | 07e4182 | 2006-11-21 01:27:08 +0000 | [diff] [blame] | 28 | |
limpbizkit | 5fb9d92 | 2008-10-14 23:35:56 +0000 | [diff] [blame] | 29 | public ConstantFactory(Initializable<T> initializable) { |
| 30 | this.initializable = initializable; |
crazyboblee | 07e4182 | 2006-11-21 01:27:08 +0000 | [diff] [blame] | 31 | } |
| 32 | |
sberlin | 888a264 | 2010-02-11 22:07:07 +0000 | [diff] [blame] | 33 | public T get(Errors errors, InternalContext context, Dependency dependency, boolean linked) |
limpbizkit | 163c48a | 2008-06-16 02:58:08 +0000 | [diff] [blame] | 34 | throws ErrorsException { |
limpbizkit | 5fb9d92 | 2008-10-14 23:35:56 +0000 | [diff] [blame] | 35 | return initializable.get(errors); |
crazyboblee | 07e4182 | 2006-11-21 01:27:08 +0000 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | public String toString() { |
sberlin | d9c913a | 2011-06-26 21:02:54 +0000 | [diff] [blame^] | 39 | return Objects.toStringHelper(ConstantFactory.class) |
limpbizkit | 5fb9d92 | 2008-10-14 23:35:56 +0000 | [diff] [blame] | 40 | .add("value", initializable) |
crazyboblee | e3adfd6 | 2007-02-02 21:30:08 +0000 | [diff] [blame] | 41 | .toString(); |
crazyboblee | 07e4182 | 2006-11-21 01:27:08 +0000 | [diff] [blame] | 42 | } |
| 43 | } |