1 /*
2 * Copyright 2007-2008 Naoki NOSE.
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 package jp.liq.container.component;
17
18 import jp.liq.container.Component;
19 import jp.liq.container.Resolver;
20
21 /**
22 * インスタンスをそのまま返すコンポーネントです。
23 * @author nose
24 */
25 public final class ObjectComponent<T> implements Component<T> {
26 private final T instance;
27 private final Class<T> type;
28 /**
29 * このクラスのインスタンスを構築します。
30 * @param type コンポーネントのロールを指定します。
31 * @param instance コンポーネントのインスタンスを指定します。
32 */
33 public ObjectComponent(Class<T> type, T instance) {
34 this.instance = instance;
35 this.type = type;
36 }
37
38 /**
39 * @see jp.liq.container.Component#getInstance(jp.liq.container.Resolver)
40 */
41 public T getInstance(Resolver resolving) {
42 return instance;
43 }
44
45 /**
46 * @see jp.liq.container.Component#getType()
47 */
48 public Class<T> getType() {
49 return type;
50 }
51
52 /**
53 * @see jp.liq.container.Component#getDescription()
54 */
55 public Object getDescription() {
56 return instance;
57 }
58 }