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 | |
kevinb9n | cad2c2b | 2007-05-15 17:28:03 +0000 | [diff] [blame] | 19 | import com.google.inject.internal.ToStringBuilder; |
crazyboblee | 235d068 | 2007-01-31 02:25:21 +0000 | [diff] [blame] | 20 | |
crazyboblee | 07e4182 | 2006-11-21 01:27:08 +0000 | [diff] [blame] | 21 | /** |
| 22 | * @author crazybob@google.com (Bob Lee) |
| 23 | */ |
| 24 | class ConstantFactory<T> implements InternalFactory<T> { |
| 25 | |
| 26 | private final T value; |
| 27 | |
crazyboblee | 712705c | 2007-09-07 03:20:30 +0000 | [diff] [blame] | 28 | public ConstantFactory(T value) { |
limpbizkit | c808df0 | 2007-08-25 03:25:13 +0000 | [diff] [blame] | 29 | this.value = value; |
crazyboblee | 07e4182 | 2006-11-21 01:27:08 +0000 | [diff] [blame] | 30 | } |
| 31 | |
limpbizkit | fcf2b8c | 2007-10-21 18:23:43 +0000 | [diff] [blame] | 32 | public T get(InternalContext context, InjectionPoint injectionPoint) { |
limpbizkit | 51515b5 | 2008-03-11 03:46:25 +0000 | [diff] [blame] | 33 | context.ensureMemberInjected(value); |
crazyboblee | 712705c | 2007-09-07 03:20:30 +0000 | [diff] [blame] | 34 | return value; |
crazyboblee | 07e4182 | 2006-11-21 01:27:08 +0000 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | public String toString() { |
crazyboblee | e3adfd6 | 2007-02-02 21:30:08 +0000 | [diff] [blame] | 38 | return new ToStringBuilder(ConstantFactory.class) |
| 39 | .add("value", value) |
| 40 | .toString(); |
crazyboblee | 07e4182 | 2006-11-21 01:27:08 +0000 | [diff] [blame] | 41 | } |
| 42 | } |