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.Resolver;
19 import jp.liq.container.reflect.ConstructorWrapper;
20 import jp.liq.container.reflect.ObjectFactory;
21
22 /**
23 * コンストラクタを使用してコンポーネントのインスタンスを生成するコンポーネントです。
24 * @author nose
25 */
26 public final class ConstructorComponent<T> extends InjectableComponent<T, ConstructorComponent<T>> {
27 private final ConstructorWrapper<T> constructor;
28
29 /**
30 * このクラスのインスタンスを構築します。
31 * @param ctor コンポーネントのインスタンスを生成するコンストラクタ。
32 * @param componentType コンポーネントの型
33 * @param recycled 生成したインスタンスを再利用する
34 */
35 public ConstructorComponent(ConstructorWrapper<T> ctor, Class<T> componentType, boolean recycled) {
36 super(componentType, ctor.getParameterTypes(), recycled);
37 this.constructor = ctor;
38 }
39
40 /**
41 * @see jp.liq.container.Component#getDescription()
42 */
43 public final Object getDescription() {
44 return constructor;
45 }
46
47 /**
48 * @see jp.liq.container.component.InjectableComponent#createObjectFactory(Resolver)
49 */
50 @Override
51 protected final ObjectFactory<T> createObjectFactory(Resolver resolver) {
52 return constructor;
53 }
54
55 /**
56 * @see jp.liq.container.component.InjectableComponent#getThis()
57 */
58 @Override
59 public ConstructorComponent<T> getThis() {
60 return this;
61 }
62 }