KickJava   Java API By Example, From Geeks To Geeks.

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


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;
7
8 import java.net.URL JavaDoc;
9 import java.util.ArrayList JavaDoc;
10 import java.util.Collections JavaDoc;
11 import java.util.HashMap JavaDoc;
12 import java.util.LinkedHashMap JavaDoc;
13 import java.util.List JavaDoc;
14 import java.util.Map JavaDoc;
15
16 import org.jfox.ioc.classloader.ClassLoaderRepository;
17 import org.jfox.ioc.depend.Dependency;
18 import org.jfox.ioc.depend.DependencyPack;
19 import org.jfox.ioc.exception.ComponentException;
20 import org.jfox.ioc.ext.ActiveComponent;
21 import org.jfox.ioc.ext.InitializableComponent;
22 import org.jfox.ioc.ext.ServicableComponent;
23 import org.jfox.ioc.logger.Logger;
24
25 /**
26  * Registry是容器的实体类,完成新建容器,注册组件,启动容器等功能。
27  * <br>
28  * 一般过程如下:
29  * <pre>
30  * Registry registry = Registry.getInstance();
31  * registry.registerComponent(...);
32  * registry.registerComponent(...);
33  * ...
34  * // 启动IoC Container,会对其中需要初始化的组件和需要启动的组件进行初始化和启动
35  * registry.start();
36  * </pre>
37  *
38  *
39  * @author <a HREF="mailto:young_yy@hotmail.com">Young Yang</a>
40  */

41
42 public class Registry {
43
44     /**
45      * IoC container 是否启动
46      */

47     private boolean started = false;
48
49     /**
50      * 日志记录
51      */

52     private Logger logger = Logger.getLogger(Registry.class.getName());
53
54     /**
55      * ClassLoader 库
56      */

57     private ClassLoaderRepository loaderRepo = new ClassLoaderRepository(new URL JavaDoc[0], Thread.currentThread().getContextClassLoader());
58
59     /**
60      * 单例实例
61      */

62     private static final Registry me = new Registry();
63     private final Repository repo = new Repository();
64
65     /**
66      * 得到Registry的单例对象
67      */

68     public static Registry getInstance() {
69         return me;
70     }
71
72     private Registry() {
73         // 设置当前线程的 ClassLoader
74
Thread.currentThread().setContextClassLoader(loaderRepo);
75     }
76
77     /**
78      * 用组件实例注册一个组件。以对象注册的组件都是单例组件。
79      * 系统根据Component的类名生成ComponentName,ComponentName的因子为类的hashCode。
80      * Type singleton 默认为 true,该组件类型只能注册一次。
81      *
82      * @see #registerComponent(Component, boolean)
83      * @param component 要注册的组件实力
84      * @throws ComponentException
85      */

86     public synchronized ComponentMeta registerComponent(Component component) throws ComponentException {
87         return registerComponent(component,false);
88     }
89
90     /**
91      * 用组件实例注册一个组件。以对象注册的组件都是单例组件。
92      * 系统根据Component的类名生成ComponentName,ComponentName的因子为类的hashCode。
93      *
94      * @param component 组件对象实例
95      * @param typeSingleton 组件类型是否单例,单例则只能注册一次
96      * @return
97      * @throws ComponentException
98      */

99     public synchronized ComponentMeta registerComponent(Component component, boolean typeSingleton) throws ComponentException {
100         ComponentMeta meta = ComponentMetaFactory.getComponentMeta(component, typeSingleton);
101         return registerComponent(meta);
102     }
103
104     /**
105      * 用组件类注册一个组件。
106      * 系统根据类implementation生成ComponentName,ComponentName的因子为implementation的hashCode。
107      * 所有参数使用默认设置:
108      * <br>
109      * 1.构造器使用不带参数的默认构造器
110      * 2.没有 setter
111      * 3.singleton 为 true
112      * 4.type singleton 为 true
113      * <br><br>
114      * 注意:该类必须实现 {@link Component} 接口
115      *
116      * @param implementation
117      * @throws ComponentException
118      */

119     public synchronized ComponentMeta registerComponent(Class JavaDoc implementation) throws ComponentException {
120         return registerComponent(ComponentName.newInstance(implementation), implementation);
121     }
122
123     public synchronized ComponentMeta registerComponent(Class JavaDoc implementation, Dependency[] constructParams) throws ComponentException {
124         return registerComponent(implementation, constructParams, DependencyPack.EMPTY_PARAMETER_PACKS, true, false);
125     }
126
127     /**
128      * 用组件类注册一个组件。
129      * 系统根据类implementation生成ComponentName,ComponentName的因子为implementation的hashCode。
130      * 所有参数使用默认设置:
131      * <br>
132      * 1.构造器使用不带参数的默认构造器
133      * 2.没有 setter
134      * 3.singleton 为 true
135      * 4.type singleton 为 true
136      * <br><br>
137      * 注意:该类必须实现 {@link Component} 接口
138      *
139      * @param implementation
140      * @throws ComponentException
141      */

142     public synchronized ComponentMeta registerComponent(Class JavaDoc implementation, Dependency[] constructorParams, DependencyPack[] setterParams, boolean singleton, boolean typeSingleton) throws ComponentException {
143         ComponentMeta meta = ComponentMetaFactory.getComponentMeta(ComponentName.newInstance(implementation), implementation, constructorParams, setterParams, singleton, typeSingleton);
144         registerComponent(meta);
145         return meta;
146
147     }
148     
149     public synchronized ComponentMeta registerComponent(ComponentName componentName,Class JavaDoc implementation) throws ComponentException {
150         return registerComponent(componentName, implementation,Dependency.EMPTY_PARAMETERS);
151     }
152
153     public synchronized ComponentMeta registerComponent(ComponentName componentName,Class JavaDoc implementation, Dependency[] constructParams) throws ComponentException {
154         return registerComponent(componentName, implementation,constructParams, DependencyPack.EMPTY_PARAMETER_PACKS, true, false);
155     }
156
157 /* public synchronized ComponentMeta registerComponent(ComponentName componentName, Parameter[] constructParams, ParameterPack[] setterParams, boolean singleton, boolean typeSingleton) throws ComponentException {
158         ComponentMeta componentMeta = ComponentMetaFactory.getComponentMeta(componentName,constructParams,setterParams,singleton,typeSingleton);
159         return registerComponent(componentMeta);
160     }*/

161
162     public synchronized ComponentMeta registerComponent(ComponentName componentName,Class JavaDoc implementation, Dependency[] constructParams, DependencyPack[] setterParams, boolean singleton, boolean typeSingleton) throws ComponentException {
163         ComponentMeta componentMeta = ComponentMetaFactory.getComponentMeta(componentName,implementation,constructParams, setterParams, singleton, typeSingleton);
164         return registerComponent(componentMeta);
165     }
166
167     /**
168      * 以 ComponentMeta 注册一个组件。ComponentMeta 对象由用户手动建立,应该使用 {@link ComponentMetaFactory} 建立ComponentMeta
169      */

170     public synchronized ComponentMeta registerComponent(ComponentMeta componentMeta) throws ComponentException {
171         doRegister(componentMeta);
172         doActive(componentMeta);
173         return componentMeta;
174     }
175
176     /**
177      * 批量注册Component,主要用于ComponentDepoyer批量注册Module的Component,
178      * 解决因为ActiveComponent导致的加载顺序问题
179      * @param componentMetas
180      * @return success component metas
181      */

182     public synchronized ComponentMeta[] registerComponentBatch(ComponentMeta[] componentMetas) {
183         List JavaDoc metas = new ArrayList JavaDoc(componentMetas.length);
184         if(componentMetas != null && componentMetas.length > 0) {
185             for(int i=0; i<componentMetas.length; i++){
186                 try {
187                     ComponentMeta meta = componentMetas[i];
188                     doRegister(meta);
189                     metas.add(meta);
190                 }
191                 catch(ComponentException e){
192                     logger.warn(e.getMessage(),e);
193                 }
194             }
195         }
196         for(int i=0;i<metas.size(); i++){
197             ComponentMeta meta = (ComponentMeta)metas.get(i);
198             try {
199                 doActive(meta);
200             }
201             catch(ComponentException e){
202                 logger.warn(e.getMessage(),e);
203             }
204         }
205         return (ComponentMeta[])metas.toArray(new ComponentMeta[metas.size()]);
206     }
207
208
209     /**
210      * 根据 ComponentName 得到 ComponentMeta
211      * @param name 组件注册名称
212      */

213     public synchronized ComponentMeta getComponentMeta(ComponentName name) throws ComponentException {
214         ComponentMeta meta = repo.getComponentMeta(name);
215         if(meta == null) {
216             throw new ComponentException("component " + name + " not found.");
217         }
218         return meta;
219     }
220
221     /**
222      * 以Component的类名注册组件。
223      * ComponentName的因子为该类的hashCode
224      *
225      * @param implementaion
226      * @return
227      * @throws ComponentException
228      */

229     public Component getComponentInstance(Class JavaDoc implementaion) throws ComponentException {
230         ComponentName name = ComponentName.newInstance(implementaion);
231         return getComponentInstance(name);
232     }
233
234     /**
235      * 以注册名称得到组件实例
236      *
237      * @param name 组件注册名称
238      * @return
239      * @throws ComponentException
240      */

241     public synchronized Component getComponentInstance(ComponentName name) throws ComponentException {
242         return getComponentInstance(name, DependencyPack.EMPTY_PARAMETER_PACKS);
243     }
244
245     /**
246      * 在生成Component Instance 之后,会马上进行 ParameterPack 的注射
247      * 主要用于有些参数在运行时才能赋值的情况
248      *
249      * @param name
250      * @param paramPacks
251      * @return
252      * @throws ComponentException
253      */

254     public synchronized Component getComponentInstance(ComponentName name, DependencyPack[] paramPacks) throws ComponentException {
255         ComponentMeta meta = null;
256         if(!isRegistered(name)) {
257             throw new ComponentException("component " + name + " not registered.");
258         }
259         meta = getComponentMeta(name);
260
261         Component comp = meta.getComponentInstance(paramPacks);
262         return comp;
263     }
264
265
266     /**
267      * 以组件注册名称注销某个组件。
268      * 如果该组件是单例的,而且是 Initializable 和/或 Serviceable,则会做 stop 和/或 destory 操作。
269      * 注销成功,返回组件的 ComponentMeta,如果该组件不存在,返回 null
270      *
271      * @see InitializableComponent
272      * @see ServicableComponent
273      * @param name 组件注册名称
274      * @throws ComponentException
275      */

276     public synchronized ComponentMeta unregisterComponent(ComponentName name) throws ComponentException {
277         logger.info("unregister component " + name);
278         ComponentMeta meta = repo.unregisterComponent(name);
279         // only stop & destroy singlton component, otherwise, must done by yourself
280
if(meta != null && meta.isSingleton()) {
281             Component comp = meta.getComponentInstance(DependencyPack.EMPTY_PARAMETER_PACKS);
282             stopComponent(meta, comp);
283             destroyComponent(meta, comp);
284         }
285         return meta;
286     }
287
288     /**
289      * 返回当前注册的组件数目
290      */

291     public int countComponents() {
292         return repo.countComponents();
293     }
294
295     /**
296      * 返回当前注册了多少类型的组件
297      */

298     public int countComponentTypes() {
299         return repo.countComponentTypes();
300     }
301
302     /**
303      * 检测该类型的组件是否注册到Registry中。不检查其子类
304      * @param implementation
305      */

306     public boolean isRegisteredImplemetation(Class JavaDoc implementation) {
307         return repo.isRegisteredImplemetation(implementation);
308     }
309
310     /**
311      * 检测该ComponentName 是否已经注册
312      * @param name 注册名称
313      */

314     public boolean isRegistered(ComponentName name) {
315         return repo.isRegistered(name);
316     }
317
318     /**
319      * 得到所有已注册的组件名称数组
320      */

321     public synchronized List JavaDoc<ComponentName> getAllComponentNames() {
322         return repo.getAllComponentNames();
323     }
324
325     public synchronized List JavaDoc<ComponentMeta> getAllComponentMetas() {
326         return repo.getAllComponentMetas();
327     }
328
329
330     /**
331      * 得到以该类注册的所有组件,包括以该类的子类注册的组件
332      *
333      * @param type 类名
334      */

335     public List JavaDoc<ComponentName> getComponentNamesByImplemetation(Class JavaDoc type) {
336         return repo.getComponentNamesByImplemetation(type);
337     }
338
339     /**
340      * 得到最先以该类注册的组件名称,包括以该类子类注册的组件。
341      * 在根据参数类型自动寻找依赖的组件时,需要用到。
342      *
343      * @param implementaion 组件类
344      */

345     public synchronized ComponentName getFirstComponentNameByImplemetation(Class JavaDoc implementaion) {
346         return repo.getFirstComponentNameByType(implementaion);
347     }
348
349     /**
350      * 得到最先以该类注册的组件名称,包括以该类子类注册的组件。
351      * @param implementaion 组件类
352      */

353     public ComponentName getLastComponentNameByImplemetation(Class JavaDoc implementaion) {
354         return repo.getLastComponentNameByType(implementaion);
355     }
356
357     /**
358      * 启动 Registry,将对注册到其中的 Initializable 和 Serviceable 的的组件进行初始化和启动
359      */

360     public synchronized void start() {
361         if(started) return;
362         logger.info("start Registry.");
363         List JavaDoc<ComponentMeta> compMetas = new ArrayList JavaDoc<ComponentMeta>(repo.getAllComponentMetas());
364         Collections.sort(compMetas);
365
366         for(ComponentMeta meta : compMetas){
367             try {
368                 Component comp = meta.getComponentInstance(DependencyPack.EMPTY_PARAMETER_PACKS);
369                 try {
370                     initComponent(meta, comp);
371                 }
372                 catch(ComponentException e) {
373                     logger.warn("init component error", e);
374                 }
375                 try {
376                     startComponent(meta, comp);
377                 }
378                 catch(ComponentException e) {
379                     logger.warn("start component error", e);
380                 }
381             }
382             catch(Exception JavaDoc e) {
383                 logger.warn("get component instance " + meta.getComponentName() + "failed.", e);
384             }
385         }
386         started = true;
387     }
388
389     /**
390      * 停止 Registry,将对注册到其中的 Initializable 和 Serviceable 的的组件进行销毁和停止
391      */

392     public synchronized void stop() {
393         if(started == false) return;
394         logger.info("stop Registry.");
395         List JavaDoc<ComponentMeta> compMetas = new ArrayList JavaDoc<ComponentMeta>(repo.getAllComponentMetas());
396         Collections.sort(compMetas);
397         Collections.reverse(compMetas);
398
399         for(ComponentMeta meta : compMetas){
400             try {
401                 //只有 singleton 的 Component 才主动 stop & destroy,其它则等待它的引用来 stop & destroy 它
402
if(meta.isSingleton()) {
403                     Component comp = meta.getComponentInstance(DependencyPack.EMPTY_PARAMETER_PACKS);
404                     if(ServicableComponent.class.isAssignableFrom(meta.getComponentImplementation())) {
405                         ServicableComponent scomp = (ServicableComponent) comp;
406                         if(scomp.isStarted()) {
407                             scomp.stop();
408                         }
409                     }
410                     if(InitializableComponent.class.isAssignableFrom(meta.getComponentImplementation())) {
411                         InitializableComponent dcomp = (InitializableComponent) comp;
412                         dcomp.destroy();
413                     }
414                 }
415             }
416             catch(Exception JavaDoc e) {
417                 e.printStackTrace();
418             }
419         }
420         started = false;
421     }
422
423     /**
424      * Registry 是否启动
425      */

426     public synchronized boolean isStarted() {
427         return started;
428     }
429
430     /**
431      * 使用 Registry 的类装载库来加载类
432      * @param impl 要加载的类
433      * @throws ClassNotFoundException
434      */

435     public Class JavaDoc loadClass(String JavaDoc impl) throws ClassNotFoundException JavaDoc {
436         return loaderRepo.loadClass(impl);
437     }
438
439     /**
440      * 往 Registry 的类装载库添加类路径
441      * @param url 可以是 jar 包的路径,或者 class 根目录
442      */

443     public void addLibraryURL(URL JavaDoc url) {
444         loaderRepo.addURL(url);
445     }
446
447     /**
448      * 得到 Registry 的类加载库
449      * @return
450      */

451     public ClassLoaderRepository getClassLoaderRepository() {
452         return loaderRepo;
453     }
454
455     /**
456      * 注册一个组件
457      * @param meta
458      * @throws ComponentException
459      */

460     private synchronized void doRegister(ComponentMeta meta) throws ComponentException {
461         logger.info("register component " + meta.getComponentName());
462         repo.registerComponent(meta);
463         // set registry
464
meta.setRegistry(this);
465         // doActive by registerComponent
466
// doActive(meta);
467
}
468
469     private synchronized void doActive(ComponentMeta meta) throws ComponentException{
470         // instance the component immediately
471
if(ActiveComponent.class.isAssignableFrom(meta.getComponentImplementation())) {
472             getComponentInstance(meta.getComponentName());
473         }
474
475     }
476
477     /**
478      * 初始化组件
479      * @param meta
480      * @param comp
481      * @throws ComponentException
482      */

483     void initComponent(ComponentMeta meta, Component comp) throws ComponentException {
484         if(InitializableComponent.class.isAssignableFrom(comp.getClass())) {
485             InitializableComponent icomp = ((InitializableComponent) comp);
486             try {
487                 logger.info("initializing component " + meta.getComponentName());
488                 icomp.init();
489                 logger.info("initialize component " + meta.getComponentName() + ", OK!");
490             }
491             catch(Exception JavaDoc e) {
492                 logger.warn("initialize component " + meta.getComponentName() + " failed.", e);
493                 throw new ComponentException(e);
494             }
495         }
496     }
497
498
499     /**
500      * 启动组件
501      * @param meta
502      * @param comp
503      * @throws ComponentException
504      */

505     void startComponent(ComponentMeta meta, Component comp) throws ComponentException {
506         // try to start component
507
if(ServicableComponent.class.isAssignableFrom(meta.getComponentImplementation())) {
508             ServicableComponent scomp = (ServicableComponent) comp;
509             try {
510                 if(!scomp.isStarted()) {
511                     logger.info("starting component " + meta.getComponentName());
512                     scomp.start();
513                     logger.info("start component " + meta.getComponentName() + ", OK!");
514                 }
515             }
516             catch(Exception JavaDoc e) {
517                 logger.info("start component " + meta.getComponentName() + " failed.", e);
518                 throw new ComponentException(e);
519             }
520         }
521     }
522
523     /**
524      * 停止组件
525      * @param meta
526      * @param comp
527      * @throws ComponentException
528      */

529     void stopComponent(ComponentMeta meta, Component comp) throws ComponentException {
530         if(comp instanceof ServicableComponent) {
531             try {
532                 ServicableComponent scomp = ((ServicableComponent) comp);
533                 if(scomp.isStarted()) {
534                     logger.info("stoping component " + meta.getComponentName());
535                     scomp.stop();
536                     logger.info("stop component " + meta.getComponentName() + ", OK!");
537                 }
538             }
539             catch(Exception JavaDoc e) {
540                 logger.warn("stop component " + meta.getComponentName() + " failed.", e);
541                 throw new ComponentException(e);
542             }
543         }
544     }
545
546     /**
547      * 销毁组件
548      * @param meta
549      * @param comp
550      * @throws org.jfox.ioc.exception.ComponentException
551      */

552     void destroyComponent(ComponentMeta meta, Component comp) throws ComponentException {
553         if(comp instanceof InitializableComponent) {
554             try {
555                 InitializableComponent scomp = ((InitializableComponent) comp);
556                 logger.info("destroying component " + meta.getComponentName());
557                 scomp.destroy();
558                 logger.info("destroy component " + meta.getComponentName() + ", OK!");
559             }
560             catch(Exception JavaDoc e) {
561                 logger.warn("destroy component " + meta.getComponentName() + " failed.", e);
562                 throw new ComponentException(e);
563             }
564         }
565     }
566
567     class Repository {
568         /**
569          * 存储 ComponentName=>ComponentMeta 映射关系
570          */

571         private Map JavaDoc<ComponentName, ComponentMeta> components = new LinkedHashMap JavaDoc<ComponentName, ComponentMeta>();
572         /**
573          * 存储 Implementation=>counter 的映射关系
574          * 可以提供一个组件类是否注册,以及一个组件类注册了多少次查询
575          */

576         private Map JavaDoc<Class JavaDoc, List JavaDoc<ComponentName>> compCounts = new HashMap JavaDoc<Class JavaDoc, List JavaDoc<ComponentName>>();
577
578         Repository() {
579         }
580
581         public synchronized void registerComponent(ComponentMeta meta) throws ComponentException {
582             ComponentName name = meta.getComponentName();
583             if(isRegistered(name)) {
584                 throw new ComponentException("Component " + name + " has already registered.");
585             }
586             else { // type singleton check
587
if(meta.isTypeSingleton()) {
588                     // have register this type
589
if(isRegisteredImplemetation(meta.getComponentImplementation())) {
590                         throw new ComponentException(meta + " is type singleton, but this type has already been registered.");
591                     }
592                 }
593                 else {
594                     // 如果先注册一个 TypeSingleton true ,然后注册一个 TypeSingleton false,也应该报错
595
if(isRegisteredImplemetation(meta.getComponentImplementation())) {
596                         List JavaDoc<ComponentName> names = getComponentNamesByImplemetation(meta.getComponentImplementation());
597                         // just only check the last Component
598
ComponentName _name = names.get(names.size() - 1);
599                         if(components.get(_name).isTypeSingleton()) {
600                             throw new ComponentException("a component of this type has already been registered before " + _name.toString());
601                         }
602                     }
603                 }
604             }
605
606             List JavaDoc<ComponentName> metas;
607             if(isRegisteredImplemetation(meta.getComponentImplementation())) {
608                 metas = (List JavaDoc<ComponentName>) (compCounts.get(meta.getComponentImplementation()));
609             }
610             else {
611                 metas = new ArrayList JavaDoc<ComponentName>();
612                 compCounts.put(meta.getComponentImplementation(), metas);
613             }
614             metas.add(name);
615
616             components.put(name, meta);
617         }
618
619         public synchronized ComponentMeta unregisterComponent(ComponentName name) throws ComponentException {
620             if(isRegistered(name)) {
621                 ComponentMeta meta = (ComponentMeta) components.remove(name);
622
623                 List JavaDoc<ComponentName> names = ((List JavaDoc<ComponentName>) compCounts.get(meta.getComponentImplementation()));
624                 names.remove(name);
625
626                 if(names.isEmpty()) {
627                     compCounts.remove(meta.getComponentImplementation());
628                 }
629                 return meta;
630             }
631             return null;
632         }
633
634         /**
635          * 根据 ComponentName 得到 ComponentMeta
636          *
637          * @param name 组件注册名称
638          */

639         public synchronized ComponentMeta getComponentMeta(ComponentName name) {
640             return (ComponentMeta) components.get(name);
641         }
642
643         public boolean isRegistered(ComponentName name) {
644             return components.containsKey(name);
645         }
646
647         public boolean isRegisteredImplemetation(Class JavaDoc clz) {
648             return compCounts.containsKey(clz);
649         }
650
651         /**
652          * 得到最先以该类注册的组件名称,包括以该类子类注册的组件。
653          *
654          * @param type 组件类
655          */

656         public ComponentName getLastComponentNameByType(Class JavaDoc type) {
657             List JavaDoc names = new ArrayList JavaDoc(components.keySet());
658             for(int i = names.size() - 1; i >= 0; i--) {
659                 ComponentName name = (ComponentName) names.get(i);
660                 if(name.getType().isAssignableFrom(type)) {
661                     return name;
662                 }
663             }
664             return null;
665         }
666
667         /**
668          * 得到最先以该类注册的组件名称,包括以该类子类注册的组件。
669          * 在根据参数类型自动寻找依赖的组件时,需要用到。
670          *
671          * @param type 组件类
672          */

673         public synchronized ComponentName getFirstComponentNameByType(Class JavaDoc type) {
674             for(ComponentName name : components.keySet()) {
675                 if(type.isAssignableFrom(name.getType())) {
676                     return name;
677                 }
678             }
679             return null;
680         }
681
682         /**
683          * 返回当前注册的组件数目
684          */

685         public synchronized int countComponents() {
686             return components.size();
687         }
688
689         /**
690          * 返回当前注册了多少类型的组件
691          */

692         public synchronized int countComponentTypes() {
693             return compCounts.size();
694         }
695
696         /**
697          * 得到所有已注册的组件名称数组
698          */

699         public synchronized List JavaDoc<ComponentName> getAllComponentNames() {
700             return Collections.unmodifiableList(new ArrayList JavaDoc<ComponentName>(components.keySet()));
701         }
702
703         public synchronized List JavaDoc<ComponentMeta> getAllComponentMetas() {
704             return Collections.unmodifiableList(new ArrayList JavaDoc<ComponentMeta>(components.values()));
705         }
706
707         /**
708          * 得到以该类注册的所有组件,包括以该类的子类注册的组件
709          *
710          * @param type 类名
711          */

712         public List JavaDoc<ComponentName> getComponentNamesByImplemetation(Class JavaDoc type) {
713             if(isRegisteredImplemetation(type)) {
714                 return compCounts.get(type);
715             }
716             else {
717                 return new ArrayList JavaDoc<ComponentName>();
718             }
719         }
720
721     }
722
723 }
724
725
Popular Tags