Example usage for org.springframework.web.context WebApplicationContext containsBean

List of usage examples for org.springframework.web.context WebApplicationContext containsBean

Introduction

In this page you can find the example usage for org.springframework.web.context WebApplicationContext containsBean.

Prototype

boolean containsBean(String name);

Source Link

Document

Does this bean factory contain a bean definition or externally registered singleton instance with the given name?

Usage

From source file:in.anjan.struts2webflow.FlowExecutorUtils.java

/**
 * {@link FlowExecutor Flow executor} must be configured in the Spring
 * web application context hierarchy./*from w  w  w  .j  a  v a2s.c  om*/
 *
 * @param flowExecutorBean {@link FlowExecutor flow executor} bean name to
 *                         be used
 * @return {@link FlowExecutor flow executor} bean
 * @throws RuntimeException in case {@link FlowExecutor flow executor} is
 *                          not configured in the Spring web application
 *                          context hierarchy.
 */
public static FlowExecutor getRequiredFlowExecutor(String flowExecutorBean) {
    // need to find the Spring web application context
    WebApplicationContext context = WebApplicationContextUtils
            .getRequiredWebApplicationContext(ServletActionContext.getServletContext());

    // have the flow executor configured?
    // if yes, get the flow execution
    // else, blame
    if (context.containsBean(flowExecutorBean))
        return context.getBean(flowExecutorBean, FlowExecutor.class);

    throw new RuntimeException("Flow executor named as '" + flowExecutorBean + "' not found!");
}

From source file:grails.util.GrailsWebUtil.java

/**
 * Looks up a GrailsApplication instance from the ServletContext.
 *
 * @param servletContext The ServletContext
 * @return A GrailsApplication or null if there isn't one
 *///from  w w w .  java2s. com
public static GrailsApplication lookupApplication(ServletContext servletContext) {
    if (servletContext == null) {
        return null;
    }

    final WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(servletContext);
    if (context == null || !context.containsBean(GrailsApplication.APPLICATION_ID)) {
        return null;
    }

    return context.getBean(GrailsApplication.APPLICATION_ID, GrailsApplication.class);
}

From source file:egovframework.rte.ptl.mvc.tags.ui.PaginationTag.java

public int doEndTag() throws JspException {

    try {// ww w .  j ava 2 s.co m

        JspWriter out = pageContext.getOut();

        PaginationManager paginationManager;

        // WebApplicationContext? id 'paginationManager' ??  Manager .
        WebApplicationContext ctx = RequestContextUtils.getWebApplicationContext(pageContext.getRequest(),
                pageContext.getServletContext());

        if (ctx.containsBean("paginationManager")) {
            paginationManager = (PaginationManager) ctx.getBean("paginationManager");
        } else {
            //bean ?  DefaultPaginationManager . ?   ?? ? ??  .
            paginationManager = new DefaultPaginationManager();
        }

        PaginationRenderer paginationRenderer = paginationManager.getRendererType(type);

        String contents = paginationRenderer.renderPagination(paginationInfo, jsFunction);

        out.println(contents);

        return EVAL_PAGE;

    } catch (IOException e) {
        throw new JspException();
    }
}

From source file:org.spring4gwt.server.SpringGwtRemoteServiceServlet.java

/**
 * Look up a spring bean with the specified name in the current web
 * application context.//  w ww  .j  a va 2s  .c  o m
 * 
 * @param name
 *            bean name
 * @return the bean
 */
protected Object getBean(String name) {
    WebApplicationContext applicationContext = WebApplicationContextUtils
            .getWebApplicationContext(getServletContext());
    if (applicationContext == null) {
        throw new IllegalStateException("No Spring web application context found");
    }
    if (!applicationContext.containsBean(name)) {
        {
            throw new IllegalArgumentException("Spring bean not found: " + name);
        }
    }
    return applicationContext.getBean(name);
}

From source file:de.knurt.ajajajava.control.ChangeLocation.java

private Location getLocation(HttpServletRequest request, WebApplicationContext context) {
    /* get the result for the given URI#locationName and
     * set home-result, if the locationName is not defined. */
    Location result;//from w w w. j a v a2s.c o  m
    String locationName = request.getParameter("hashID");
    if (locationName != null && context.containsBean(locationName)) {
        result = (Location) context.getBean(locationName);
    } else {
        LocationManager lc = (LocationManager) context.getBean("locationManager");
        result = lc.getDefaultLocation();
    }
    return result;
}

From source file:org.brutusin.rpc.RpcWebInitializer.java

public void onStartup(final ServletContext ctx) throws ServletException {
    final RpcServlet rpcServlet = registerRpcServlet(ctx);
    final WebsocketFilter websocketFilter = new WebsocketFilter();
    FilterRegistration.Dynamic dynamic = ctx.addFilter(WebsocketFilter.class.getName(), websocketFilter);
    dynamic.addMappingForUrlPatterns(null, false, RpcConfig.getInstance().getPath() + "/wskt");
    JsonCodec.getInstance().registerStringFormat(MetaDataInputStream.class, "inputstream");
    final Bean<RpcSpringContext> rpcCtxBean = new Bean<RpcSpringContext>();
    ctx.addListener(new ServletRequestListener() {

        public void requestDestroyed(ServletRequestEvent sre) {
            GlobalThreadLocal.clear();/*from   w  w w  .  j a v a  2s. c om*/
        }

        public void requestInitialized(ServletRequestEvent sre) {
            GlobalThreadLocal.set(new GlobalThreadLocal((HttpServletRequest) sre.getServletRequest(), null));
        }
    });
    ctx.addListener(new ServletContextListener() {

        public void contextInitialized(ServletContextEvent sce) {
            RpcSpringContext rpcCtx = createRpcSpringContext(ctx);
            rpcCtxBean.setValue(rpcCtx);
            rpcServlet.setRpcCtx(rpcCtx);
            initWebsocketRpcRuntime(ctx, rpcCtx);
            ctx.setAttribute(RpcSpringContext.class.getName(), rpcCtx);
        }

        public void contextDestroyed(ServletContextEvent sce) {
            LOGGER.info("Destroying RPC context");
            if (rpcCtxBean.getValue() != null) {
                rpcCtxBean.getValue().destroy();
            }
        }
    });
    ctx.addListener(new ServletContextAttributeListener() {
        public void attributeAdded(ServletContextAttributeEvent event) {
            if (event.getName().equals(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE)) {
                updateRootContext();
            }
        }

        public void attributeRemoved(ServletContextAttributeEvent event) {
            if (event.getName().equals(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE)) {
                updateRootContext();
            }
        }

        public void attributeReplaced(ServletContextAttributeEvent event) {
            if (event.getName().equals(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE)) {
                updateRootContext();
            }
        }

        private void updateRootContext() {
            WebApplicationContext rootCtx = WebApplicationContextUtils.getWebApplicationContext(ctx);
            if (rootCtx != null) {
                if (rpcCtxBean.getValue() != null) {
                    rpcCtxBean.getValue().setParent(rootCtx);
                }
                if (rootCtx.containsBean("springSecurityFilterChain")) {
                    LOGGER.info("Moving WebsocketFilter behind springSecurityFilterChain");
                    websocketFilter.disable();
                    FilterChainProxy fcp = (FilterChainProxy) rootCtx.getBean("springSecurityFilterChain");
                    fcp.getFilterChains().get(0).getFilters().add(new WebsocketFilter());
                }
            }
        }
    });
}

From source file:org.hdiv.filter.ValidatorFilter.java

/**
 * Init required dependencies/*w ww.j av  a2  s.  co m*/
 */
protected void initDependencies() {

    if (this.hdivConfig == null) {
        ServletContext servletContext = getServletContext();
        WebApplicationContext context = WebApplicationContextUtils
                .getRequiredWebApplicationContext(servletContext);

        this.hdivConfig = (HDIVConfig) context.getBean("config");
        this.validationHelper = (IValidationHelper) context.getBean("validatorHelper");
        if (context.containsBean("multipartConfig")) {
            // For applications without Multipart requests
            this.multipartConfig = (IMultipartConfig) context.getBean("multipartConfig");
        }

        this.errorHandler = (ValidatorErrorHandler) context.getBean("validatorErrorHandler");
    }

}

From source file:org.zkoss.zk.grails.web.ZULUrlMappingsFilter.java

@Override
protected void initFilterBean() throws ServletException {
    super.initFilterBean();
    urlHelper.setUrlDecode(false);//from w  w w .  j  a  v  a2  s .  c o m
    final ServletContext servletContext = getServletContext();
    final WebApplicationContext applicationContext = WebApplicationContextUtils
            .getRequiredWebApplicationContext(servletContext);
    handlerInterceptors = WebUtils.lookupHandlerInterceptors(servletContext);
    application = WebUtils.lookupApplication(servletContext);
    viewResolver = WebUtils.lookupViewResolver(servletContext);
    ApplicationContext mainContext = application.getMainContext();
    urlConverter = mainContext.getBean(UrlConverter.BEAN_NAME, UrlConverter.class);
    if (application != null) {
        grailsConfig = new GrailsConfig(application);
    }

    if (applicationContext.containsBean(MimeType.BEAN_NAME)) {
        this.mimeTypes = applicationContext.getBean(MimeType.BEAN_NAME, MimeType[].class);
    }

    composerMapping = applicationContext.getBean(ComposerMapping.BEAN_NAME, ComposerMapping.class);

    createStackTraceFilterer();
}

From source file:com.webapp.tags.MainNav.java

/**
 * Retrieve the instance of the WebApp which is configured with components, 
 * as opposed to using static members./*from w w  w  .  j  av  a 2s.c  o m*/
 * 
 * <p>This will have the currently set list of features and menu locations 
 * for this application instance.</p>
 * 
 * @return The currently configured system description with all the features specified.
 */
private WebApp getSystemDescription() {

    if (webapp == null) {
        WebApplicationContext applicationContext = WebApplicationContextUtils
                .getWebApplicationContext(((PageContext) getJspContext()).getServletContext());

        if (applicationContext != null) {
            String[] names = applicationContext.getBeanDefinitionNames();
            if (names.length > 0) {
                for (int x = 0; x < names.length; x++) {
                    LOG.trace("BEAN: " + names[x]);
                }
            } else {
                LOG.error("There are NO BEAN NAMES!");
            }
        } else {
            LOG.error("There is no application context available to the custom tags!");
        }

        if (applicationContext != null && applicationContext.containsBean(WebApp.SYSTEM_DESCRIPTION)) {
            webapp = (WebApp) applicationContext.getBean(WebApp.SYSTEM_DESCRIPTION);
        }
        if (webapp == null) {
            LOG.warn("Could not get system description...creating one");
            webapp = new WebApp();
        }
    }

    return webapp;
}

From source file:org.alfresco.web.bean.wcm.AVMUtil.java

public static String getPreviewURI(String storeId, String assetPath) {
    if (!deprecatedPreviewURIGeneratorChecked) {
        if (deprecatedPreviewURIGenerator == null) {
            // backwards compatibility - will hide new implementation, until custom providers/context are migrated
            WebApplicationContext wac = FacesContextUtils
                    .getRequiredWebApplicationContext(FacesContext.getCurrentInstance());

            if (wac.containsBean(SPRING_BEAN_NAME_PREVIEW_URI_SERVICE)) {
                // if the bean is present retrieve it
                deprecatedPreviewURIGenerator = (PreviewURIService) wac
                        .getBean(SPRING_BEAN_NAME_PREVIEW_URI_SERVICE, PreviewURIService.class);

                logger.warn("Found deprecated '" + SPRING_BEAN_NAME_PREVIEW_URI_SERVICE
                        + "' config - which will be used instead of new 'WCMPreviewURIService' until migrated (changing web project preview provider will have no effect)");
            }/*  ww w  .j a v  a  2  s  .  co  m*/
        }

        deprecatedPreviewURIGeneratorChecked = true;
    }

    if (deprecatedPreviewURIGenerator != null) {
        return deprecatedPreviewURIGenerator.getPreviewURI(storeId, assetPath);
    }

    return getPreviewURIService().getPreviewURI(storeId, assetPath);
}