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 | |
| 17 | package com.google.inject; |
| 18 | |
limpbizkit | 9dc32d4 | 2008-06-15 11:29:10 +0000 | [diff] [blame] | 19 | import com.google.inject.internal.Errors; |
limpbizkit | 163c48a | 2008-06-16 02:58:08 +0000 | [diff] [blame] | 20 | import com.google.inject.internal.ErrorsException; |
limpbizkit | 76c24b1 | 2008-12-25 04:32:41 +0000 | [diff] [blame] | 21 | import com.google.inject.internal.InternalContext; |
| 22 | import com.google.inject.internal.InternalFactory; |
kevinb9n | cad2c2b | 2007-05-15 17:28:03 +0000 | [diff] [blame] | 23 | import com.google.inject.internal.ToStringBuilder; |
limpbizkit | a98bc7a | 2008-08-29 16:52:44 +0000 | [diff] [blame] | 24 | import com.google.inject.spi.Dependency; |
crazyboblee | 235d068 | 2007-01-31 02:25:21 +0000 | [diff] [blame] | 25 | |
crazyboblee | 07e4182 | 2006-11-21 01:27:08 +0000 | [diff] [blame] | 26 | /** |
| 27 | * @author crazybob@google.com (Bob Lee) |
| 28 | */ |
| 29 | class ConstantFactory<T> implements InternalFactory<T> { |
| 30 | |
limpbizkit | 5fb9d92 | 2008-10-14 23:35:56 +0000 | [diff] [blame] | 31 | private final Initializable<T> initializable; |
crazyboblee | 07e4182 | 2006-11-21 01:27:08 +0000 | [diff] [blame] | 32 | |
limpbizkit | 5fb9d92 | 2008-10-14 23:35:56 +0000 | [diff] [blame] | 33 | public ConstantFactory(Initializable<T> initializable) { |
| 34 | this.initializable = initializable; |
crazyboblee | 07e4182 | 2006-11-21 01:27:08 +0000 | [diff] [blame] | 35 | } |
| 36 | |
limpbizkit | a98bc7a | 2008-08-29 16:52:44 +0000 | [diff] [blame] | 37 | public T get(Errors errors, InternalContext context, Dependency dependency) |
limpbizkit | 163c48a | 2008-06-16 02:58:08 +0000 | [diff] [blame] | 38 | throws ErrorsException { |
limpbizkit | 5fb9d92 | 2008-10-14 23:35:56 +0000 | [diff] [blame] | 39 | return initializable.get(errors); |
crazyboblee | 07e4182 | 2006-11-21 01:27:08 +0000 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | public String toString() { |
crazyboblee | e3adfd6 | 2007-02-02 21:30:08 +0000 | [diff] [blame] | 43 | return new ToStringBuilder(ConstantFactory.class) |
limpbizkit | 5fb9d92 | 2008-10-14 23:35:56 +0000 | [diff] [blame] | 44 | .add("value", initializable) |
crazyboblee | e3adfd6 | 2007-02-02 21:30:08 +0000 | [diff] [blame] | 45 | .toString(); |
crazyboblee | 07e4182 | 2006-11-21 01:27:08 +0000 | [diff] [blame] | 46 | } |
| 47 | } |