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