KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfox > ioc > ComponentContext


1 package org.jfox.ioc;
2
3 import java.util.Collections JavaDoc;
4 import java.util.HashMap JavaDoc;
5 import java.util.Iterator JavaDoc;
6
7 /**
8  * 组件的上下文环境,在取得组件实例的时候由Registry设置
9  *
10  * @author <a HREF="mailto:yy.young@gmail.com">Young Yang</a>
11  */

12
13 public class ComponentContext {
14
15     private String JavaDoc module;
16     
17     /**
18      * 组件的所在的模块
19      */

20     private String JavaDoc moduleDesc;
21
22     /**
23      * 组件的模块所在的目录
24      */

25     private String JavaDoc moduleDir;
26
27     /**
28      * 组件是否单例
29      */

30     private boolean singleton;
31
32     /**
33      * 组件是否类别单例
34      */

35     private boolean typeSingleton;
36
37     /**
38      * 用户设置的属性
39      */

40     private HashMap JavaDoc attributes = new HashMap JavaDoc();
41
42     private Registry registry;
43
44     public ComponentContext() {
45     }
46     
47     /**
48      * @return Returns the module.
49      */

50     public String JavaDoc getModule() {
51         return module;
52     }
53
54     /**
55      * @param module The module to set.
56      */

57     void setModule(String JavaDoc module) {
58         this.module = module;
59     }
60
61     public String JavaDoc getModuleDesc() {
62         return moduleDesc;
63     }
64
65     void setModuleDesc(String JavaDoc module) {
66         this.moduleDesc = module;
67     }
68
69     public String JavaDoc getModuleDir() {
70         return moduleDir;
71     }
72
73     void setModuleDir(String JavaDoc moduleDir) {
74         this.moduleDir = moduleDir;
75     }
76
77     public boolean isSingleton() {
78         return singleton;
79     }
80
81     void setSingleton(boolean singleton) {
82         this.singleton = singleton;
83     }
84
85     public boolean isTypeSingleton() {
86         return typeSingleton;
87     }
88
89     void setTypeSingleton(boolean typeSingleton) {
90         this.typeSingleton = typeSingleton;
91     }
92
93     /**
94      * 得到所有自定义属性的名称
95      */

96     public Iterator JavaDoc getAttributeNames() {
97         return Collections.unmodifiableMap(new HashMap JavaDoc(attributes)).keySet()
98                 .iterator();
99     }
100
101     /**
102      * 设置组件上下文的用户自定义属性。如果该属性名称已经存在,则会覆盖
103      *
104      * @param name
105      * @param value
106      */

107     public synchronized void setAttribute(String JavaDoc name, Object JavaDoc value) {
108         attributes.put(name, value);
109     }
110
111     /**
112      * 删除一个已经设置的用户自定义属性
113      *
114      * @param name
115      * @return 返回删除的自定义属性的值
116      */

117     public synchronized Object JavaDoc removeAttribute(String JavaDoc name) {
118         return attributes.remove(name);
119     }
120
121     /**
122      * 根据属性名称取得自定义属性的值
123      *
124      * @param name
125      * @return 返回自定义属性的值
126      */

127     public Object JavaDoc getAttribute(String JavaDoc name) {
128         return attributes.get(name);
129     }
130
131     public Registry getRegistry() {
132         return registry;
133     }
134
135     void setRegistry(Registry registry) {
136         this.registry = registry;
137     }
138
139     public static void main(String JavaDoc[] args) {
140
141     }
142 }
143
144
Popular Tags