Example usage for org.springframework.context.support ClassPathXmlApplicationContext setDisplayName

List of usage examples for org.springframework.context.support ClassPathXmlApplicationContext setDisplayName

Introduction

In this page you can find the example usage for org.springframework.context.support ClassPathXmlApplicationContext setDisplayName.

Prototype

public void setDisplayName(String displayName) 

Source Link

Document

Set a friendly name for this context.

Usage

From source file:org.cleverbus.core.common.extension.AbstractExtensionConfigurationLoader.java

private void loadExtension(String extConfigLocation, int extNumber) throws Exception {
    Log.debug("new extension context for '" + extConfigLocation + "' started ...");

    ClassPathXmlApplicationContext extContext = new ClassPathXmlApplicationContext(parentContext);
    extContext.setId("CleverBus extension nr. " + extNumber);
    extContext.setDisplayName("CleverBus extension context for '" + extConfigLocation + '"');
    extContext.setConfigLocation(extConfigLocation);

    extContext.refresh();//from   w ww. ja  v  a  2 s . c om

    // add routes into Camel context
    if (isAutoRouteAdding()) {
        Map<String, AbstractExtRoute> beansOfType = extContext.getBeansOfType(AbstractExtRoute.class);
        for (Map.Entry<String, AbstractExtRoute> entry : beansOfType.entrySet()) {
            AbstractExtRoute route = entry.getValue();

            // note: route with existing route ID will override the previous one
            //  it's not possible automatically change route ID before adding to Camel context
            camelContext.addRoutes(route);
        }
    }

    Log.debug("new extension context for '" + extConfigLocation + "' was successfully created");
}

From source file:org.entando.entando.plugins.jpcomponentinstaller.aps.system.services.installer.DefaultComponentInstaller.java

private ApplicationContext loadContext(String[] configLocations, URLClassLoader cl, String contextDisplayName,
        Properties properties) throws Exception {
    ServletContext servletContext = ((ConfigurableWebApplicationContext) this._applicationContext)
            .getServletContext();//from w w  w. j ava  2s  .c o m
    //if plugin's classes have been loaded we can go on
    List<ClassPathXmlApplicationContext> ctxList = (List<ClassPathXmlApplicationContext>) servletContext
            .getAttribute("pluginsContextsList");
    if (ctxList == null) {
        ctxList = new ArrayList<ClassPathXmlApplicationContext>();
        servletContext.setAttribute("pluginsContextsList", ctxList);
    }
    ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
    ClassPathXmlApplicationContext newContext = null;
    try {
        //create a new spring context with the classloader and the paths defined as parameter in pluginsInstallerContext.xml.
        //The new context is given the default webapplication context as its parent  
        Thread.currentThread().setContextClassLoader(cl);
        newContext = new ClassPathXmlApplicationContext();
        //ClassPathXmlApplicationContext newContext = new ClassPathXmlApplicationContext(configLocations, applicationContext);    
        PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer();
        configurer.setProperties(properties);
        newContext.addBeanFactoryPostProcessor(configurer);
        newContext.setClassLoader(cl);
        newContext.setParent(this._applicationContext);
        String[] configLocs = new String[] { "classpath:spring/restServerConfig.xml",
                "classpath:spring/baseSystemConfig.xml" };
        newContext.setConfigLocations(configLocs);
        newContext.refresh();
        BaseConfigManager baseConfigManager = (BaseConfigManager) ((ConfigurableWebApplicationContext) this._applicationContext)
                .getBean("BaseConfigManager");
        baseConfigManager.init();
        newContext.setConfigLocations(configLocations);
        newContext.refresh();
        newContext.setDisplayName(contextDisplayName);
        ClassPathXmlApplicationContext currentCtx = (ClassPathXmlApplicationContext) this
                .getStoredContext(contextDisplayName);
        if (currentCtx != null) {
            currentCtx.close();
            ctxList.remove(currentCtx);
        }
        ctxList.add(newContext);

    } catch (Exception e) {
        _logger.error("Unexpected error loading application context: " + e.getMessage());
        e.printStackTrace();
        throw e;
    } finally {
        Thread.currentThread().setContextClassLoader(currentClassLoader);
    }
    return newContext;
}