blob: 291a10d1b2eee1c9e10c1d271d128e61f149d35a [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
limpbizkit9dc32d42008-06-15 11:29:10 +000019import com.google.inject.internal.Errors;
limpbizkit163c48a2008-06-16 02:58:08 +000020import com.google.inject.internal.ErrorsException;
limpbizkit76c24b12008-12-25 04:32:41 +000021import com.google.inject.internal.InternalContext;
22import com.google.inject.internal.InternalFactory;
kevinb9ncad2c2b2007-05-15 17:28:03 +000023import com.google.inject.internal.ToStringBuilder;
limpbizkita98bc7a2008-08-29 16:52:44 +000024import com.google.inject.spi.Dependency;
crazyboblee235d0682007-01-31 02:25:21 +000025
crazyboblee07e41822006-11-21 01:27:08 +000026/**
27 * @author crazybob@google.com (Bob Lee)
28 */
29class ConstantFactory<T> implements InternalFactory<T> {
30
limpbizkit5fb9d922008-10-14 23:35:56 +000031 private final Initializable<T> initializable;
crazyboblee07e41822006-11-21 01:27:08 +000032
limpbizkit5fb9d922008-10-14 23:35:56 +000033 public ConstantFactory(Initializable<T> initializable) {
34 this.initializable = initializable;
crazyboblee07e41822006-11-21 01:27:08 +000035 }
36
limpbizkita98bc7a2008-08-29 16:52:44 +000037 public T get(Errors errors, InternalContext context, Dependency dependency)
limpbizkit163c48a2008-06-16 02:58:08 +000038 throws ErrorsException {
limpbizkit5fb9d922008-10-14 23:35:56 +000039 return initializable.get(errors);
crazyboblee07e41822006-11-21 01:27:08 +000040 }
41
42 public String toString() {
crazybobleee3adfd62007-02-02 21:30:08 +000043 return new ToStringBuilder(ConstantFactory.class)
limpbizkit5fb9d922008-10-14 23:35:56 +000044 .add("value", initializable)
crazybobleee3adfd62007-02-02 21:30:08 +000045 .toString();
crazyboblee07e41822006-11-21 01:27:08 +000046 }
47}