List of usage examples for javax.servlet.jsp JspContext getAttribute
abstract public Object getAttribute(String name, int scope);
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//from w w w.j a va 2 s . com * {@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."); }