List of usage examples for org.springframework.context ApplicationContext getParent
@Nullable ApplicationContext getParent();
From source file:org.sakaiproject.blti.ProviderServlet.java
@Override public void init(ServletConfig config) throws ServletException { super.init(config); siteEmailPreferenceSetter = (SiteEmailPreferenceSetter) ComponentManager.getInstance() .get("org.sakaiproject.lti.api.SiteEmailPreferenceSetter"); if (siteEmailPreferenceSetter == null) { throw new ServletException("Failed to set siteEmailPreferenceSetter."); }/*from w w w . j a v a 2 s .c o m*/ siteMembershipUpdater = (SiteMembershipUpdater) ComponentManager.getInstance() .get("org.sakaiproject.lti.api.SiteMembershipUpdater"); if (siteMembershipUpdater == null) { throw new ServletException("Failed to set siteMembershipUpdater."); } siteMembershipsSynchroniser = (SiteMembershipsSynchroniser) ComponentManager.getInstance() .get("org.sakaiproject.lti.api.SiteMembershipsSynchroniser"); if (siteMembershipsSynchroniser == null) { throw new ServletException("Failed to set siteMembershipsSynchroniser."); } userFinderOrCreator = (UserFinderOrCreator) ComponentManager.getInstance() .get("org.sakaiproject.lti.api.UserFinderOrCreator"); if (userFinderOrCreator == null) { throw new ServletException("Failed to set userFinderOrCreator."); } userPictureSetter = (UserPictureSetter) ComponentManager.getInstance() .get("org.sakaiproject.lti.api.UserPictureSetter"); if (userPictureSetter == null) { throw new ServletException("Failed to set userPictureSettter."); } userLocaleSetter = (UserLocaleSetter) ComponentManager.getInstance() .get("org.sakaiproject.lti.api.UserLocaleSetter"); if (userLocaleSetter == null) { throw new ServletException("Failed to set userLocaleSettter."); } ltiService = (LTIService) ComponentManager.getInstance().get("org.sakaiproject.lti.api.LTIService"); if (ltiService == null) { throw new ServletException("Failed to set ltiService."); } ApplicationContext ac = WebApplicationContextUtils.getWebApplicationContext(config.getServletContext()); // load all instance of BLTIProcessor in component mgr by type detection Collection processors = ac.getParent().getBeansOfType(BLTIProcessor.class).values(); bltiProcessors = new ArrayList(processors); // sort in using getOrder() method // sort them so the execution order is determined consistenly - by getOrder() Collections.sort(bltiProcessors, new Comparator() { public int compare(Object o1, Object o2) { return ((Comparable) ((BLTIProcessor) (o1)).getOrder()) .compareTo(((BLTIProcessor) (o2)).getOrder()); } }); }
From source file:org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.java
private ApplicationConfigurationProperties extract(ApplicationContext context) { Map<String, ContextConfigurationProperties> contextProperties = new HashMap<>(); ApplicationContext target = context; while (target != null) { contextProperties.put(target.getId(), describeConfigurationProperties(target, getObjectMapper())); target = target.getParent(); }/*w w w . ja v a2 s.co m*/ return new ApplicationConfigurationProperties(contextProperties); }
From source file:org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.java
private ContextConfigurationProperties describeConfigurationProperties(ApplicationContext context, ObjectMapper mapper) {//from w ww . j a va 2 s. c om ConfigurationBeanFactoryMetadata beanFactoryMetadata = getBeanFactoryMetadata(context); Map<String, Object> beans = getConfigurationPropertiesBeans(context, beanFactoryMetadata); Map<String, ConfigurationPropertiesBeanDescriptor> beanDescriptors = new HashMap<>(); beans.forEach((beanName, bean) -> { String prefix = extractPrefix(context, beanFactoryMetadata, beanName); beanDescriptors.put(beanName, new ConfigurationPropertiesBeanDescriptor(prefix, sanitize(prefix, safeSerialize(mapper, bean, prefix)))); }); return new ContextConfigurationProperties(beanDescriptors, (context.getParent() != null) ? context.getParent().getId() : null); }
From source file:org.springframework.boot.actuate.endpoint.ConfigurationPropertiesReportEndpoint.java
private Map<String, Object> extract(ApplicationContext context, ObjectMapper mapper) { Map<String, Object> result = new HashMap<String, Object>(); ConfigurationBeanFactoryMetaData beanFactoryMetaData = getBeanFactoryMetaData(context); Map<String, Object> beans = getConfigurationPropertiesBeans(context, beanFactoryMetaData); for (Map.Entry<String, Object> entry : beans.entrySet()) { String beanName = entry.getKey(); Object bean = entry.getValue(); Map<String, Object> root = new HashMap<String, Object>(); String prefix = extractPrefix(context, beanFactoryMetaData, beanName, bean); root.put("prefix", prefix); root.put("properties", sanitize(safeSerialize(mapper, bean, prefix))); result.put(beanName, root);//ww w . j a v a2s . c o m } if (context.getParent() != null) { result.put("parent", extract(context.getParent(), mapper)); } return result; }
From source file:org.springframework.boot.actuate.endpoint.jmx.EndpointMBeanExporter.java
private boolean parentContextContainsSameBean(ApplicationContext applicationContext, String beanKey) { if (applicationContext.getParent() != null) { try {//from www. ja va2s . com this.applicationContext.getParent().getBean(beanKey, Endpoint.class); return true; } catch (BeansException ex) { return parentContextContainsSameBean(applicationContext.getParent(), beanKey); } } return false; }
From source file:org.springframework.test.context.web.AbstractGenericWebContextLoader.java
/** * Configures web resources for the supplied web application context (WAC). * <h4>Implementation Details</h4> * <p>If the supplied WAC has no parent or its parent is not a WAC, the * supplied WAC will be configured as the Root WAC (see "<em>Root WAC * Configuration</em>" below).//ww w . j av a 2 s . c o m * <p>Otherwise the context hierarchy of the supplied WAC will be traversed * to find the top-most WAC (i.e., the root); and the {@link ServletContext} * of the Root WAC will be set as the {@code ServletContext} for the supplied * WAC. * <h4>Root WAC Configuration</h4> * <ul> * <li>The resource base path is retrieved from the supplied * {@code WebMergedContextConfiguration}.</li> * <li>A {@link ResourceLoader} is instantiated for the {@link MockServletContext}: * if the resource base path is prefixed with "{@code classpath:}", a * {@link DefaultResourceLoader} will be used; otherwise, a * {@link FileSystemResourceLoader} will be used.</li> * <li>A {@code MockServletContext} will be created using the resource base * path and resource loader.</li> * <li>The supplied {@link GenericWebApplicationContext} is then stored in * the {@code MockServletContext} under the * {@link WebApplicationContext#ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE} key.</li> * <li>Finally, the {@code MockServletContext} is set in the * {@code WebApplicationContext}.</li> * @param context the web application context for which to configure the web resources * @param webMergedConfig the merged context configuration to use to load the web application context */ protected void configureWebResources(GenericWebApplicationContext context, WebMergedContextConfiguration webMergedConfig) { ApplicationContext parent = context.getParent(); // If the WebApplicationContext has no parent or the parent is not a WebApplicationContext, // set the current context as the root WebApplicationContext: if (parent == null || (!(parent instanceof WebApplicationContext))) { String resourceBasePath = webMergedConfig.getResourceBasePath(); ResourceLoader resourceLoader = (resourceBasePath.startsWith(ResourceLoader.CLASSPATH_URL_PREFIX) ? new DefaultResourceLoader() : new FileSystemResourceLoader()); ServletContext servletContext = new MockServletContext(resourceBasePath, resourceLoader); servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, context); context.setServletContext(servletContext); } else { ServletContext servletContext = null; // Find the root WebApplicationContext while (parent != null) { if (parent instanceof WebApplicationContext && !(parent.getParent() instanceof WebApplicationContext)) { servletContext = ((WebApplicationContext) parent).getServletContext(); break; } parent = parent.getParent(); } Assert.state(servletContext != null, "Failed to find root WebApplicationContext in the context hierarchy"); context.setServletContext(servletContext); } }
From source file:org.springframework.ui.context.support.UiApplicationContextUtils.java
/** * Initialize the ThemeSource for the given application context, * autodetecting a bean with the name "themeSource". If no such * bean is found, a default (empty) ThemeSource will be used. * @param context current application context * @return the initialized theme source (will never be {@code null}) * @see #THEME_SOURCE_BEAN_NAME/*from w ww .ja v a 2 s .c om*/ */ public static ThemeSource initThemeSource(ApplicationContext context) { if (context.containsLocalBean(THEME_SOURCE_BEAN_NAME)) { ThemeSource themeSource = context.getBean(THEME_SOURCE_BEAN_NAME, ThemeSource.class); // Make ThemeSource aware of parent ThemeSource. if (context.getParent() instanceof ThemeSource && themeSource instanceof HierarchicalThemeSource) { HierarchicalThemeSource hts = (HierarchicalThemeSource) themeSource; if (hts.getParentThemeSource() == null) { // Only set parent context as parent ThemeSource if no parent ThemeSource // registered already. hts.setParentThemeSource((ThemeSource) context.getParent()); } } if (logger.isDebugEnabled()) { logger.debug("Using ThemeSource [" + themeSource + "]"); } return themeSource; } else { // Use default ThemeSource to be able to accept getTheme calls, either // delegating to parent context's default or to local ResourceBundleThemeSource. HierarchicalThemeSource themeSource = null; if (context.getParent() instanceof ThemeSource) { themeSource = new DelegatingThemeSource(); themeSource.setParentThemeSource((ThemeSource) context.getParent()); } else { themeSource = new ResourceBundleThemeSource(); } if (logger.isDebugEnabled()) { logger.debug("Unable to locate ThemeSource with name '" + THEME_SOURCE_BEAN_NAME + "': using default [" + themeSource + "]"); } return themeSource; } }
From source file:org.springframework.xd.dirt.module.ModuleDeployer.java
@Override public void setApplicationContext(ApplicationContext context) { this.context = context; this.globalContext = context.getParent().getParent(); }