/** * {@inheritDoc} */ public void close() { m_hasBeenClosed = true; if (!lateRefresh) { m_ac.stop(); } if(m_ac.isActive()) { m_ac.publishEvent(new SakaiComponentEvent(this, SakaiComponentEvent.Type.STOPPING)); } m_ac.close(); }
/** * {@inheritDoc} */ public boolean contains(String ifaceName) { boolean found = m_ac.containsBeanDefinition(ifaceName); return found; }
/** * {@inheritDoc} */ public void loadComponent(String ifaceName, Object component) { // Spring doesn't list these in getBeanDefinitionNames, so we keep track m_loadedComponents.add(ifaceName); m_ac.getBeanFactory().registerSingleton(ifaceName, component); }
checkSecurityPath(); m_ac = new SakaiApplicationContext(); m_ac.setInitialSingletonNames(CONFIGURATION_COMPONENTS); configLocationList.add("file:" + localConfigLocation); m_ac.setConfigLocations(configLocationList.toArray(new String[0])); try { m_ac.refresh(); m_ac.start(); m_ac.publishEvent(new SakaiComponentEvent(this, SakaiComponentEvent.Type.STARTED)); } catch (Exception e) { if (Boolean.valueOf(System.getProperty(SHUTDOWN_ON_ERROR, "false"))) {
/** * Load component manager configurations. A more normal hook for this is * the "refreshBeanFactory" method, but it's declared final by GenericApplicationContext. */ protected void prepareBeanFactory(ConfigurableListableBeanFactory beanFactory) { super.prepareBeanFactory(beanFactory); try { loadBeanDefinitions(beanFactory); } catch (IOException e) { throw new ApplicationContextException("I/O error parsing XML document for application context [" + getDisplayName() + "]", e); } }
/** * {@inheritDoc} */ public Object get(String ifaceName) { Object component = null; try { component = m_ac.getBean(ifaceName); } catch (NoSuchBeanDefinitionException e) { // This is an expected outcome, we don't usually want logs if (log.isDebugEnabled()) { log.debug("get(" + ifaceName + "): " + e, e); } } catch (Exception e) { log.error("get(" + ifaceName + "): ", e); } return component; }
/** * Before post-processing, load beans which have declared that they want to add post-processors * dynamically. */ protected void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) { invokePostProcessorCreators(beanFactory); super.postProcessBeanFactory(beanFactory); }
/** * {@inheritDoc} */ public Set getRegisteredInterfaces() { Set rv = new HashSet(); // get the registered ones String[] names = m_ac.getBeanDefinitionNames(); for (int i = 0; i < names.length; i++) { rv.add(names[i]); } // add the loaded ones for (Iterator iLoaded = m_loadedComponents.iterator(); iLoaded .hasNext();) { String loaded = (String) iLoaded.next(); rv.add(loaded); } return rv; }
/** * Add bean-created post processors. * @param beanFactory */ public void invokePostProcessorCreators(ConfigurableListableBeanFactory beanFactory) { String[] postProcessorCreatorNames = beanFactory.getBeanNamesForType(BeanFactoryPostProcessorCreator.class, false, false); for (int i = 0; i < postProcessorCreatorNames.length; i++) { BeanFactoryPostProcessorCreator postProcessorCreator = (BeanFactoryPostProcessorCreator)beanFactory.getBean(postProcessorCreatorNames[i]); for (BeanFactoryPostProcessor beanFactoryPostProcessor : postProcessorCreator.getBeanFactoryPostProcessors()) { addBeanFactoryPostProcessor(beanFactoryPostProcessor); } } }
/** * Load initial beans before going through the default logic. */ protected void onRefresh() throws BeansException { if (initialSingletonNames != null) { for (int i = 0; i < initialSingletonNames.length; i++) { getBean(initialSingletonNames[i]); } } super.onRefresh(); }
/** * {@inheritDoc} */ public <T> T get(Class<T> iface) { T component = null; try { component = m_ac.getBean(iface.getName(), iface); } catch (NoSuchBeanDefinitionException e) { // This is an expected outcome, we don't usually want logs if (log.isDebugEnabled()) { log.debug("get(" + iface.getName() + "): " + e, e); } } catch (Exception e) { log.error("get(" + iface.getName() + "): ", e); } return component; }
/** * {@inheritDoc} */ public boolean contains(Class iface) { boolean found = m_ac.containsBeanDefinition(iface.getName()); return found; }
/** * {@inheritDoc} */ public void loadComponent(Class iface, Object component) { // Spring doesn't list these in getBeanDefinitionNames, so we keep track m_loadedComponents.add(iface.getName()); m_ac.getBeanFactory().registerSingleton(iface.getName(), component); }