List of usage examples for org.springframework.context ApplicationContext getParent
@Nullable ApplicationContext getParent();
From source file:org.shept.util.SheptBeanFactoryUtils.java
public static ApplicationContext getRootContext(ApplicationContext ctx) { if (ctx.getParent() == null) { return ctx; }/*from w ww . j a va2 s .co m*/ return ctx.getParent(); }
From source file:org.opensprout.osaf.util.ApplicationContextUtils.java
public static <T> T getBeanByType(ApplicationContext applicationContext, Class<T> clazz) { Map beanMap = applicationContext.getBeansOfType(clazz); int size = beanMap.size(); if (size == 0) { if (applicationContext.getParent() != null) return getBeanByType(applicationContext.getParent(), clazz); throw new NoSuchBeanDefinitionException(clazz.getSimpleName()); }/*ww w.j a v a 2 s.com*/ if (size > 1) throw new NoSuchBeanDefinitionException( "No unique bean definition type [" + clazz.getSimpleName() + "]"); return (T) beanMap.values().iterator().next(); }
From source file:com.bstek.dorado.spring.RemovableBeanUtils.java
public static void destroyRemovableBeans(ApplicationContext applicationContext) { long start = System.currentTimeMillis(); int removed = 0; removed += doDestroyRemovableBeans(applicationContext); ApplicationContext parent = applicationContext.getParent(); if (parent != null) { removed += doDestroyRemovableBeans(parent); }/*from w w w.j a v a 2s. c om*/ logger.info(removed + " Bean(s) unregisted in " + (System.currentTimeMillis() - start) + "ms."); }
From source file:org.zkoss.spring.security.SecurityUtil.java
private static void initializeIfRequired() { if (_applicationContext != null) { return;/* w ww. ja v a2 s . com*/ } _applicationContext = SpringUtil.getApplicationContext(); Map map = new HashMap(); ApplicationContext context = _applicationContext; while (context != null) { map.putAll(context.getBeansOfType(AclService.class)); context = context.getParent(); } if (map.size() != 1) { throw new UiException( "Found incorrect number of AclService instances in application context - you must have only have one!"); } _aclService = (AclService) map.values().iterator().next(); map = _applicationContext.getBeansOfType(SidRetrievalStrategy.class); if (map.size() == 0) { _sidRetrievalStrategy = new SidRetrievalStrategyImpl(); } else if (map.size() == 1) { _sidRetrievalStrategy = (SidRetrievalStrategy) map.values().iterator().next(); } else { throw new UiException("Found incorrect number of SidRetrievalStrategy instances in application " + "context - you must have only have one!"); } map = _applicationContext.getBeansOfType(ObjectIdentityRetrievalStrategy.class); if (map.size() == 0) { _objectIdentityRetrievalStrategy = new ObjectIdentityRetrievalStrategyImpl(); } else if (map.size() == 1) { _objectIdentityRetrievalStrategy = (ObjectIdentityRetrievalStrategy) map.values().iterator().next(); } else { throw new UiException("Found incorrect number of ObjectIdentityRetrievalStrategy instances in " + "application context - you must have only have one!"); } map = _applicationContext.getBeansOfType(PermissionFactory.class); if (map.size() == 0) { permissionFactory = new DefaultPermissionFactory(); } else if (map.size() == 1) { permissionFactory = (PermissionFactory) map.values().iterator().next(); } else { throw new UiException("Found incorrect number of PermissionFactory instances in " + "application context - you must have only have one!"); } }
From source file:com.kurento.kmf.spring.RootWebApplicationContextParentRecoverer.java
@Override public void setApplicationContext(ApplicationContext applicationContext) { this.parentContext = applicationContext.getParent(); }
From source file:org.exoplatform.acceptance.lifecycle.DevelopmentInitializer.java
/** * {@inheritDoc}/* w w w .j a va 2s . co m*/ * Handle an application event. */ @Override public void onApplicationEvent(ContextRefreshedEvent event) { super.onApplicationEvent(event); ApplicationContext context = (ApplicationContext) event.getSource(); // Load data in the root context only if (context.getParent() == null) { devDataLoaderService.initializeData(); } LOGGER.info("Data are ready for development."); }
From source file:org.exoplatform.acceptance.lifecycle.ProductionInitializer.java
/** * {@inheritDoc}/* w w w . j ava 2 s.c o m*/ * Handle an application event. */ @Override public void onApplicationEvent(ContextRefreshedEvent event) { ApplicationContext context = (ApplicationContext) event.getSource(); // Execute once at the root context only if (context.getParent() == null) { if (credentialService.findByType(Credential.Type.NONE).size() == 0) { // Always load the NO CREDENTIAL entry in the repository if it doesn't exist credentialService.updateOrCreate(Credential.NONE); } // Otherwise we load its ID in our Singleton Credential.NONE.setId(credentialService.findByName(Credential.NONE.getName()).getId()); LOGGER.info("NoCredential ID : {}", Credential.NONE.getId()); // We may add an upgrade system here if necessary LOGGER.info("Data are ready for production."); } }
From source file:tomekkup.helenos.context.PostConfiguringClusterListener.java
@Override public void onApplicationEvent(ContextRefreshedEvent event) { if (isReady(event)) { ApplicationContext applicationContext = event.getApplicationContext(); ClusterConfiguration configuration = clusterConfigDao.getActive(); propagadeConfigChanges(applicationContext.getParent(), configuration.createCluster()); }//from w w w. ja v a2 s. c o m }
From source file:org.bpmscript.process.spring.ApplicationContextDefinitionConfigurationLookup.java
/** * @see org.bpmscript.process.IProperties#getProperty(java.lang.String, java.lang.String) *//*from w ww . j a va 2 s . c o m*/ @SuppressWarnings("unchecked") public IDefinitionConfiguration getDefinitionConfiguration(String definitionName) { if (context != null) { HashMap<String, IDefinitionConfiguration> beansOfType = new HashMap<String, IDefinitionConfiguration>(); ApplicationContext temp = context; while (temp != null) { beansOfType.putAll(temp.getBeansOfType(IDefinitionConfiguration.class)); temp = temp.getParent(); } Object result = beansOfType.get(prefix + definitionName); if (result != null) { return (IDefinitionConfiguration) result; } } return new DefinitionConfiguration(); }
From source file:org.cleverbus.core.conf.ConfigurationChecker.java
/** * Checks configuration./*from w w w. ja va2s .com*/ * * @param context the application context */ void checkConfiguration(ApplicationContext context) { Log.debug("Checking configuration validity ..."); Assert.state(context.getParent() != null, "ConfigurationChecker must be initialized in child context"); try { if (checkUrl) { checkLocalhostUri(); } checkPatterns(); // go through "local" checks if (checks != null) { for (ConfCheck check : checks) { check.check(); } } } catch (ConfigurationException ex) { Log.error("Configuration error", ex); // stop parent context (I don't know how to stop it in other way) ConfigurableApplicationContext rootContext = (ConfigurableApplicationContext) context.getParent(); rootContext.close(); } }