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

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

Introduction

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

Prototype

String[] getBeanDefinitionNames();

Source Link

Document

Return the names of all beans defined in this factory.

Usage

From source file:org.ws13.vaadin.osgi.dm.app.SpringApplicationServlet.java

/**
 * Get the application bean in Spring's context.
 * //from  ww  w .j  a  v a 2s. c  o m
 * @see AbstractApplicationServlet#getNewApplication(HttpServletRequest)
 */
@Override
protected Application getNewApplication(HttpServletRequest request) throws ServletException {

    WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(getServletContext());

    if (wac == null) {
        throw new ServletException("Cannot get an handle on Spring's context. Is Spring running?"
                + "Check there's an org.springframework.web.context.ContextLoaderListener configured.");
    }

    String[] beanDefinitionNames = wac.getBeanDefinitionNames();
    for (String string : beanDefinitionNames) {
        System.out.println("SpringApplicationServlet.getNewApplication() ->" + string);
    }

    Application bean = wac.getBean(name, Application.class);

    if (!(bean instanceof Application)) {

        throw new ServletException("Bean " + name + " is not of expected class Application");
    }

    return bean;
}

From source file:org.ws13.vaadin.osgi.dm.app.SpringApplicationServlet.java

/**
 * Get the application class from the bean configured in Spring's context.
 * /* w ww .  j  a  va 2 s . c o  m*/
 * @see AbstractApplicationServlet#getApplicationClass()
 */
@Override
protected Class<? extends Application> getApplicationClass() throws ClassNotFoundException {

    WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(getServletContext());

    if (wac == null) {
        throw new ClassNotFoundException("Cannot get an handle on Spring's context. Is Spring running? "
                + "Check there's an org.springframework.web.context.ContextLoaderListener configured.");
    }
    String[] beanDefinitionNames = wac.getBeanDefinitionNames();
    for (String string : beanDefinitionNames) {
        System.out.println("SpringApplicationServlet.getApplicationClass() " + string);
    }

    Application bean = wac.getBean(name, Application.class);

    if (bean == null) {

        throw new ClassNotFoundException("No application bean found under name " + name);
    }

    return bean.getClass();
}

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./*w w  w  .  j a  v a 2 s.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;
}