/** * Convenience method to get a service bean from the Sakai component manager. * * @param beanId The id of the service * @return The service, or null if the ID is not registered */ public Object getService(String beanId) { try { return componentManager.get(beanId); } catch (Exception e) { log.error(e); return null; } }
/** * create a component manager based on a list of component.xml * * @param configPaths a ';' seperated list of xml bean config files * @throws IOException */ public TestComponentManagerContainer(String configPaths) throws IOException { // we assume that all the jars are in the same classloader, so this will // not check for // incorrect bindings and will not fully replicate the tomcat // experience, but is an easier environment // to work within for kernel testing. // For a more complex structure we could use the kernel poms in the repo // to generate the dep list. if (ComponentManager.m_componentManager != null) { log.info("Closing existing Component Manager "); /* try { ComponentManager.m_componentManager.close(); } catch ( Throwable t ) { log.warn("Close Failed with message, safe to ignore "+t.getMessage()); } */ log.info("Closing Complete "); ComponentManager.m_componentManager = null; } log.info("Starting Component Manager with [" + configPaths + "]"); ComponentManager.setLateRefresh(true); componentManager = (SpringCompMgr) ComponentManager.getInstance(); ConfigurableApplicationContext ac = componentManager.getApplicationContext(); ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); // we could take the kernel bootstrap from from the classpath in future // rather than from // the filesystem List<Resource> config = new ArrayList<Resource>(); String[] configPath = configPaths.split(";"); for (String p : configPath) { File xml = new File(p); config.add(new FileSystemResource(xml.getCanonicalPath())); } loadComponent(ac, config, classLoader); ac.refresh(); log.debug("Finished starting the component manager"); // TODO Auto-generated constructor stub }