blob: f02e6cfd8ac28f8067e3ae863e499fd8f6b57ed6 [file] [log] [blame]
crazyboblee07e41822006-11-21 01:27:08 +00001/**
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
17package com.google.inject;
18
kevinb9ncad2c2b2007-05-15 17:28:03 +000019import com.google.inject.internal.ToStringBuilder;
crazyboblee235d0682007-01-31 02:25:21 +000020
crazyboblee07e41822006-11-21 01:27:08 +000021/**
22 * @author crazybob@google.com (Bob Lee)
23 */
24class ConstantFactory<T> implements InternalFactory<T> {
25
26 private final T value;
27
crazyboblee712705c2007-09-07 03:20:30 +000028 public ConstantFactory(T value) {
limpbizkitc808df02007-08-25 03:25:13 +000029 this.value = value;
crazyboblee07e41822006-11-21 01:27:08 +000030 }
31
limpbizkitfcf2b8c2007-10-21 18:23:43 +000032 public T get(InternalContext context, InjectionPoint injectionPoint) {
limpbizkit51515b52008-03-11 03:46:25 +000033 context.ensureMemberInjected(value);
crazyboblee712705c2007-09-07 03:20:30 +000034 return value;
crazyboblee07e41822006-11-21 01:27:08 +000035 }
36
37 public String toString() {
crazybobleee3adfd62007-02-02 21:30:08 +000038 return new ToStringBuilder(ConstantFactory.class)
39 .add("value", value)
40 .toString();
crazyboblee07e41822006-11-21 01:27:08 +000041 }
42}