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