KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfox > ioc > depend > ComponentRefDependency


1 /* JFox, the OpenSource J2EE Application Server
2  *
3  * Distributable under GNU LGPL license by gun.org
4  * more details please visit http://www.huihoo.org/jfox
5  */

6 package org.jfox.ioc.depend;
7
8 import org.jfox.ioc.ComponentName;
9 import org.jfox.ioc.Registry;
10 import org.jfox.ioc.exception.ComponentException;
11
12 /**
13  * 通过组件注册的ComponentName来表示引用关系
14  *
15  * @author <a HREF="mailto:young_yy@hotmail.com">Young Yang</a>
16  */

17
18 public class ComponentRefDependency implements RefDependency {
19     private Class JavaDoc type = null;
20     /**
21      * ComponentName of the ref component
22      */

23     private ComponentName refCompName;
24     private Object JavaDoc value;
25
26     public ComponentRefDependency(ComponentName refComponentName) {
27         this.refCompName = refComponentName;
28         this.type = refCompName.getType();
29     }
30
31     public Class JavaDoc getType() {
32         return type;
33     }
34
35     public String JavaDoc getLiteralValue() {
36         return refCompName.toString();
37     }
38
39     public ComponentName getRefComponentName() {
40         return refCompName;
41     }
42
43     /**
44      * 如果已经解析过,则直接返回缓存的值,否则通过ComponentName由Registry取得依赖组件的值
45      *
46      * @throws org.jfox.ioc.exception.ComponentException 如果依赖的组件没有被注册,或者生成依赖组件的实例时发生例外,则抛出ComponentException
47      */

48     public Object JavaDoc resolveValue(Registry registry) throws ComponentException {
49         if(value != null) return value;
50         value = registry.getComponentInstance(refCompName);
51         return value;
52     }
53
54     public String JavaDoc toString() {
55         return "ComponentRefParameter{" +
56                 "type=" + type.getName() +
57                 ", refCompName='" + refCompName + "'" +
58                 ", value=" + (value == null ? "NOT RESOVLED" : value.toString()) +
59                 "}";
60     }
61
62     public static void main(String JavaDoc[] args) {
63
64     }
65
66 }
67
Popular Tags