Example usage for javax.servlet.jsp JspContext getAttributeNamesInScope

List of usage examples for javax.servlet.jsp JspContext getAttributeNamesInScope

Introduction

In this page you can find the example usage for javax.servlet.jsp JspContext getAttributeNamesInScope.

Prototype


abstract public Enumeration<String> getAttributeNamesInScope(int scope);

Source Link

Document

Enumerate all the attributes in a given scope.

Usage

From source file:org.shredzone.commons.taglib.proxy.AbstractTagProxy.java

/**
 * Gets the {@link BeanFactory} from the given {@link JspContext}. The default
 * implementation automagically finds a {@link BeanFactory} that was previously set by
 * a {@link FrameworkServlet}. The result is cached.
 *
 * @param jspContext//  w w  w .j a  v a2  s  .co  m
 *            {@link JspContext} to be used
 * @return {@link BeanFactory} found
 */
@SuppressWarnings("unchecked")
protected BeanFactory getBeanFactory(JspContext jspContext) {
    Object bfCache = jspContext.getAttribute(TAGPROXY_BEANFACTORY_CACHE, PageContext.APPLICATION_SCOPE);
    if (bfCache != null && bfCache instanceof BeanFactory) {
        return (BeanFactory) bfCache;
    }

    Enumeration<String> en = jspContext.getAttributeNamesInScope(PageContext.APPLICATION_SCOPE);
    while (en.hasMoreElements()) {
        String attribute = en.nextElement();
        if (attribute.startsWith(FrameworkServlet.SERVLET_CONTEXT_PREFIX)) {
            Object bf = jspContext.getAttribute(attribute, PageContext.APPLICATION_SCOPE);
            if (bf != null && bf instanceof BeanFactory) {
                BeanFactory bfBean = (BeanFactory) bf;
                jspContext.setAttribute(TAGPROXY_BEANFACTORY_CACHE, bfBean, PageContext.APPLICATION_SCOPE);
                return bfBean;
            }
        }
    }

    throw new IllegalStateException(
            "Could not find a BeanFactory. Use a FrameworkServlet or @BeanFactoryReference.");
}