FileDocCategorySizeDatePackage
JspContextWrapper.javaAPI DocApache Tomcat 6.0.1412526Fri Jul 20 04:20:32 BST 2007org.apache.jasper.runtime

JspContextWrapper

public class JspContextWrapper extends javax.servlet.jsp.PageContext implements javax.servlet.jsp.el.VariableResolver
Implementation of a JSP Context Wrapper. The JSP Context Wrapper is a JspContext created and maintained by a tag handler implementation. It wraps the Invoking JSP Context, that is, the JspContext instance passed to the tag handler by the invoking page via setJspContext().
author
Kin-man Chung
author
Jan Luehe
author
Jacob Hookom

Fields Summary
private javax.servlet.jsp.PageContext
invokingJspCtxt
private transient HashMap
pageAttributes
private ArrayList
nestedVars
private ArrayList
atBeginVars
private ArrayList
atEndVars
private Map
aliases
private HashMap
originalNestedVars
Constructors Summary
public JspContextWrapper(javax.servlet.jsp.JspContext jspContext, ArrayList nestedVars, ArrayList atBeginVars, ArrayList atEndVars, Map aliases)

		this.invokingJspCtxt = (PageContext) jspContext;
		this.nestedVars = nestedVars;
		this.atBeginVars = atBeginVars;
		this.atEndVars = atEndVars;
		this.pageAttributes = new HashMap<String, Object>(16);
		this.aliases = aliases;

		if (nestedVars != null) {
			this.originalNestedVars = new HashMap<String, Object>(nestedVars.size());
		}
		syncBeginTagFile();
	
Methods Summary
private voidcopyTagToPageScope(int scope)
Copies the variables of the given scope from the virtual page scope of this JSP context wrapper to the page scope of the invoking JSP context.

param
scope variable scope (one of NESTED, AT_BEGIN, or AT_END)

		Iterator iter = null;

		switch (scope) {
		case VariableInfo.NESTED:
			if (nestedVars != null) {
				iter = nestedVars.iterator();
			}
			break;
		case VariableInfo.AT_BEGIN:
			if (atBeginVars != null) {
				iter = atBeginVars.iterator();
			}
			break;
		case VariableInfo.AT_END:
			if (atEndVars != null) {
				iter = atEndVars.iterator();
			}
			break;
		}

		while ((iter != null) && iter.hasNext()) {
			String varName = (String) iter.next();
			Object obj = getAttribute(varName);
			varName = findAlias(varName);
			if (obj != null) {
				invokingJspCtxt.setAttribute(varName, obj);
			} else {
				invokingJspCtxt.removeAttribute(varName, PAGE_SCOPE);
			}
		}
	
private java.lang.StringfindAlias(java.lang.String varName)
Checks to see if the given variable name is used as an alias, and if so, returns the variable name for which it is used as an alias.

param
varName The variable name to check
return
The variable name for which varName is used as an alias, or varName if it is not being used as an alias


		if (aliases == null)
			return varName;

		String alias = (String) aliases.get(varName);
		if (alias == null) {
			return varName;
		}
		return alias;
	
public java.lang.ObjectfindAttribute(java.lang.String name)


		if (name == null) {
			throw new NullPointerException(Localizer
					.getMessage("jsp.error.attribute.null_name"));
		}

		Object o = pageAttributes.get(name);
		if (o == null) {
			o = invokingJspCtxt.getAttribute(name, REQUEST_SCOPE);
			if (o == null) {
				if (getSession() != null) {
					o = invokingJspCtxt.getAttribute(name, SESSION_SCOPE);
				}
				if (o == null) {
					o = invokingJspCtxt.getAttribute(name, APPLICATION_SCOPE);
				}
			}
		}

		return o;
	
public voidforward(java.lang.String relativeUrlPath)

		invokingJspCtxt.forward(relativeUrlPath);
	
public java.lang.ObjectgetAttribute(java.lang.String name)


		if (name == null) {
			throw new NullPointerException(Localizer
					.getMessage("jsp.error.attribute.null_name"));
		}

		return pageAttributes.get(name);
	
public java.lang.ObjectgetAttribute(java.lang.String name, int scope)


		if (name == null) {
			throw new NullPointerException(Localizer
					.getMessage("jsp.error.attribute.null_name"));
		}

		if (scope == PAGE_SCOPE) {
			return pageAttributes.get(name);
		}

		return invokingJspCtxt.getAttribute(name, scope);
	
public java.util.EnumerationgetAttributeNamesInScope(int scope)

		if (scope == PAGE_SCOPE) {
			return new Enumerator(pageAttributes.keySet().iterator());
		}

		return invokingJspCtxt.getAttributeNamesInScope(scope);
	
public intgetAttributesScope(java.lang.String name)


		if (name == null) {
			throw new NullPointerException(Localizer
					.getMessage("jsp.error.attribute.null_name"));
		}

		if (pageAttributes.get(name) != null) {
			return PAGE_SCOPE;
		} else {
			return invokingJspCtxt.getAttributesScope(name);
		}
	
public javax.el.ELContextgetELContext()

        // instead decorate!!!
        
        return this.invokingJspCtxt.getELContext();
        
        /*
		if (this.elContext != null) {
			JspFactory jspFact = JspFactory.getDefaultFactory();
			ServletContext servletContext = this.getServletContext();
			JspApplicationContextImpl jspCtx = (JspApplicationContextImpl) jspFact
					.getJspApplicationContext(servletContext);
			this.elContext = jspCtx.createELContext(this);
		}
		return this.elContext;
        */
	
public java.lang.ExceptiongetException()

		return invokingJspCtxt.getException();
	
public javax.servlet.jsp.el.ExpressionEvaluatorgetExpressionEvaluator()

		return invokingJspCtxt.getExpressionEvaluator();
	
public javax.servlet.jsp.JspWritergetOut()

		return invokingJspCtxt.getOut();
	
public java.lang.ObjectgetPage()

		return invokingJspCtxt.getPage();
	
public javax.servlet.ServletRequestgetRequest()

		return invokingJspCtxt.getRequest();
	
public javax.servlet.ServletResponsegetResponse()

		return invokingJspCtxt.getResponse();
	
public javax.servlet.ServletConfiggetServletConfig()

		return invokingJspCtxt.getServletConfig();
	
public javax.servlet.ServletContextgetServletContext()

		return invokingJspCtxt.getServletContext();
	
public javax.servlet.http.HttpSessiongetSession()

		return invokingJspCtxt.getSession();
	
public javax.servlet.jsp.el.VariableResolvergetVariableResolver()

		return this;
	
public voidhandlePageException(java.lang.Exception ex)

		// Should never be called since handleException() called with a
		// Throwable in the generated servlet.
		handlePageException((Throwable) ex);
	
public voidhandlePageException(java.lang.Throwable t)

		invokingJspCtxt.handlePageException(t);
	
public voidinclude(java.lang.String relativeUrlPath)

		invokingJspCtxt.include(relativeUrlPath);
	
public voidinclude(java.lang.String relativeUrlPath, boolean flush)

		include(relativeUrlPath, false); // XXX
	
public voidinitialize(javax.servlet.Servlet servlet, javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, java.lang.String errorPageURL, boolean needsSession, int bufferSize, boolean autoFlush)

	
public javax.servlet.jsp.JspWriterpopBody()

		return invokingJspCtxt.popBody();
	
public javax.servlet.jsp.tagext.BodyContentpushBody()

		return invokingJspCtxt.pushBody();
	
public javax.servlet.jsp.JspWriterpushBody(java.io.Writer writer)

		return invokingJspCtxt.pushBody(writer);
	
public voidrelease()

		invokingJspCtxt.release();
	
public voidremoveAttribute(java.lang.String name)


		if (name == null) {
			throw new NullPointerException(Localizer
					.getMessage("jsp.error.attribute.null_name"));
		}

		pageAttributes.remove(name);
		invokingJspCtxt.removeAttribute(name, REQUEST_SCOPE);
		if (getSession() != null) {
			invokingJspCtxt.removeAttribute(name, SESSION_SCOPE);
		}
		invokingJspCtxt.removeAttribute(name, APPLICATION_SCOPE);
	
public voidremoveAttribute(java.lang.String name, int scope)


		if (name == null) {
			throw new NullPointerException(Localizer
					.getMessage("jsp.error.attribute.null_name"));
		}

		if (scope == PAGE_SCOPE) {
			pageAttributes.remove(name);
		} else {
			invokingJspCtxt.removeAttribute(name, scope);
		}
	
public java.lang.ObjectresolveVariable(java.lang.String pName)
VariableResolver interface

		ELContext ctx = this.getELContext();
		return ctx.getELResolver().getValue(ctx, null, pName);
	
private voidrestoreNestedVariables()
Restores the values of any NESTED variables in the invoking JSP context.

		if (nestedVars != null) {
			Iterator iter = nestedVars.iterator();
			while (iter.hasNext()) {
				String varName = (String) iter.next();
				varName = findAlias(varName);
				Object obj = originalNestedVars.get(varName);
				if (obj != null) {
					invokingJspCtxt.setAttribute(varName, obj);
				} else {
					invokingJspCtxt.removeAttribute(varName, PAGE_SCOPE);
				}
			}
		}
	
private voidsaveNestedVariables()
Saves the values of any NESTED variables that are present in the invoking JSP context, so they can later be restored.

		if (nestedVars != null) {
			Iterator iter = nestedVars.iterator();
			while (iter.hasNext()) {
				String varName = (String) iter.next();
				varName = findAlias(varName);
				Object obj = invokingJspCtxt.getAttribute(varName);
				if (obj != null) {
					originalNestedVars.put(varName, obj);
				}
			}
		}
	
public voidsetAttribute(java.lang.String name, java.lang.Object value)


		if (name == null) {
			throw new NullPointerException(Localizer
					.getMessage("jsp.error.attribute.null_name"));
		}

		if (value != null) {
			pageAttributes.put(name, value);
		} else {
			removeAttribute(name, PAGE_SCOPE);
		}
	
public voidsetAttribute(java.lang.String name, java.lang.Object value, int scope)


		if (name == null) {
			throw new NullPointerException(Localizer
					.getMessage("jsp.error.attribute.null_name"));
		}

		if (scope == PAGE_SCOPE) {
			if (value != null) {
				pageAttributes.put(name, value);
			} else {
				removeAttribute(name, PAGE_SCOPE);
			}
		} else {
			invokingJspCtxt.setAttribute(name, value, scope);
		}
	
public voidsyncBeforeInvoke()
Synchronize variables before fragment invokation

		copyTagToPageScope(VariableInfo.NESTED);
		copyTagToPageScope(VariableInfo.AT_BEGIN);
	
public voidsyncBeginTagFile()
Synchronize variables at begin of tag file

		saveNestedVariables();
	
public voidsyncEndTagFile()
Synchronize variables at end of tag file

		copyTagToPageScope(VariableInfo.AT_BEGIN);
		copyTagToPageScope(VariableInfo.AT_END);
		restoreNestedVariables();