blob: 633d5de01c02c7e1275ccd842ff6ad2a48db2b29 [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
limpbizkit5ae41eb2009-06-06 17:51:27 +000017package com.google.inject.internal;
crazyboblee07e41822006-11-21 01:27:08 +000018
sberlind9c913a2011-06-26 21:02:54 +000019import com.google.common.base.Objects;
limpbizkita98bc7a2008-08-29 16:52:44 +000020import com.google.inject.spi.Dependency;
crazyboblee235d0682007-01-31 02:25:21 +000021
crazyboblee07e41822006-11-21 01:27:08 +000022/**
23 * @author crazybob@google.com (Bob Lee)
24 */
limpbizkit5ae41eb2009-06-06 17:51:27 +000025final class ConstantFactory<T> implements InternalFactory<T> {
crazyboblee07e41822006-11-21 01:27:08 +000026
limpbizkit5fb9d922008-10-14 23:35:56 +000027 private final Initializable<T> initializable;
crazyboblee07e41822006-11-21 01:27:08 +000028
limpbizkit5fb9d922008-10-14 23:35:56 +000029 public ConstantFactory(Initializable<T> initializable) {
30 this.initializable = initializable;
crazyboblee07e41822006-11-21 01:27:08 +000031 }
32
sberlin888a2642010-02-11 22:07:07 +000033 public T get(Errors errors, InternalContext context, Dependency dependency, boolean linked)
limpbizkit163c48a2008-06-16 02:58:08 +000034 throws ErrorsException {
limpbizkit5fb9d922008-10-14 23:35:56 +000035 return initializable.get(errors);
crazyboblee07e41822006-11-21 01:27:08 +000036 }
37
38 public String toString() {
sberlind9c913a2011-06-26 21:02:54 +000039 return Objects.toStringHelper(ConstantFactory.class)
limpbizkit5fb9d922008-10-14 23:35:56 +000040 .add("value", initializable)
crazybobleee3adfd62007-02-02 21:30:08 +000041 .toString();
crazyboblee07e41822006-11-21 01:27:08 +000042 }
43}