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.Objects; |
| 20 | import com.google.inject.internal.ToStringBuilder; |
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 | */ |
| 25 | class ConstantFactory<T> implements InternalFactory<T> { |
| 26 | |
| 27 | private final T value; |
limpbizkit | c808df0 | 2007-08-25 03:25:13 +0000 | [diff] [blame^] | 28 | private final Object source; |
crazyboblee | 07e4182 | 2006-11-21 01:27:08 +0000 | [diff] [blame] | 29 | |
limpbizkit | c808df0 | 2007-08-25 03:25:13 +0000 | [diff] [blame^] | 30 | public ConstantFactory(T value, Object source) { |
| 31 | this.value = value; |
| 32 | this.source = source; |
crazyboblee | 07e4182 | 2006-11-21 01:27:08 +0000 | [diff] [blame] | 33 | } |
| 34 | |
limpbizkit | c808df0 | 2007-08-25 03:25:13 +0000 | [diff] [blame^] | 35 | public T get(InternalContext context) { |
| 36 | return context.sanitize(value, source); |
crazyboblee | 07e4182 | 2006-11-21 01:27:08 +0000 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | public String toString() { |
crazyboblee | e3adfd6 | 2007-02-02 21:30:08 +0000 | [diff] [blame] | 40 | return new ToStringBuilder(ConstantFactory.class) |
| 41 | .add("value", value) |
| 42 | .toString(); |
crazyboblee | 07e4182 | 2006-11-21 01:27:08 +0000 | [diff] [blame] | 43 | } |
| 44 | } |