KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > container > util > ContainerUtil


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

5 package org.exoplatform.container.util;
6
7 import java.util.Collection JavaDoc;
8 import java.util.Collections JavaDoc;
9 import java.util.Iterator JavaDoc;
10 import org.exoplatform.container.ExoContainer;
11 import org.exoplatform.container.configuration.ConfigurationManager;
12 import org.exoplatform.container.configuration.ServiceConfiguration;
13 import org.exoplatform.container.groovy.GroovyManager;
14 /**
15  * @author Tuan Nguyen (tuan08@users.sourceforge.net)
16  * @since Oct 28, 2004
17  * @version $Id: ContainerUtil.java,v 1.1 2004/10/29 01:55:23 tuan08 Exp $
18  */

19 public class ContainerUtil {
20   static public Collection JavaDoc getConfigurationURL(String JavaDoc configuration) throws Exception JavaDoc {
21     ClassLoader JavaDoc cl = Thread.currentThread().getContextClassLoader() ;
22     Collection JavaDoc c = Collections.list(cl.getResources(configuration)) ;
23     return c ;
24   }
25   
26   static public void populate(ExoContainer container , ConfigurationManager conf) {
27     Collection JavaDoc serviceConfigurations = conf.getServiceConfigurations();
28     if(serviceConfigurations == null) return;
29     Iterator JavaDoc i = serviceConfigurations.iterator() ;
30     ClassLoader JavaDoc loader = Thread.currentThread().getContextClassLoader() ;
31     while(i.hasNext()) {
32       ServiceConfiguration sconf = (ServiceConfiguration) i.next() ;
33       String JavaDoc type = sconf.getServiceType() ;
34       String JavaDoc key = sconf.getServiceKey() ;
35       try {
36         Class JavaDoc classType = loader.loadClass(type) ;
37         if(key == null) {
38           //container.registerManageableComponentImplementation(classType) ;
39
container.registerComponentImplementation(classType) ;
40         } else {
41           try {
42             Class JavaDoc keyType = loader.loadClass(key) ;
43             //container.registerManageableComponentImplementation(keyType, classType) ;
44
container.registerComponentImplementation(keyType, classType) ;
45           } catch (Exception JavaDoc ex) {
46             //container.registerManageableComponentImplementation(key, classType) ;
47
container.registerComponentImplementation(key, classType) ;
48           }
49         }
50       } catch (ClassNotFoundException JavaDoc ex) {
51         ex.printStackTrace() ;
52       }
53     }
54   }
55
56   static public void populateGroovy(ExoContainer container , ConfigurationManager conf) throws Exception JavaDoc {
57     Iterator JavaDoc i = conf.getGroovyServiceConfigurations().iterator() ;
58     GroovyManager gmanager = container.getGroovyManager() ;
59     while(i.hasNext()) {
60       ServiceConfiguration sconf = (ServiceConfiguration) i.next() ;
61       String JavaDoc type = sconf.getServiceType() ;
62       gmanager.getObject(type) ;
63     }
64   }
65 }
66
Popular Tags