Example usage for org.springframework.web.context ConfigurableWebApplicationContext setNamespace

List of usage examples for org.springframework.web.context ConfigurableWebApplicationContext setNamespace

Introduction

In this page you can find the example usage for org.springframework.web.context ConfigurableWebApplicationContext setNamespace.

Prototype

void setNamespace(@Nullable String namespace);

Source Link

Document

Set the namespace for this web application context, to be used for building a default context config location.

Usage

From source file:nz.co.senanque.vaadinsupport.application.SpringApplicationLoader.java

public static ApplicationContext loadContext(Application application, HttpServletRequest request) {

    // Logging/*from   w  w w  . j a v  a2  s.  c o m*/
    log.info("loading application context for Vaadin application " + application.getClass().getSimpleName());
    CURRENT_APPLICATION.set(application);

    // Find the application context associated with the servlet; it will be the parent
    ServletContext servletContext;
    try {
        // getServletContext() is a servlet AIP 3.0 method, so don't freak out if it's not there
        servletContext = (ServletContext) HttpServletRequest.class.getMethod("getServletContext")
                .invoke(request);
    } catch (Exception e) {
        servletContext = ContextLoader.getCurrentWebApplicationContext().getServletContext();
    }
    WebApplicationContext parent = WebApplicationContextUtils.getWebApplicationContext(servletContext);

    // Create and configure a new application context for this Application instance
    ConfigurableWebApplicationContext context = new XmlWebApplicationContext();
    context.setId(
            ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX + servletContext.getContextPath()
                    + "/" + application.getClass().getSimpleName() + "-" + UNIQUE_INDEX.incrementAndGet());
    context.setParent(parent);
    context.setServletContext(servletContext);
    //context.setServletConfig(??);
    context.setNamespace(application.getClass().getSimpleName());

    // Refresh context
    context.refresh();

    CURRENT_APPLICATION.set(null);
    return context;
}

From source file:com.workingmouse.webservice.axis.SpringAxisServlet.java

/**
 * Instantiate the WebApplicationContext for the SpringAxisServlet, either a default
 * XmlWebApplicationContext or a custom context class if set. This implementation
 * expects custom contexts to implement ConfigurableWebApplicationContext.
 * Can be overridden in subclasses./*w  w w  .  ja va  2  s.  c  o  m*/
 *
 * @throws org.springframework.beans.BeansException
 *      if the context couldn't be initialized
 *
 * @see #setContextClass
 *
 * @see org.springframework.web.context.support.XmlWebApplicationContext
 */
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent)
        throws BeansException {

    if (LOG.isDebugEnabled()) {
        LOG.debug("Servlet with name '" + getServletName()
                + "' will try to create custom WebApplicationContext context of class '"
                + getContextClass().getName() + "'" + " using parent context [" + parent + "]");
    }
    if (!ConfigurableWebApplicationContext.class.isAssignableFrom(getContextClass())) {
        throw new ApplicationContextException("Fatal initialization error in servlet with name '"
                + getServletName() + "': custom WebApplicationContext class [" + getContextClass().getName()
                + "] is not of type ConfigurableWebApplicationContext");
    }

    ConfigurableWebApplicationContext wac = createContextInstance();
    wac.setParent(parent);
    wac.setServletContext(getServletContext());
    wac.setNamespace(getNamespace());

    if (this.contextConfigLocation != null) {
        wac.setConfigLocations(StringUtils.tokenizeToStringArray(this.contextConfigLocation,
                ConfigurableWebApplicationContext.CONFIG_LOCATION_DELIMITERS, true, true));
    }
    wac.refresh();
    return wac;
}

From source file:org.sarons.spring4me.web.filter.PageFilter.java

protected ConfigurableWebApplicationContext initPageApplicationContext() {
    WebApplicationContext root = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
    ////w  w w.  j  av a  2s . co  m
    ConfigurableWebApplicationContext wac = (ConfigurableWebApplicationContext) BeanUtils
            .instantiateClass(contextClass);
    wac.setParent(root);
    wac.setServletContext(getServletContext());
    wac.setServletConfig(new DelegatingServletConfig(getServletContext()));
    wac.setNamespace(getNamespace());
    wac.setConfigLocation(getWidgetConfigLocation());
    wac.refresh();
    //
    return wac;
}

From source file:org.pentaho.platform.web.servlet.JAXRSServlet.java

protected ApplicationContext getAppContext() {

    ConfigurableWebApplicationContext wac = new XmlWebApplicationContext() {
        @Override/*from w  w  w. ja  va  2s. c o  m*/
        protected Resource getResourceByPath(String path) {
            return new FileSystemResource(new File(path));
        }
    };

    wac.setServletContext(getServletContext());
    wac.setServletConfig(getServletConfig());
    wac.setNamespace(getServletName());
    String springFile = PentahoSystem.getApplicationContext()
            .getSolutionPath("system" + File.separator + "pentahoServices.spring.xml"); //$NON-NLS-1$ //$NON-NLS-2$
    wac.setConfigLocations(new String[] { springFile });
    wac.refresh();

    return wac;
}

From source file:org.springframework.web.struts.ContextLoaderPlugIn.java

/**
 * Instantiate the WebApplicationContext for the ActionServlet, either a default
 * XmlWebApplicationContext or a custom context class if set. This implementation
 * expects custom contexts to implement ConfigurableWebApplicationContext.
 * Can be overridden in subclasses./*from w  w  w  . jav a  2s.  c om*/
 * @throws org.springframework.beans.BeansException if the context couldn't be initialized
 * @see #setContextClass
 * @see org.springframework.web.context.support.XmlWebApplicationContext
 */
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent)
        throws BeansException {

    if (logger.isDebugEnabled()) {
        logger.debug("ContextLoaderPlugIn for Struts ActionServlet '" + getServletName() + "', module '"
                + getModulePrefix() + "' will try to create custom WebApplicationContext "
                + "context of class '" + getContextClass().getName() + "', using parent context [" + parent
                + "]");
    }
    if (!ConfigurableWebApplicationContext.class.isAssignableFrom(getContextClass())) {
        throw new ApplicationContextException(
                "Fatal initialization error in ContextLoaderPlugIn for Struts ActionServlet '"
                        + getServletName() + "', module '" + getModulePrefix()
                        + "': custom WebApplicationContext class [" + getContextClass().getName()
                        + "] is not of type ConfigurableWebApplicationContext");
    }

    ConfigurableWebApplicationContext wac = (ConfigurableWebApplicationContext) BeanUtils
            .instantiateClass(getContextClass());
    wac.setParent(parent);
    wac.setServletContext(getServletContext());
    wac.setNamespace(getNamespace());
    if (getContextConfigLocation() != null) {
        wac.setConfigLocations(StringUtils.tokenizeToStringArray(getContextConfigLocation(),
                ConfigurableWebApplicationContext.CONFIG_LOCATION_DELIMITERS));
    }
    wac.addBeanFactoryPostProcessor(new BeanFactoryPostProcessor() {
        public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
            beanFactory.addBeanPostProcessor(new ActionServletAwareProcessor(getActionServlet()));
        }
    });
    wac.refresh();
    return wac;
}